-
Notifications
You must be signed in to change notification settings - Fork 0
/
st-blurred-dialog.js
88 lines (82 loc) · 2.28 KB
/
st-blurred-dialog.js
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
angular.module("stBlurredDialog",[])
.constant('stBlurredDialogClasses',{
blurredRegion: 'st-blurred-region'
})
.factory('stBlurredDialog', ['$timeout', function($timeout){
var state = {
subscribers: [],
isOpen: false,
dialogData: null
};
return {
open: function(pathToTemplate, data){
$timeout(function(){
state.dialogData = data;
state.isOpen = true;
angular.forEach(state.subscribers, function(subscriberCb){
subscriberCb(state.isOpen, pathToTemplate);
});
});
},
close: function(){
$timeout(function(){
state.isOpen = false;
angular.forEach(state.subscribers, function(subscriberCb){
subscriberCb(state.isOpen);
});
});
},
isOpen: function(){
return state.isOpen;
},
getDialogData: function(){
return state.dialogData;
},
subscribe: function(cb){
state.subscribers.push(cb);
}
}
}])
// This directive is used to blur the page
.directive('stBlurredDialogRegion', [function(){
return {
restrict: "A",
scope: {},
controller: ['$scope', 'stBlurredDialog', '$element', 'stBlurredDialogClasses', function($scope, stBlurredDialog, $element, stBlurredDialogClasses){
stBlurredDialog.subscribe(function(isOpen, path, data){
if(isOpen){
$element.addClass(stBlurredDialogClasses.blurredRegion);
}
else{
$element.removeClass(stBlurredDialogClasses.blurredRegion);
}
});
}],
link: function(scope, element, attrs){
}
}
}])
// This directive is used to show the modal dialog
.directive('stBlurredDialogOverlay', [function(){
return {
restrict: 'E',
replace: true,
template: "<div ng-if='model.isOpen' class='st-blurred-region-overlay'><div ng-include src='model.pathToTemplate'></div></div>",
controller: ['$scope', 'stBlurredDialog', '$element', function($scope, stBlurredDialog, $element){
$scope.model = {
// We need to bind to the state of the service to check for state changes
isOpen: false,
pathToTemplate: null
};
stBlurredDialog.subscribe(function(isOpen, path){
$scope.model.isOpen = isOpen;
$scope.model.pathToTemplate = path;
});
$scope.close = function(){
stBlurredDialog.close();
}
}],
link: function(scope, element, attrs){
}
}
}]);