-
Notifications
You must be signed in to change notification settings - Fork 28
/
sm-accordion.js
110 lines (92 loc) · 2.54 KB
/
sm-accordion.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
(function(app)
{
app
.factory('SemanticAccordionLink', ['SemanticUI', SemanticAccordionLink])
.directive('smAccordionBind', ['SemanticUI', SemanticAccordionBind])
.directive('smAccordion', ['SemanticAccordionLink', SemanticAccordion])
.directive('smAccordionGroup', SemanticAccordionGroup)
;
var BEHAVIORS = {
smAccordionOpen: 'open',
smAccordionCloseOthers: 'close others',
smAccordionClose: 'close',
smAccordionToggle: 'toggle'
};
angular.forEach( BEHAVIORS, function(method, directive)
{
app.directive( directive, ['SemanticUI', function(SemanticUI)
{
return SemanticUI.createBehavior( directive, 'accordion', method );
}]);
});
function SemanticAccordionBind(SemanticUI)
{
return SemanticUI.createBind( 'smAccordionBind', 'accordion' );
}
function SemanticAccordion(SemanticAccordionLink)
{
return {
restrict: 'E',
replace: true,
transclude: true,
scope: {
/* Optional */
settings: '=',
onInit: '=',
/* Events */
onOpening: '=',
onOpen: '=',
onClosing: '=',
onClose: '=',
onChange: '='
},
template: '<div class="ui accordion" ng-transclude></div>',
link: SemanticAccordionLink
};
}
function SemanticAccordionLink(SemanticUI)
{
return function(scope, element, attributes)
{
element.ready(function()
{
var settings = scope.settings || {};
SemanticUI.linkSettings( scope, element, attributes, 'accordion', true );
SemanticUI.linkEvents( scope, settings, $.fn.accordion.settings, {
onOpening: 'onOpening',
onOpen: 'onOpen',
onClosing: 'onClosing',
onClose: 'onClose',
onChange: 'onChange'
});
element.accordion( settings );
if ( angular.isFunction( scope.onInit ) )
{
scope.onInit( element );
}
});
};
}
function SemanticAccordionGroup()
{
return {
restrict: 'E',
required: 'title',
transclude: true,
scope: {
/* Required */
title: '=',
/* Optional */
active: '='
},
template: [
'<div class="title" ng-class="{active: active}">',
' <i class="dropdown icon"></i>',
' {{ title }}',
'</div>',
'<div class="content" ng-class="{active: active}" ng-transclude>',
'</div>'
].join('\n')
}
}
})( angular.module('semantic-ui-accordion', ['semantic-ui-core']) );