1
1
angular . module ( 'ui.scroll.grid' , [ ] )
2
- . directive ( 'uiScrollTh' , [ '$log' , '$timeout' , function ( console , $timeout ) {
2
+ . directive ( 'uiScrollTh' , [ '$log' , '$timeout' , function ( console , $timeout ) {
3
3
4
4
function GridAdapter ( controller ) {
5
5
@@ -9,12 +9,12 @@ angular.module('ui.scroll.grid', [])
9
9
10
10
this . columnFromPoint = ( x , y ) => controller . columnFromPoint ( x , y ) ;
11
11
12
- Object . defineProperty ( this , 'columns' , { get : ( ) => controller . getColumns ( ) } ) ;
12
+ Object . defineProperty ( this , 'columns' , { get : ( ) => controller . getColumns ( ) } ) ;
13
13
}
14
14
15
15
function ColumnAdapter ( controller , column ) {
16
16
17
- this . css = function ( /* attr, value */ ) {
17
+ this . css = function ( /* attr, value */ ) {
18
18
var attr = arguments [ 0 ] ;
19
19
var value = arguments [ 1 ] ;
20
20
if ( arguments . length == 1 ) {
@@ -31,7 +31,7 @@ angular.module('ui.scroll.grid', [])
31
31
32
32
this . exchangeWith = ( index ) => controller . exchangeWith ( column , index ) ;
33
33
34
- Object . defineProperty ( this , 'columnId' , { get : ( ) => column . id } ) ;
34
+ Object . defineProperty ( this , 'columnId' , { get : ( ) => column . id } ) ;
35
35
}
36
36
37
37
function ColumnController ( controller , columns , header ) {
@@ -43,13 +43,13 @@ angular.module('ui.scroll.grid', [])
43
43
44
44
// controller api methods
45
45
46
- this . applyLayout = function ( layout ) {
46
+ this . applyLayout = function ( layout ) {
47
47
this . css = angular . extend ( { } , layout . css ) ;
48
48
this . mapTo = layout . mapTo ;
49
49
applyCss ( this . header , this . css ) ;
50
50
} ;
51
51
52
- this . moveBefore = function ( target ) {
52
+ this . moveBefore = function ( target ) {
53
53
if ( target ) {
54
54
moveBefore ( header , target . header ) ;
55
55
controller . forEachRow ( ( row ) => moveBefore ( row [ this . id ] , row [ target . id ] ) ) ;
@@ -59,7 +59,7 @@ angular.module('ui.scroll.grid', [])
59
59
}
60
60
} ;
61
61
62
- this . columnFromPoint = function ( x , y ) {
62
+ this . columnFromPoint = function ( x , y ) {
63
63
if ( insidePoint ( header , x , y ) ) {
64
64
return this ;
65
65
}
@@ -70,7 +70,7 @@ angular.module('ui.scroll.grid', [])
70
70
return result ;
71
71
} ;
72
72
73
- this . applyCss = function ( target ) {
73
+ this . applyCss = function ( target ) {
74
74
applyCss ( target , this . css ) ;
75
75
} ;
76
76
@@ -116,11 +116,11 @@ angular.module('ui.scroll.grid', [])
116
116
scrollViewport . adapter . transform = ( scope , item ) => transform ( rowMap . get ( scope ) , item ) ;
117
117
} ) ;
118
118
119
- this . registerColumn = function ( header ) {
119
+ this . registerColumn = function ( header ) {
120
120
columns . push ( new ColumnController ( this , columns , header ) ) ;
121
121
} ;
122
122
123
- this . registerCell = function ( scope , cell ) {
123
+ this . registerCell = function ( scope , cell ) {
124
124
let row = rowMap . get ( scope ) ;
125
125
if ( ! row ) {
126
126
row = [ ] ;
@@ -133,7 +133,7 @@ angular.module('ui.scroll.grid', [])
133
133
return true ;
134
134
} ;
135
135
136
- this . unregisterCell = function ( scope , cell ) {
136
+ this . unregisterCell = function ( scope , cell ) {
137
137
let row = rowMap . get ( scope ) ;
138
138
let i = row . indexOf ( cell ) ;
139
139
row . splice ( i , 1 ) ;
@@ -142,30 +142,29 @@ angular.module('ui.scroll.grid', [])
142
142
}
143
143
} ;
144
144
145
- this . forEachRow = function ( callback ) {
145
+ this . forEachRow = function ( callback ) {
146
146
rowMap . forEach ( callback ) ;
147
147
} ;
148
148
149
- this . getColumns = function ( ) {
149
+ this . getColumns = function ( ) {
150
150
let result = [ ] ;
151
151
columns . slice ( )
152
152
. sort ( ( a , b ) => a . mapTo - b . mapTo )
153
153
. forEach ( ( column ) => result . push ( new ColumnAdapter ( this , column ) ) ) ;
154
154
return result ;
155
155
} ;
156
156
157
- this . getLayout = function ( ) {
157
+ this . getLayout = function ( ) {
158
158
let result = [ ] ;
159
159
columns . forEach ( ( column , index ) => result . push ( {
160
- index : index ,
161
- css : angular . extend ( { } , column . css ) ,
162
- mapTo : column . mapTo
163
- } )
164
- ) ;
160
+ index : index ,
161
+ css : angular . extend ( { } , column . css ) ,
162
+ mapTo : column . mapTo
163
+ } ) ) ;
165
164
return result ;
166
165
} ;
167
166
168
- this . applyLayout = function ( layouts ) {
167
+ this . applyLayout = function ( layouts ) {
169
168
if ( ! layouts || layouts . length != columns . length ) {
170
169
throw new Error ( 'Failed to apply layout - number of layouts should match number of columns' ) ;
171
170
}
@@ -174,7 +173,7 @@ angular.module('ui.scroll.grid', [])
174
173
rowMap . forEach ( ( row ) => transform ( row ) ) ;
175
174
} ;
176
175
177
- this . moveBefore = function ( selected , target ) {
176
+ this . moveBefore = function ( selected , target ) {
178
177
let index = target ;
179
178
180
179
if ( target % 1 !== 0 ) {
@@ -184,7 +183,8 @@ angular.module('ui.scroll.grid', [])
184
183
return ; // throw an error?
185
184
}
186
185
187
- let mapTo = selected . mapTo , next = null ;
186
+ let mapTo = selected . mapTo ,
187
+ next = null ;
188
188
index -= mapTo < index ? 1 : 0 ;
189
189
190
190
columns . forEach ( c => {
@@ -197,15 +197,15 @@ angular.module('ui.scroll.grid', [])
197
197
selected . moveBefore ( next ) ;
198
198
} ;
199
199
200
- this . exchangeWith = function ( selected , index ) {
200
+ this . exchangeWith = function ( selected , index ) {
201
201
if ( index < 0 || index >= columns . length ) {
202
202
return ;
203
203
}
204
204
columns . find ( c => c . mapTo === index ) . mapTo = selected . mapTo ;
205
205
selected . mapTo = index ;
206
206
} ;
207
207
208
- this . columnFromPoint = function ( x , y ) {
208
+ this . columnFromPoint = function ( x , y ) {
209
209
let column = columns . find ( col => col . columnFromPoint ( x , y ) ) ;
210
210
return column ? new ColumnAdapter ( this , column ) : undefined ;
211
211
} ;
@@ -237,17 +237,31 @@ angular.module('ui.scroll.grid', [])
237
237
} ;
238
238
} ] )
239
239
240
- . directive ( 'uiScrollTd' , function ( ) {
241
- return {
242
- require : [ '?^^uiScrollViewport' ] ,
243
- restrict : 'A' ,
244
- link : ( $scope , element , $attr , controllers ) => {
245
- if ( controllers [ 0 ] ) {
246
- let gridController = controllers [ 0 ] . gridController ;
247
- if ( gridController . registerCell ( $scope , element ) ) {
248
- $scope . $on ( '$destroy' , ( ) => gridController . unregisterCell ( $scope , element ) ) ;
249
- }
250
- }
240
+ . directive ( 'uiScrollTd' , function ( ) {
241
+ return {
242
+ require : [ '?^^uiScrollViewport' ] ,
243
+ restrict : 'A' ,
244
+ link : ( $scope , element , $attr , controllers ) => {
245
+ if ( ! controllers [ 0 ] ) {
246
+ return ;
251
247
}
252
- } ;
253
- } ) ;
248
+ let scope = $scope ;
249
+ let tdInitializer = $scope . uiScrollTdInitializer ;
250
+ if ( ! tdInitializer ) {
251
+ tdInitializer = $scope . uiScrollTdInitializer = {
252
+ linking : true
253
+ } ;
254
+ }
255
+ if ( ! tdInitializer . linking ) {
256
+ scope = tdInitializer . scope ;
257
+ }
258
+ let gridController = controllers [ 0 ] . gridController ;
259
+ if ( gridController . registerCell ( scope , element ) ) {
260
+ $scope . $on ( '$destroy' , ( ) => gridController . unregisterCell ( scope , element ) ) ;
261
+ }
262
+ if ( ! tdInitializer . linking ) {
263
+ tdInitializer . onLink ( ) ;
264
+ }
265
+ }
266
+ } ;
267
+ } ) ;
0 commit comments