forked from ClickerMonkey/SemanticUI-Angular
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sm-menu.js
71 lines (63 loc) · 2.15 KB
/
sm-menu.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
(function(app)
{
app
.controller('SemanticMenuController', ['$scope', SemanticMenuController])
.directive('smMenu', ['SemanticUI', SemanticMenu])
;
function SemanticMenu(SemanticUI)
{
return {
restrict: 'E',
replace: true,
scope: {
/* Required */
items: '=',
label: '&',
/* Optional */
onClick: '&',
children: '&',
description: '&',
icon: '&',
hidden: '&',
divider: '&'
},
template: [
'<div class="menu">',
'<div ng-repeat="i in items" ng-hide="isHidden( i )" ng-class="{item: !isDivider( i ), divider: isDivider( i )}" ng-click="onClick({item: i, $event:$event})">',
'<i class="{{ getIcon( i ) }} icon" ng-if="getIcon( i )"></i>',
'<span class="description" ng-if="getDescription( i )">{{ getDescription( i ) }}</span>',
'{{ getLabel( i ) }}',
'<sm-menu ng-if="hasChildren( i )" items="getChildren( i )" label="getLabel( item )" children="getChildren( item )" description="getDescription( item )" icon="getIcon( item )" hidden="isHidden( item )" divider="isDivider( item )" on-click="onClick({item: item, $event: $event})"></sm-menu>',
'</div>',
'</div>'
].join('\n'),
controller: 'SemanticMenuController',
compile: SemanticUI.RecursiveCompiler()
};
}
function SemanticMenuController($scope)
{
$scope.hasChildren = function(item) {
var children = $scope.children({item: item});
return children && children.length;
};
$scope.getChildren = function(item) {
return $scope.children({item: item});
};
$scope.getLabel = function(item) {
return $scope.label({item: item});
};
$scope.getIcon = function(item) {
return $scope.icon({item: item});
}
$scope.getDescription = function(item) {
return $scope.description({item: item});
};
$scope.isHidden = function(item) {
return $scope.hidden({item: item});
};
$scope.isDivider = function(item) {
return $scope.divider({item: item});
};
}
})( angular.module('semantic-ui-menu', ['semantic-ui-core']) );