@ -15,10 +15,10 @@
//default consts of excheck
var _consts = {
event : {
CHECK : "ztree_check"
CHECK : "ztree_check" ,
} ,
id : {
CHECK : "_check"
CHECK : "_check" ,
} ,
checkbox : {
STYLE : "checkbox" ,
@ -28,13 +28,13 @@
TRUE : "true" ,
FULL : "full" ,
PART : "part" ,
FOCUS : "focus"
FOCUS : "focus" ,
} ,
radio : {
STYLE : "radio" ,
TYPE _ALL : "all" ,
TYPE _LEVEL : "level"
}
TYPE _LEVEL : "level" ,
} ,
} ,
//default setting of excheck
_setting = {
@ -46,19 +46,19 @@
chkDisabledInherit : false ,
radioType : _consts . radio . TYPE _LEVEL ,
chkboxType : {
"Y" : "ps" ,
"N" : "ps"
}
Y : "ps" ,
N : "ps" ,
} ,
} ,
data : {
key : {
checked : "checked"
}
checked : "checked" ,
} ,
} ,
callback : {
beforeCheck : null ,
onCheck : null
}
onCheck : null ,
} ,
} ,
//default root of excheck
_initRoot = function ( setting ) {
@ -66,8 +66,7 @@
r . radioCheckedList = [ ] ;
} ,
//default cache of excheck
_initCache = function ( treeId ) {
} ,
_initCache = function ( treeId ) { } ,
//default bind event of excheck
_bindEvent = function ( setting ) {
var o = setting . treeObj ,
@ -86,22 +85,37 @@
_eventProxy = function ( e ) {
var target = e . target ,
setting = data . getSetting ( e . data . treeId ) ,
tId = "" , node = null ,
nodeEventType = "" , treeEventType = "" ,
nodeEventCallback = null , treeEventCallback = null ;
tId = "" ,
node = null ,
nodeEventType = "" ,
treeEventType = "" ,
nodeEventCallback = null ,
treeEventCallback = null ;
if ( tools . eqs ( e . type , "mouseover" ) ) {
if ( setting . check . enable && tools . eqs ( target . tagName , "span" ) && target . getAttribute ( "treeNode" + consts . id . CHECK ) !== null ) {
if (
setting . check . enable &&
tools . eqs ( target . tagName , "span" ) &&
target . getAttribute ( "treeNode" + consts . id . CHECK ) !== null
) {
tId = tools . getNodeMainDom ( target ) . id ;
nodeEventType = "mouseoverCheck" ;
}
} else if ( tools . eqs ( e . type , "mouseout" ) ) {
if ( setting . check . enable && tools . eqs ( target . tagName , "span" ) && target . getAttribute ( "treeNode" + consts . id . CHECK ) !== null ) {
if (
setting . check . enable &&
tools . eqs ( target . tagName , "span" ) &&
target . getAttribute ( "treeNode" + consts . id . CHECK ) !== null
) {
tId = tools . getNodeMainDom ( target ) . id ;
nodeEventType = "mouseoutCheck" ;
}
} else if ( tools . eqs ( e . type , "click" ) ) {
if ( setting . check . enable && tools . eqs ( target . tagName , "span" ) && target . getAttribute ( "treeNode" + consts . id . CHECK ) !== null ) {
if (
setting . check . enable &&
tools . eqs ( target . tagName , "span" ) &&
target . getAttribute ( "treeNode" + consts . id . CHECK ) !== null
) {
tId = tools . getNodeMainDom ( target ) . id ;
nodeEventType = "checkNode" ;
}
@ -126,7 +140,7 @@
nodeEventType : nodeEventType ,
nodeEventCallback : nodeEventCallback ,
treeEventType : treeEventType ,
treeEventCallback : treeEventCallback
treeEventCallback : treeEventCallback ,
} ;
return proxyResult ;
} ,
@ -140,7 +154,8 @@
if ( typeof n . nocheck == "string" ) n . nocheck = tools . eqs ( n . nocheck , "true" ) ;
n . nocheck = ! ! n . nocheck || ( setting . check . nocheckInherit && parentNode && ! ! parentNode . nocheck ) ;
if ( typeof n . chkDisabled == "string" ) n . chkDisabled = tools . eqs ( n . chkDisabled , "true" ) ;
n . chkDisabled = ! ! n . chkDisabled || ( setting . check . chkDisabledInherit && parentNode && ! ! parentNode . chkDisabled ) ;
n . chkDisabled =
! ! n . chkDisabled || ( setting . check . chkDisabledInherit && parentNode && ! ! parentNode . chkDisabled ) ;
if ( typeof n . halfCheck == "string" ) n . halfCheck = tools . eqs ( n . halfCheck , "true" ) ;
n . halfCheck = ! ! n . halfCheck ;
n . check _Child _State = - 1 ;
@ -149,7 +164,11 @@
return data . getCheckStatus ( setting , n ) ;
} ;
if ( setting . check . chkStyle == consts . radio . STYLE && setting . check . radioType == consts . radio . TYPE _ALL && n [ checkedKey ] ) {
if (
setting . check . chkStyle == consts . radio . STYLE &&
setting . check . radioType == consts . radio . TYPE _ALL &&
n [ checkedKey ]
) {
var r = data . getRoot ( setting ) ;
r . radioCheckedList . push ( n ) ;
}
@ -159,7 +178,17 @@
var checkedKey = setting . data . key . checked ;
if ( setting . check . enable ) {
data . makeChkFlag ( setting , node ) ;
html . push ( "<span ID='" , node . tId , consts . id . CHECK , "' class='" , view . makeChkClass ( setting , node ) , "' treeNode" , consts . id . CHECK , ( node . nocheck === true ? " style='display:none;'" : "" ) , "></span>" ) ;
html . push (
"<span ID='" ,
node . tId ,
consts . id . CHECK ,
"' class='" ,
view . makeChkClass ( setting , node ) ,
"' treeNode" ,
consts . id . CHECK ,
node . nocheck === true ? " style='display:none;'" : "" ,
"></span>"
) ;
}
} ,
//update zTreeObj, add method of check
@ -174,13 +203,17 @@
if ( node [ checkedKey ] === checked && ! checkTypeFlag ) {
return ;
} else if ( callbackFlag && tools . apply ( this . setting . callback . beforeCheck , [ this . setting . treeId , node ] , true ) == false ) {
} else if (
callbackFlag &&
tools . apply ( this . setting . callback . beforeCheck , [ this . setting . treeId , node ] , true ) == false
) {
return ;
}
if ( tools . uCanDo ( this . setting ) && this . setting . check . enable && node . nocheck !== true ) {
node [ checkedKey ] = checked ;
var checkObj = $$ ( node , consts . id . CHECK , this . setting ) ;
if ( checkTypeFlag || this . setting . check . chkStyle === consts . radio . STYLE ) view . checkNodeRelation ( this . setting , node ) ;
if ( checkTypeFlag || this . setting . check . chkStyle === consts . radio . STYLE )
view . checkNodeRelation ( this . setting , node ) ;
view . setChkClass ( this . setting , checkObj , node ) ;
view . repairParentChkClassWithSelf ( this . setting , node ) ;
if ( callbackFlag ) {
@ -195,7 +228,7 @@
zTreeTools . getCheckedNodes = function ( checked ) {
var childKey = this . setting . data . key . children ;
checked = ( checked !== false ) ;
checked = checked !== false ;
return data . getTreeCheckedNodes ( this . setting , data . getRoot ( this . setting ) [ childKey ] , checked ) ;
} ;
@ -219,7 +252,8 @@
var nObj = $$ ( node , this . setting ) ;
if ( nObj . get ( 0 ) && tools . uCanDo ( this . setting ) ) {
var checkObj = $$ ( node , consts . id . CHECK , this . setting ) ;
if ( checkTypeFlag == true || this . setting . check . chkStyle === consts . radio . STYLE ) view . checkNodeRelation ( this . setting , node ) ;
if ( checkTypeFlag == true || this . setting . check . chkStyle === consts . radio . STYLE )
view . checkNodeRelation ( this . setting , node ) ;
view . setChkClass ( this . setting , checkObj , node ) ;
view . repairParentChkClassWithSelf ( this . setting , node ) ;
}
@ -243,7 +277,13 @@
var checkedKey = setting . data . key . checked ,
r = {
checked : node [ checkedKey ] ,
half : node . halfCheck ? node . halfCheck : ( setting . check . chkStyle == consts . radio . STYLE ? ( node . check _Child _State === 2 ) : ( node [ checkedKey ] ? ( node . check _Child _State > - 1 && node . check _Child _State < 2 ) : ( node . check _Child _State > 0 ) ) )
half : node . halfCheck
? node . halfCheck
: setting . check . chkStyle == consts . radio . STYLE
? node . check _Child _State === 2
: node [ checkedKey ]
? node . check _Child _State > - 1 && node . check _Child _State < 2
: node . check _Child _State > 0 ,
} ;
return r ;
} ,
@ -251,7 +291,10 @@
if ( ! nodes ) return [ ] ;
var childKey = setting . data . key . children ,
checkedKey = setting . data . key . checked ,
onlyOne = ( checked && setting . check . chkStyle == consts . radio . STYLE && setting . check . radioType == consts . radio . TYPE _ALL ) ;
onlyOne =
checked &&
setting . check . chkStyle == consts . radio . STYLE &&
setting . check . radioType == consts . radio . TYPE _ALL ;
results = ! results ? [ ] : results ;
for ( var i = 0 , l = nodes . length ; i < l ; i ++ ) {
if ( nodes [ i ] . nocheck !== true && nodes [ i ] . chkDisabled !== true && nodes [ i ] [ checkedKey ] == checked ) {
@ -273,7 +316,11 @@
checkedKey = setting . data . key . checked ;
results = ! results ? [ ] : results ;
for ( var i = 0 , l = nodes . length ; i < l ; i ++ ) {
if ( nodes [ i ] . nocheck !== true && nodes [ i ] . chkDisabled !== true && nodes [ i ] [ checkedKey ] != nodes [ i ] . checkedOld ) {
if (
nodes [ i ] . nocheck !== true &&
nodes [ i ] . chkDisabled !== true &&
nodes [ i ] [ checkedKey ] != nodes [ i ] . checkedOld
) {
results . push ( nodes [ i ] ) ;
}
data . getTreeChangeCheckedNodes ( setting , nodes [ i ] [ childKey ] , results ) ;
@ -311,9 +358,9 @@
} else if ( cNode . halfCheck === true ) {
tmp = 1 ;
} else if ( cNode [ checkedKey ] ) {
tmp = ( cNode . check _Child _State === - 1 || cNode . check _Child _State === 2 ) ? 2 : 1 ;
tmp = cNode . check _Child _State === - 1 || cNode . check _Child _State === 2 ? 2 : 1 ;
} else {
tmp = ( cNode . check _Child _State > 0 ) ? 1 : 0 ;
tmp = cNode . check _Child _State > 0 ? 1 : 0 ;
}
if ( tmp === 1 ) {
chkFlag = 1 ;
@ -331,7 +378,7 @@
}
}
node . check _Child _State = chkFlag ;
}
} ,
} ,
//method of event proxy
_event = { } ,
@ -365,14 +412,16 @@
node . check _Focus = false ;
view . setChkClass ( setting , checkObj , node ) ;
return true ;
}
} ,
} ,
//method of tools for zTree
_tools = { } ,
//method of operate ztree dom
_view = {
checkNodeRelation : function ( setting , node ) {
var pNode , i , l ,
var pNode ,
i ,
l ,
childKey = setting . data . key . children ,
checkedKey = setting . data . key . checked ,
r = consts . radio ;
@ -394,7 +443,7 @@
}
checkedList . push ( node ) ;
} else {
var parentNode = ( node . parentTId ) ? node . getParentNode ( ) : data . getRoot ( setting ) ;
var parentNode = node . parentTId ? node . getParentNode ( ) : data . getRoot ( setting ) ;
for ( i = 0 , l = parentNode [ childKey ] . length ; i < l ; i ++ ) {
pNode = parentNode [ childKey ] [ i ] ;
if ( pNode [ checkedKey ] && pNode != node ) {
@ -411,12 +460,17 @@
}
}
}
} else {
if ( node [ checkedKey ] && ( ! node [ childKey ] || node [ childKey ] . length == 0 || setting . check . chkboxType . Y . indexOf ( "s" ) > - 1 ) ) {
if (
node [ checkedKey ] &&
( ! node [ childKey ] || node [ childKey ] . length == 0 || setting . check . chkboxType . Y . indexOf ( "s" ) > - 1 )
) {
view . setSonNodeCheckBox ( setting , node , true ) ;
}
if ( ! node [ checkedKey ] && ( ! node [ childKey ] || node [ childKey ] . length == 0 || setting . check . chkboxType . N . indexOf ( "s" ) > - 1 ) ) {
if (
! node [ checkedKey ] &&
( ! node [ childKey ] || node [ childKey ] . length == 0 || setting . check . chkboxType . N . indexOf ( "s" ) > - 1 )
) {
view . setSonNodeCheckBox ( setting , node , false ) ;
}
if ( node [ checkedKey ] && setting . check . chkboxType . Y . indexOf ( "p" ) > - 1 ) {
@ -429,35 +483,42 @@
} ,
makeChkClass : function ( setting , node ) {
var checkedKey = setting . data . key . checked ,
c = consts . checkbox , r = consts . radio ,
c = consts . checkbox ,
r = consts . radio ,
checkboxType = setting . check . chkboxType ;
var notEffectByOtherNode = ( checkboxType . Y === "" && checkboxType . N === "" ) ;
var notEffectByOtherNode = checkboxType . Y === "" && checkboxType . N === "" ;
fullStyle = "" ;
if ( node . chkDisabled === true ) {
fullStyle = c . DISABLED ;
} else if ( node . halfCheck ) {
fullStyle = c . PART ;
} else if ( setting . check . chkStyle == r . STYLE ) {
fullStyle = ( node . check _Child _State < 1 ) ? c . FULL : c . PART ;
fullStyle = node . check _Child _State < 1 ? c . FULL : c . PART ;
} else {
fullStyle = node [ checkedKey ] ? ( ( node . check _Child _State === 2 || node . check _Child _State === - 1 ) || notEffectByOtherNode ? c . FULL : c . PART ) : ( ( node . check _Child _State < 1 || notEffectByOtherNode ) ? c . FULL : c . PART ) ;
fullStyle = node [ checkedKey ]
? node . check _Child _State === 2 || node . check _Child _State === - 1 || notEffectByOtherNode
? c . FULL
: c . PART
: node . check _Child _State < 1 || notEffectByOtherNode
? c . FULL
: c . PART ;
}
var chkName = setting . check . chkStyle + "_" + ( node [ checkedKey ] ? c . TRUE : c . FALSE ) + "_" + fullStyle ;
chkName = ( node . check _Focus && node . chkDisabled !== true ) ? chkName + "_" + c . FOCUS : chkName ;
chkName = node . check _Focus && node . chkDisabled !== true ? chkName + "_" + c . FOCUS : chkName ;
var chClass = consts . className . BUTTON + " " + c . DEFAULT + " " + chkName ;
switch ( chkName ) {
case 'checkbox_true_part' :
case 'checkbox_true_part_focus' :
chClass += ' bi-half-button bi-high-light-border' ;
case "checkbox_true_part" :
case "checkbox_true_part_focus" :
chClass += " bi-half-button bi-high-light-border" ;
break ;
case 'checkbox_true_full' :
case 'checkbox_true_full_focus' :
chClass += ' bi-checkbox checkbox-content bi-high-light-background active' ;
case "checkbox_true_full" :
case "checkbox_true_full_focus" :
chClass += " bi-checkbox checkbox-content bi-high-light-background active" ;
break ;
case 'checkbox_false_full' :
case 'checkbox_false_full_focus' :
case "checkbox_false_full" :
case "checkbox_false_full_focus" :
default :
chClass += ' bi-checkbox checkbox-content' ;
chClass += " bi-checkbox checkbox-content" ;
break ;
}
return chClass + ( node . disabled ? " disabled" : "" ) ;
@ -528,7 +589,7 @@
} else {
obj . show ( ) ;
}
obj . attr ( 'class' , view . makeChkClass ( setting , node ) ) ;
obj . attr ( "class" , view . makeChkClass ( setting , node ) ) ;
} ,
setParentNodeCheckBox : function ( setting , node , value , srcNode ) {
var childKey = setting . data . key . children ,
@ -548,8 +609,13 @@
if ( ! value ) {
var pNodes = node . getParentNode ( ) [ childKey ] ;
for ( var i = 0 , l = pNodes . length ; i < l ; i ++ ) {
if ( ( pNodes [ i ] . nocheck !== true && pNodes [ i ] . chkDisabled !== true && pNodes [ i ] [ checkedKey ] )
|| ( ( pNodes [ i ] . nocheck === true || pNodes [ i ] . chkDisabled === true ) && pNodes [ i ] . check _Child _State > 0 ) ) {
if (
( pNodes [ i ] . nocheck !== true &&
pNodes [ i ] . chkDisabled !== true &&
pNodes [ i ] [ checkedKey ] ) ||
( ( pNodes [ i ] . nocheck === true || pNodes [ i ] . chkDisabled === true ) &&
pNodes [ i ] . check _Child _State > 0 )
) {
pSign = false ;
break ;
}
@ -582,24 +648,28 @@
}
if ( node . nocheck !== true && node . chkDisabled !== true ) {
node [ checkedKey ] = value ;
if ( ! hasDisable ) node . check _Child _State = ( node [ childKey ] && node [ childKey ] . length > 0 ) ? ( value ? 2 : 0 ) : - 1 ;
if ( ! hasDisable )
node . check _Child _State = node [ childKey ] && node [ childKey ] . length > 0 ? ( value ? 2 : 0 ) : - 1 ;
} else {
node . check _Child _State = - 1 ;
}
view . setChkClass ( setting , checkObj , node ) ;
if ( setting . check . autoCheckTrigger && node != srcNode && node . nocheck !== true && node . chkDisabled !== true ) {
if (
setting . check . autoCheckTrigger &&
node != srcNode &&
node . nocheck !== true &&
node . chkDisabled !== true
) {
setting . treeObj . trigger ( consts . event . CHECK , [ null , setting . treeId , node ] ) ;
}
}
}
} ,
} ,
_z = {
tools : _tools ,
view : _view ,
event : _event ,
data : _data
data : _data ,
} ;
$ . extend ( true , $ . fn . zTree . consts , _consts ) ;
$ . extend ( true , $ . fn . zTree . _z , _z ) ;