-
Notifications
You must be signed in to change notification settings - Fork 28
/
sm-sidebar.js
129 lines (106 loc) · 3.04 KB
/
sm-sidebar.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
(function(app)
{
app
.factory('SemanticSidebarLink', ['SemanticUI', SemanticSidebarLink])
.directive('smSidebarBind', ['SemanticUI', SemanticSidebarBind])
.directive('smSidebar', ['SemanticSidebarLink', SemanticSidebar])
;
var BEHAVIORS = {
smSidebarShow: 'show',
smSidebarHide: 'hide',
smSidebarToggle: 'toggle',
smSidebarPushPage: 'push page',
smSidebarPullPage: 'pull page',
smSidebarAddBodyCss: 'add body css',
smSidebarRemoveBodyCss: 'remove body css'
};
angular.forEach( BEHAVIORS, function(method, directive)
{
app.directive( directive, ['SemanticUI', function(SemanticUI)
{
return SemanticUI.createBehavior( directive, 'sidebar', method );
}]);
});
function SemanticSidebarBind(SemanticUI)
{
return SemanticUI.createBind( 'smSidebarBind', 'sidebar' );
}
function SemanticSidebar(SemanticSidebarLink)
{
return {
restrict: 'E',
replace: true,
scope: {
/* Required */
items: '=',
label: '&',
/* Optional */
onClick: '&',
visible: '=',
settings: '=',
onInit: '=',
/* Events */
onVisible: '=',
onShow: '=',
onChange: '=',
onHide: '=',
onHidden: '='
},
template: [
'<div class="ui sidebar">',
' <a class="item" ng-repeat="i in items" sm-html="label({item:i})" ng-click="onClick({item:i, $event:$event})"></a>',
'</div>'
].join('\n'),
link: SemanticSidebarLink
};
}
function SemanticSidebarLink(SemanticUI)
{
return function(scope, element, attributes)
{
var settings = scope.settings || {};
SemanticUI.setDefaultFunction( scope, 'label', attributes, function(locals){return locals.item} );
SemanticUI.linkSettings( scope, element, attributes, 'sidebar' );
if ( attributes.visible )
{
var visibleWatcher = SemanticUI.watcher( scope, 'visible',
function(updated) {
element.sidebar( updated ? 'show' : 'hide' );
}
);
SemanticUI.onEvent( settings, 'onHide',
function() {
visibleWatcher.set( false );
}
);
SemanticUI.onEvent( settings, 'onShow',
function() {
visibleWatcher.set( true );
}
);
}
SemanticUI.linkEvents( scope, settings, $.fn.sidebar.settings, {
onVisible: 'onVisible',
onShow: 'onShow',
onChange: 'onChange',
onHide: 'onHide',
onHidden: 'onHidden'
});
var pusher = $('.pusher');
if ( pusher.length )
{
element.insertBefore( pusher );
}
// Initialize the element with the given settings.
element.sidebar( settings );
if ( scope.visible )
{
element.sidebar( 'show' );
}
if ( angular.isFunction( scope.onInit ) )
{
scope.onInit( element );
}
};
}
})( angular.module('semantic-ui-sidebar', ['semantic-ui-core']) );