182
182
return this ;
183
183
} ,
184
184
//
185
- setOptions ( opts , val ) {
185
+ setOptions : function ( opts , val ) {
186
186
if ( typeof opts === 'string' ) {
187
187
if ( opts === 'pan' ) {
188
188
if ( val ) {
223
223
return this ;
224
224
} ,
225
225
//
226
- panStartHandler ( e ) {
226
+ panStartHandler : function ( e ) {
227
227
var $chart = $ ( e . delegateTarget ) ;
228
228
if ( $ ( e . target ) . closest ( '.node' ) . length || ( e . touches && e . touches . length > 1 ) ) {
229
229
$chart . data ( 'panning' , false ) ;
291
291
} ) ;
292
292
} ,
293
293
//
294
- panEndHandler ( e ) {
294
+ panEndHandler : function ( e ) {
295
295
if ( e . data . chart . data ( 'panning' ) ) {
296
296
e . data . chart . data ( 'panning' , false ) . css ( 'cursor' , 'default' ) . off ( 'mousemove' ) ;
297
297
}
298
298
} ,
299
299
//
300
- bindPan ( ) {
300
+ bindPan : function ( ) {
301
301
this . $chartContainer . css ( 'overflow' , 'hidden' ) ;
302
302
this . $chart . on ( 'mousedown touchstart' , this . panStartHandler ) ;
303
303
$ ( document ) . on ( 'mouseup touchend' , { 'chart' : this . $chart } , this . panEndHandler ) ;
304
304
} ,
305
305
//
306
- unbindPan ( ) {
306
+ unbindPan : function ( ) {
307
307
this . $chartContainer . css ( 'overflow' , 'auto' ) ;
308
308
this . $chart . off ( 'mousedown touchstart' , this . panStartHandler ) ;
309
309
$ ( document ) . off ( 'mouseup touchend' , this . panEndHandler ) ;
310
310
} ,
311
311
//
312
- zoomWheelHandler ( e ) {
312
+ zoomWheelHandler : function ( e ) {
313
313
var oc = e . data . oc ;
314
314
e . preventDefault ( ) ;
315
315
var newScale = 1 + ( e . originalEvent . deltaY > 0 ? - 0.2 : 0.2 ) ;
316
316
oc . setChartScale ( oc . $chart , newScale ) ;
317
317
} ,
318
318
//
319
- zoomStartHandler ( e ) {
319
+ zoomStartHandler : function ( e ) {
320
320
if ( e . touches && e . touches . length === 2 ) {
321
321
var oc = e . data . oc ;
322
322
oc . $chart . data ( 'pinching' , true ) ;
323
323
var dist = oc . getPinchDist ( e ) ;
324
324
oc . $chart . data ( 'pinchDistStart' , dist ) ;
325
325
}
326
326
} ,
327
- zoomingHandler ( e ) {
327
+ zoomingHandler : function ( e ) {
328
328
var oc = e . data . oc ;
329
329
if ( oc . $chart . data ( 'pinching' ) ) {
330
330
var dist = oc . getPinchDist ( e ) ;
331
331
oc . $chart . data ( 'pinchDistEnd' , dist ) ;
332
332
}
333
333
} ,
334
- zoomEndHandler ( e ) {
334
+ zoomEndHandler : function ( e ) {
335
335
var oc = e . data . oc ;
336
336
if ( oc . $chart . data ( 'pinching' ) ) {
337
337
oc . $chart . data ( 'pinching' , false ) ;
344
344
}
345
345
} ,
346
346
//
347
- bindZoom ( ) {
347
+ bindZoom : function ( ) {
348
348
this . $chartContainer . on ( 'wheel' , { 'oc' : this } , this . zoomWheelHandler ) ;
349
349
this . $chartContainer . on ( 'touchstart' , { 'oc' : this } , this . zoomStartHandler ) ;
350
350
$ ( document ) . on ( 'touchmove' , { 'oc' : this } , this . zoomingHandler ) ;
351
351
$ ( document ) . on ( 'touchend' , { 'oc' : this } , this . zoomEndHandler ) ;
352
352
} ,
353
- unbindZoom ( ) {
353
+ unbindZoom : function ( ) {
354
354
this . $chartContainer . off ( 'wheel' , this . zoomWheelHandler ) ;
355
355
this . $chartContainer . off ( 'touchstart' , this . zoomStartHandler ) ;
356
356
$ ( document ) . off ( 'touchmove' , this . zoomingHandler ) ;
357
357
$ ( document ) . off ( 'touchend' , this . zoomEndHandler ) ;
358
358
} ,
359
359
//
360
- getPinchDist ( e ) {
360
+ getPinchDist : function ( e ) {
361
361
return Math . sqrt ( ( e . touches [ 0 ] . clientX - e . touches [ 1 ] . clientX ) * ( e . touches [ 0 ] . clientX - e . touches [ 1 ] . clientX ) +
362
362
( e . touches [ 0 ] . clientY - e . touches [ 1 ] . clientY ) * ( e . touches [ 0 ] . clientY - e . touches [ 1 ] . clientY ) ) ;
363
363
} ,
364
364
//
365
- setChartScale ( $chart , newScale ) {
365
+ setChartScale : function ( $chart , newScale ) {
366
366
var opts = $chart . data ( 'options' ) ;
367
367
var lastTf = $chart . css ( 'transform' ) ;
368
368
var matrix = '' ;
385
385
}
386
386
} ,
387
387
//
388
- buildJsonDS ( $li ) {
388
+ buildJsonDS : function ( $li ) {
389
389
var that = this ;
390
390
var subObj = {
391
391
'name' : $li . contents ( ) . eq ( 0 ) . text ( ) . trim ( ) ,
401
401
return subObj ;
402
402
} ,
403
403
//
404
- attachRel ( data , flags ) {
404
+ attachRel : function ( data , flags ) {
405
405
var that = this ;
406
406
data . relationship = flags + ( data . children && data . children . length > 0 ? 1 : 0 ) ;
407
407
if ( data . children ) {
412
412
return data ;
413
413
} ,
414
414
//
415
- loopChart ( $chart ) {
415
+ loopChart : function ( $chart ) {
416
416
var that = this ;
417
417
var $tr = $chart . find ( 'tr:first' ) ;
418
418
var subObj = { 'id' : $tr . find ( '.node' ) [ 0 ] . id } ;
423
423
return subObj ;
424
424
} ,
425
425
//
426
- getHierarchy ( $chart ) {
426
+ getHierarchy : function ( $chart ) {
427
427
var $chart = $chart || this . $chart ;
428
428
if ( ! $chart . find ( '.node:first' ) [ 0 ] . id ) {
429
429
return 'Error: Nodes of orghcart to be exported must have id attribute!' ;
430
430
}
431
431
return this . loopChart ( $chart ) ;
432
432
} ,
433
433
// detect the exist/display state of related node
434
- getNodeState ( $node , relation ) {
434
+ getNodeState : function ( $node , relation ) {
435
435
var $target = { } ;
436
436
if ( relation === 'parent' ) {
437
437
$target = $node . closest ( '.nodes' ) . siblings ( ':first' ) ;
449
449
return { 'exist' : false , 'visible' : false } ;
450
450
} ,
451
451
// find the related nodes
452
- getRelatedNodes ( $node , relation ) {
452
+ getRelatedNodes : function ( $node , relation ) {
453
453
if ( relation === 'parent' ) {
454
454
return $node . closest ( '.nodes' ) . parent ( ) . children ( ':first' ) . find ( '.node' ) ;
455
455
} else if ( relation === 'children' ) {
459
459
}
460
460
} ,
461
461
// recursively hide the ancestor node and sibling nodes of the specified node
462
- hideParent ( $node ) {
462
+ hideParent : function ( $node ) {
463
463
var $temp = $node . closest ( 'table' ) . closest ( 'tr' ) . siblings ( ) ;
464
464
if ( $temp . eq ( 0 ) . find ( '.spinner' ) . length ) {
465
465
$node . closest ( '.orgchart' ) . data ( 'inAjax' , false ) ;
487
487
}
488
488
} ,
489
489
// show the parent node of the specified node
490
- showParent ( $node ) {
490
+ showParent : function ( $node ) {
491
491
var that = this ;
492
492
// just show only one superior level
493
493
var $temp = $node . closest ( 'table' ) . closest ( 'tr' ) . siblings ( ) . removeClass ( 'hidden' ) ;
504
504
} ) ;
505
505
} ,
506
506
// recursively hide the descendant nodes of the specified node
507
- hideChildren ( $node ) {
507
+ hideChildren : function ( $node ) {
508
508
var that = this ;
509
509
var $temp = $node . closest ( 'tr' ) . siblings ( ) ;
510
510
if ( $temp . last ( ) . find ( '.spinner' ) . length ) {
529
529
} ) ;
530
530
} ,
531
531
// show the children nodes of the specified node
532
- showChildren ( $node ) {
532
+ showChildren : function ( $node ) {
533
533
var that = this ;
534
534
var $levels = $node . closest ( 'tr' ) . siblings ( ) ;
535
535
var isVerticalDesc = $levels . is ( '.verticalNodes' ) ? true : false ;
546
546
} ) ;
547
547
} ,
548
548
// hide the sibling nodes of the specified node
549
- hideSiblings ( $node , direction ) {
549
+ hideSiblings : function ( $node , direction ) {
550
550
var that = this ;
551
551
var $nodeContainer = $node . closest ( 'table' ) . parent ( ) ;
552
552
if ( $nodeContainer . siblings ( ) . find ( '.spinner' ) . length ) {
580
580
} ) ;
581
581
} ,
582
582
// show the sibling nodes of the specified node
583
- showSiblings ( $node , direction ) {
583
+ showSiblings : function ( $node , direction ) {
584
584
var that = this ;
585
585
// firstly, show the sibling td tags
586
586
var $siblings = $ ( ) ;
619
619
} ) ;
620
620
} ,
621
621
// start up loading status for requesting new nodes
622
- startLoading ( $arrow , $node , options ) {
622
+ startLoading : function ( $arrow , $node , options ) {
623
623
var $chart = $node . closest ( '.orgchart' ) ;
624
624
if ( typeof $chart . data ( 'inAjax' ) !== 'undefined' && $chart . data ( 'inAjax' ) === true ) {
625
625
return false ;
633
633
return true ;
634
634
} ,
635
635
// terminate loading status for requesting new nodes
636
- endLoading ( $arrow , $node , options ) {
636
+ endLoading : function ( $arrow , $node , options ) {
637
637
var $chart = $node . closest ( 'div.orgchart' ) ;
638
638
$arrow . removeClass ( 'hidden' ) ;
639
639
$node . find ( '.spinner' ) . remove ( ) ;
642
642
$ ( '.oc-export-btn' + ( options . chartClass !== '' ? '.' + options . chartClass : '' ) ) . prop ( 'disabled' , false ) ;
643
643
} ,
644
644
// whether the cursor is hovering over the node
645
- isInAction ( $node ) {
645
+ isInAction : function ( $node ) {
646
646
return $node . children ( '.edge' ) . attr ( 'class' ) . indexOf ( 'fa-' ) > - 1 ? true : false ;
647
647
} ,
648
648
//
649
- switchVerticalArrow ( $arrow ) {
649
+ switchVerticalArrow : function ( $arrow ) {
650
650
$arrow . toggleClass ( 'fa-chevron-up' ) . toggleClass ( 'fa-chevron-down' ) ;
651
651
} ,
652
652
//
653
- switchHorizontalArrow ( $node ) {
653
+ switchHorizontalArrow : function ( $node ) {
654
654
var opts = $node . closest ( '.orgchart' ) . data ( 'options' ) ;
655
655
if ( opts . toggleSiblingsResp && ( typeof opts . ajaxURL === 'undefined' || $node . closest ( '.nodes' ) . data ( 'siblingsLoaded' ) ) ) {
656
656
var $prevSib = $node . closest ( 'table' ) . parent ( ) . prev ( ) ;
677
677
}
678
678
} ,
679
679
//
680
- repaint ( node ) {
680
+ repaint : function ( node ) {
681
681
if ( node ) {
682
682
node . style . offsetWidth = node . offsetWidth ;
683
683
}
684
684
} ,
685
685
// create node
686
- createNode ( nodeData , level , opts ) {
686
+ createNode : function ( nodeData , level , opts ) {
687
687
var that = this ;
688
688
$ . each ( nodeData . children , function ( index , child ) {
689
689
child . parentId = nodeData . id ;
1038
1038
return dtd . promise ( ) ;
1039
1039
} ,
1040
1040
// recursively build the tree
1041
- buildHierarchy ( $appendTo , nodeData , level , opts , callback ) {
1041
+ buildHierarchy : function ( $appendTo , nodeData , level , opts , callback ) {
1042
1042
var that = this ;
1043
1043
var $nodeWrapper ;
1044
1044
// Construct the node
1108
1108
}
1109
1109
} ,
1110
1110
// build the child nodes of specific node
1111
- buildChildNode ( $appendTo , nodeData , opts , callback ) {
1111
+ buildChildNode : function ( $appendTo , nodeData , opts , callback ) {
1112
1112
var opts = opts || $appendTo . closest ( '.orgchart' ) . data ( 'options' ) ;
1113
1113
var data = nodeData . children || nodeData . siblings ;
1114
1114
$appendTo . find ( 'td:first' ) . attr ( 'colspan' , data . length * 2 ) ;
1115
1115
this . buildHierarchy ( $appendTo , { 'children' : data } , 0 , opts , callback ) ;
1116
1116
} ,
1117
1117
// exposed method
1118
- addChildren ( $node , data , opts ) {
1118
+ addChildren : function ( $node , data , opts ) {
1119
1119
var that = this ;
1120
1120
var opts = opts || $node . closest ( '.orgchart' ) . data ( 'options' ) ;
1121
1121
var count = 0 ;
1132
1132
} ) ;
1133
1133
} ,
1134
1134
// build the parent node of specific node
1135
- buildParentNode ( $currentRoot , nodeData , opts , callback ) {
1135
+ buildParentNode : function ( $currentRoot , nodeData , opts , callback ) {
1136
1136
var that = this ;
1137
1137
var $table = $ ( '<table>' ) ;
1138
1138
nodeData . relationship = nodeData . relationship || '001' ;
1153
1153
} ) ;
1154
1154
} ,
1155
1155
// exposed method
1156
- addParent ( $currentRoot , data , opts ) {
1156
+ addParent : function ( $currentRoot , data , opts ) {
1157
1157
var that = this ;
1158
1158
this . buildParentNode ( $currentRoot , data , opts , function ( ) {
1159
1159
if ( ! $currentRoot . children ( '.topEdge' ) . length ) {
1163
1163
} ) ;
1164
1164
} ,
1165
1165
// subsequent processing of build sibling nodes
1166
- complementLine ( $oneSibling , siblingCount , existingSibligCount ) {
1166
+ complementLine : function ( $oneSibling , siblingCount , existingSibligCount ) {
1167
1167
var lines = '' ;
1168
1168
for ( var i = 0 ; i < existingSibligCount ; i ++ ) {
1169
1169
lines += '<td class="leftLine topLine"> </td><td class="rightLine topLine"> </td>' ;
1172
1172
. end ( ) . next ( ) . children ( ':first' ) . after ( lines ) ;
1173
1173
} ,
1174
1174
// build the sibling nodes of specific node
1175
- buildSiblingNode ( $nodeChart , nodeData , opts , callback ) {
1175
+ buildSiblingNode : function ( $nodeChart , nodeData , opts , callback ) {
1176
1176
var that = this ;
1177
1177
var opts = opts || $nodeChart . closest ( '.orgchart' ) . data ( 'options' ) ;
1178
1178
var newSiblingCount = nodeData . siblings ? nodeData . siblings . length : nodeData . children . length ;
1216
1216
}
1217
1217
} ,
1218
1218
//
1219
- addSiblings ( $node , data , opts ) {
1219
+ addSiblings : function ( $node , data , opts ) {
1220
1220
var that = this ;
1221
1221
this . buildSiblingNode ( $node . closest ( 'table' ) , data , opts , function ( ) {
1222
1222
$node . closest ( '.nodes' ) . data ( 'siblingsLoaded' , true ) ;
1227
1227
} ) ;
1228
1228
} ,
1229
1229
//
1230
- removeNodes ( $node ) {
1230
+ removeNodes : function ( $node ) {
1231
1231
var $parent = $node . closest ( 'table' ) . parent ( ) ;
1232
1232
var $sibs = $parent . parent ( ) . siblings ( ) ;
1233
1233
if ( $parent . is ( 'td' ) ) {
1250
1250
return new OrgChart ( this , opts ) . init ( ) ;
1251
1251
} ;
1252
1252
1253
- } ) ) ;
1253
+ } ) ) ;
0 commit comments