123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504 |
- /*
- * JQuery zTree core v3.5.16-beta.1
- * http://zTree.me/
- *
- * Copyright (c) 2010 Hunter.z
- *
- * Licensed same as jquery - MIT License
- * http://www.opensource.org/licenses/mit-license.php
- *
- * email: hunter.z@263.net
- * Date: 2014-03-28
- */
- (function($){
- var settings = {}, roots = {}, caches = {},
- //default consts of core
- _consts = {
- className: {
- BUTTON: "button",
- LEVEL: "level",
- ICO_LOADING: "ico_loading",
- SWITCH: "switch"
- },
- event: {
- NODECREATED: "ztree_nodeCreated",
- CLICK: "ztree_click",
- EXPAND: "ztree_expand",
- COLLAPSE: "ztree_collapse",
- ASYNC_SUCCESS: "ztree_async_success",
- ASYNC_ERROR: "ztree_async_error",
- REMOVE: "ztree_remove"
- },
- id: {
- A: "_a",
- ICON: "_ico",
- SPAN: "_span",
- SWITCH: "_switch",
- UL: "_ul"
- },
- line: {
- ROOT: "root",
- ROOTS: "roots",
- CENTER: "center",
- BOTTOM: "bottom",
- NOLINE: "noline",
- LINE: "line"
- },
- folder: {
- OPEN: "open",
- CLOSE: "close",
- DOCU: "docu"
- },
- node: {
- CURSELECTED: "curSelectedNode"
- }
- },
- //default setting of core
- _setting = {
- treeId: "",
- treeObj: null,
- view: {
- addDiyDom: null,
- autoCancelSelected: true,
- dblClickExpand: true,
- expandSpeed: "fast",
- fontCss: {},
- nameIsHTML: false,
- selectedMulti: true,
- showIcon: true,
- showLine: true,
- showTitle: true,
- txtSelectedEnable: false
- },
- data: {
- key: {
- children: "children",
- name: "name",
- title: "",
- url: "url"
- },
- simpleData: {
- enable: false,
- idKey: "id",
- pIdKey: "pId",
- rootPId: null
- },
- keep: {
- parent: false,
- leaf: false
- }
- },
- async: {
- enable: false,
- contentType: "application/x-www-form-urlencoded",
- type: "post",
- dataType: "text",
- url: "",
- autoParam: [],
- otherParam: [],
- dataFilter: null
- },
- callback: {
- beforeAsync:null,
- beforeClick:null,
- beforeDblClick:null,
- beforeRightClick:null,
- beforeMouseDown:null,
- beforeMouseUp:null,
- beforeExpand:null,
- beforeCollapse:null,
- beforeRemove:null,
- onAsyncError:null,
- onAsyncSuccess:null,
- onNodeCreated:null,
- onClick:null,
- onDblClick:null,
- onRightClick:null,
- onMouseDown:null,
- onMouseUp:null,
- onExpand:null,
- onCollapse:null,
- onRemove:null
- }
- },
- //default root of core
- //zTree use root to save full data
- _initRoot = function (setting) {
- var r = data.getRoot(setting);
- if (!r) {
- r = {};
- data.setRoot(setting, r);
- }
- r[setting.data.key.children] = [];
- r.expandTriggerFlag = false;
- r.curSelectedList = [];
- r.noSelection = true;
- r.createdNodes = [];
- r.zId = 0;
- r._ver = (new Date()).getTime();
- },
- //default cache of core
- _initCache = function(setting) {
- var c = data.getCache(setting);
- if (!c) {
- c = {};
- data.setCache(setting, c);
- }
- c.nodes = [];
- c.doms = [];
- },
- //default bindEvent of core
- _bindEvent = function(setting) {
- var o = setting.treeObj,
- c = consts.event;
- o.bind(c.NODECREATED, function (event, treeId, node) {
- tools.apply(setting.callback.onNodeCreated, [event, treeId, node]);
- });
- o.bind(c.CLICK, function (event, srcEvent, treeId, node, clickFlag) {
- tools.apply(setting.callback.onClick, [srcEvent, treeId, node, clickFlag]);
- });
- o.bind(c.EXPAND, function (event, treeId, node) {
- tools.apply(setting.callback.onExpand, [event, treeId, node]);
- });
- o.bind(c.COLLAPSE, function (event, treeId, node) {
- tools.apply(setting.callback.onCollapse, [event, treeId, node]);
- });
- o.bind(c.ASYNC_SUCCESS, function (event, treeId, node, msg) {
- tools.apply(setting.callback.onAsyncSuccess, [event, treeId, node, msg]);
- });
- o.bind(c.ASYNC_ERROR, function (event, treeId, node, XMLHttpRequest, textStatus, errorThrown) {
- tools.apply(setting.callback.onAsyncError, [event, treeId, node, XMLHttpRequest, textStatus, errorThrown]);
- });
- o.bind(c.REMOVE, function (event, treeId, treeNode) {
- tools.apply(setting.callback.onRemove, [event, treeId, treeNode]);
- });
- },
- _unbindEvent = function(setting) {
- var o = setting.treeObj,
- c = consts.event;
- o.unbind(c.NODECREATED)
- .unbind(c.CLICK)
- .unbind(c.EXPAND)
- .unbind(c.COLLAPSE)
- .unbind(c.ASYNC_SUCCESS)
- .unbind(c.ASYNC_ERROR)
- .unbind(c.REMOVE);
- },
- //default event proxy of core
- _eventProxy = function(event) {
- var target = event.target,
- setting = data.getSetting(event.data.treeId),
- tId = "", node = null,
- nodeEventType = "", treeEventType = "",
- nodeEventCallback = null, treeEventCallback = null,
- tmp = null;
- if (tools.eqs(event.type, "mousedown")) {
- treeEventType = "mousedown";
- } else if (tools.eqs(event.type, "mouseup")) {
- treeEventType = "mouseup";
- } else if (tools.eqs(event.type, "contextmenu")) {
- treeEventType = "contextmenu";
- } else if (tools.eqs(event.type, "click")) {
- if (tools.eqs(target.tagName, "span") && target.getAttribute("treeNode"+ consts.id.SWITCH) !== null) {
- tId = tools.getNodeMainDom(target).id;
- nodeEventType = "switchNode";
- } else {
- tmp = tools.getMDom(setting, target, [{tagName:"a", attrName:"treeNode"+consts.id.A}]);
- if (tmp) {
- tId = tools.getNodeMainDom(tmp).id;
- nodeEventType = "clickNode";
- }
- }
- } else if (tools.eqs(event.type, "dblclick")) {
- treeEventType = "dblclick";
- tmp = tools.getMDom(setting, target, [{tagName:"a", attrName:"treeNode"+consts.id.A}]);
- if (tmp) {
- tId = tools.getNodeMainDom(tmp).id;
- nodeEventType = "switchNode";
- }
- }
- if (treeEventType.length > 0 && tId.length == 0) {
- tmp = tools.getMDom(setting, target, [{tagName:"a", attrName:"treeNode"+consts.id.A}]);
- if (tmp) {tId = tools.getNodeMainDom(tmp).id;}
- }
- // event to node
- if (tId.length>0) {
- node = data.getNodeCache(setting, tId);
- switch (nodeEventType) {
- case "switchNode" :
- if (!node.isParent) {
- nodeEventType = "";
- } else if (tools.eqs(event.type, "click")
- || (tools.eqs(event.type, "dblclick") && tools.apply(setting.view.dblClickExpand, [setting.treeId, node], setting.view.dblClickExpand))) {
- nodeEventCallback = handler.onSwitchNode;
- } else {
- nodeEventType = "";
- }
- break;
- case "clickNode" :
- nodeEventCallback = handler.onClickNode;
- break;
- }
- }
- // event to zTree
- switch (treeEventType) {
- case "mousedown" :
- treeEventCallback = handler.onZTreeMousedown;
- break;
- case "mouseup" :
- treeEventCallback = handler.onZTreeMouseup;
- break;
- case "dblclick" :
- treeEventCallback = handler.onZTreeDblclick;
- break;
- case "contextmenu" :
- treeEventCallback = handler.onZTreeContextmenu;
- break;
- }
- var proxyResult = {
- stop: false,
- node: node,
- nodeEventType: nodeEventType,
- nodeEventCallback: nodeEventCallback,
- treeEventType: treeEventType,
- treeEventCallback: treeEventCallback
- };
- return proxyResult
- },
- //default init node of core
- _initNode = function(setting, level, n, parentNode, isFirstNode, isLastNode, openFlag) {
- if (!n) return;
- var r = data.getRoot(setting),
- childKey = setting.data.key.children;
- n.level = level;
- n.tId = setting.treeId + "_" + (++r.zId);
- n.parentTId = parentNode ? parentNode.tId : null;
- n.open = (typeof n.open == "string") ? tools.eqs(n.open, "true") : !!n.open;
- if (n[childKey] && n[childKey].length > 0) {
- n.isParent = true;
- n.zAsync = true;
- } else {
- n.isParent = (typeof n.isParent == "string") ? tools.eqs(n.isParent, "true") : !!n.isParent;
- n.open = (n.isParent && !setting.async.enable) ? n.open : false;
- n.zAsync = !n.isParent;
- }
- n.isFirstNode = isFirstNode;
- n.isLastNode = isLastNode;
- n.getParentNode = function() {return data.getNodeCache(setting, n.parentTId);};
- n.getPreNode = function() {return data.getPreNode(setting, n);};
- n.getNextNode = function() {return data.getNextNode(setting, n);};
- n.isAjaxing = false;
- data.fixPIdKeyValue(setting, n);
- },
- _init = {
- bind: [_bindEvent],
- unbind: [_unbindEvent],
- caches: [_initCache],
- nodes: [_initNode],
- proxys: [_eventProxy],
- roots: [_initRoot],
- beforeA: [],
- afterA: [],
- innerBeforeA: [],
- innerAfterA: [],
- zTreeTools: []
- },
- //method of operate data
- data = {
- addNodeCache: function(setting, node) {
- data.getCache(setting).nodes[data.getNodeCacheId(node.tId)] = node;
- },
- getNodeCacheId: function(tId) {
- return tId.substring(tId.lastIndexOf("_")+1);
- },
- addAfterA: function(afterA) {
- _init.afterA.push(afterA);
- },
- addBeforeA: function(beforeA) {
- _init.beforeA.push(beforeA);
- },
- addInnerAfterA: function(innerAfterA) {
- _init.innerAfterA.push(innerAfterA);
- },
- addInnerBeforeA: function(innerBeforeA) {
- _init.innerBeforeA.push(innerBeforeA);
- },
- addInitBind: function(bindEvent) {
- _init.bind.push(bindEvent);
- },
- addInitUnBind: function(unbindEvent) {
- _init.unbind.push(unbindEvent);
- },
- addInitCache: function(initCache) {
- _init.caches.push(initCache);
- },
- addInitNode: function(initNode) {
- _init.nodes.push(initNode);
- },
- addInitProxy: function(initProxy, isFirst) {
- if (!!isFirst) {
- _init.proxys.splice(0,0,initProxy);
- } else {
- _init.proxys.push(initProxy);
- }
- },
- addInitRoot: function(initRoot) {
- _init.roots.push(initRoot);
- },
- addNodesData: function(setting, parentNode, nodes) {
- var childKey = setting.data.key.children;
- if (!parentNode[childKey]) parentNode[childKey] = [];
- if (parentNode[childKey].length > 0) {
- parentNode[childKey][parentNode[childKey].length - 1].isLastNode = false;
- view.setNodeLineIcos(setting, parentNode[childKey][parentNode[childKey].length - 1]);
- }
- parentNode.isParent = true;
- parentNode[childKey] = parentNode[childKey].concat(nodes);
- },
- addSelectedNode: function(setting, node) {
- var root = data.getRoot(setting);
- if (!data.isSelectedNode(setting, node)) {
- root.curSelectedList.push(node);
- }
- },
- addCreatedNode: function(setting, node) {
- if (!!setting.callback.onNodeCreated || !!setting.view.addDiyDom) {
- var root = data.getRoot(setting);
- root.createdNodes.push(node);
- }
- },
- addZTreeTools: function(zTreeTools) {
- _init.zTreeTools.push(zTreeTools);
- },
- exSetting: function(s) {
- $.extend(true, _setting, s);
- },
- fixPIdKeyValue: function(setting, node) {
- if (setting.data.simpleData.enable) {
- node[setting.data.simpleData.pIdKey] = node.parentTId ? node.getParentNode()[setting.data.simpleData.idKey] : setting.data.simpleData.rootPId;
- }
- },
- getAfterA: function(setting, node, array) {
- for (var i=0, j=_init.afterA.length; i<j; i++) {
- _init.afterA[i].apply(this, arguments);
- }
- },
- getBeforeA: function(setting, node, array) {
- for (var i=0, j=_init.beforeA.length; i<j; i++) {
- _init.beforeA[i].apply(this, arguments);
- }
- },
- getInnerAfterA: function(setting, node, array) {
- for (var i=0, j=_init.innerAfterA.length; i<j; i++) {
- _init.innerAfterA[i].apply(this, arguments);
- }
- },
- getInnerBeforeA: function(setting, node, array) {
- for (var i=0, j=_init.innerBeforeA.length; i<j; i++) {
- _init.innerBeforeA[i].apply(this, arguments);
- }
- },
- getCache: function(setting) {
- return caches[setting.treeId];
- },
- getNextNode: function(setting, node) {
- if (!node) return null;
- var childKey = setting.data.key.children,
- p = node.parentTId ? node.getParentNode() : data.getRoot(setting);
- for (var i=0, l=p[childKey].length-1; i<=l; i++) {
- if (p[childKey][i] === node) {
- return (i==l ? null : p[childKey][i+1]);
- }
- }
- return null;
- },
- getNodeByParam: function(setting, nodes, key, value) {
- if (!nodes || !key) return null;
- var childKey = setting.data.key.children;
- for (var i = 0, l = nodes.length; i < l; i++) {
- if (nodes[i][key] == value) {
- return nodes[i];
- }
- var tmp = data.getNodeByParam(setting, nodes[i][childKey], key, value);
- if (tmp) return tmp;
- }
- return null;
- },
- getNodeCache: function(setting, tId) {
- if (!tId) return null;
- var n = caches[setting.treeId].nodes[data.getNodeCacheId(tId)];
- return n ? n : null;
- },
- getNodeName: function(setting, node) {
- var nameKey = setting.data.key.name;
- return "" + node[nameKey];
- },
- getNodeTitle: function(setting, node) {
- var t = setting.data.key.title === "" ? setting.data.key.name : setting.data.key.title;
- return "" + node[t];
- },
- getNodes: function(setting) {
- return data.getRoot(setting)[setting.data.key.children];
- },
- getNodesByParam: function(setting, nodes, key, value) {
- if (!nodes || !key) return [];
- var childKey = setting.data.key.children,
- result = [];
- for (var i = 0, l = nodes.length; i < l; i++) {
- if (nodes[i][key] == value) {
- result.push(nodes[i]);
- }
- result = result.concat(data.getNodesByParam(setting, nodes[i][childKey], key, value));
- }
- return result;
- },
- getNodesByParamFuzzy: function(setting, nodes, key, value) {
- if (!nodes || !key) return [];
- var childKey = setting.data.key.children,
- result = [];
- value = value.toLowerCase();
- for (var i = 0, l = nodes.length; i < l; i++) {
- if (typeof nodes[i][key] == "string" && nodes[i][key].toLowerCase().indexOf(value)>-1) {
- result.push(nodes[i]);
- }
- result = result.concat(data.getNodesByParamFuzzy(setting, nodes[i][childKey], key, value));
- }
- return result;
- },
- getNodesByFilter: function(setting, nodes, filter, isSingle, invokeParam) {
- if (!nodes) return (isSingle ? null : []);
- var childKey = setting.data.key.children,
- result = isSingle ? null : [];
- for (var i = 0, l = nodes.length; i < l; i++) {
- if (tools.apply(filter, [nodes[i], invokeParam], false)) {
- if (isSingle) {return nodes[i];}
- result.push(nodes[i]);
- }
- var tmpResult = data.getNodesByFilter(setting, nodes[i][childKey], filter, isSingle, invokeParam);
- if (isSingle && !!tmpResult) {return tmpResult;}
- result = isSingle ? tmpResult : result.concat(tmpResult);
- }
- return result;
- },
- getPreNode: function(setting, node) {
- if (!node) return null;
- var childKey = setting.data.key.children,
- p = node.parentTId ? node.getParentNode() : data.getRoot(setting);
- for (var i=0, l=p[childKey].length; i<l; i++) {
- if (p[childKey][i] === node) {
- return (i==0 ? null : p[childKey][i-1]);
- }
- }
- return null;
- },
- getRoot: function(setting) {
- return setting ? roots[setting.treeId] : null;
- },
- getRoots: function() {
- return roots;
- },
- getSetting: function(treeId) {
- return settings[treeId];
- },
- getSettings: function() {
- return settings;
- },
- getZTreeTools: function(treeId) {
- var r = this.getRoot(this.getSetting(treeId));
- return r ? r.treeTools : null;
- },
- initCache: function(setting) {
- for (var i=0, j=_init.caches.length; i<j; i++) {
- _init.caches[i].apply(this, arguments);
- }
- },
- initNode: function(setting, level, node, parentNode, preNode, nextNode) {
- for (var i=0, j=_init.nodes.length; i<j; i++) {
- _init.nodes[i].apply(this, arguments);
- }
- },
- initRoot: function(setting) {
- for (var i=0, j=_init.roots.length; i<j; i++) {
- _init.roots[i].apply(this, arguments);
- }
- },
- isSelectedNode: function(setting, node) {
- var root = data.getRoot(setting);
- for (var i=0, j=root.curSelectedList.length; i<j; i++) {
- if(node === root.curSelectedList[i]) return true;
- }
- return false;
- },
- removeNodeCache: function(setting, node) {
- var childKey = setting.data.key.children;
- if (node[childKey]) {
- for (var i=0, l=node[childKey].length; i<l; i++) {
- arguments.callee(setting, node[childKey][i]);
- }
- }
- data.getCache(setting).nodes[data.getNodeCacheId(node.tId)] = null;
- },
- removeSelectedNode: function(setting, node) {
- var root = data.getRoot(setting);
- for (var i=0, j=root.curSelectedList.length; i<j; i++) {
- if(node === root.curSelectedList[i] || !data.getNodeCache(setting, root.curSelectedList[i].tId)) {
- root.curSelectedList.splice(i, 1);
- i--;j--;
- }
- }
- },
- setCache: function(setting, cache) {
- caches[setting.treeId] = cache;
- },
- setRoot: function(setting, root) {
- roots[setting.treeId] = root;
- },
- setZTreeTools: function(setting, zTreeTools) {
- for (var i=0, j=_init.zTreeTools.length; i<j; i++) {
- _init.zTreeTools[i].apply(this, arguments);
- }
- },
- transformToArrayFormat: function (setting, nodes) {
- if (!nodes) return [];
- var childKey = setting.data.key.children,
- r = [];
- if (tools.isArray(nodes)) {
- for (var i=0, l=nodes.length; i<l; i++) {
- r.push(nodes[i]);
- if (nodes[i][childKey])
- r = r.concat(data.transformToArrayFormat(setting, nodes[i][childKey]));
- }
- } else {
- r.push(nodes);
- if (nodes[childKey])
- r = r.concat(data.transformToArrayFormat(setting, nodes[childKey]));
- }
- return r;
- },
- transformTozTreeFormat: function(setting, sNodes) {
- var i,l,
- key = setting.data.simpleData.idKey,
- parentKey = setting.data.simpleData.pIdKey,
- childKey = setting.data.key.children;
- if (!key || key=="" || !sNodes) return [];
- if (tools.isArray(sNodes)) {
- var r = [];
- var tmpMap = [];
- for (i=0, l=sNodes.length; i<l; i++) {
- tmpMap[sNodes[i][key]] = sNodes[i];
- }
- for (i=0, l=sNodes.length; i<l; i++) {
- if (tmpMap[sNodes[i][parentKey]] && sNodes[i][key] != sNodes[i][parentKey]) {
- if (!tmpMap[sNodes[i][parentKey]][childKey])
- tmpMap[sNodes[i][parentKey]][childKey] = [];
- tmpMap[sNodes[i][parentKey]][childKey].push(sNodes[i]);
- } else {
- r.push(sNodes[i]);
- }
- }
- return r;
- }else {
- return [sNodes];
- }
- }
- },
- //method of event proxy
- event = {
- bindEvent: function(setting) {
- for (var i=0, j=_init.bind.length; i<j; i++) {
- _init.bind[i].apply(this, arguments);
- }
- },
- unbindEvent: function(setting) {
- for (var i=0, j=_init.unbind.length; i<j; i++) {
- _init.unbind[i].apply(this, arguments);
- }
- },
- bindTree: function(setting) {
- var eventParam = {
- treeId: setting.treeId
- },
- o = setting.treeObj;
- if (!setting.view.txtSelectedEnable) {
- // for can't select text
- o.bind('selectstart', function(e){
- var node
- var n = e.originalEvent.srcElement.nodeName.toLowerCase();
- return (n === "input" || n === "textarea" );
- }).css({
- "-moz-user-select":"-moz-none"
- });
- }
- o.bind('click', eventParam, event.proxy);
- o.bind('dblclick', eventParam, event.proxy);
- o.bind('mouseover', eventParam, event.proxy);
- o.bind('mouseout', eventParam, event.proxy);
- o.bind('mousedown', eventParam, event.proxy);
- o.bind('mouseup', eventParam, event.proxy);
- o.bind('contextmenu', eventParam, event.proxy);
- },
- unbindTree: function(setting) {
- var o = setting.treeObj;
- o.unbind('click', event.proxy)
- .unbind('dblclick', event.proxy)
- .unbind('mouseover', event.proxy)
- .unbind('mouseout', event.proxy)
- .unbind('mousedown', event.proxy)
- .unbind('mouseup', event.proxy)
- .unbind('contextmenu', event.proxy);
- },
- doProxy: function(e) {
- var results = [];
- for (var i=0, j=_init.proxys.length; i<j; i++) {
- var proxyResult = _init.proxys[i].apply(this, arguments);
- results.push(proxyResult);
- if (proxyResult.stop) {
- break;
- }
- }
- return results;
- },
- proxy: function(e) {
- var setting = data.getSetting(e.data.treeId);
- if (!tools.uCanDo(setting, e)) return true;
- var results = event.doProxy(e),
- r = true, x = false;
- for (var i=0, l=results.length; i<l; i++) {
- var proxyResult = results[i];
- if (proxyResult.nodeEventCallback) {
- x = true;
- r = proxyResult.nodeEventCallback.apply(proxyResult, [e, proxyResult.node]) && r;
- }
- if (proxyResult.treeEventCallback) {
- x = true;
- r = proxyResult.treeEventCallback.apply(proxyResult, [e, proxyResult.node]) && r;
- }
- }
- return r;
- }
- },
- //method of event handler
- handler = {
- onSwitchNode: function (event, node) {
- var setting = data.getSetting(event.data.treeId);
- if (node.open) {
- if (tools.apply(setting.callback.beforeCollapse, [setting.treeId, node], true) == false) return true;
- data.getRoot(setting).expandTriggerFlag = true;
- view.switchNode(setting, node);
- } else {
- if (tools.apply(setting.callback.beforeExpand, [setting.treeId, node], true) == false) return true;
- data.getRoot(setting).expandTriggerFlag = true;
- view.switchNode(setting, node);
- }
- return true;
- },
- onClickNode: function (event, node) {
- var setting = data.getSetting(event.data.treeId),
- clickFlag = ( (setting.view.autoCancelSelected && (event.ctrlKey || event.metaKey)) && data.isSelectedNode(setting, node)) ? 0 : (setting.view.autoCancelSelected && (event.ctrlKey || event.metaKey) && setting.view.selectedMulti) ? 2 : 1;
- if (tools.apply(setting.callback.beforeClick, [setting.treeId, node, clickFlag], true) == false) return true;
- if (clickFlag === 0) {
- view.cancelPreSelectedNode(setting, node);
- } else {
- view.selectNode(setting, node, clickFlag === 2);
- }
- setting.treeObj.trigger(consts.event.CLICK, [event, setting.treeId, node, clickFlag]);
- return true;
- },
- onZTreeMousedown: function(event, node) {
- var setting = data.getSetting(event.data.treeId);
- if (tools.apply(setting.callback.beforeMouseDown, [setting.treeId, node], true)) {
- tools.apply(setting.callback.onMouseDown, [event, setting.treeId, node]);
- }
- return true;
- },
- onZTreeMouseup: function(event, node) {
- var setting = data.getSetting(event.data.treeId);
- if (tools.apply(setting.callback.beforeMouseUp, [setting.treeId, node], true)) {
- tools.apply(setting.callback.onMouseUp, [event, setting.treeId, node]);
- }
- return true;
- },
- onZTreeDblclick: function(event, node) {
- var setting = data.getSetting(event.data.treeId);
- if (tools.apply(setting.callback.beforeDblClick, [setting.treeId, node], true)) {
- tools.apply(setting.callback.onDblClick, [event, setting.treeId, node]);
- }
- return true;
- },
- onZTreeContextmenu: function(event, node) {
- var setting = data.getSetting(event.data.treeId);
- if (tools.apply(setting.callback.beforeRightClick, [setting.treeId, node], true)) {
- tools.apply(setting.callback.onRightClick, [event, setting.treeId, node]);
- }
- return (typeof setting.callback.onRightClick) != "function";
- }
- },
- //method of tools for zTree
- tools = {
- apply: function(fun, param, defaultValue) {
- if ((typeof fun) == "function") {
- return fun.apply(zt, param?param:[]);
- }
- return defaultValue;
- },
- canAsync: function(setting, node) {
- var childKey = setting.data.key.children;
- return (setting.async.enable && node && node.isParent && !(node.zAsync || (node[childKey] && node[childKey].length > 0)));
- },
- clone: function (obj){
- if (obj === null) return null;
- var o = tools.isArray(obj) ? [] : {};
- for(var i in obj){
- o[i] = (obj[i] instanceof Date) ? new Date(obj[i].getTime()) : (typeof obj[i] === "object" ? arguments.callee(obj[i]) : obj[i]);
- }
- return o;
- },
- eqs: function(str1, str2) {
- return str1.toLowerCase() === str2.toLowerCase();
- },
- isArray: function(arr) {
- return Object.prototype.toString.apply(arr) === "[object Array]";
- },
- $: function(node, exp, setting) {
- if (!!exp && typeof exp != "string") {
- setting = exp;
- exp = "";
- }
- if (typeof node == "string") {
- return $(node, setting ? setting.treeObj.get(0).ownerDocument : null);
- } else {
- return $("#" + node.tId + exp, setting ? setting.treeObj : null);
- }
- },
- getMDom: function (setting, curDom, targetExpr) {
- if (!curDom) return null;
- while (curDom && curDom.id !== setting.treeId) {
- for (var i=0, l=targetExpr.length; curDom.tagName && i<l; i++) {
- if (tools.eqs(curDom.tagName, targetExpr[i].tagName) && curDom.getAttribute(targetExpr[i].attrName) !== null) {
- return curDom;
- }
- }
- curDom = curDom.parentNode;
- }
- return null;
- },
- getNodeMainDom:function(target) {
- return ($(target).parent("li").get(0) || $(target).parentsUntil("li").parent().get(0));
- },
- isChildOrSelf: function(dom, parentId) {
- return ( $(dom).closest("#" + parentId).length> 0 );
- },
- uCanDo: function(setting, e) {
- return true;
- }
- },
- //method of operate ztree dom
- view = {
- addNodes: function(setting, parentNode, newNodes, isSilent) {
- if (setting.data.keep.leaf && parentNode && !parentNode.isParent) {
- return;
- }
- if (!tools.isArray(newNodes)) {
- newNodes = [newNodes];
- }
- if (setting.data.simpleData.enable) {
- newNodes = data.transformTozTreeFormat(setting, newNodes);
- }
- if (parentNode) {
- var target_switchObj = $$(parentNode, consts.id.SWITCH, setting),
- target_icoObj = $$(parentNode, consts.id.ICON, setting),
- target_ulObj = $$(parentNode, consts.id.UL, setting);
- if (!parentNode.open) {
- view.replaceSwitchClass(parentNode, target_switchObj, consts.folder.CLOSE);
- view.replaceIcoClass(parentNode, target_icoObj, consts.folder.CLOSE);
- parentNode.open = false;
- target_ulObj.css({
- "display": "none"
- });
- }
- data.addNodesData(setting, parentNode, newNodes);
- view.createNodes(setting, parentNode.level + 1, newNodes, parentNode);
- if (!isSilent) {
- view.expandCollapseParentNode(setting, parentNode, true);
- }
- } else {
- data.addNodesData(setting, data.getRoot(setting), newNodes);
- view.createNodes(setting, 0, newNodes, null);
- }
- },
- appendNodes: function(setting, level, nodes, parentNode, initFlag, openFlag) {
- if (!nodes) return [];
- var html = [],
- childKey = setting.data.key.children;
- for (var i = 0, l = nodes.length; i < l; i++) {
- var node = nodes[i];
- if (initFlag) {
- var tmpPNode = (parentNode) ? parentNode: data.getRoot(setting),
- tmpPChild = tmpPNode[childKey],
- isFirstNode = ((tmpPChild.length == nodes.length) && (i == 0)),
- isLastNode = (i == (nodes.length - 1));
- data.initNode(setting, level, node, parentNode, isFirstNode, isLastNode, openFlag);
- data.addNodeCache(setting, node);
- }
- var childHtml = [];
- if (node[childKey] && node[childKey].length > 0) {
- //make child html first, because checkType
- childHtml = view.appendNodes(setting, level + 1, node[childKey], node, initFlag, openFlag && node.open);
- }
- if (openFlag) {
- view.makeDOMNodeMainBefore(html, setting, node);
- view.makeDOMNodeLine(html, setting, node);
- data.getBeforeA(setting, node, html);
- view.makeDOMNodeNameBefore(html, setting, node);
- data.getInnerBeforeA(setting, node, html);
- view.makeDOMNodeIcon(html, setting, node);
- data.getInnerAfterA(setting, node, html);
- view.makeDOMNodeNameAfter(html, setting, node);
- data.getAfterA(setting, node, html);
- if (node.isParent && node.open) {
- view.makeUlHtml(setting, node, html, childHtml.join(''));
- }
- view.makeDOMNodeMainAfter(html, setting, node);
- data.addCreatedNode(setting, node);
- }
- }
- return html;
- },
- appendParentULDom: function(setting, node) {
- var html = [],
- nObj = $$(node, setting);
- if (!nObj.get(0) && !!node.parentTId) {
- view.appendParentULDom(setting, node.getParentNode());
- nObj = $$(node, setting);
- }
- var ulObj = $$(node, consts.id.UL, setting);
- if (ulObj.get(0)) {
- ulObj.remove();
- }
- var childKey = setting.data.key.children,
- childHtml = view.appendNodes(setting, node.level+1, node[childKey], node, false, true);
- view.makeUlHtml(setting, node, html, childHtml.join(''));
- nObj.append(html.join(''));
- },
- asyncNode: function(setting, node, isSilent, callback) {
- var i, l;
- if (node && !node.isParent) {
- tools.apply(callback);
- return false;
- } else if (node && node.isAjaxing) {
- return false;
- } else if (tools.apply(setting.callback.beforeAsync, [setting.treeId, node], true) == false) {
- tools.apply(callback);
- return false;
- }
- if (node) {
- node.isAjaxing = true;
- var icoObj = $$(node, consts.id.ICON, setting);
- icoObj.attr({"style":"", "class":consts.className.BUTTON + " " + consts.className.ICO_LOADING});
- }
- var tmpParam = {};
- for (i = 0, l = setting.async.autoParam.length; node && i < l; i++) {
- var pKey = setting.async.autoParam[i].split("="), spKey = pKey;
- if (pKey.length>1) {
- spKey = pKey[1];
- pKey = pKey[0];
- }
- tmpParam[spKey] = node[pKey];
- }
- if (tools.isArray(setting.async.otherParam)) {
- for (i = 0, l = setting.async.otherParam.length; i < l; i += 2) {
- tmpParam[setting.async.otherParam[i]] = setting.async.otherParam[i + 1];
- }
- } else {
- for (var p in setting.async.otherParam) {
- tmpParam[p] = setting.async.otherParam[p];
- }
- }
- var _tmpV = data.getRoot(setting)._ver;
- $.ajax({
- contentType: setting.async.contentType,
- type: setting.async.type,
- url: tools.apply(setting.async.url, [setting.treeId, node], setting.async.url),
- data: tmpParam,
- dataType: setting.async.dataType,
- success: function(msg) {
- if (_tmpV != data.getRoot(setting)._ver) {
- return;
- }
- var newNodes = [];
- try {
- if (!msg || msg.length == 0) {
- newNodes = [];
- } else if (typeof msg == "string") {
- newNodes = eval("(" + msg + ")");
- } else {
- newNodes = msg;
- }
- } catch(err) {
- newNodes = msg;
- }
- if (node) {
- node.isAjaxing = null;
- node.zAsync = true;
- }
- view.setNodeLineIcos(setting, node);
- if (newNodes && newNodes !== "") {
- newNodes = tools.apply(setting.async.dataFilter, [setting.treeId, node, newNodes], newNodes);
- view.addNodes(setting, node, !!newNodes ? tools.clone(newNodes) : [], !!isSilent);
- } else {
- view.addNodes(setting, node, [], !!isSilent);
- }
- setting.treeObj.trigger(consts.event.ASYNC_SUCCESS, [setting.treeId, node, msg]);
- tools.apply(callback);
- },
- error: function(XMLHttpRequest, textStatus, errorThrown) {
- if (_tmpV != data.getRoot(setting)._ver) {
- return;
- }
- if (node) node.isAjaxing = null;
- view.setNodeLineIcos(setting, node);
- setting.treeObj.trigger(consts.event.ASYNC_ERROR, [setting.treeId, node, XMLHttpRequest, textStatus, errorThrown]);
- }
- });
- return true;
- },
- cancelPreSelectedNode: function (setting, node) {
- var list = data.getRoot(setting).curSelectedList;
- for (var i=0, j=list.length-1; j>=i; j--) {
- if (!node || node === list[j]) {
- $$(list[j], consts.id.A, setting).removeClass(consts.node.CURSELECTED);
- if (node) {
- data.removeSelectedNode(setting, node);
- break;
- }
- }
- }
- if (!node) data.getRoot(setting).curSelectedList = [];
- },
- createNodeCallback: function(setting) {
- if (!!setting.callback.onNodeCreated || !!setting.view.addDiyDom) {
- var root = data.getRoot(setting);
- while (root.createdNodes.length>0) {
- var node = root.createdNodes.shift();
- tools.apply(setting.view.addDiyDom, [setting.treeId, node]);
- if (!!setting.callback.onNodeCreated) {
- setting.treeObj.trigger(consts.event.NODECREATED, [setting.treeId, node]);
- }
- }
- }
- },
- createNodes: function(setting, level, nodes, parentNode) {
- if (!nodes || nodes.length == 0) return;
- var root = data.getRoot(setting),
- childKey = setting.data.key.children,
- openFlag = !parentNode || parentNode.open || !!$$(parentNode[childKey][0], setting).get(0);
- root.createdNodes = [];
- var zTreeHtml = view.appendNodes(setting, level, nodes, parentNode, true, openFlag);
- if (!parentNode) {
- setting.treeObj.append(zTreeHtml.join(''));
- } else {
- var ulObj = $$(parentNode, consts.id.UL, setting);
- if (ulObj.get(0)) {
- ulObj.append(zTreeHtml.join(''));
- }
- }
- view.createNodeCallback(setting);
- },
- destroy: function(setting) {
- if (!setting) return;
- data.initCache(setting);
- data.initRoot(setting);
- event.unbindTree(setting);
- event.unbindEvent(setting);
- setting.treeObj.empty();
- delete settings[setting.treeId];
- },
- expandCollapseNode: function(setting, node, expandFlag, animateFlag, callback) {
- var root = data.getRoot(setting),
- childKey = setting.data.key.children;
- if (!node) {
- tools.apply(callback, []);
- return;
- }
- if (root.expandTriggerFlag) {
- var _callback = callback;
- callback = function(){
- if (_callback) _callback();
- if (node.open) {
- setting.treeObj.trigger(consts.event.EXPAND, [setting.treeId, node]);
- } else {
- setting.treeObj.trigger(consts.event.COLLAPSE, [setting.treeId, node]);
- }
- };
- root.expandTriggerFlag = false;
- }
- if (!node.open && node.isParent && ((!$$(node, consts.id.UL, setting).get(0)) || (node[childKey] && node[childKey].length>0 && !$$(node[childKey][0], setting).get(0)))) {
- view.appendParentULDom(setting, node);
- view.createNodeCallback(setting);
- }
- if (node.open == expandFlag) {
- tools.apply(callback, []);
- return;
- }
- var ulObj = $$(node, consts.id.UL, setting),
- switchObj = $$(node, consts.id.SWITCH, setting),
- icoObj = $$(node, consts.id.ICON, setting);
- if (node.isParent) {
- node.open = !node.open;
- if (node.iconOpen && node.iconClose) {
- icoObj.attr("style", view.makeNodeIcoStyle(setting, node));
- }
- if (node.open) {
- view.replaceSwitchClass(node, switchObj, consts.folder.OPEN);
- view.replaceIcoClass(node, icoObj, consts.folder.OPEN);
- if (animateFlag == false || setting.view.expandSpeed == "") {
- ulObj.show();
- tools.apply(callback, []);
- } else {
- if (node[childKey] && node[childKey].length > 0) {
- ulObj.slideDown(setting.view.expandSpeed, callback);
- } else {
- ulObj.show();
- tools.apply(callback, []);
- }
- }
- } else {
- view.replaceSwitchClass(node, switchObj, consts.folder.CLOSE);
- view.replaceIcoClass(node, icoObj, consts.folder.CLOSE);
- if (animateFlag == false || setting.view.expandSpeed == "" || !(node[childKey] && node[childKey].length > 0)) {
- ulObj.hide();
- tools.apply(callback, []);
- } else {
- ulObj.slideUp(setting.view.expandSpeed, callback);
- }
- }
- } else {
- tools.apply(callback, []);
- }
- },
- expandCollapseParentNode: function(setting, node, expandFlag, animateFlag, callback) {
- if (!node) return;
- if (!node.parentTId) {
- view.expandCollapseNode(setting, node, expandFlag, animateFlag, callback);
- return;
- } else {
- view.expandCollapseNode(setting, node, expandFlag, animateFlag);
- }
- if (node.parentTId) {
- view.expandCollapseParentNode(setting, node.getParentNode(), expandFlag, animateFlag, callback);
- }
- },
- expandCollapseSonNode: function(setting, node, expandFlag, animateFlag, callback) {
- var root = data.getRoot(setting),
- childKey = setting.data.key.children,
- treeNodes = (node) ? node[childKey]: root[childKey],
- selfAnimateSign = (node) ? false : animateFlag,
- expandTriggerFlag = data.getRoot(setting).expandTriggerFlag;
- data.getRoot(setting).expandTriggerFlag = false;
- if (treeNodes) {
- for (var i = 0, l = treeNodes.length; i < l; i++) {
- if (treeNodes[i]) view.expandCollapseSonNode(setting, treeNodes[i], expandFlag, selfAnimateSign);
- }
- }
- data.getRoot(setting).expandTriggerFlag = expandTriggerFlag;
- view.expandCollapseNode(setting, node, expandFlag, animateFlag, callback );
- },
- makeDOMNodeIcon: function(html, setting, node) {
- var nameStr = data.getNodeName(setting, node),
- name = setting.view.nameIsHTML ? nameStr : nameStr.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>');
- html.push("<span id='", node.tId, consts.id.ICON,
- "' title='' treeNode", consts.id.ICON," class='", view.makeNodeIcoClass(setting, node),
- "' style='", view.makeNodeIcoStyle(setting, node), "'></span><span id='", node.tId, consts.id.SPAN,
- "'>",name,"</span>");
- },
- makeDOMNodeLine: function(html, setting, node) {
- html.push("<span id='", node.tId, consts.id.SWITCH, "' title='' class='", view.makeNodeLineClass(setting, node), "' treeNode", consts.id.SWITCH,"></span>");
- },
- makeDOMNodeMainAfter: function(html, setting, node) {
- html.push("</li>");
- },
- makeDOMNodeMainBefore: function(html, setting, node) {
- html.push("<li id='", node.tId, "' class='", consts.className.LEVEL, node.level,"' tabindex='0' hidefocus='true' treenode>");
- },
- makeDOMNodeNameAfter: function(html, setting, node) {
- html.push("</a>");
- },
- makeDOMNodeNameBefore: function(html, setting, node) {
- var title = data.getNodeTitle(setting, node),
- url = view.makeNodeUrl(setting, node),
- fontcss = view.makeNodeFontCss(setting, node),
- fontStyle = [];
- for (var f in fontcss) {
- fontStyle.push(f, ":", fontcss[f], ";");
- }
- html.push("<a id='", node.tId, consts.id.A, "' class='", consts.className.LEVEL, node.level,"' treeNode", consts.id.A," onclick=\"", (node.click || ''),
- "\" ", ((url != null && url.length > 0) ? "href='" + url + "'" : ""), " target='",view.makeNodeTarget(node),"' style='", fontStyle.join(''),
- "'");
- if (tools.apply(setting.view.showTitle, [setting.treeId, node], setting.view.showTitle) && title) {html.push("title='", title.replace(/'/g,"'").replace(/</g,'<').replace(/>/g,'>'),"'");}
- html.push(">");
- },
- makeNodeFontCss: function(setting, node) {
- var fontCss = tools.apply(setting.view.fontCss, [setting.treeId, node], setting.view.fontCss);
- return (fontCss && ((typeof fontCss) != "function")) ? fontCss : {};
- },
- makeNodeIcoClass: function(setting, node) {
- var icoCss = ["ico"];
- if (!node.isAjaxing) {
- icoCss[0] = (node.iconSkin ? node.iconSkin + "_" : "") + icoCss[0];
- if (node.isParent) {
- icoCss.push(node.open ? consts.folder.OPEN : consts.folder.CLOSE);
- } else {
- icoCss.push(consts.folder.DOCU);
- }
- }
- return consts.className.BUTTON + " " + icoCss.join('_');
- },
- makeNodeIcoStyle: function(setting, node) {
- var icoStyle = [];
- if (!node.isAjaxing) {
- var icon = (node.isParent && node.iconOpen && node.iconClose) ? (node.open ? node.iconOpen : node.iconClose) : node.icon;
- if (icon) icoStyle.push("background:url(", icon, ") 0 0 no-repeat;");
- if (setting.view.showIcon == false || !tools.apply(setting.view.showIcon, [setting.treeId, node], true)) {
- icoStyle.push("width:0px;height:0px;");
- }
- }
- return icoStyle.join('');
- },
- makeNodeLineClass: function(setting, node) {
- var lineClass = [];
- if (setting.view.showLine) {
- if (node.level == 0 && node.isFirstNode && node.isLastNode) {
- lineClass.push(consts.line.ROOT);
- } else if (node.level == 0 && node.isFirstNode) {
- lineClass.push(consts.line.ROOTS);
- } else if (node.isLastNode) {
- lineClass.push(consts.line.BOTTOM);
- } else {
- lineClass.push(consts.line.CENTER);
- }
- } else {
- lineClass.push(consts.line.NOLINE);
- }
- if (node.isParent) {
- lineClass.push(node.open ? consts.folder.OPEN : consts.folder.CLOSE);
- } else {
- lineClass.push(consts.folder.DOCU);
- }
- return view.makeNodeLineClassEx(node) + lineClass.join('_');
- },
- makeNodeLineClassEx: function(node) {
- return consts.className.BUTTON + " " + consts.className.LEVEL + node.level + " " + consts.className.SWITCH + " ";
- },
- makeNodeTarget: function(node) {
- return (node.target || "_blank");
- },
- makeNodeUrl: function(setting, node) {
- var urlKey = setting.data.key.url;
- return node[urlKey] ? node[urlKey] : null;
- },
- makeUlHtml: function(setting, node, html, content) {
- html.push("<ul id='", node.tId, consts.id.UL, "' class='", consts.className.LEVEL, node.level, " ", view.makeUlLineClass(setting, node), "' style='display:", (node.open ? "block": "none"),"'>");
- html.push(content);
- html.push("</ul>");
- },
- makeUlLineClass: function(setting, node) {
- return ((setting.view.showLine && !node.isLastNode) ? consts.line.LINE : "");
- },
- removeChildNodes: function(setting, node) {
- if (!node) return;
- var childKey = setting.data.key.children,
- nodes = node[childKey];
- if (!nodes) return;
- for (var i = 0, l = nodes.length; i < l; i++) {
- data.removeNodeCache(setting, nodes[i]);
- }
- data.removeSelectedNode(setting);
- delete node[childKey];
- if (!setting.data.keep.parent) {
- node.isParent = false;
- node.open = false;
- var tmp_switchObj = $$(node, consts.id.SWITCH, setting),
- tmp_icoObj = $$(node, consts.id.ICON, setting);
- view.replaceSwitchClass(node, tmp_switchObj, consts.folder.DOCU);
- view.replaceIcoClass(node, tmp_icoObj, consts.folder.DOCU);
- $$(node, consts.id.UL, setting).remove();
- } else {
- $$(node, consts.id.UL, setting).empty();
- }
- },
- setFirstNode: function(setting, parentNode) {
- var childKey = setting.data.key.children, childLength = parentNode[childKey].length;
- if ( childLength > 0) {
- parentNode[childKey][0].isFirstNode = true;
- }
- },
- setLastNode: function(setting, parentNode) {
- var childKey = setting.data.key.children, childLength = parentNode[childKey].length;
- if ( childLength > 0) {
- parentNode[childKey][childLength - 1].isLastNode = true;
- }
- },
- removeNode: function(setting, node) {
- var root = data.getRoot(setting),
- childKey = setting.data.key.children,
- parentNode = (node.parentTId) ? node.getParentNode() : root;
- node.isFirstNode = false;
- node.isLastNode = false;
- node.getPreNode = function() {return null;};
- node.getNextNode = function() {return null;};
- if (!data.getNodeCache(setting, node.tId)) {
- return;
- }
- $$(node, setting).remove();
- data.removeNodeCache(setting, node);
- data.removeSelectedNode(setting, node);
- for (var i = 0, l = parentNode[childKey].length; i < l; i++) {
- if (parentNode[childKey][i].tId == node.tId) {
- parentNode[childKey].splice(i, 1);
- break;
- }
- }
- view.setFirstNode(setting, parentNode);
- view.setLastNode(setting, parentNode);
- var tmp_ulObj,tmp_switchObj,tmp_icoObj,
- childLength = parentNode[childKey].length;
- //repair nodes old parent
- if (!setting.data.keep.parent && childLength == 0) {
- //old parentNode has no child nodes
- parentNode.isParent = false;
- parentNode.open = false;
- tmp_ulObj = $$(parentNode, consts.id.UL, setting);
- tmp_switchObj = $$(parentNode, consts.id.SWITCH, setting);
- tmp_icoObj = $$(parentNode, consts.id.ICON, setting);
- view.replaceSwitchClass(parentNode, tmp_switchObj, consts.folder.DOCU);
- view.replaceIcoClass(parentNode, tmp_icoObj, consts.folder.DOCU);
- tmp_ulObj.css("display", "none");
- } else if (setting.view.showLine && childLength > 0) {
- //old parentNode has child nodes
- var newLast = parentNode[childKey][childLength - 1];
- tmp_ulObj = $$(newLast, consts.id.UL, setting);
- tmp_switchObj = $$(newLast, consts.id.SWITCH, setting);
- tmp_icoObj = $$(newLast, consts.id.ICON, setting);
- if (parentNode == root) {
- if (parentNode[childKey].length == 1) {
- //node was root, and ztree has only one root after move node
- view.replaceSwitchClass(newLast, tmp_switchObj, consts.line.ROOT);
- } else {
- var tmp_first_switchObj = $$(parentNode[childKey][0], consts.id.SWITCH, setting);
- view.replaceSwitchClass(parentNode[childKey][0], tmp_first_switchObj, consts.line.ROOTS);
- view.replaceSwitchClass(newLast, tmp_switchObj, consts.line.BOTTOM);
- }
- } else {
- view.replaceSwitchClass(newLast, tmp_switchObj, consts.line.BOTTOM);
- }
- tmp_ulObj.removeClass(consts.line.LINE);
- }
- },
- replaceIcoClass: function(node, obj, newName) {
- if (!obj || node.isAjaxing) return;
- var tmpName = obj.attr("class");
- if (tmpName == undefined) return;
- var tmpList = tmpName.split("_");
- switch (newName) {
- case consts.folder.OPEN:
- case consts.folder.CLOSE:
- case consts.folder.DOCU:
- tmpList[tmpList.length-1] = newName;
- break;
- }
- obj.attr("class", tmpList.join("_"));
- },
- replaceSwitchClass: function(node, obj, newName) {
- if (!obj) return;
- var tmpName = obj.attr("class");
- if (tmpName == undefined) return;
- var tmpList = tmpName.split("_");
- switch (newName) {
- case consts.line.ROOT:
- case consts.line.ROOTS:
- case consts.line.CENTER:
- case consts.line.BOTTOM:
- case consts.line.NOLINE:
- tmpList[0] = view.makeNodeLineClassEx(node) + newName;
- break;
- case consts.folder.OPEN:
- case consts.folder.CLOSE:
- case consts.folder.DOCU:
- tmpList[1] = newName;
- break;
- }
- obj.attr("class", tmpList.join("_"));
- if (newName !== consts.folder.DOCU) {
- obj.removeAttr("disabled");
- } else {
- obj.attr("disabled", "disabled");
- }
- },
- selectNode: function(setting, node, addFlag) {
- if (!addFlag) {
- view.cancelPreSelectedNode(setting);
- }
- $$(node, consts.id.A, setting).addClass(consts.node.CURSELECTED);
- data.addSelectedNode(setting, node);
- },
- setNodeFontCss: function(setting, treeNode) {
- var aObj = $$(treeNode, consts.id.A, setting),
- fontCss = view.makeNodeFontCss(setting, treeNode);
- if (fontCss) {
- aObj.css(fontCss);
- }
- },
- setNodeLineIcos: function(setting, node) {
- if (!node) return;
- var switchObj = $$(node, consts.id.SWITCH, setting),
- ulObj = $$(node, consts.id.UL, setting),
- icoObj = $$(node, consts.id.ICON, setting),
- ulLine = view.makeUlLineClass(setting, node);
- if (ulLine.length==0) {
- ulObj.removeClass(consts.line.LINE);
- } else {
- ulObj.addClass(ulLine);
- }
- switchObj.attr("class", view.makeNodeLineClass(setting, node));
- if (node.isParent) {
- switchObj.removeAttr("disabled");
- } else {
- switchObj.attr("disabled", "disabled");
- }
- icoObj.removeAttr("style");
- icoObj.attr("style", view.makeNodeIcoStyle(setting, node));
- icoObj.attr("class", view.makeNodeIcoClass(setting, node));
- },
- setNodeName: function(setting, node) {
- var title = data.getNodeTitle(setting, node),
- nObj = $$(node, consts.id.SPAN, setting);
- nObj.empty();
- if (setting.view.nameIsHTML) {
- nObj.html(data.getNodeName(setting, node));
- } else {
- nObj.text(data.getNodeName(setting, node));
- }
- if (tools.apply(setting.view.showTitle, [setting.treeId, node], setting.view.showTitle)) {
- var aObj = $$(node, consts.id.A, setting);
- aObj.attr("title", !title ? "" : title);
- }
- },
- setNodeTarget: function(setting, node) {
- var aObj = $$(node, consts.id.A, setting);
- aObj.attr("target", view.makeNodeTarget(node));
- },
- setNodeUrl: function(setting, node) {
- var aObj = $$(node, consts.id.A, setting),
- url = view.makeNodeUrl(setting, node);
- if (url == null || url.length == 0) {
- aObj.removeAttr("href");
- } else {
- aObj.attr("href", url);
- }
- },
- switchNode: function(setting, node) {
- if (node.open || !tools.canAsync(setting, node)) {
- view.expandCollapseNode(setting, node, !node.open);
- } else if (setting.async.enable) {
- if (!view.asyncNode(setting, node)) {
- view.expandCollapseNode(setting, node, !node.open);
- return;
- }
- } else if (node) {
- view.expandCollapseNode(setting, node, !node.open);
- }
- }
- };
- // zTree defind
- $.fn.zTree = {
- consts : _consts,
- _z : {
- tools: tools,
- view: view,
- event: event,
- data: data
- },
- getZTreeObj: function(treeId) {
- var o = data.getZTreeTools(treeId);
- return o ? o : null;
- },
- destroy: function(treeId) {
- if (!!treeId && treeId.length > 0) {
- view.destroy(data.getSetting(treeId));
- } else {
- for(var s in settings) {
- view.destroy(settings[s]);
- }
- }
- },
- init: function(obj, zSetting, zNodes) {
- var setting = tools.clone(_setting);
- $.extend(true, setting, zSetting);
- setting.treeId = obj.attr("id");
- setting.treeObj = obj;
- setting.treeObj.empty();
- settings[setting.treeId] = setting;
- //For some older browser,(e.g., ie6)
- if(typeof document.body.style.maxHeight === "undefined") {
- setting.view.expandSpeed = "";
- }
- data.initRoot(setting);
- var root = data.getRoot(setting),
- childKey = setting.data.key.children;
- zNodes = zNodes ? tools.clone(tools.isArray(zNodes)? zNodes : [zNodes]) : [];
- if (setting.data.simpleData.enable) {
- root[childKey] = data.transformTozTreeFormat(setting, zNodes);
- } else {
- root[childKey] = zNodes;
- }
- data.initCache(setting);
- event.unbindTree(setting);
- event.bindTree(setting);
- event.unbindEvent(setting);
- event.bindEvent(setting);
- var zTreeTools = {
- setting : setting,
- addNodes : function(parentNode, newNodes, isSilent) {
- if (!newNodes) return null;
- if (!parentNode) parentNode = null;
- if (parentNode && !parentNode.isParent && setting.data.keep.leaf) return null;
- var xNewNodes = tools.clone(tools.isArray(newNodes)? newNodes: [newNodes]);
- function addCallback() {
- view.addNodes(setting, parentNode, xNewNodes, (isSilent==true));
- }
- if (tools.canAsync(setting, parentNode)) {
- view.asyncNode(setting, parentNode, isSilent, addCallback);
- } else {
- addCallback();
- }
- return xNewNodes;
- },
- cancelSelectedNode : function(node) {
- view.cancelPreSelectedNode(setting, node);
- },
- destroy : function() {
- view.destroy(setting);
- },
- expandAll : function(expandFlag) {
- expandFlag = !!expandFlag;
- view.expandCollapseSonNode(setting, null, expandFlag, true);
- return expandFlag;
- },
- expandNode : function(node, expandFlag, sonSign, focus, callbackFlag) {
- if (!node || !node.isParent) return null;
- if (expandFlag !== true && expandFlag !== false) {
- expandFlag = !node.open;
- }
- callbackFlag = !!callbackFlag;
- if (callbackFlag && expandFlag && (tools.apply(setting.callback.beforeExpand, [setting.treeId, node], true) == false)) {
- return null;
- } else if (callbackFlag && !expandFlag && (tools.apply(setting.callback.beforeCollapse, [setting.treeId, node], true) == false)) {
- return null;
- }
- if (expandFlag && node.parentTId) {
- view.expandCollapseParentNode(setting, node.getParentNode(), expandFlag, false);
- }
- if (expandFlag === node.open && !sonSign) {
- return null;
- }
- data.getRoot(setting).expandTriggerFlag = callbackFlag;
- if (!tools.canAsync(setting, node) && sonSign) {
- view.expandCollapseSonNode(setting, node, expandFlag, true, function() {
- if (focus !== false) {try{$$(node, setting).focus().blur();}catch(e){}}
- });
- } else {
- node.open = !expandFlag;
- view.switchNode(this.setting, node);
- if (focus !== false) {try{$$(node, setting).focus().blur();}catch(e){}}
- }
- return expandFlag;
- },
- getNodes : function() {
- return data.getNodes(setting);
- },
- getNodeByParam : function(key, value, parentNode) {
- if (!key) return null;
- return data.getNodeByParam(setting, parentNode?parentNode[setting.data.key.children]:data.getNodes(setting), key, value);
- },
- getNodeByTId : function(tId) {
- return data.getNodeCache(setting, tId);
- },
- getNodesByParam : function(key, value, parentNode) {
- if (!key) return null;
- return data.getNodesByParam(setting, parentNode?parentNode[setting.data.key.children]:data.getNodes(setting), key, value);
- },
- getNodesByParamFuzzy : function(key, value, parentNode) {
- if (!key) return null;
- return data.getNodesByParamFuzzy(setting, parentNode?parentNode[setting.data.key.children]:data.getNodes(setting), key, value);
- },
- getNodesByFilter: function(filter, isSingle, parentNode, invokeParam) {
- isSingle = !!isSingle;
- if (!filter || (typeof filter != "function")) return (isSingle ? null : []);
- return data.getNodesByFilter(setting, parentNode?parentNode[setting.data.key.children]:data.getNodes(setting), filter, isSingle, invokeParam);
- },
- getNodeIndex : function(node) {
- if (!node) return null;
- var childKey = setting.data.key.children,
- parentNode = (node.parentTId) ? node.getParentNode() : data.getRoot(setting);
- for (var i=0, l = parentNode[childKey].length; i < l; i++) {
- if (parentNode[childKey][i] == node) return i;
- }
- return -1;
- },
- getSelectedNodes : function() {
- var r = [], list = data.getRoot(setting).curSelectedList;
- for (var i=0, l=list.length; i<l; i++) {
- r.push(list[i]);
- }
- return r;
- },
- isSelectedNode : function(node) {
- return data.isSelectedNode(setting, node);
- },
- reAsyncChildNodes : function(parentNode, reloadType, isSilent) {
- if (!this.setting.async.enable) return;
- var isRoot = !parentNode;
- if (isRoot) {
- parentNode = data.getRoot(setting);
- }
- if (reloadType=="refresh") {
- var childKey = this.setting.data.key.children;
- for (var i = 0, l = parentNode[childKey] ? parentNode[childKey].length : 0; i < l; i++) {
- data.removeNodeCache(setting, parentNode[childKey][i]);
- }
- data.removeSelectedNode(setting);
- parentNode[childKey] = [];
- if (isRoot) {
- this.setting.treeObj.empty();
- } else {
- var ulObj = $$(parentNode, consts.id.UL, setting);
- ulObj.empty();
- }
- }
- view.asyncNode(this.setting, isRoot? null:parentNode, !!isSilent);
- },
- refresh : function() {
- this.setting.treeObj.empty();
- var root = data.getRoot(setting),
- nodes = root[setting.data.key.children]
- data.initRoot(setting);
- root[setting.data.key.children] = nodes
- data.initCache(setting);
- view.createNodes(setting, 0, root[setting.data.key.children]);
- },
- removeChildNodes : function(node) {
- if (!node) return null;
- var childKey = setting.data.key.children,
- nodes = node[childKey];
- view.removeChildNodes(setting, node);
- return nodes ? nodes : null;
- },
- removeNode : function(node, callbackFlag) {
- if (!node) return;
- callbackFlag = !!callbackFlag;
- if (callbackFlag && tools.apply(setting.callback.beforeRemove, [setting.treeId, node], true) == false) return;
- view.removeNode(setting, node);
- if (callbackFlag) {
- this.setting.treeObj.trigger(consts.event.REMOVE, [setting.treeId, node]);
- }
- },
- selectNode : function(node, addFlag) {
- if (!node) return;
- if (tools.uCanDo(setting)) {
- addFlag = setting.view.selectedMulti && addFlag;
- if (node.parentTId) {
- view.expandCollapseParentNode(setting, node.getParentNode(), true, false, function() {
- try{$$(node, setting).focus().blur();}catch(e){}
- });
- } else {
- try{$$(node, setting).focus().blur();}catch(e){}
- }
- view.selectNode(setting, node, addFlag);
- }
- },
- transformTozTreeNodes : function(simpleNodes) {
- return data.transformTozTreeFormat(setting, simpleNodes);
- },
- transformToArray : function(nodes) {
- return data.transformToArrayFormat(setting, nodes);
- },
- updateNode : function(node, checkTypeFlag) {
- if (!node) return;
- var nObj = $$(node, setting);
- if (nObj.get(0) && tools.uCanDo(setting)) {
- view.setNodeName(setting, node);
- view.setNodeTarget(setting, node);
- view.setNodeUrl(setting, node);
- view.setNodeLineIcos(setting, node);
- view.setNodeFontCss(setting, node);
- }
- }
- }
- root.treeTools = zTreeTools;
- data.setZTreeTools(setting, zTreeTools);
- if (root[childKey] && root[childKey].length > 0) {
- view.createNodes(setting, 0, root[childKey]);
- } else if (setting.async.enable && setting.async.url && setting.async.url !== '') {
- view.asyncNode(setting);
- }
- return zTreeTools;
- }
- };
- var zt = $.fn.zTree,
- $$ = tools.$,
- consts = zt.consts;
- })(jQuery);
- /*
- * JQuery zTree excheck v3.5.16-beta.1
- * http://zTree.me/
- *
- * Copyright (c) 2010 Hunter.z
- *
- * Licensed same as jquery - MIT License
- * http://www.opensource.org/licenses/mit-license.php
- *
- * email: hunter.z@263.net
- * Date: 2014-03-28
- */
- (function($){
- //default consts of excheck
- var _consts = {
- event: {
- CHECK: "ztree_check"
- },
- id: {
- CHECK: "_check"
- },
- checkbox: {
- STYLE: "checkbox",
- DEFAULT: "chk",
- DISABLED: "disable",
- FALSE: "false",
- TRUE: "true",
- FULL: "full",
- PART: "part",
- FOCUS: "focus"
- },
- radio: {
- STYLE: "radio",
- TYPE_ALL: "all",
- TYPE_LEVEL: "level"
- }
- },
- //default setting of excheck
- _setting = {
- check: {
- enable: false,
- autoCheckTrigger: false,
- chkStyle: _consts.checkbox.STYLE,
- nocheckInherit: false,
- chkDisabledInherit: false,
- radioType: _consts.radio.TYPE_LEVEL,
- chkboxType: {
- "Y": "ps",
- "N": "ps"
- }
- },
- data: {
- key: {
- checked: "checked"
- }
- },
- callback: {
- beforeCheck:null,
- onCheck:null
- }
- },
- //default root of excheck
- _initRoot = function (setting) {
- var r = data.getRoot(setting);
- r.radioCheckedList = [];
- },
- //default cache of excheck
- _initCache = function(treeId) {},
- //default bind event of excheck
- _bindEvent = function(setting) {
- var o = setting.treeObj,
- c = consts.event;
- o.bind(c.CHECK, function (event, srcEvent, treeId, node) {
- event.srcEvent = srcEvent;
- tools.apply(setting.callback.onCheck, [event, treeId, node]);
- });
- },
- _unbindEvent = function(setting) {
- var o = setting.treeObj,
- c = consts.event;
- o.unbind(c.CHECK);
- },
- //default event proxy of excheck
- _eventProxy = function(e) {
- var target = e.target,
- setting = data.getSetting(e.data.treeId),
- 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) {
- 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) {
- 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) {
- tId = tools.getNodeMainDom(target).id;
- nodeEventType = "checkNode";
- }
- }
- if (tId.length>0) {
- node = data.getNodeCache(setting, tId);
- switch (nodeEventType) {
- case "checkNode" :
- nodeEventCallback = _handler.onCheckNode;
- break;
- case "mouseoverCheck" :
- nodeEventCallback = _handler.onMouseoverCheck;
- break;
- case "mouseoutCheck" :
- nodeEventCallback = _handler.onMouseoutCheck;
- break;
- }
- }
- var proxyResult = {
- stop: nodeEventType === "checkNode",
- node: node,
- nodeEventType: nodeEventType,
- nodeEventCallback: nodeEventCallback,
- treeEventType: treeEventType,
- treeEventCallback: treeEventCallback
- };
- return proxyResult
- },
- //default init node of excheck
- _initNode = function(setting, level, n, parentNode, isFirstNode, isLastNode, openFlag) {
- if (!n) return;
- var checkedKey = setting.data.key.checked;
- if (typeof n[checkedKey] == "string") n[checkedKey] = tools.eqs(n[checkedKey], "true");
- n[checkedKey] = !!n[checkedKey];
- n.checkedOld = n[checkedKey];
- 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);
- if (typeof n.halfCheck == "string") n.halfCheck = tools.eqs(n.halfCheck, "true");
- n.halfCheck = !!n.halfCheck;
- n.check_Child_State = -1;
- n.check_Focus = false;
- n.getCheckStatus = function() {return data.getCheckStatus(setting, n);};
- 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);
- }
- },
- //add dom for check
- _beforeA = function(setting, node, html) {
- 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>");
- }
- },
- //update zTreeObj, add method of check
- _zTreeTools = function(setting, zTreeTools) {
- zTreeTools.checkNode = function(node, checked, checkTypeFlag, callbackFlag) {
- var checkedKey = this.setting.data.key.checked;
- if (node.chkDisabled === true) return;
- if (checked !== true && checked !== false) {
- checked = !node[checkedKey];
- }
- callbackFlag = !!callbackFlag;
- if (node[checkedKey] === checked && !checkTypeFlag) {
- return;
- } 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);
- view.setChkClass(this.setting, checkObj, node);
- view.repairParentChkClassWithSelf(this.setting, node);
- if (callbackFlag) {
- this.setting.treeObj.trigger(consts.event.CHECK, [null, this.setting.treeId, node]);
- }
- }
- }
- zTreeTools.checkAllNodes = function(checked) {
- view.repairAllChk(this.setting, !!checked);
- }
- zTreeTools.getCheckedNodes = function(checked) {
- var childKey = this.setting.data.key.children;
- checked = (checked !== false);
- return data.getTreeCheckedNodes(this.setting, data.getRoot(this.setting)[childKey], checked);
- }
- zTreeTools.getChangeCheckedNodes = function() {
- var childKey = this.setting.data.key.children;
- return data.getTreeChangeCheckedNodes(this.setting, data.getRoot(this.setting)[childKey]);
- }
- zTreeTools.setChkDisabled = function(node, disabled, inheritParent, inheritChildren) {
- disabled = !!disabled;
- inheritParent = !!inheritParent;
- inheritChildren = !!inheritChildren;
- view.repairSonChkDisabled(this.setting, node, disabled, inheritChildren);
- view.repairParentChkDisabled(this.setting, node.getParentNode(), disabled, inheritParent);
- }
- var _updateNode = zTreeTools.updateNode;
- zTreeTools.updateNode = function(node, checkTypeFlag) {
- if (_updateNode) _updateNode.apply(zTreeTools, arguments);
- if (!node || !this.setting.check.enable) return;
- 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);
- view.setChkClass(this.setting, checkObj, node);
- view.repairParentChkClassWithSelf(this.setting, node);
- }
- }
- },
- //method of operate data
- _data = {
- getRadioCheckedList: function(setting) {
- var checkedList = data.getRoot(setting).radioCheckedList;
- for (var i=0, j=checkedList.length; i<j; i++) {
- if(!data.getNodeCache(setting, checkedList[i].tId)) {
- checkedList.splice(i, 1);
- i--; j--;
- }
- }
- return checkedList;
- },
- getCheckStatus: function(setting, node) {
- if (!setting.check.enable || node.nocheck || node.chkDisabled) return null;
- 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)))
- };
- return r;
- },
- getTreeCheckedNodes: function(setting, nodes, checked, results) {
- 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);
- 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) {
- results.push(nodes[i]);
- if(onlyOne) {
- break;
- }
- }
- data.getTreeCheckedNodes(setting, nodes[i][childKey], checked, results);
- if(onlyOne && results.length > 0) {
- break;
- }
- }
- return results;
- },
- getTreeChangeCheckedNodes: function(setting, nodes, results) {
- if (!nodes) return [];
- var childKey = setting.data.key.children,
- 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) {
- results.push(nodes[i]);
- }
- data.getTreeChangeCheckedNodes(setting, nodes[i][childKey], results);
- }
- return results;
- },
- makeChkFlag: function(setting, node) {
- if (!node) return;
- var childKey = setting.data.key.children,
- checkedKey = setting.data.key.checked,
- chkFlag = -1;
- if (node[childKey]) {
- for (var i = 0, l = node[childKey].length; i < l; i++) {
- var cNode = node[childKey][i];
- var tmp = -1;
- if (setting.check.chkStyle == consts.radio.STYLE) {
- if (cNode.nocheck === true || cNode.chkDisabled === true) {
- tmp = cNode.check_Child_State;
- } else if (cNode.halfCheck === true) {
- tmp = 2;
- } else if (cNode[checkedKey]) {
- tmp = 2;
- } else {
- tmp = cNode.check_Child_State > 0 ? 2:0;
- }
- if (tmp == 2) {
- chkFlag = 2; break;
- } else if (tmp == 0){
- chkFlag = 0;
- }
- } else if (setting.check.chkStyle == consts.checkbox.STYLE) {
- if (cNode.nocheck === true || cNode.chkDisabled === true) {
- tmp = cNode.check_Child_State;
- } else if (cNode.halfCheck === true) {
- tmp = 1;
- } else if (cNode[checkedKey] ) {
- tmp = (cNode.check_Child_State === -1 || cNode.check_Child_State === 2) ? 2 : 1;
- } else {
- tmp = (cNode.check_Child_State > 0) ? 1 : 0;
- }
- if (tmp === 1) {
- chkFlag = 1; break;
- } else if (tmp === 2 && chkFlag > -1 && i > 0 && tmp !== chkFlag) {
- chkFlag = 1; break;
- } else if (chkFlag === 2 && tmp > -1 && tmp < 2) {
- chkFlag = 1; break;
- } else if (tmp > -1) {
- chkFlag = tmp;
- }
- }
- }
- }
- node.check_Child_State = chkFlag;
- }
- },
- //method of event proxy
- _event = {
- },
- //method of event handler
- _handler = {
- onCheckNode: function (event, node) {
- if (node.chkDisabled === true) return false;
- var setting = data.getSetting(event.data.treeId),
- checkedKey = setting.data.key.checked;
- if (tools.apply(setting.callback.beforeCheck, [setting.treeId, node], true) == false) return true;
- node[checkedKey] = !node[checkedKey];
- view.checkNodeRelation(setting, node);
- var checkObj = $$(node, consts.id.CHECK, setting);
- view.setChkClass(setting, checkObj, node);
- view.repairParentChkClassWithSelf(setting, node);
- setting.treeObj.trigger(consts.event.CHECK, [event, setting.treeId, node]);
- return true;
- },
- onMouseoverCheck: function(event, node) {
- if (node.chkDisabled === true) return false;
- var setting = data.getSetting(event.data.treeId),
- checkObj = $$(node, consts.id.CHECK, setting);
- node.check_Focus = true;
- view.setChkClass(setting, checkObj, node);
- return true;
- },
- onMouseoutCheck: function(event, node) {
- if (node.chkDisabled === true) return false;
- var setting = data.getSetting(event.data.treeId),
- checkObj = $$(node, consts.id.CHECK, setting);
- 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,
- childKey = setting.data.key.children,
- checkedKey = setting.data.key.checked,
- r = consts.radio;
- if (setting.check.chkStyle == r.STYLE) {
- var checkedList = data.getRadioCheckedList(setting);
- if (node[checkedKey]) {
- if (setting.check.radioType == r.TYPE_ALL) {
- for (i = checkedList.length-1; i >= 0; i--) {
- pNode = checkedList[i];
- if (pNode[checkedKey] && pNode != node) {
- pNode[checkedKey] = false;
- checkedList.splice(i, 1);
- view.setChkClass(setting, $$(pNode, consts.id.CHECK, setting), pNode);
- if (pNode.parentTId != node.parentTId) {
- view.repairParentChkClassWithSelf(setting, pNode);
- }
- }
- }
- checkedList.push(node);
- } else {
- 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) {
- pNode[checkedKey] = false;
- view.setChkClass(setting, $$(pNode, consts.id.CHECK, setting), pNode);
- }
- }
- }
- } else if (setting.check.radioType == r.TYPE_ALL) {
- for (i = 0, l = checkedList.length; i < l; i++) {
- if (node == checkedList[i]) {
- checkedList.splice(i, 1);
- break;
- }
- }
- }
- } else {
- 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)) {
- view.setSonNodeCheckBox(setting, node, false);
- }
- if (node[checkedKey] && setting.check.chkboxType.Y.indexOf("p") > -1) {
- view.setParentNodeCheckBox(setting, node, true);
- }
- if (!node[checkedKey] && setting.check.chkboxType.N.indexOf("p") > -1) {
- view.setParentNodeCheckBox(setting, node, false);
- }
- }
- },
- makeChkClass: function(setting, node) {
- var checkedKey = setting.data.key.checked,
- c = consts.checkbox, r = consts.radio,
- 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;
- } else {
- fullStyle = node[checkedKey] ? ((node.check_Child_State === 2 || node.check_Child_State === -1) ? c.FULL:c.PART) : ((node.check_Child_State < 1)? 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;
- return consts.className.BUTTON + " " + c.DEFAULT + " " + chkName;
- },
- repairAllChk: function(setting, checked) {
- if (setting.check.enable && setting.check.chkStyle === consts.checkbox.STYLE) {
- var checkedKey = setting.data.key.checked,
- childKey = setting.data.key.children,
- root = data.getRoot(setting);
- for (var i = 0, l = root[childKey].length; i<l ; i++) {
- var node = root[childKey][i];
- if (node.nocheck !== true && node.chkDisabled !== true) {
- node[checkedKey] = checked;
- }
- view.setSonNodeCheckBox(setting, node, checked);
- }
- }
- },
- repairChkClass: function(setting, node) {
- if (!node) return;
- data.makeChkFlag(setting, node);
- if (node.nocheck !== true) {
- var checkObj = $$(node, consts.id.CHECK, setting);
- view.setChkClass(setting, checkObj, node);
- }
- },
- repairParentChkClass: function(setting, node) {
- if (!node || !node.parentTId) return;
- var pNode = node.getParentNode();
- view.repairChkClass(setting, pNode);
- view.repairParentChkClass(setting, pNode);
- },
- repairParentChkClassWithSelf: function(setting, node) {
- if (!node) return;
- var childKey = setting.data.key.children;
- if (node[childKey] && node[childKey].length > 0) {
- view.repairParentChkClass(setting, node[childKey][0]);
- } else {
- view.repairParentChkClass(setting, node);
- }
- },
- repairSonChkDisabled: function(setting, node, chkDisabled, inherit) {
- if (!node) return;
- var childKey = setting.data.key.children;
- if (node.chkDisabled != chkDisabled) {
- node.chkDisabled = chkDisabled;
- }
- view.repairChkClass(setting, node);
- if (node[childKey] && inherit) {
- for (var i = 0, l = node[childKey].length; i < l; i++) {
- var sNode = node[childKey][i];
- view.repairSonChkDisabled(setting, sNode, chkDisabled, inherit);
- }
- }
- },
- repairParentChkDisabled: function(setting, node, chkDisabled, inherit) {
- if (!node) return;
- if (node.chkDisabled != chkDisabled && inherit) {
- node.chkDisabled = chkDisabled;
- }
- view.repairChkClass(setting, node);
- view.repairParentChkDisabled(setting, node.getParentNode(), chkDisabled, inherit);
- },
- setChkClass: function(setting, obj, node) {
- if (!obj) return;
- if (node.nocheck === true) {
- obj.hide();
- } else {
- obj.show();
- }
- obj.attr('class', view.makeChkClass(setting, node));
- },
- setParentNodeCheckBox: function(setting, node, value, srcNode) {
- var childKey = setting.data.key.children,
- checkedKey = setting.data.key.checked,
- checkObj = $$(node, consts.id.CHECK, setting);
- if (!srcNode) srcNode = node;
- data.makeChkFlag(setting, node);
- if (node.nocheck !== true && node.chkDisabled !== true) {
- node[checkedKey] = value;
- view.setChkClass(setting, checkObj, node);
- if (setting.check.autoCheckTrigger && node != srcNode) {
- setting.treeObj.trigger(consts.event.CHECK, [null, setting.treeId, node]);
- }
- }
- if (node.parentTId) {
- var pSign = true;
- 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)) {
- pSign = false;
- break;
- }
- }
- }
- if (pSign) {
- view.setParentNodeCheckBox(setting, node.getParentNode(), value, srcNode);
- }
- }
- },
- setSonNodeCheckBox: function(setting, node, value, srcNode) {
- if (!node) return;
- var childKey = setting.data.key.children,
- checkedKey = setting.data.key.checked,
- checkObj = $$(node, consts.id.CHECK, setting);
- if (!srcNode) srcNode = node;
- var hasDisable = false;
- if (node[childKey]) {
- for (var i = 0, l = node[childKey].length; i < l && node.chkDisabled !== true; i++) {
- var sNode = node[childKey][i];
- view.setSonNodeCheckBox(setting, sNode, value, srcNode);
- if (sNode.chkDisabled === true) hasDisable = true;
- }
- }
- if (node != data.getRoot(setting) && node.chkDisabled !== true) {
- if (hasDisable && node.nocheck !== true) {
- data.makeChkFlag(setting, node);
- }
- 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;
- } else {
- node.check_Child_State = -1;
- }
- view.setChkClass(setting, checkObj, node);
- 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
- };
- $.extend(true, $.fn.zTree.consts, _consts);
- $.extend(true, $.fn.zTree._z, _z);
- var zt = $.fn.zTree,
- tools = zt._z.tools,
- consts = zt.consts,
- view = zt._z.view,
- data = zt._z.data,
- event = zt._z.event,
- $$ = tools.$;
- data.exSetting(_setting);
- data.addInitBind(_bindEvent);
- data.addInitUnBind(_unbindEvent);
- data.addInitCache(_initCache);
- data.addInitNode(_initNode);
- data.addInitProxy(_eventProxy, true);
- data.addInitRoot(_initRoot);
- data.addBeforeA(_beforeA);
- data.addZTreeTools(_zTreeTools);
- var _createNodes = view.createNodes;
- view.createNodes = function(setting, level, nodes, parentNode) {
- if (_createNodes) _createNodes.apply(view, arguments);
- if (!nodes) return;
- view.repairParentChkClassWithSelf(setting, parentNode);
- }
- var _removeNode = view.removeNode;
- view.removeNode = function(setting, node) {
- var parentNode = node.getParentNode();
- if (_removeNode) _removeNode.apply(view, arguments);
- if (!node || !parentNode) return;
- view.repairChkClass(setting, parentNode);
- view.repairParentChkClass(setting, parentNode);
- }
- var _appendNodes = view.appendNodes;
- view.appendNodes = function(setting, level, nodes, parentNode, initFlag, openFlag) {
- var html = "";
- if (_appendNodes) {
- html = _appendNodes.apply(view, arguments);
- }
- if (parentNode) {
- data.makeChkFlag(setting, parentNode);
- }
- return html;
- }
- })(jQuery);
- /*
- * JQuery zTree exedit v3.5.16-beta.1
- * http://zTree.me/
- *
- * Copyright (c) 2010 Hunter.z
- *
- * Licensed same as jquery - MIT License
- * http://www.opensource.org/licenses/mit-license.php
- *
- * email: hunter.z@263.net
- * Date: 2014-03-28
- */
- (function($){
- //default consts of exedit
- var _consts = {
- event: {
- DRAG: "ztree_drag",
- DROP: "ztree_drop",
- RENAME: "ztree_rename",
- DRAGMOVE:"ztree_dragmove"
- },
- id: {
- EDIT: "_edit",
- INPUT: "_input",
- REMOVE: "_remove"
- },
- move: {
- TYPE_INNER: "inner",
- TYPE_PREV: "prev",
- TYPE_NEXT: "next"
- },
- node: {
- CURSELECTED_EDIT: "curSelectedNode_Edit",
- TMPTARGET_TREE: "tmpTargetzTree",
- TMPTARGET_NODE: "tmpTargetNode"
- }
- },
- //default setting of exedit
- _setting = {
- edit: {
- enable: false,
- editNameSelectAll: false,
- showRemoveBtn: true,
- showRenameBtn: true,
- removeTitle: "remove",
- renameTitle: "rename",
- drag: {
- autoExpandTrigger: false,
- isCopy: true,
- isMove: true,
- prev: true,
- next: true,
- inner: true,
- minMoveSize: 5,
- borderMax: 10,
- borderMin: -5,
- maxShowNodeNum: 5,
- autoOpenTime: 500
- }
- },
- view: {
- addHoverDom: null,
- removeHoverDom: null
- },
- callback: {
- beforeDrag:null,
- beforeDragOpen:null,
- beforeDrop:null,
- beforeEditName:null,
- beforeRename:null,
- onDrag:null,
- onDragMove:null,
- onDrop:null,
- onRename:null
- }
- },
- //default root of exedit
- _initRoot = function (setting) {
- var r = data.getRoot(setting), rs = data.getRoots();
- r.curEditNode = null;
- r.curEditInput = null;
- r.curHoverNode = null;
- r.dragFlag = 0;
- r.dragNodeShowBefore = [];
- r.dragMaskList = new Array();
- rs.showHoverDom = true;
- },
- //default cache of exedit
- _initCache = function(treeId) {},
- //default bind event of exedit
- _bindEvent = function(setting) {
- var o = setting.treeObj;
- var c = consts.event;
- o.bind(c.RENAME, function (event, treeId, treeNode, isCancel) {
- tools.apply(setting.callback.onRename, [event, treeId, treeNode, isCancel]);
- });
- o.bind(c.DRAG, function (event, srcEvent, treeId, treeNodes) {
- tools.apply(setting.callback.onDrag, [srcEvent, treeId, treeNodes]);
- });
- o.bind(c.DRAGMOVE,function(event, srcEvent, treeId, treeNodes){
- tools.apply(setting.callback.onDragMove,[srcEvent, treeId, treeNodes]);
- });
- o.bind(c.DROP, function (event, srcEvent, treeId, treeNodes, targetNode, moveType, isCopy) {
- tools.apply(setting.callback.onDrop, [srcEvent, treeId, treeNodes, targetNode, moveType, isCopy]);
- });
- },
- _unbindEvent = function(setting) {
- var o = setting.treeObj;
- var c = consts.event;
- o.unbind(c.RENAME);
- o.unbind(c.DRAG);
- o.unbind(c.DRAGMOVE);
- o.unbind(c.DROP);
- },
- //default event proxy of exedit
- _eventProxy = function(e) {
- var target = e.target,
- setting = data.getSetting(e.data.treeId),
- relatedTarget = e.relatedTarget,
- tId = "", node = null,
- nodeEventType = "", treeEventType = "",
- nodeEventCallback = null, treeEventCallback = null,
- tmp = null;
- if (tools.eqs(e.type, "mouseover")) {
- tmp = tools.getMDom(setting, target, [{tagName:"a", attrName:"treeNode"+consts.id.A}]);
- if (tmp) {
- tId = tools.getNodeMainDom(tmp).id;
- nodeEventType = "hoverOverNode";
- }
- } else if (tools.eqs(e.type, "mouseout")) {
- tmp = tools.getMDom(setting, relatedTarget, [{tagName:"a", attrName:"treeNode"+consts.id.A}]);
- if (!tmp) {
- tId = "remove";
- nodeEventType = "hoverOutNode";
- }
- } else if (tools.eqs(e.type, "mousedown")) {
- tmp = tools.getMDom(setting, target, [{tagName:"a", attrName:"treeNode"+consts.id.A}]);
- if (tmp) {
- tId = tools.getNodeMainDom(tmp).id;
- nodeEventType = "mousedownNode";
- }
- }
- if (tId.length>0) {
- node = data.getNodeCache(setting, tId);
- switch (nodeEventType) {
- case "mousedownNode" :
- nodeEventCallback = _handler.onMousedownNode;
- break;
- case "hoverOverNode" :
- nodeEventCallback = _handler.onHoverOverNode;
- break;
- case "hoverOutNode" :
- nodeEventCallback = _handler.onHoverOutNode;
- break;
- }
- }
- var proxyResult = {
- stop: false,
- node: node,
- nodeEventType: nodeEventType,
- nodeEventCallback: nodeEventCallback,
- treeEventType: treeEventType,
- treeEventCallback: treeEventCallback
- };
- return proxyResult
- },
- //default init node of exedit
- _initNode = function(setting, level, n, parentNode, isFirstNode, isLastNode, openFlag) {
- if (!n) return;
- n.isHover = false;
- n.editNameFlag = false;
- },
- //update zTreeObj, add method of edit
- _zTreeTools = function(setting, zTreeTools) {
- zTreeTools.cancelEditName = function(newName) {
- var root = data.getRoot(this.setting);
- if (!root.curEditNode) return;
- view.cancelCurEditNode(this.setting, newName?newName:null, true);
- }
- zTreeTools.copyNode = function(targetNode, node, moveType, isSilent) {
- if (!node) return null;
- if (targetNode && !targetNode.isParent && this.setting.data.keep.leaf && moveType === consts.move.TYPE_INNER) return null;
- var _this = this,
- newNode = tools.clone(node);
- if (!targetNode) {
- targetNode = null;
- moveType = consts.move.TYPE_INNER;
- }
- if (moveType == consts.move.TYPE_INNER) {
- function copyCallback() {
- view.addNodes(_this.setting, targetNode, [newNode], isSilent);
- }
- if (tools.canAsync(this.setting, targetNode)) {
- view.asyncNode(this.setting, targetNode, isSilent, copyCallback);
- } else {
- copyCallback();
- }
- } else {
- view.addNodes(this.setting, targetNode.parentNode, [newNode], isSilent);
- view.moveNode(this.setting, targetNode, newNode, moveType, false, isSilent);
- }
- return newNode;
- }
- zTreeTools.editName = function(node) {
- if (!node || !node.tId || node !== data.getNodeCache(this.setting, node.tId)) return;
- if (node.parentTId) view.expandCollapseParentNode(this.setting, node.getParentNode(), true);
- view.editNode(this.setting, node)
- }
- zTreeTools.moveNode = function(targetNode, node, moveType, isSilent) {
- if (!node) return node;
- if (targetNode && !targetNode.isParent && this.setting.data.keep.leaf && moveType === consts.move.TYPE_INNER) {
- return null;
- } else if (targetNode && ((node.parentTId == targetNode.tId && moveType == consts.move.TYPE_INNER) || $$(node, this.setting).find("#" + targetNode.tId).length > 0)) {
- return null;
- } else if (!targetNode) {
- targetNode = null;
- }
- var _this = this;
- function moveCallback() {
- view.moveNode(_this.setting, targetNode, node, moveType, false, isSilent);
- }
- if (tools.canAsync(this.setting, targetNode) && moveType === consts.move.TYPE_INNER) {
- view.asyncNode(this.setting, targetNode, isSilent, moveCallback);
- } else {
- moveCallback();
- }
- return node;
- }
- zTreeTools.setEditable = function(editable) {
- this.setting.edit.enable = editable;
- return this.refresh();
- }
- },
- //method of operate data
- _data = {
- setSonNodeLevel: function(setting, parentNode, node) {
- if (!node) return;
- var childKey = setting.data.key.children;
- node.level = (parentNode)? parentNode.level + 1 : 0;
- if (!node[childKey]) return;
- for (var i = 0, l = node[childKey].length; i < l; i++) {
- if (node[childKey][i]) data.setSonNodeLevel(setting, node, node[childKey][i]);
- }
- }
- },
- //method of event proxy
- _event = {
- },
- //method of event handler
- _handler = {
- onHoverOverNode: function(event, node) {
- var setting = data.getSetting(event.data.treeId),
- root = data.getRoot(setting);
- if (root.curHoverNode != node) {
- _handler.onHoverOutNode(event);
- }
- root.curHoverNode = node;
- view.addHoverDom(setting, node);
- },
- onHoverOutNode: function(event, node) {
- var setting = data.getSetting(event.data.treeId),
- root = data.getRoot(setting);
- if (root.curHoverNode && !data.isSelectedNode(setting, root.curHoverNode)) {
- view.removeTreeDom(setting, root.curHoverNode);
- root.curHoverNode = null;
- }
- },
- onMousedownNode: function(eventMouseDown, _node) {
- var i,l,
- setting = data.getSetting(eventMouseDown.data.treeId),
- root = data.getRoot(setting), roots = data.getRoots();
- //right click can't drag & drop
- if (eventMouseDown.button == 2 || !setting.edit.enable || (!setting.edit.drag.isCopy && !setting.edit.drag.isMove)) return true;
- //input of edit node name can't drag & drop
- var target = eventMouseDown.target,
- _nodes = data.getRoot(setting).curSelectedList,
- nodes = [];
- if (!data.isSelectedNode(setting, _node)) {
- nodes = [_node];
- } else {
- for (i=0, l=_nodes.length; i<l; i++) {
- if (_nodes[i].editNameFlag && tools.eqs(target.tagName, "input") && target.getAttribute("treeNode"+consts.id.INPUT) !== null) {
- return true;
- }
- nodes.push(_nodes[i]);
- if (nodes[0].parentTId !== _nodes[i].parentTId) {
- nodes = [_node];
- break;
- }
- }
- }
- view.editNodeBlur = true;
- view.cancelCurEditNode(setting);
- var doc = $(setting.treeObj.get(0).ownerDocument),
- body = $(setting.treeObj.get(0).ownerDocument.body), curNode, tmpArrow, tmpTarget,
- isOtherTree = false,
- targetSetting = setting,
- sourceSetting = setting,
- preNode, nextNode,
- preTmpTargetNodeId = null,
- preTmpMoveType = null,
- tmpTargetNodeId = null,
- moveType = consts.move.TYPE_INNER,
- mouseDownX = eventMouseDown.clientX,
- mouseDownY = eventMouseDown.clientY,
- startTime = (new Date()).getTime();
- if (tools.uCanDo(setting)) {
- doc.bind("mousemove", _docMouseMove);
- }
- function _docMouseMove(event) {
- //avoid start drag after click node
- if (root.dragFlag == 0 && Math.abs(mouseDownX - event.clientX) < setting.edit.drag.minMoveSize
- && Math.abs(mouseDownY - event.clientY) < setting.edit.drag.minMoveSize) {
- return true;
- }
- var i, l, tmpNode, tmpDom, tmpNodes,
- childKey = setting.data.key.children;
- body.css("cursor", "pointer");
- if (root.dragFlag == 0) {
- if (tools.apply(setting.callback.beforeDrag, [setting.treeId, nodes], true) == false) {
- _docMouseUp(event);
- return true;
- }
- for (i=0, l=nodes.length; i<l; i++) {
- if (i==0) {
- root.dragNodeShowBefore = [];
- }
- tmpNode = nodes[i];
- if (tmpNode.isParent && tmpNode.open) {
- view.expandCollapseNode(setting, tmpNode, !tmpNode.open);
- root.dragNodeShowBefore[tmpNode.tId] = true;
- } else {
- root.dragNodeShowBefore[tmpNode.tId] = false;
- }
- }
- root.dragFlag = 1;
- roots.showHoverDom = false;
- tools.showIfameMask(setting, true);
- //sort
- var isOrder = true, lastIndex = -1;
- if (nodes.length>1) {
- var pNodes = nodes[0].parentTId ? nodes[0].getParentNode()[childKey] : data.getNodes(setting);
- tmpNodes = [];
- for (i=0, l=pNodes.length; i<l; i++) {
- if (root.dragNodeShowBefore[pNodes[i].tId] !== undefined) {
- if (isOrder && lastIndex > -1 && (lastIndex+1) !== i) {
- isOrder = false;
- }
- tmpNodes.push(pNodes[i]);
- lastIndex = i;
- }
- if (nodes.length === tmpNodes.length) {
- nodes = tmpNodes;
- break;
- }
- }
- }
- if (isOrder) {
- preNode = nodes[0].getPreNode();
- nextNode = nodes[nodes.length-1].getNextNode();
- }
- //set node in selected
- curNode = $$("<ul class='zTreeDragUL'></ul>", setting);
- for (i=0, l=nodes.length; i<l; i++) {
- tmpNode = nodes[i];
- tmpNode.editNameFlag = false;
- view.selectNode(setting, tmpNode, i>0);
- view.removeTreeDom(setting, tmpNode);
- if (i > setting.edit.drag.maxShowNodeNum-1) {
- continue;
- }
- tmpDom = $$("<li id='"+ tmpNode.tId +"_tmp'></li>", setting);
- tmpDom.append($$(tmpNode, consts.id.A, setting).clone());
- tmpDom.css("padding", "0");
- tmpDom.children("#" + tmpNode.tId + consts.id.A).removeClass(consts.node.CURSELECTED);
- curNode.append(tmpDom);
- if (i == setting.edit.drag.maxShowNodeNum-1) {
- tmpDom = $$("<li id='"+ tmpNode.tId +"_moretmp'><a> ... </a></li>", setting);
- curNode.append(tmpDom);
- }
- }
- curNode.attr("id", nodes[0].tId + consts.id.UL + "_tmp");
- curNode.addClass(setting.treeObj.attr("class"));
- curNode.appendTo(body);
- tmpArrow = $$("<span class='tmpzTreeMove_arrow'></span>", setting);
- tmpArrow.attr("id", "zTreeMove_arrow_tmp");
- tmpArrow.appendTo(body);
- setting.treeObj.trigger(consts.event.DRAG, [event, setting.treeId, nodes]);
- }
- if (root.dragFlag == 1) {
- if (tmpTarget && tmpArrow.attr("id") == event.target.id && tmpTargetNodeId && (event.clientX + doc.scrollLeft()+2) > ($("#" + tmpTargetNodeId + consts.id.A, tmpTarget).offset().left)) {
- var xT = $("#" + tmpTargetNodeId + consts.id.A, tmpTarget);
- event.target = (xT.length > 0) ? xT.get(0) : event.target;
- } else if (tmpTarget) {
- tmpTarget.removeClass(consts.node.TMPTARGET_TREE);
- if (tmpTargetNodeId) $("#" + tmpTargetNodeId + consts.id.A, tmpTarget).removeClass(consts.node.TMPTARGET_NODE + "_" + consts.move.TYPE_PREV)
- .removeClass(consts.node.TMPTARGET_NODE + "_" + _consts.move.TYPE_NEXT).removeClass(consts.node.TMPTARGET_NODE + "_" + _consts.move.TYPE_INNER);
- }
- tmpTarget = null;
- tmpTargetNodeId = null;
- //judge drag & drop in multi ztree
- isOtherTree = false;
- targetSetting = setting;
- var settings = data.getSettings();
- for (var s in settings) {
- if (settings[s].treeId && settings[s].edit.enable && settings[s].treeId != setting.treeId
- && (event.target.id == settings[s].treeId || $(event.target).parents("#" + settings[s].treeId).length>0)) {
- isOtherTree = true;
- targetSetting = settings[s];
- }
- }
- var docScrollTop = doc.scrollTop(),
- docScrollLeft = doc.scrollLeft(),
- treeOffset = targetSetting.treeObj.offset(),
- scrollHeight = targetSetting.treeObj.get(0).scrollHeight,
- scrollWidth = targetSetting.treeObj.get(0).scrollWidth,
- dTop = (event.clientY + docScrollTop - treeOffset.top),
- dBottom = (targetSetting.treeObj.height() + treeOffset.top - event.clientY - docScrollTop),
- dLeft = (event.clientX + docScrollLeft - treeOffset.left),
- dRight = (targetSetting.treeObj.width() + treeOffset.left - event.clientX - docScrollLeft),
- isTop = (dTop < setting.edit.drag.borderMax && dTop > setting.edit.drag.borderMin),
- isBottom = (dBottom < setting.edit.drag.borderMax && dBottom > setting.edit.drag.borderMin),
- isLeft = (dLeft < setting.edit.drag.borderMax && dLeft > setting.edit.drag.borderMin),
- isRight = (dRight < setting.edit.drag.borderMax && dRight > setting.edit.drag.borderMin),
- isTreeInner = dTop > setting.edit.drag.borderMin && dBottom > setting.edit.drag.borderMin && dLeft > setting.edit.drag.borderMin && dRight > setting.edit.drag.borderMin,
- isTreeTop = (isTop && targetSetting.treeObj.scrollTop() <= 0),
- isTreeBottom = (isBottom && (targetSetting.treeObj.scrollTop() + targetSetting.treeObj.height()+10) >= scrollHeight),
- isTreeLeft = (isLeft && targetSetting.treeObj.scrollLeft() <= 0),
- isTreeRight = (isRight && (targetSetting.treeObj.scrollLeft() + targetSetting.treeObj.width()+10) >= scrollWidth);
- if (event.target && tools.isChildOrSelf(event.target, targetSetting.treeId)) {
- //get node <li> dom
- var targetObj = event.target;
- while (targetObj && targetObj.tagName && !tools.eqs(targetObj.tagName, "li") && targetObj.id != targetSetting.treeId) {
- targetObj = targetObj.parentNode;
- }
- var canMove = true;
- //don't move to self or children of self
- for (i=0, l=nodes.length; i<l; i++) {
- tmpNode = nodes[i];
- if (targetObj.id === tmpNode.tId) {
- canMove = false;
- break;
- } else if ($$(tmpNode, setting).find("#" + targetObj.id).length > 0) {
- canMove = false;
- break;
- }
- }
- if (canMove && event.target && tools.isChildOrSelf(event.target, targetObj.id + consts.id.A)) {
- tmpTarget = $(targetObj);
- tmpTargetNodeId = targetObj.id;
- }
- }
- //the mouse must be in zTree
- tmpNode = nodes[0];
- if (isTreeInner && tools.isChildOrSelf(event.target, targetSetting.treeId)) {
- //judge mouse move in root of ztree
- if (!tmpTarget && (event.target.id == targetSetting.treeId || isTreeTop || isTreeBottom || isTreeLeft || isTreeRight) && (isOtherTree || (!isOtherTree && tmpNode.parentTId))) {
- tmpTarget = targetSetting.treeObj;
- }
- //auto scroll top
- if (isTop) {
- targetSetting.treeObj.scrollTop(targetSetting.treeObj.scrollTop()-10);
- } else if (isBottom) {
- targetSetting.treeObj.scrollTop(targetSetting.treeObj.scrollTop()+10);
- }
- if (isLeft) {
- targetSetting.treeObj.scrollLeft(targetSetting.treeObj.scrollLeft()-10);
- } else if (isRight) {
- targetSetting.treeObj.scrollLeft(targetSetting.treeObj.scrollLeft()+10);
- }
- //auto scroll left
- if (tmpTarget && tmpTarget != targetSetting.treeObj && tmpTarget.offset().left < targetSetting.treeObj.offset().left) {
- targetSetting.treeObj.scrollLeft(targetSetting.treeObj.scrollLeft()+ tmpTarget.offset().left - targetSetting.treeObj.offset().left);
- }
- }
- curNode.css({
- "top": (event.clientY + docScrollTop + 3) + "px",
- "left": (event.clientX + docScrollLeft + 3) + "px"
- });
- var dX = 0;
- var dY = 0;
- if (tmpTarget && tmpTarget.attr("id")!=targetSetting.treeId) {
- var tmpTargetNode = tmpTargetNodeId == null ? null: data.getNodeCache(targetSetting, tmpTargetNodeId),
- isCopy = ((event.ctrlKey || event.metaKey) && setting.edit.drag.isMove && setting.edit.drag.isCopy) || (!setting.edit.drag.isMove && setting.edit.drag.isCopy),
- isPrev = !!(preNode && tmpTargetNodeId === preNode.tId),
- isNext = !!(nextNode && tmpTargetNodeId === nextNode.tId),
- isInner = (tmpNode.parentTId && tmpNode.parentTId == tmpTargetNodeId),
- canPrev = (isCopy || !isNext) && tools.apply(targetSetting.edit.drag.prev, [targetSetting.treeId, nodes, tmpTargetNode], !!targetSetting.edit.drag.prev),
- canNext = (isCopy || !isPrev) && tools.apply(targetSetting.edit.drag.next, [targetSetting.treeId, nodes, tmpTargetNode], !!targetSetting.edit.drag.next),
- canInner = (isCopy || !isInner) && !(targetSetting.data.keep.leaf && !tmpTargetNode.isParent) && tools.apply(targetSetting.edit.drag.inner, [targetSetting.treeId, nodes, tmpTargetNode], !!targetSetting.edit.drag.inner);
- if (!canPrev && !canNext && !canInner) {
- tmpTarget = null;
- tmpTargetNodeId = "";
- moveType = consts.move.TYPE_INNER;
- tmpArrow.css({
- "display":"none"
- });
- if (window.zTreeMoveTimer) {
- clearTimeout(window.zTreeMoveTimer);
- window.zTreeMoveTargetNodeTId = null
- }
- } else {
- var tmpTargetA = $("#" + tmpTargetNodeId + consts.id.A, tmpTarget),
- tmpNextA = tmpTargetNode.isLastNode ? null : $("#" + tmpTargetNode.getNextNode().tId + consts.id.A, tmpTarget.next()),
- tmpTop = tmpTargetA.offset().top,
- tmpLeft = tmpTargetA.offset().left,
- prevPercent = canPrev ? (canInner ? 0.25 : (canNext ? 0.5 : 1) ) : -1,
- nextPercent = canNext ? (canInner ? 0.75 : (canPrev ? 0.5 : 0) ) : -1,
- dY_percent = (event.clientY + docScrollTop - tmpTop)/tmpTargetA.height();
- if ((prevPercent==1 ||dY_percent<=prevPercent && dY_percent>=-.2) && canPrev) {
- dX = 1 - tmpArrow.width();
- dY = tmpTop - tmpArrow.height()/2;
- moveType = consts.move.TYPE_PREV;
- } else if ((nextPercent==0 || dY_percent>=nextPercent && dY_percent<=1.2) && canNext) {
- dX = 1 - tmpArrow.width();
- dY = (tmpNextA == null || (tmpTargetNode.isParent && tmpTargetNode.open)) ? (tmpTop + tmpTargetA.height() - tmpArrow.height()/2) : (tmpNextA.offset().top - tmpArrow.height()/2);
- moveType = consts.move.TYPE_NEXT;
- }else {
- dX = 5 - tmpArrow.width();
- dY = tmpTop;
- moveType = consts.move.TYPE_INNER;
- }
- tmpArrow.css({
- "display":"block",
- "top": dY + "px",
- "left": (tmpLeft + dX) + "px"
- });
- tmpTargetA.addClass(consts.node.TMPTARGET_NODE + "_" + moveType);
- if (preTmpTargetNodeId != tmpTargetNodeId || preTmpMoveType != moveType) {
- startTime = (new Date()).getTime();
- }
- if (tmpTargetNode && tmpTargetNode.isParent && moveType == consts.move.TYPE_INNER) {
- var startTimer = true;
- if (window.zTreeMoveTimer && window.zTreeMoveTargetNodeTId !== tmpTargetNode.tId) {
- clearTimeout(window.zTreeMoveTimer);
- window.zTreeMoveTargetNodeTId = null;
- }else if (window.zTreeMoveTimer && window.zTreeMoveTargetNodeTId === tmpTargetNode.tId) {
- startTimer = false;
- }
- if (startTimer) {
- window.zTreeMoveTimer = setTimeout(function() {
- if (moveType != consts.move.TYPE_INNER) return;
- if (tmpTargetNode && tmpTargetNode.isParent && !tmpTargetNode.open && (new Date()).getTime() - startTime > targetSetting.edit.drag.autoOpenTime
- && tools.apply(targetSetting.callback.beforeDragOpen, [targetSetting.treeId, tmpTargetNode], true)) {
- view.switchNode(targetSetting, tmpTargetNode);
- if (targetSetting.edit.drag.autoExpandTrigger) {
- targetSetting.treeObj.trigger(consts.event.EXPAND, [targetSetting.treeId, tmpTargetNode]);
- }
- }
- }, targetSetting.edit.drag.autoOpenTime+50);
- window.zTreeMoveTargetNodeTId = tmpTargetNode.tId;
- }
- }
- }
- } else {
- moveType = consts.move.TYPE_INNER;
- if (tmpTarget && tools.apply(targetSetting.edit.drag.inner, [targetSetting.treeId, nodes, null], !!targetSetting.edit.drag.inner)) {
- tmpTarget.addClass(consts.node.TMPTARGET_TREE);
- } else {
- tmpTarget = null;
- }
- tmpArrow.css({
- "display":"none"
- });
- if (window.zTreeMoveTimer) {
- clearTimeout(window.zTreeMoveTimer);
- window.zTreeMoveTargetNodeTId = null;
- }
- }
- preTmpTargetNodeId = tmpTargetNodeId;
- preTmpMoveType = moveType;
- setting.treeObj.trigger(consts.event.DRAGMOVE, [event, setting.treeId, nodes]);
- }
- return false;
- }
- doc.bind("mouseup", _docMouseUp);
- function _docMouseUp(event) {
- if (window.zTreeMoveTimer) {
- clearTimeout(window.zTreeMoveTimer);
- window.zTreeMoveTargetNodeTId = null;
- }
- preTmpTargetNodeId = null;
- preTmpMoveType = null;
- doc.unbind("mousemove", _docMouseMove);
- doc.unbind("mouseup", _docMouseUp);
- doc.unbind("selectstart", _docSelect);
- body.css("cursor", "auto");
- if (tmpTarget) {
- tmpTarget.removeClass(consts.node.TMPTARGET_TREE);
- if (tmpTargetNodeId) $("#" + tmpTargetNodeId + consts.id.A, tmpTarget).removeClass(consts.node.TMPTARGET_NODE + "_" + consts.move.TYPE_PREV)
- .removeClass(consts.node.TMPTARGET_NODE + "_" + _consts.move.TYPE_NEXT).removeClass(consts.node.TMPTARGET_NODE + "_" + _consts.move.TYPE_INNER);
- }
- tools.showIfameMask(setting, false);
- roots.showHoverDom = true;
- if (root.dragFlag == 0) return;
- root.dragFlag = 0;
- var i, l, tmpNode;
- for (i=0, l=nodes.length; i<l; i++) {
- tmpNode = nodes[i];
- if (tmpNode.isParent && root.dragNodeShowBefore[tmpNode.tId] && !tmpNode.open) {
- view.expandCollapseNode(setting, tmpNode, !tmpNode.open);
- delete root.dragNodeShowBefore[tmpNode.tId];
- }
- }
- if (curNode) curNode.remove();
- if (tmpArrow) tmpArrow.remove();
- var isCopy = ((event.ctrlKey || event.metaKey) && setting.edit.drag.isMove && setting.edit.drag.isCopy) || (!setting.edit.drag.isMove && setting.edit.drag.isCopy);
- if (!isCopy && tmpTarget && tmpTargetNodeId && nodes[0].parentTId && tmpTargetNodeId==nodes[0].parentTId && moveType == consts.move.TYPE_INNER) {
- tmpTarget = null;
- }
- if (tmpTarget) {
- var dragTargetNode = tmpTargetNodeId == null ? null: data.getNodeCache(targetSetting, tmpTargetNodeId);
- if (tools.apply(setting.callback.beforeDrop, [targetSetting.treeId, nodes, dragTargetNode, moveType, isCopy], true) == false) {
- view.selectNodes(sourceSetting, nodes);
- return;
- }
- var newNodes = isCopy ? tools.clone(nodes) : nodes;
- function dropCallback() {
- if (isOtherTree) {
- if (!isCopy) {
- for(var i=0, l=nodes.length; i<l; i++) {
- view.removeNode(setting, nodes[i]);
- }
- }
- if (moveType == consts.move.TYPE_INNER) {
- view.addNodes(targetSetting, dragTargetNode, newNodes);
- } else {
- view.addNodes(targetSetting, dragTargetNode.getParentNode(), newNodes);
- if (moveType == consts.move.TYPE_PREV) {
- for (i=0, l=newNodes.length; i<l; i++) {
- view.moveNode(targetSetting, dragTargetNode, newNodes[i], moveType, false);
- }
- } else {
- for (i=-1, l=newNodes.length-1; i<l; l--) {
- view.moveNode(targetSetting, dragTargetNode, newNodes[l], moveType, false);
- }
- }
- }
- } else {
- if (isCopy && moveType == consts.move.TYPE_INNER) {
- view.addNodes(targetSetting, dragTargetNode, newNodes);
- } else {
- if (isCopy) {
- view.addNodes(targetSetting, dragTargetNode.getParentNode(), newNodes);
- }
- if (moveType != consts.move.TYPE_NEXT) {
- for (i=0, l=newNodes.length; i<l; i++) {
- view.moveNode(targetSetting, dragTargetNode, newNodes[i], moveType, false);
- }
- } else {
- for (i=-1, l=newNodes.length-1; i<l; l--) {
- view.moveNode(targetSetting, dragTargetNode, newNodes[l], moveType, false);
- }
- }
- }
- }
- view.selectNodes(targetSetting, newNodes);
- $$(newNodes[0], setting).focus().blur();
- setting.treeObj.trigger(consts.event.DROP, [event, targetSetting.treeId, newNodes, dragTargetNode, moveType, isCopy]);
- }
- if (moveType == consts.move.TYPE_INNER && tools.canAsync(targetSetting, dragTargetNode)) {
- view.asyncNode(targetSetting, dragTargetNode, false, dropCallback);
- } else {
- dropCallback();
- }
- } else {
- view.selectNodes(sourceSetting, nodes);
- setting.treeObj.trigger(consts.event.DROP, [event, setting.treeId, nodes, null, null, null]);
- }
- }
- doc.bind("selectstart", _docSelect);
- function _docSelect() {
- return false;
- }
- //Avoid FireFox's Bug
- //If zTree Div CSS set 'overflow', so drag node outside of zTree, and event.target is error.
- if(eventMouseDown.preventDefault) {
- eventMouseDown.preventDefault();
- }
- return true;
- }
- },
- //method of tools for zTree
- _tools = {
- getAbs: function (obj) {
- var oRect = obj.getBoundingClientRect(),
- scrollTop = document.body.scrollTop+document.documentElement.scrollTop,
- scrollLeft = document.body.scrollLeft+document.documentElement.scrollLeft;
- return [oRect.left+scrollLeft,oRect.top+scrollTop];
- },
- inputFocus: function(inputObj) {
- if (inputObj.get(0)) {
- inputObj.focus();
- tools.setCursorPosition(inputObj.get(0), inputObj.val().length);
- }
- },
- inputSelect: function(inputObj) {
- if (inputObj.get(0)) {
- inputObj.focus();
- inputObj.select();
- }
- },
- setCursorPosition: function(obj, pos){
- if(obj.setSelectionRange) {
- obj.focus();
- obj.setSelectionRange(pos,pos);
- } else if (obj.createTextRange) {
- var range = obj.createTextRange();
- range.collapse(true);
- range.moveEnd('character', pos);
- range.moveStart('character', pos);
- range.select();
- }
- },
- showIfameMask: function(setting, showSign) {
- var root = data.getRoot(setting);
- //clear full mask
- while (root.dragMaskList.length > 0) {
- root.dragMaskList[0].remove();
- root.dragMaskList.shift();
- }
- if (showSign) {
- //show mask
- var iframeList = $$("iframe", setting);
- for (var i = 0, l = iframeList.length; i < l; i++) {
- var obj = iframeList.get(i),
- r = tools.getAbs(obj),
- dragMask = $$("<div id='zTreeMask_" + i + "' class='zTreeMask' style='top:" + r[1] + "px; left:" + r[0] + "px; width:" + obj.offsetWidth + "px; height:" + obj.offsetHeight + "px;'></div>", setting);
- dragMask.appendTo($$("body", setting));
- root.dragMaskList.push(dragMask);
- }
- }
- }
- },
- //method of operate ztree dom
- _view = {
- addEditBtn: function(setting, node) {
- if (node.editNameFlag || $$(node, consts.id.EDIT, setting).length > 0) {
- return;
- }
- if (!tools.apply(setting.edit.showRenameBtn, [setting.treeId, node], setting.edit.showRenameBtn)) {
- return;
- }
- var aObj = $$(node, consts.id.A, setting),
- editStr = "<span class='" + consts.className.BUTTON + " edit' id='" + node.tId + consts.id.EDIT + "' title='"+tools.apply(setting.edit.renameTitle, [setting.treeId, node], setting.edit.renameTitle)+"' treeNode"+consts.id.EDIT+" style='display:none;'></span>";
- aObj.append(editStr);
- $$(node, consts.id.EDIT, setting).bind('click',
- function() {
- if (!tools.uCanDo(setting) || tools.apply(setting.callback.beforeEditName, [setting.treeId, node], true) == false) return false;
- view.editNode(setting, node);
- return false;
- }
- ).show();
- },
- addRemoveBtn: function(setting, node) {
- if (node.editNameFlag || $$(node, consts.id.REMOVE, setting).length > 0) {
- return;
- }
- if (!tools.apply(setting.edit.showRemoveBtn, [setting.treeId, node], setting.edit.showRemoveBtn)) {
- return;
- }
- var aObj = $$(node, consts.id.A, setting),
- removeStr = "<span class='" + consts.className.BUTTON + " remove' id='" + node.tId + consts.id.REMOVE + "' title='"+tools.apply(setting.edit.removeTitle, [setting.treeId, node], setting.edit.removeTitle)+"' treeNode"+consts.id.REMOVE+" style='display:none;'></span>";
- aObj.append(removeStr);
- $$(node, consts.id.REMOVE, setting).bind('click',
- function() {
- if (!tools.uCanDo(setting) || tools.apply(setting.callback.beforeRemove, [setting.treeId, node], true) == false) return false;
- view.removeNode(setting, node);
- setting.treeObj.trigger(consts.event.REMOVE, [setting.treeId, node]);
- return false;
- }
- ).bind('mousedown',
- function(eventMouseDown) {
- return true;
- }
- ).show();
- },
- addHoverDom: function(setting, node) {
- if (data.getRoots().showHoverDom) {
- node.isHover = true;
- if (setting.edit.enable) {
- view.addEditBtn(setting, node);
- view.addRemoveBtn(setting, node);
- }
- tools.apply(setting.view.addHoverDom, [setting.treeId, node]);
- }
- },
- cancelCurEditNode: function (setting, forceName, isCancel) {
- var root = data.getRoot(setting),
- nameKey = setting.data.key.name,
- node = root.curEditNode;
- if (node) {
- var inputObj = root.curEditInput,
- newName = forceName ? forceName:(isCancel ? node[nameKey]: inputObj.val());
- if (tools.apply(setting.callback.beforeRename, [setting.treeId, node, newName, isCancel], true) === false) {
- return false;
- } else {
- node[nameKey] = newName;
- setting.treeObj.trigger(consts.event.RENAME, [setting.treeId, node, isCancel]);
- }
- var aObj = $$(node, consts.id.A, setting);
- aObj.removeClass(consts.node.CURSELECTED_EDIT);
- inputObj.unbind();
- view.setNodeName(setting, node);
- node.editNameFlag = false;
- root.curEditNode = null;
- root.curEditInput = null;
- view.selectNode(setting, node, false);
- }
- root.noSelection = true;
- return true;
- },
- editNode: function(setting, node) {
- var root = data.getRoot(setting);
- view.editNodeBlur = false;
- if (data.isSelectedNode(setting, node) && root.curEditNode == node && node.editNameFlag) {
- setTimeout(function() {tools.inputFocus(root.curEditInput);}, 0);
- return;
- }
- var nameKey = setting.data.key.name;
- node.editNameFlag = true;
- view.removeTreeDom(setting, node);
- view.cancelCurEditNode(setting);
- view.selectNode(setting, node, false);
- $$(node, consts.id.SPAN, setting).html("<input type=text class='rename' id='" + node.tId + consts.id.INPUT + "' treeNode" + consts.id.INPUT + " >");
- var inputObj = $$(node, consts.id.INPUT, setting);
- inputObj.attr("value", node[nameKey]);
- if (setting.edit.editNameSelectAll) {
- tools.inputSelect(inputObj);
- } else {
- tools.inputFocus(inputObj);
- }
- inputObj.bind('blur', function(event) {
- if (!view.editNodeBlur) {
- view.cancelCurEditNode(setting);
- }
- }).bind('keydown', function(event) {
- if (event.keyCode=="13") {
- view.editNodeBlur = true;
- view.cancelCurEditNode(setting);
- } else if (event.keyCode=="27") {
- view.cancelCurEditNode(setting, null, true);
- }
- }).bind('click', function(event) {
- return false;
- }).bind('dblclick', function(event) {
- return false;
- });
- $$(node, consts.id.A, setting).addClass(consts.node.CURSELECTED_EDIT);
- root.curEditInput = inputObj;
- root.noSelection = false;
- root.curEditNode = node;
- },
- moveNode: function(setting, targetNode, node, moveType, animateFlag, isSilent) {
- var root = data.getRoot(setting),
- childKey = setting.data.key.children;
- if (targetNode == node) return;
- if (setting.data.keep.leaf && targetNode && !targetNode.isParent && moveType == consts.move.TYPE_INNER) return;
- var oldParentNode = (node.parentTId ? node.getParentNode(): root),
- targetNodeIsRoot = (targetNode === null || targetNode == root);
- if (targetNodeIsRoot && targetNode === null) targetNode = root;
- if (targetNodeIsRoot) moveType = consts.move.TYPE_INNER;
- var targetParentNode = (targetNode.parentTId ? targetNode.getParentNode() : root);
- if (moveType != consts.move.TYPE_PREV && moveType != consts.move.TYPE_NEXT) {
- moveType = consts.move.TYPE_INNER;
- }
- if (moveType == consts.move.TYPE_INNER) {
- if (targetNodeIsRoot) {
- //parentTId of root node is null
- node.parentTId = null;
- } else {
- if (!targetNode.isParent) {
- targetNode.isParent = true;
- targetNode.open = !!targetNode.open;
- view.setNodeLineIcos(setting, targetNode);
- }
- node.parentTId = targetNode.tId;
- }
- }
- //move node Dom
- var targetObj, target_ulObj;
- if (targetNodeIsRoot) {
- targetObj = setting.treeObj;
- target_ulObj = targetObj;
- } else {
- if (!isSilent && moveType == consts.move.TYPE_INNER) {
- view.expandCollapseNode(setting, targetNode, true, false);
- } else if (!isSilent) {
- view.expandCollapseNode(setting, targetNode.getParentNode(), true, false);
- }
- targetObj = $$(targetNode, setting);
- target_ulObj = $$(targetNode, consts.id.UL, setting);
- if (!!targetObj.get(0) && !target_ulObj.get(0)) {
- var ulstr = [];
- view.makeUlHtml(setting, targetNode, ulstr, '');
- targetObj.append(ulstr.join(''));
- }
- target_ulObj = $$(targetNode, consts.id.UL, setting);
- }
- var nodeDom = $$(node, setting);
- if (!nodeDom.get(0)) {
- nodeDom = view.appendNodes(setting, node.level, [node], null, false, true).join('');
- } else if (!targetObj.get(0)) {
- nodeDom.remove();
- }
- if (target_ulObj.get(0) && moveType == consts.move.TYPE_INNER) {
- target_ulObj.append(nodeDom);
- } else if (targetObj.get(0) && moveType == consts.move.TYPE_PREV) {
- targetObj.before(nodeDom);
- } else if (targetObj.get(0) && moveType == consts.move.TYPE_NEXT) {
- targetObj.after(nodeDom);
- }
- //repair the data after move
- var i,l,
- tmpSrcIndex = -1,
- tmpTargetIndex = 0,
- oldNeighbor = null,
- newNeighbor = null,
- oldLevel = node.level;
- if (node.isFirstNode) {
- tmpSrcIndex = 0;
- if (oldParentNode[childKey].length > 1 ) {
- oldNeighbor = oldParentNode[childKey][1];
- oldNeighbor.isFirstNode = true;
- }
- } else if (node.isLastNode) {
- tmpSrcIndex = oldParentNode[childKey].length -1;
- oldNeighbor = oldParentNode[childKey][tmpSrcIndex - 1];
- oldNeighbor.isLastNode = true;
- } else {
- for (i = 0, l = oldParentNode[childKey].length; i < l; i++) {
- if (oldParentNode[childKey][i].tId == node.tId) {
- tmpSrcIndex = i;
- break;
- }
- }
- }
- if (tmpSrcIndex >= 0) {
- oldParentNode[childKey].splice(tmpSrcIndex, 1);
- }
- if (moveType != consts.move.TYPE_INNER) {
- for (i = 0, l = targetParentNode[childKey].length; i < l; i++) {
- if (targetParentNode[childKey][i].tId == targetNode.tId) tmpTargetIndex = i;
- }
- }
- if (moveType == consts.move.TYPE_INNER) {
- if (!targetNode[childKey]) targetNode[childKey] = new Array();
- if (targetNode[childKey].length > 0) {
- newNeighbor = targetNode[childKey][targetNode[childKey].length - 1];
- newNeighbor.isLastNode = false;
- }
- targetNode[childKey].splice(targetNode[childKey].length, 0, node);
- node.isLastNode = true;
- node.isFirstNode = (targetNode[childKey].length == 1);
- } else if (targetNode.isFirstNode && moveType == consts.move.TYPE_PREV) {
- targetParentNode[childKey].splice(tmpTargetIndex, 0, node);
- newNeighbor = targetNode;
- newNeighbor.isFirstNode = false;
- node.parentTId = targetNode.parentTId;
- node.isFirstNode = true;
- node.isLastNode = false;
- } else if (targetNode.isLastNode && moveType == consts.move.TYPE_NEXT) {
- targetParentNode[childKey].splice(tmpTargetIndex + 1, 0, node);
- newNeighbor = targetNode;
- newNeighbor.isLastNode = false;
- node.parentTId = targetNode.parentTId;
- node.isFirstNode = false;
- node.isLastNode = true;
- } else {
- if (moveType == consts.move.TYPE_PREV) {
- targetParentNode[childKey].splice(tmpTargetIndex, 0, node);
- } else {
- targetParentNode[childKey].splice(tmpTargetIndex + 1, 0, node);
- }
- node.parentTId = targetNode.parentTId;
- node.isFirstNode = false;
- node.isLastNode = false;
- }
- data.fixPIdKeyValue(setting, node);
- data.setSonNodeLevel(setting, node.getParentNode(), node);
- //repair node what been moved
- view.setNodeLineIcos(setting, node);
- view.repairNodeLevelClass(setting, node, oldLevel)
- //repair node's old parentNode dom
- if (!setting.data.keep.parent && oldParentNode[childKey].length < 1) {
- //old parentNode has no child nodes
- oldParentNode.isParent = false;
- oldParentNode.open = false;
- var tmp_ulObj = $$(oldParentNode, consts.id.UL, setting),
- tmp_switchObj = $$(oldParentNode, consts.id.SWITCH, setting),
- tmp_icoObj = $$(oldParentNode, consts.id.ICON, setting);
- view.replaceSwitchClass(oldParentNode, tmp_switchObj, consts.folder.DOCU);
- view.replaceIcoClass(oldParentNode, tmp_icoObj, consts.folder.DOCU);
- tmp_ulObj.css("display", "none");
- } else if (oldNeighbor) {
- //old neigbor node
- view.setNodeLineIcos(setting, oldNeighbor);
- }
- //new neigbor node
- if (newNeighbor) {
- view.setNodeLineIcos(setting, newNeighbor);
- }
- //repair checkbox / radio
- if (!!setting.check && setting.check.enable && view.repairChkClass) {
- view.repairChkClass(setting, oldParentNode);
- view.repairParentChkClassWithSelf(setting, oldParentNode);
- if (oldParentNode != node.parent)
- view.repairParentChkClassWithSelf(setting, node);
- }
- //expand parents after move
- if (!isSilent) {
- view.expandCollapseParentNode(setting, node.getParentNode(), true, animateFlag);
- }
- },
- removeEditBtn: function(setting, node) {
- $$(node, consts.id.EDIT, setting).unbind().remove();
- },
- removeRemoveBtn: function(setting, node) {
- $$(node, consts.id.REMOVE, setting).unbind().remove();
- },
- removeTreeDom: function(setting, node) {
- node.isHover = false;
- view.removeEditBtn(setting, node);
- view.removeRemoveBtn(setting, node);
- tools.apply(setting.view.removeHoverDom, [setting.treeId, node]);
- },
- repairNodeLevelClass: function(setting, node, oldLevel) {
- if (oldLevel === node.level) return;
- var liObj = $$(node, setting),
- aObj = $$(node, consts.id.A, setting),
- ulObj = $$(node, consts.id.UL, setting),
- oldClass = consts.className.LEVEL + oldLevel,
- newClass = consts.className.LEVEL + node.level;
- liObj.removeClass(oldClass);
- liObj.addClass(newClass);
- aObj.removeClass(oldClass);
- aObj.addClass(newClass);
- ulObj.removeClass(oldClass);
- ulObj.addClass(newClass);
- },
- selectNodes : function(setting, nodes) {
- for (var i=0, l=nodes.length; i<l; i++) {
- view.selectNode(setting, nodes[i], i>0);
- }
- }
- },
- _z = {
- tools: _tools,
- view: _view,
- event: _event,
- data: _data
- };
- $.extend(true, $.fn.zTree.consts, _consts);
- $.extend(true, $.fn.zTree._z, _z);
- var zt = $.fn.zTree,
- tools = zt._z.tools,
- consts = zt.consts,
- view = zt._z.view,
- data = zt._z.data,
- event = zt._z.event,
- $$ = tools.$;
- data.exSetting(_setting);
- data.addInitBind(_bindEvent);
- data.addInitUnBind(_unbindEvent);
- data.addInitCache(_initCache);
- data.addInitNode(_initNode);
- data.addInitProxy(_eventProxy);
- data.addInitRoot(_initRoot);
- data.addZTreeTools(_zTreeTools);
- var _cancelPreSelectedNode = view.cancelPreSelectedNode;
- view.cancelPreSelectedNode = function (setting, node) {
- var list = data.getRoot(setting).curSelectedList;
- for (var i=0, j=list.length; i<j; i++) {
- if (!node || node === list[i]) {
- view.removeTreeDom(setting, list[i]);
- if (node) break;
- }
- }
- if (_cancelPreSelectedNode) _cancelPreSelectedNode.apply(view, arguments);
- }
- var _createNodes = view.createNodes;
- view.createNodes = function(setting, level, nodes, parentNode) {
- if (_createNodes) {
- _createNodes.apply(view, arguments);
- }
- if (!nodes) return;
- if (view.repairParentChkClassWithSelf) {
- view.repairParentChkClassWithSelf(setting, parentNode);
- }
- }
- var _makeNodeUrl = view.makeNodeUrl;
- view.makeNodeUrl = function(setting, node) {
- return setting.edit.enable ? null : (_makeNodeUrl.apply(view, arguments));
- }
- var _removeNode = view.removeNode;
- view.removeNode = function(setting, node) {
- var root = data.getRoot(setting);
- if (root.curEditNode === node) root.curEditNode = null;
- if (_removeNode) {
- _removeNode.apply(view, arguments);
- }
- }
- var _selectNode = view.selectNode;
- view.selectNode = function(setting, node, addFlag) {
- var root = data.getRoot(setting);
- if (data.isSelectedNode(setting, node) && root.curEditNode == node && node.editNameFlag) {
- return false;
- }
- if (_selectNode) _selectNode.apply(view, arguments);
- view.addHoverDom(setting, node);
- return true;
- }
- var _uCanDo = tools.uCanDo;
- tools.uCanDo = function(setting, e) {
- var root = data.getRoot(setting);
- if (e && (tools.eqs(e.type, "mouseover") || tools.eqs(e.type, "mouseout") || tools.eqs(e.type, "mousedown") || tools.eqs(e.type, "mouseup"))) {
- return true;
- }
- if (root.curEditNode) {
- view.editNodeBlur = false;
- root.curEditInput.focus();
- }
- return (!root.curEditNode) && (_uCanDo ? _uCanDo.apply(view, arguments) : true);
- }
- })(jQuery);
|