11'use strict' ;
22
33angular . module ( 'angularify.semantic.sidebar' , [ ] )
4-
5- . controller ( 'SideBarController' , [ '$scope' , function ( $scope ) {
6- $scope . side_bar_items = [ ] ;
7-
8- this . add_sidebar_items = function ( scope ) {
9- $scope . side_bar_items . push ( scope ) ;
10-
11- scope . $on ( '$destroy' , function ( event ) {
12- this . remove_side_bar_item ( scope ) ;
13- } ) ;
14-
15- return $scope . side_bar_items ;
16- }
17-
18- this . remove_side_bar_item = function ( scope ) {
19- var index = $scope . side_bar_items . indexOf ( scope ) ;
20- if ( index !== - 1 )
21- $scope . side_bar_items . splice ( index , 1 ) ;
22- }
23-
24- this . disactivate_all_items = function ( ) {
25- var i = 0 ;
26- for ( i in $scope . side_bar_items ) {
27- $scope . side_bar_items [ i ] . item_class = 'item' ;
28- }
29- }
30-
31- } ] )
32-
334. directive ( 'sidebar' , function ( ) {
345 return {
356 restrict : "E" ,
367 replace : true ,
378 transclude : true ,
38- controller : 'SideBarController ' ,
9+ template : '<div class="ui sidebar" ng-transclude></div> ' ,
3910 scope : {
40- model : '=ngModel '
11+ buttonClass : '='
4112 } ,
42- template : '<div class="{{sidebar_class}}" ng-transclude></div>' ,
43- link : function ( scope , element , attrs , SideBarController ) {
44- scope . sidebar_class = 'ui red vertical demo sidebar menu' ;
45-
46- if ( scope . model !== true )
47- scope . model = false ;
48-
49- scope . $watch ( 'model' , function ( val ) {
50- if ( val == true )
51- scope . sidebar_class = 'ui red vertical demo sidebar menu active' ;
52- else
53- scope . sidebar_class = 'ui red vertical demo sidebar menu' ;
54- } ) ;
55- }
56- }
57- } )
58-
59- . directive ( 'sidebarItem' , function ( ) {
60- return {
61- restrict : "E" ,
62- replace : true ,
63- transclude : true ,
64- require :'^sidebar' ,
65- scope : {
66- title : "@" ,
67- icon : "@" ,
68- href : "@"
69- } ,
70- template : '<a class="{{item_class}}"><i class="{{icon_class}}"></i>{{title}}</a>' ,
71- link : function ( scope , element , attrs , SideBarController ) {
72- //if (scope.href == 'undefined')
73- // scope.href = '/#';
74-
75- // set up item class
76- scope . item_class = 'item' ;
77-
78- //
79- // Set up icon
80- //
81- if ( scope . icon == undefined )
82- scope . icon_class = 'home icon' ;
83- else
84- scope . icon_class = scope . icon + ' icon' ;
85-
86- // add new sidebar item
87- SideBarController . add_sidebar_items ( scope ) ;
88-
89- //
90- // Handle click
91- //
92- element . bind ( 'click' , function ( ) {
93- // make all item innactive
94- SideBarController . disactivate_all_items ( ) ;
95- // set up active item
96- scope . $apply ( function ( ) { scope . item_class = 'active item' } ) ;
97- } ) ;
13+ link : function ( scope , element , attrs ) {
14+ debugger ;
15+ element . sidebar ( 'attach events' , scope . buttonClass ) ;
9816 }
9917 }
100- } )
18+ } ) ;
0 commit comments