1
1
/*
2
2
*
3
- * Tabelizer 1.0.2 - multi level grouping indicators for tables
4
- * Version 1.0.2
3
+ * Tabelizer 1.0.3 - multi level grouping indicators for tables
4
+ * Version 1.0.3
5
5
* @requires jQuery v1.6+ and jQuery.ui core
6
6
*
7
7
* Copyright (c) 2014 Rafael Huisman
21
21
( function ( $ ) {
22
22
var self = { } ;
23
23
24
+ self . isFunction = function ( func ) {
25
+ return func && { } . toString . call ( func ) === '[object Function]' ;
26
+ }
27
+
24
28
self . rowClicker = function ( evt ) {
25
- var $row = $ ( evt . currentTarget ) ;
29
+
30
+ if ( typeof self . conf . onBeforeRowClick != 'undefined' && self . isFunction ( self . conf . onBeforeRowClick ) )
31
+ self . conf . onBeforeRowClick . apply ( self . getPublicObj ( ) , [ evt ] ) ;
32
+
33
+ var $elm = $ ( evt . currentTarget ) ;
34
+
35
+ if ( ! $elm . is ( 'tr' ) )
36
+ $elm = $elm . parentsUntil ( 'tr' ) . parent ( )
37
+
38
+ $row = $elm ;
39
+
26
40
var id = $row . attr ( 'id' ) ;
27
41
28
42
//Simple toggle for contract/expand logic
36
50
37
51
//After any contraction or expansion we need to resetup the lines since they will likely change.
38
52
self . updateLines ( ) ;
53
+
54
+ if ( typeof self . conf . onAfterRowClick != 'undefined' && self . isFunction ( self . conf . onAfterRowClick ) )
55
+ self . conf . onAfterRowClick . apply ( self . getPublicObj ( ) , [ evt ] ) ;
56
+
57
+ return self . getPublicObj ( ) ;
39
58
}
40
59
41
60
self . updateLines = function ( ) {
81
100
$prevRow . addClass ( ' l' + ( parseInt ( x ) ) + '-last' )
82
101
}
83
102
}
103
+
104
+ return self . getPublicObj ( ) ;
84
105
}
85
106
86
107
//this method toggles the children on or off, including a sliding motion
139
160
140
161
prevRowLevel = rowLevel ;
141
162
} ) ;
163
+
164
+ return self . getPublicObj ( ) ;
165
+ }
166
+
167
+ self . updateData = function ( ) {
168
+ self . caller . data ( 'tabelizer' , self ) ;
142
169
}
143
170
144
171
self . maxLevel = 0 ;
177
204
//Add the expanded class, which through css adds in the arrow image
178
205
$firstCol . html ( levelLines + ' <div class="expander"></div> ' + firstColVal ) ;
179
206
180
- //apply the method to be called on each row click
181
- $row . on ( 'click' , self . rowClicker ) ;
207
+ //apply the method to be called on each row click, if fullRowClickable is set to false, then only the expander is clickable
208
+ if ( self . conf . fullRowClickable )
209
+ $row . on ( 'click' , self . conf . onRowClick ) ;
210
+ else
211
+ $row . find ( '.expander' ) . on ( 'click' , self . conf . onRowClick ) ;
182
212
prevLevel = currentLevel ;
183
213
$prevRow = $row ;
184
214
}
185
215
} ) ;
186
216
187
217
self . updateLines ( ) ;
218
+
219
+ if ( typeof self . conf . onReady != 'undefined' && self . isFunction ( self . conf . onReady ) )
220
+ self . conf . onReady . apply ( self . getPublicObj ( ) , [ ] ) ;
221
+
222
+ return self . getPublicObj ( ) ;
188
223
}
189
-
224
+
225
+ self . getPublicObj = function ( ) { return {
226
+ options : self . conf ,
227
+ toggleChildren : self . toggleChildren ,
228
+ updateLines : self . updateLines ,
229
+ rowClicker : self . rowClicker ,
230
+ maxLevel : self . maxLevel ,
231
+ updateData : self . updateData
232
+ } } ;
233
+
234
+ self . conf = {
235
+ onRowClick : self . rowClicker ,
236
+ fullRowClickable : true , //must be set before init
237
+ onBeforeRowClick : null ,
238
+ onAfterRowClick : null ,
239
+ onReady : null
240
+ } ;
241
+
190
242
$ . fn . tabelize = function ( confProp ) {
191
- self . caller = this ;
192
- self . init ( ) ;
243
+
244
+ var existingSelf = this . data ( 'tabelizer' ) ;
245
+ if ( typeof existingSelf == 'undefined' ) {
246
+ $ . extend ( self . conf , confProp ) ;
247
+ self . caller = this ;
248
+ self . init ( ) ;
249
+
250
+ } else {
251
+ self = existingSelf ;
252
+ $ . extend ( self . conf , confProp ) ;
253
+ }
254
+ //Store copy of self in data for repeat calls, update it after any repeating call
255
+ self . updateData ( ) ;
256
+
257
+ return self . getPublicObj ( )
193
258
} ;
194
259
} ) ( jQuery ) ;
0 commit comments