forked from ClickerMonkey/SemanticUI-Angular
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sm-dimmer.js
100 lines (80 loc) · 2.29 KB
/
sm-dimmer.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
89
90
91
92
93
94
95
96
97
98
99
100
(function(app)
{
app
.factory('SemanticDimmerLink', ['SemanticUI', SemanticDimmerLink])
.directive('smDimmerBind', ['SemanticUI', SemanticDimmerBind])
.directive('smDimmer', ['SemanticDimmerLink', SemanticDimmer])
;
var BEHAVIORS = {
smDimmerShow: 'show',
smDimmerHide: 'hide',
smDimmerToggle: 'toggle'
};
angular.forEach( BEHAVIORS, function(method, directive)
{
app.directive( directive, ['SemanticUI', function(SemanticUI)
{
return SemanticUI.createBehavior( directive, 'dimmer', method );
}]);
});
function SemanticDimmerBind(SemanticUI)
{
return SemanticUI.createBind( 'smDimmerBind', 'dimmer' );
}
function SemanticDimmer(SemanticDimmerLink)
{
return {
restrict: 'E',
replace: true,
transclude: true,
scope: {
/* Optional */
visible: '=',
settings: '=',
onInit: '=',
/* Events */
onShow: '=',
onHide: '=',
onChange: '='
},
template: '<div class="ui dimmer" ng-transclude></div>',
link: SemanticDimmerLink
};
}
function SemanticDimmerLink(SemanticUI)
{
return function(scope, element, attributes)
{
var settings = scope.settings || {};
SemanticUI.linkSettings( scope, element, attributes, 'dimmer' );
// If the visible attribute is specified, listen to onHide and update modal when variable changes.
if ( attributes.visible )
{
var visibleWatcher = SemanticUI.watcher( scope, 'visible',
function(updated) {
element.dimmer( updated ? 'show' : 'hide' );
}
);
SemanticUI.onEvent( settings, 'onShow',
function(value) {
visibleWatcher.set( true );
}
);
SemanticUI.onEvent( settings, 'onHide',
function(value) {
visibleWatcher.set( false );
}
);
}
SemanticUI.linkEvents( scope, settings, $.fn.dimmer.settings, {
onShow: 'onShow',
onHide: 'onHide',
onChange: 'onChange'
});
element.dimmer( settings );
if ( angular.isFunction( scope.onInit ) ) {
scope.onInit( element );
}
};
}
})( angular.module('semantic-ui-dimmer', ['semantic-ui-core']) );