-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathangular-popup-window.js
More file actions
56 lines (47 loc) · 1.51 KB
/
angular-popup-window.js
File metadata and controls
56 lines (47 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
(function() {
'use strict';
angular.module('popup', [])
/**
* @ngdoc service
* @name popup.service.PopUp
* @module popup
* @description
* Opens/manages browser pop-up windows.
*/
.service('PopUp', ['$log', '$window', '$q', '$interval',
function($log, $window, $q, $interval) {
/**
* @ngdoc method
* @name popup.service.PopUp#open
* @description
* Opens a new window and returns a promise that will resolve when the
* window is closed.
*
* @param {string} url to point the window to.
* @param {string} name of the window.
* @param {string} options to apply to the window (likely height/width).
*/
this.open = function(url, name, options) {
$log.debug('PopUp', 'opening', url, name, options);
var d = $q.defer();
var optionsPieces = [];
angular.forEach(options, function(val, key) {
optionsPieces.push(key + '=' + val);
});
// open the window
var win = $window.open(url, name, optionsPieces.join(','));
// setup an interval to watch the window for manual dismiss.
var watcher = $interval(function() {
if (win.closed || !win.window) {
$log.debug('PopUp', 'closed');
d.resolve();
$interval.cancel(watcher);
}
}, 100, 0, false);
// ship back the promise so that the caller can know when the
// window closes
return d.promise;
};
}
]);
})();