jquery.ztree.all.js 146 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843
  1. /*
  2. * JQuery zTree core
  3. * v3.5.42
  4. * http://treejs.cn/
  5. *
  6. * Copyright (c) 2010 Hunter.z
  7. *
  8. * Licensed same as jquery - MIT License
  9. * http://www.opensource.org/licenses/mit-license.php
  10. *
  11. * Date: 2020-01-19
  12. */
  13. (function ($) {
  14. var settings = {}, roots = {}, caches = {},
  15. //default consts of core
  16. _consts = {
  17. className: {
  18. BUTTON: "button",
  19. LEVEL: "level",
  20. ICO_LOADING: "ico_loading",
  21. SWITCH: "switch",
  22. NAME: 'node_name'
  23. },
  24. event: {
  25. NODECREATED: "ztree_nodeCreated",
  26. CLICK: "ztree_click",
  27. EXPAND: "ztree_expand",
  28. COLLAPSE: "ztree_collapse",
  29. ASYNC_SUCCESS: "ztree_async_success",
  30. ASYNC_ERROR: "ztree_async_error",
  31. REMOVE: "ztree_remove",
  32. SELECTED: "ztree_selected",
  33. UNSELECTED: "ztree_unselected"
  34. },
  35. id: {
  36. A: "_a",
  37. ICON: "_ico",
  38. SPAN: "_span",
  39. SWITCH: "_switch",
  40. UL: "_ul"
  41. },
  42. line: {
  43. ROOT: "root",
  44. ROOTS: "roots",
  45. CENTER: "center",
  46. BOTTOM: "bottom",
  47. NOLINE: "noline",
  48. LINE: "line"
  49. },
  50. folder: {
  51. OPEN: "open",
  52. CLOSE: "close",
  53. DOCU: "docu"
  54. },
  55. node: {
  56. CURSELECTED: "curSelectedNode"
  57. }
  58. },
  59. //default setting of core
  60. _setting = {
  61. treeId: "",
  62. treeObj: null,
  63. view: {
  64. addDiyDom: null,
  65. autoCancelSelected: true,
  66. dblClickExpand: true,
  67. expandSpeed: "fast",
  68. fontCss: {},
  69. nameIsHTML: false,
  70. selectedMulti: true,
  71. showIcon: true,
  72. showLine: true,
  73. showTitle: true,
  74. txtSelectedEnable: false
  75. },
  76. data: {
  77. key: {
  78. isParent: "isParent",
  79. children: "children",
  80. name: "name",
  81. title: "",
  82. url: "url",
  83. icon: "icon"
  84. },
  85. simpleData: {
  86. enable: false,
  87. idKey: "id",
  88. pIdKey: "pId",
  89. rootPId: null
  90. },
  91. keep: {
  92. parent: false,
  93. leaf: false
  94. }
  95. },
  96. async: {
  97. enable: false,
  98. contentType: "application/x-www-form-urlencoded",
  99. type: "post",
  100. dataType: "text",
  101. headers: {},
  102. xhrFields: {},
  103. url: "",
  104. autoParam: [],
  105. otherParam: [],
  106. dataFilter: null
  107. },
  108. callback: {
  109. beforeAsync: null,
  110. beforeClick: null,
  111. beforeDblClick: null,
  112. beforeRightClick: null,
  113. beforeMouseDown: null,
  114. beforeMouseUp: null,
  115. beforeExpand: null,
  116. beforeCollapse: null,
  117. beforeRemove: null,
  118. onAsyncError: null,
  119. onAsyncSuccess: null,
  120. onNodeCreated: null,
  121. onClick: null,
  122. onDblClick: null,
  123. onRightClick: null,
  124. onMouseDown: null,
  125. onMouseUp: null,
  126. onExpand: null,
  127. onCollapse: null,
  128. onRemove: null
  129. }
  130. },
  131. //default root of core
  132. //zTree use root to save full data
  133. _initRoot = function (setting) {
  134. var r = data.getRoot(setting);
  135. if (!r) {
  136. r = {};
  137. data.setRoot(setting, r);
  138. }
  139. data.nodeChildren(setting, r, []);
  140. r.expandTriggerFlag = false;
  141. r.curSelectedList = [];
  142. r.noSelection = true;
  143. r.createdNodes = [];
  144. r.zId = 0;
  145. r._ver = (new Date()).getTime();
  146. },
  147. //default cache of core
  148. _initCache = function (setting) {
  149. var c = data.getCache(setting);
  150. if (!c) {
  151. c = {};
  152. data.setCache(setting, c);
  153. }
  154. c.nodes = [];
  155. c.doms = [];
  156. },
  157. //default bindEvent of core
  158. _bindEvent = function (setting) {
  159. var o = setting.treeObj,
  160. c = consts.event;
  161. o.bind(c.NODECREATED, function (event, treeId, node) {
  162. tools.apply(setting.callback.onNodeCreated, [event, treeId, node]);
  163. });
  164. o.bind(c.CLICK, function (event, srcEvent, treeId, node, clickFlag) {
  165. tools.apply(setting.callback.onClick, [srcEvent, treeId, node, clickFlag]);
  166. });
  167. o.bind(c.EXPAND, function (event, treeId, node) {
  168. tools.apply(setting.callback.onExpand, [event, treeId, node]);
  169. });
  170. o.bind(c.COLLAPSE, function (event, treeId, node) {
  171. tools.apply(setting.callback.onCollapse, [event, treeId, node]);
  172. });
  173. o.bind(c.ASYNC_SUCCESS, function (event, treeId, node, msg) {
  174. tools.apply(setting.callback.onAsyncSuccess, [event, treeId, node, msg]);
  175. });
  176. o.bind(c.ASYNC_ERROR, function (event, treeId, node, XMLHttpRequest, textStatus, errorThrown) {
  177. tools.apply(setting.callback.onAsyncError, [event, treeId, node, XMLHttpRequest, textStatus, errorThrown]);
  178. });
  179. o.bind(c.REMOVE, function (event, treeId, treeNode) {
  180. tools.apply(setting.callback.onRemove, [event, treeId, treeNode]);
  181. });
  182. o.bind(c.SELECTED, function (event, treeId, node) {
  183. tools.apply(setting.callback.onSelected, [treeId, node]);
  184. });
  185. o.bind(c.UNSELECTED, function (event, treeId, node) {
  186. tools.apply(setting.callback.onUnSelected, [treeId, node]);
  187. });
  188. },
  189. _unbindEvent = function (setting) {
  190. var o = setting.treeObj,
  191. c = consts.event;
  192. o.unbind(c.NODECREATED)
  193. .unbind(c.CLICK)
  194. .unbind(c.EXPAND)
  195. .unbind(c.COLLAPSE)
  196. .unbind(c.ASYNC_SUCCESS)
  197. .unbind(c.ASYNC_ERROR)
  198. .unbind(c.REMOVE)
  199. .unbind(c.SELECTED)
  200. .unbind(c.UNSELECTED);
  201. },
  202. //default event proxy of core
  203. _eventProxy = function (event) {
  204. var target = event.target,
  205. setting = data.getSetting(event.data.treeId),
  206. tId = "", node = null,
  207. nodeEventType = "", treeEventType = "",
  208. nodeEventCallback = null, treeEventCallback = null,
  209. tmp = null;
  210. if (tools.eqs(event.type, "mousedown")) {
  211. treeEventType = "mousedown";
  212. } else if (tools.eqs(event.type, "mouseup")) {
  213. treeEventType = "mouseup";
  214. } else if (tools.eqs(event.type, "contextmenu")) {
  215. treeEventType = "contextmenu";
  216. } else if (tools.eqs(event.type, "click")) {
  217. if (tools.eqs(target.tagName, "span") && target.getAttribute("treeNode" + consts.id.SWITCH) !== null) {
  218. tId = tools.getNodeMainDom(target).id;
  219. nodeEventType = "switchNode";
  220. } else {
  221. tmp = tools.getMDom(setting, target, [{tagName: "a", attrName: "treeNode" + consts.id.A}]);
  222. if (tmp) {
  223. tId = tools.getNodeMainDom(tmp).id;
  224. nodeEventType = "clickNode";
  225. }
  226. }
  227. } else if (tools.eqs(event.type, "dblclick")) {
  228. treeEventType = "dblclick";
  229. tmp = tools.getMDom(setting, target, [{tagName: "a", attrName: "treeNode" + consts.id.A}]);
  230. if (tmp) {
  231. tId = tools.getNodeMainDom(tmp).id;
  232. nodeEventType = "switchNode";
  233. }
  234. }
  235. if (treeEventType.length > 0 && tId.length == 0) {
  236. tmp = tools.getMDom(setting, target, [{tagName: "a", attrName: "treeNode" + consts.id.A}]);
  237. if (tmp) {
  238. tId = tools.getNodeMainDom(tmp).id;
  239. }
  240. }
  241. // event to node
  242. if (tId.length > 0) {
  243. node = data.getNodeCache(setting, tId);
  244. switch (nodeEventType) {
  245. case "switchNode" :
  246. var isParent = data.nodeIsParent(setting, node);
  247. if (!isParent) {
  248. nodeEventType = "";
  249. } else if (tools.eqs(event.type, "click")
  250. || (tools.eqs(event.type, "dblclick") && tools.apply(setting.view.dblClickExpand, [setting.treeId, node], setting.view.dblClickExpand))) {
  251. nodeEventCallback = handler.onSwitchNode;
  252. } else {
  253. nodeEventType = "";
  254. }
  255. break;
  256. case "clickNode" :
  257. nodeEventCallback = handler.onClickNode;
  258. break;
  259. }
  260. }
  261. // event to zTree
  262. switch (treeEventType) {
  263. case "mousedown" :
  264. treeEventCallback = handler.onZTreeMousedown;
  265. break;
  266. case "mouseup" :
  267. treeEventCallback = handler.onZTreeMouseup;
  268. break;
  269. case "dblclick" :
  270. treeEventCallback = handler.onZTreeDblclick;
  271. break;
  272. case "contextmenu" :
  273. treeEventCallback = handler.onZTreeContextmenu;
  274. break;
  275. }
  276. var proxyResult = {
  277. stop: false,
  278. node: node,
  279. nodeEventType: nodeEventType,
  280. nodeEventCallback: nodeEventCallback,
  281. treeEventType: treeEventType,
  282. treeEventCallback: treeEventCallback
  283. };
  284. return proxyResult
  285. },
  286. //default init node of core
  287. _initNode = function (setting, level, n, parentNode, isFirstNode, isLastNode, openFlag) {
  288. if (!n) return;
  289. var r = data.getRoot(setting),
  290. children = data.nodeChildren(setting, n);
  291. n.level = level;
  292. n.tId = setting.treeId + "_" + (++r.zId);
  293. n.parentTId = parentNode ? parentNode.tId : null;
  294. n.open = (typeof n.open == "string") ? tools.eqs(n.open, "true") : !!n.open;
  295. var isParent = data.nodeIsParent(setting, n);
  296. if (tools.isArray(children)) {
  297. data.nodeIsParent(setting, n, true);
  298. n.zAsync = true;
  299. } else {
  300. isParent = data.nodeIsParent(setting, n, isParent);
  301. n.open = (isParent && !setting.async.enable) ? n.open : false;
  302. n.zAsync = !isParent;
  303. }
  304. n.isFirstNode = isFirstNode;
  305. n.isLastNode = isLastNode;
  306. n.getParentNode = function () {
  307. return data.getNodeCache(setting, n.parentTId);
  308. };
  309. n.getPreNode = function () {
  310. return data.getPreNode(setting, n);
  311. };
  312. n.getNextNode = function () {
  313. return data.getNextNode(setting, n);
  314. };
  315. n.getIndex = function () {
  316. return data.getNodeIndex(setting, n);
  317. };
  318. n.getPath = function () {
  319. return data.getNodePath(setting, n);
  320. };
  321. n.isAjaxing = false;
  322. data.fixPIdKeyValue(setting, n);
  323. },
  324. _init = {
  325. bind: [_bindEvent],
  326. unbind: [_unbindEvent],
  327. caches: [_initCache],
  328. nodes: [_initNode],
  329. proxys: [_eventProxy],
  330. roots: [_initRoot],
  331. beforeA: [],
  332. afterA: [],
  333. innerBeforeA: [],
  334. innerAfterA: [],
  335. zTreeTools: []
  336. },
  337. //method of operate data
  338. data = {
  339. addNodeCache: function (setting, node) {
  340. data.getCache(setting).nodes[data.getNodeCacheId(node.tId)] = node;
  341. },
  342. getNodeCacheId: function (tId) {
  343. return tId.substring(tId.lastIndexOf("_") + 1);
  344. },
  345. addAfterA: function (afterA) {
  346. _init.afterA.push(afterA);
  347. },
  348. addBeforeA: function (beforeA) {
  349. _init.beforeA.push(beforeA);
  350. },
  351. addInnerAfterA: function (innerAfterA) {
  352. _init.innerAfterA.push(innerAfterA);
  353. },
  354. addInnerBeforeA: function (innerBeforeA) {
  355. _init.innerBeforeA.push(innerBeforeA);
  356. },
  357. addInitBind: function (bindEvent) {
  358. _init.bind.push(bindEvent);
  359. },
  360. addInitUnBind: function (unbindEvent) {
  361. _init.unbind.push(unbindEvent);
  362. },
  363. addInitCache: function (initCache) {
  364. _init.caches.push(initCache);
  365. },
  366. addInitNode: function (initNode) {
  367. _init.nodes.push(initNode);
  368. },
  369. addInitProxy: function (initProxy, isFirst) {
  370. if (!!isFirst) {
  371. _init.proxys.splice(0, 0, initProxy);
  372. } else {
  373. _init.proxys.push(initProxy);
  374. }
  375. },
  376. addInitRoot: function (initRoot) {
  377. _init.roots.push(initRoot);
  378. },
  379. addNodesData: function (setting, parentNode, index, nodes) {
  380. var children = data.nodeChildren(setting, parentNode), params;
  381. if (!children) {
  382. children = data.nodeChildren(setting, parentNode, []);
  383. index = -1;
  384. } else if (index >= children.length) {
  385. index = -1;
  386. }
  387. if (children.length > 0 && index === 0) {
  388. children[0].isFirstNode = false;
  389. view.setNodeLineIcos(setting, children[0]);
  390. } else if (children.length > 0 && index < 0) {
  391. children[children.length - 1].isLastNode = false;
  392. view.setNodeLineIcos(setting, children[children.length - 1]);
  393. }
  394. data.nodeIsParent(setting, parentNode, true);
  395. if (index < 0) {
  396. data.nodeChildren(setting, parentNode, children.concat(nodes));
  397. } else {
  398. params = [index, 0].concat(nodes);
  399. children.splice.apply(children, params);
  400. }
  401. },
  402. addSelectedNode: function (setting, node) {
  403. var root = data.getRoot(setting);
  404. if (!data.isSelectedNode(setting, node)) {
  405. root.curSelectedList.push(node);
  406. }
  407. },
  408. addCreatedNode: function (setting, node) {
  409. if (!!setting.callback.onNodeCreated || !!setting.view.addDiyDom) {
  410. var root = data.getRoot(setting);
  411. root.createdNodes.push(node);
  412. }
  413. },
  414. addZTreeTools: function (zTreeTools) {
  415. _init.zTreeTools.push(zTreeTools);
  416. },
  417. exSetting: function (s) {
  418. $.extend(true, _setting, s);
  419. },
  420. fixPIdKeyValue: function (setting, node) {
  421. if (setting.data.simpleData.enable) {
  422. node[setting.data.simpleData.pIdKey] = node.parentTId ? node.getParentNode()[setting.data.simpleData.idKey] : setting.data.simpleData.rootPId;
  423. }
  424. },
  425. getAfterA: function (setting, node, array) {
  426. for (var i = 0, j = _init.afterA.length; i < j; i++) {
  427. _init.afterA[i].apply(this, arguments);
  428. }
  429. },
  430. getBeforeA: function (setting, node, array) {
  431. for (var i = 0, j = _init.beforeA.length; i < j; i++) {
  432. _init.beforeA[i].apply(this, arguments);
  433. }
  434. },
  435. getInnerAfterA: function (setting, node, array) {
  436. for (var i = 0, j = _init.innerAfterA.length; i < j; i++) {
  437. _init.innerAfterA[i].apply(this, arguments);
  438. }
  439. },
  440. getInnerBeforeA: function (setting, node, array) {
  441. for (var i = 0, j = _init.innerBeforeA.length; i < j; i++) {
  442. _init.innerBeforeA[i].apply(this, arguments);
  443. }
  444. },
  445. getCache: function (setting) {
  446. return caches[setting.treeId];
  447. },
  448. getNodeIndex: function (setting, node) {
  449. if (!node) return null;
  450. var p = node.parentTId ? node.getParentNode() : data.getRoot(setting),
  451. children = data.nodeChildren(setting, p);
  452. for (var i = 0, l = children.length - 1; i <= l; i++) {
  453. if (children[i] === node) {
  454. return i;
  455. }
  456. }
  457. return -1;
  458. },
  459. getNextNode: function (setting, node) {
  460. if (!node) return null;
  461. var p = node.parentTId ? node.getParentNode() : data.getRoot(setting),
  462. children = data.nodeChildren(setting, p);
  463. for (var i = 0, l = children.length - 1; i <= l; i++) {
  464. if (children[i] === node) {
  465. return (i == l ? null : children[i + 1]);
  466. }
  467. }
  468. return null;
  469. },
  470. getNodeByParam: function (setting, nodes, key, value) {
  471. if (!nodes || !key) return null;
  472. for (var i = 0, l = nodes.length; i < l; i++) {
  473. var node = nodes[i];
  474. if (node[key] == value) {
  475. return nodes[i];
  476. }
  477. var children = data.nodeChildren(setting, node);
  478. var tmp = data.getNodeByParam(setting, children, key, value);
  479. if (tmp) return tmp;
  480. }
  481. return null;
  482. },
  483. getNodeCache: function (setting, tId) {
  484. if (!tId) return null;
  485. var n = caches[setting.treeId].nodes[data.getNodeCacheId(tId)];
  486. return n ? n : null;
  487. },
  488. getNodePath: function (setting, node) {
  489. if (!node) return null;
  490. var path;
  491. if (node.parentTId) {
  492. path = node.getParentNode().getPath();
  493. } else {
  494. path = [];
  495. }
  496. if (path) {
  497. path.push(node);
  498. }
  499. return path;
  500. },
  501. getNodes: function (setting) {
  502. return data.nodeChildren(setting, data.getRoot(setting));
  503. },
  504. getNodesByParam: function (setting, nodes, key, value) {
  505. if (!nodes || !key) return [];
  506. var result = [];
  507. for (var i = 0, l = nodes.length; i < l; i++) {
  508. var node = nodes[i];
  509. if (node[key] == value) {
  510. result.push(node);
  511. }
  512. var children = data.nodeChildren(setting, node);
  513. result = result.concat(data.getNodesByParam(setting, children, key, value));
  514. }
  515. return result;
  516. },
  517. getNodesByParamFuzzy: function (setting, nodes, key, value) {
  518. if (!nodes || !key) return [];
  519. var result = [];
  520. value = value.toLowerCase();
  521. for (var i = 0, l = nodes.length; i < l; i++) {
  522. var node = nodes[i];
  523. if (typeof node[key] == "string" && nodes[i][key].toLowerCase().indexOf(value) > -1) {
  524. result.push(node);
  525. }
  526. var children = data.nodeChildren(setting, node);
  527. result = result.concat(data.getNodesByParamFuzzy(setting, children, key, value));
  528. }
  529. return result;
  530. },
  531. getNodesByFilter: function (setting, nodes, filter, isSingle, invokeParam) {
  532. if (!nodes) return (isSingle ? null : []);
  533. var result = isSingle ? null : [];
  534. for (var i = 0, l = nodes.length; i < l; i++) {
  535. var node = nodes[i];
  536. if (tools.apply(filter, [node, invokeParam], false)) {
  537. if (isSingle) {
  538. return node;
  539. }
  540. result.push(node);
  541. }
  542. var children = data.nodeChildren(setting, node);
  543. var tmpResult = data.getNodesByFilter(setting, children, filter, isSingle, invokeParam);
  544. if (isSingle && !!tmpResult) {
  545. return tmpResult;
  546. }
  547. result = isSingle ? tmpResult : result.concat(tmpResult);
  548. }
  549. return result;
  550. },
  551. getPreNode: function (setting, node) {
  552. if (!node) return null;
  553. var p = node.parentTId ? node.getParentNode() : data.getRoot(setting),
  554. children = data.nodeChildren(setting, p);
  555. for (var i = 0, l = children.length; i < l; i++) {
  556. if (children[i] === node) {
  557. return (i == 0 ? null : children[i - 1]);
  558. }
  559. }
  560. return null;
  561. },
  562. getRoot: function (setting) {
  563. return setting ? roots[setting.treeId] : null;
  564. },
  565. getRoots: function () {
  566. return roots;
  567. },
  568. getSetting: function (treeId) {
  569. return settings[treeId];
  570. },
  571. getSettings: function () {
  572. return settings;
  573. },
  574. getZTreeTools: function (treeId) {
  575. var r = this.getRoot(this.getSetting(treeId));
  576. return r ? r.treeTools : null;
  577. },
  578. initCache: function (setting) {
  579. for (var i = 0, j = _init.caches.length; i < j; i++) {
  580. _init.caches[i].apply(this, arguments);
  581. }
  582. },
  583. initNode: function (setting, level, node, parentNode, preNode, nextNode) {
  584. for (var i = 0, j = _init.nodes.length; i < j; i++) {
  585. _init.nodes[i].apply(this, arguments);
  586. }
  587. },
  588. initRoot: function (setting) {
  589. for (var i = 0, j = _init.roots.length; i < j; i++) {
  590. _init.roots[i].apply(this, arguments);
  591. }
  592. },
  593. isSelectedNode: function (setting, node) {
  594. var root = data.getRoot(setting);
  595. for (var i = 0, j = root.curSelectedList.length; i < j; i++) {
  596. if (node === root.curSelectedList[i]) return true;
  597. }
  598. return false;
  599. },
  600. nodeChildren: function (setting, node, newChildren) {
  601. if (!node) {
  602. return null;
  603. }
  604. var key = setting.data.key.children;
  605. if (typeof newChildren !== 'undefined') {
  606. node[key] = newChildren;
  607. }
  608. return node[key];
  609. },
  610. nodeIsParent: function (setting, node, newIsParent) {
  611. if (!node) {
  612. return false;
  613. }
  614. var key = setting.data.key.isParent;
  615. if (typeof newIsParent !== 'undefined') {
  616. if (typeof newIsParent === "string") {
  617. newIsParent = tools.eqs(newIsParent, "true");
  618. }
  619. newIsParent = !!newIsParent;
  620. node[key] = newIsParent;
  621. } else if (typeof node[key] == "string"){
  622. node[key] = tools.eqs(node[key], "true");
  623. } else {
  624. node[key] = !!node[key];
  625. }
  626. return node[key];
  627. },
  628. nodeName: function (setting, node, newName) {
  629. var key = setting.data.key.name;
  630. if (typeof newName !== 'undefined') {
  631. node[key] = newName;
  632. }
  633. return "" + node[key];
  634. },
  635. nodeTitle: function (setting, node) {
  636. var t = setting.data.key.title === "" ? setting.data.key.name : setting.data.key.title;
  637. return "" + node[t];
  638. },
  639. removeNodeCache: function (setting, node) {
  640. var children = data.nodeChildren(setting, node);
  641. if (children) {
  642. for (var i = 0, l = children.length; i < l; i++) {
  643. data.removeNodeCache(setting, children[i]);
  644. }
  645. }
  646. data.getCache(setting).nodes[data.getNodeCacheId(node.tId)] = null;
  647. },
  648. removeSelectedNode: function (setting, node) {
  649. var root = data.getRoot(setting);
  650. for (var i = 0, j = root.curSelectedList.length; i < j; i++) {
  651. if (node === root.curSelectedList[i] || !data.getNodeCache(setting, root.curSelectedList[i].tId)) {
  652. root.curSelectedList.splice(i, 1);
  653. setting.treeObj.trigger(consts.event.UNSELECTED, [setting.treeId, node]);
  654. i--;
  655. j--;
  656. }
  657. }
  658. },
  659. setCache: function (setting, cache) {
  660. caches[setting.treeId] = cache;
  661. },
  662. setRoot: function (setting, root) {
  663. roots[setting.treeId] = root;
  664. },
  665. setZTreeTools: function (setting, zTreeTools) {
  666. for (var i = 0, j = _init.zTreeTools.length; i < j; i++) {
  667. _init.zTreeTools[i].apply(this, arguments);
  668. }
  669. },
  670. transformToArrayFormat: function (setting, nodes) {
  671. if (!nodes) return [];
  672. var r = [];
  673. if (tools.isArray(nodes)) {
  674. for (var i = 0, l = nodes.length; i < l; i++) {
  675. var node = nodes[i];
  676. _do(node);
  677. }
  678. } else {
  679. _do(nodes);
  680. }
  681. return r;
  682. function _do(_node) {
  683. r.push(_node);
  684. var children = data.nodeChildren(setting, _node);
  685. if (children) {
  686. r = r.concat(data.transformToArrayFormat(setting, children));
  687. }
  688. }
  689. },
  690. transformTozTreeFormat: function (setting, sNodes) {
  691. var i, l,
  692. key = setting.data.simpleData.idKey,
  693. parentKey = setting.data.simpleData.pIdKey;
  694. if (!key || key == "" || !sNodes) return [];
  695. if (tools.isArray(sNodes)) {
  696. var r = [];
  697. var tmpMap = {};
  698. for (i = 0, l = sNodes.length; i < l; i++) {
  699. tmpMap[sNodes[i][key]] = sNodes[i];
  700. }
  701. for (i = 0, l = sNodes.length; i < l; i++) {
  702. var p = tmpMap[sNodes[i][parentKey]];
  703. if (p && sNodes[i][key] != sNodes[i][parentKey]) {
  704. var children = data.nodeChildren(setting, p);
  705. if (!children) {
  706. children = data.nodeChildren(setting, p, []);
  707. }
  708. children.push(sNodes[i]);
  709. } else {
  710. r.push(sNodes[i]);
  711. }
  712. }
  713. return r;
  714. } else {
  715. return [sNodes];
  716. }
  717. }
  718. },
  719. //method of event proxy
  720. event = {
  721. bindEvent: function (setting) {
  722. for (var i = 0, j = _init.bind.length; i < j; i++) {
  723. _init.bind[i].apply(this, arguments);
  724. }
  725. },
  726. unbindEvent: function (setting) {
  727. for (var i = 0, j = _init.unbind.length; i < j; i++) {
  728. _init.unbind[i].apply(this, arguments);
  729. }
  730. },
  731. bindTree: function (setting) {
  732. var eventParam = {
  733. treeId: setting.treeId
  734. },
  735. o = setting.treeObj;
  736. if (!setting.view.txtSelectedEnable) {
  737. // for can't select text
  738. o.bind('selectstart', handler.onSelectStart).css({
  739. "-moz-user-select": "-moz-none"
  740. });
  741. }
  742. o.bind('click', eventParam, event.proxy);
  743. o.bind('dblclick', eventParam, event.proxy);
  744. o.bind('mouseover', eventParam, event.proxy);
  745. o.bind('mouseout', eventParam, event.proxy);
  746. o.bind('mousedown', eventParam, event.proxy);
  747. o.bind('mouseup', eventParam, event.proxy);
  748. o.bind('contextmenu', eventParam, event.proxy);
  749. },
  750. unbindTree: function (setting) {
  751. var o = setting.treeObj;
  752. o.unbind('selectstart', handler.onSelectStart)
  753. .unbind('click', event.proxy)
  754. .unbind('dblclick', event.proxy)
  755. .unbind('mouseover', event.proxy)
  756. .unbind('mouseout', event.proxy)
  757. .unbind('mousedown', event.proxy)
  758. .unbind('mouseup', event.proxy)
  759. .unbind('contextmenu', event.proxy);
  760. },
  761. doProxy: function (e) {
  762. var results = [];
  763. for (var i = 0, j = _init.proxys.length; i < j; i++) {
  764. var proxyResult = _init.proxys[i].apply(this, arguments);
  765. results.push(proxyResult);
  766. if (proxyResult.stop) {
  767. break;
  768. }
  769. }
  770. return results;
  771. },
  772. proxy: function (e) {
  773. var setting = data.getSetting(e.data.treeId);
  774. if (!tools.uCanDo(setting, e)) return true;
  775. var results = event.doProxy(e),
  776. r = true, x = false;
  777. for (var i = 0, l = results.length; i < l; i++) {
  778. var proxyResult = results[i];
  779. if (proxyResult.nodeEventCallback) {
  780. x = true;
  781. r = proxyResult.nodeEventCallback.apply(proxyResult, [e, proxyResult.node]) && r;
  782. }
  783. if (proxyResult.treeEventCallback) {
  784. x = true;
  785. r = proxyResult.treeEventCallback.apply(proxyResult, [e, proxyResult.node]) && r;
  786. }
  787. }
  788. return r;
  789. }
  790. },
  791. //method of event handler
  792. handler = {
  793. onSwitchNode: function (event, node) {
  794. var setting = data.getSetting(event.data.treeId);
  795. if (node.open) {
  796. if (tools.apply(setting.callback.beforeCollapse, [setting.treeId, node], true) == false) return true;
  797. data.getRoot(setting).expandTriggerFlag = true;
  798. view.switchNode(setting, node);
  799. } else {
  800. if (tools.apply(setting.callback.beforeExpand, [setting.treeId, node], true) == false) return true;
  801. data.getRoot(setting).expandTriggerFlag = true;
  802. view.switchNode(setting, node);
  803. }
  804. return true;
  805. },
  806. onClickNode: function (event, node) {
  807. var setting = data.getSetting(event.data.treeId),
  808. 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;
  809. if (tools.apply(setting.callback.beforeClick, [setting.treeId, node, clickFlag], true) == false) return true;
  810. if (clickFlag === 0) {
  811. view.cancelPreSelectedNode(setting, node);
  812. } else {
  813. view.selectNode(setting, node, clickFlag === 2);
  814. }
  815. setting.treeObj.trigger(consts.event.CLICK, [event, setting.treeId, node, clickFlag]);
  816. return true;
  817. },
  818. onZTreeMousedown: function (event, node) {
  819. var setting = data.getSetting(event.data.treeId);
  820. if (tools.apply(setting.callback.beforeMouseDown, [setting.treeId, node], true)) {
  821. tools.apply(setting.callback.onMouseDown, [event, setting.treeId, node]);
  822. }
  823. return true;
  824. },
  825. onZTreeMouseup: function (event, node) {
  826. var setting = data.getSetting(event.data.treeId);
  827. if (tools.apply(setting.callback.beforeMouseUp, [setting.treeId, node], true)) {
  828. tools.apply(setting.callback.onMouseUp, [event, setting.treeId, node]);
  829. }
  830. return true;
  831. },
  832. onZTreeDblclick: function (event, node) {
  833. var setting = data.getSetting(event.data.treeId);
  834. if (tools.apply(setting.callback.beforeDblClick, [setting.treeId, node], true)) {
  835. tools.apply(setting.callback.onDblClick, [event, setting.treeId, node]);
  836. }
  837. return true;
  838. },
  839. onZTreeContextmenu: function (event, node) {
  840. var setting = data.getSetting(event.data.treeId);
  841. if (tools.apply(setting.callback.beforeRightClick, [setting.treeId, node], true)) {
  842. tools.apply(setting.callback.onRightClick, [event, setting.treeId, node]);
  843. }
  844. return (typeof setting.callback.onRightClick) != "function";
  845. },
  846. onSelectStart: function (e) {
  847. var n = e.originalEvent.srcElement.nodeName.toLowerCase();
  848. return (n === "input" || n === "textarea");
  849. }
  850. },
  851. //method of tools for zTree
  852. tools = {
  853. apply: function (fun, param, defaultValue) {
  854. if ((typeof fun) == "function") {
  855. return fun.apply(zt, param ? param : []);
  856. }
  857. return defaultValue;
  858. },
  859. canAsync: function (setting, node) {
  860. var children = data.nodeChildren(setting, node);
  861. var isParent = data.nodeIsParent(setting, node);
  862. return (setting.async.enable && node && isParent && !(node.zAsync || (children && children.length > 0)));
  863. },
  864. clone: function (obj) {
  865. if (obj === null) return null;
  866. var o = tools.isArray(obj) ? [] : {};
  867. for (var i in obj) {
  868. o[i] = (obj[i] instanceof Date) ? new Date(obj[i].getTime()) : (typeof obj[i] === "object" ? tools.clone(obj[i]) : obj[i]);
  869. }
  870. return o;
  871. },
  872. eqs: function (str1, str2) {
  873. return str1.toLowerCase() === str2.toLowerCase();
  874. },
  875. isArray: function (arr) {
  876. return Object.prototype.toString.apply(arr) === "[object Array]";
  877. },
  878. isElement: function (o) {
  879. return (
  880. typeof HTMLElement === "object" ? o instanceof HTMLElement : //DOM2
  881. o && typeof o === "object" && o !== null && o.nodeType === 1 && typeof o.nodeName === "string"
  882. );
  883. },
  884. $: function (node, exp, setting) {
  885. if (!!exp && typeof exp != "string") {
  886. setting = exp;
  887. exp = "";
  888. }
  889. if (typeof node == "string") {
  890. return $(node, setting ? setting.treeObj.get(0).ownerDocument : null);
  891. } else {
  892. return $("#" + node.tId + exp, setting ? setting.treeObj : null);
  893. }
  894. },
  895. getMDom: function (setting, curDom, targetExpr) {
  896. if (!curDom) return null;
  897. while (curDom && curDom.id !== setting.treeId) {
  898. for (var i = 0, l = targetExpr.length; curDom.tagName && i < l; i++) {
  899. if (tools.eqs(curDom.tagName, targetExpr[i].tagName) && curDom.getAttribute(targetExpr[i].attrName) !== null) {
  900. return curDom;
  901. }
  902. }
  903. curDom = curDom.parentNode;
  904. }
  905. return null;
  906. },
  907. getNodeMainDom: function (target) {
  908. return ($(target).parent("li").get(0) || $(target).parentsUntil("li").parent().get(0));
  909. },
  910. isChildOrSelf: function (dom, parentId) {
  911. return ($(dom).closest("#" + parentId).length > 0);
  912. },
  913. uCanDo: function (setting, e) {
  914. return true;
  915. }
  916. },
  917. //method of operate ztree dom
  918. view = {
  919. addNodes: function (setting, parentNode, index, newNodes, isSilent) {
  920. var isParent = data.nodeIsParent(setting, parentNode);
  921. if (setting.data.keep.leaf && parentNode && !isParent) {
  922. return;
  923. }
  924. if (!tools.isArray(newNodes)) {
  925. newNodes = [newNodes];
  926. }
  927. if (setting.data.simpleData.enable) {
  928. newNodes = data.transformTozTreeFormat(setting, newNodes);
  929. }
  930. if (parentNode) {
  931. var target_switchObj = $$(parentNode, consts.id.SWITCH, setting),
  932. target_icoObj = $$(parentNode, consts.id.ICON, setting),
  933. target_ulObj = $$(parentNode, consts.id.UL, setting);
  934. if (!parentNode.open) {
  935. view.replaceSwitchClass(parentNode, target_switchObj, consts.folder.CLOSE);
  936. view.replaceIcoClass(parentNode, target_icoObj, consts.folder.CLOSE);
  937. parentNode.open = false;
  938. target_ulObj.css({
  939. "display": "none"
  940. });
  941. }
  942. data.addNodesData(setting, parentNode, index, newNodes);
  943. view.createNodes(setting, parentNode.level + 1, newNodes, parentNode, index);
  944. if (!isSilent) {
  945. view.expandCollapseParentNode(setting, parentNode, true);
  946. }
  947. } else {
  948. data.addNodesData(setting, data.getRoot(setting), index, newNodes);
  949. view.createNodes(setting, 0, newNodes, null, index);
  950. }
  951. },
  952. appendNodes: function (setting, level, nodes, parentNode, index, initFlag, openFlag) {
  953. if (!nodes) return [];
  954. var html = [];
  955. var tmpPNode = (parentNode) ? parentNode : data.getRoot(setting),
  956. tmpPChild = data.nodeChildren(setting, tmpPNode),
  957. isFirstNode, isLastNode;
  958. if (!tmpPChild || index >= tmpPChild.length - nodes.length) {
  959. index = -1;
  960. }
  961. for (var i = 0, l = nodes.length; i < l; i++) {
  962. var node = nodes[i];
  963. if (initFlag) {
  964. isFirstNode = ((index === 0 || tmpPChild.length == nodes.length) && (i == 0));
  965. isLastNode = (index < 0 && i == (nodes.length - 1));
  966. data.initNode(setting, level, node, parentNode, isFirstNode, isLastNode, openFlag);
  967. data.addNodeCache(setting, node);
  968. }
  969. var isParent = data.nodeIsParent(setting, node);
  970. var childHtml = [];
  971. var children = data.nodeChildren(setting, node);
  972. if (children && children.length > 0) {
  973. //make child html first, because checkType
  974. childHtml = view.appendNodes(setting, level + 1, children, node, -1, initFlag, openFlag && node.open);
  975. }
  976. if (openFlag) {
  977. view.makeDOMNodeMainBefore(html, setting, node);
  978. view.makeDOMNodeLine(html, setting, node);
  979. data.getBeforeA(setting, node, html);
  980. view.makeDOMNodeNameBefore(html, setting, node);
  981. data.getInnerBeforeA(setting, node, html);
  982. view.makeDOMNodeIcon(html, setting, node);
  983. data.getInnerAfterA(setting, node, html);
  984. view.makeDOMNodeNameAfter(html, setting, node);
  985. data.getAfterA(setting, node, html);
  986. if (isParent && node.open) {
  987. view.makeUlHtml(setting, node, html, childHtml.join(''));
  988. }
  989. view.makeDOMNodeMainAfter(html, setting, node);
  990. data.addCreatedNode(setting, node);
  991. }
  992. }
  993. return html;
  994. },
  995. appendParentULDom: function (setting, node) {
  996. var html = [],
  997. nObj = $$(node, setting);
  998. if (!nObj.get(0) && !!node.parentTId) {
  999. view.appendParentULDom(setting, node.getParentNode());
  1000. nObj = $$(node, setting);
  1001. }
  1002. var ulObj = $$(node, consts.id.UL, setting);
  1003. if (ulObj.get(0)) {
  1004. ulObj.remove();
  1005. }
  1006. var children = data.nodeChildren(setting, node),
  1007. childHtml = view.appendNodes(setting, node.level + 1, children, node, -1, false, true);
  1008. view.makeUlHtml(setting, node, html, childHtml.join(''));
  1009. nObj.append(html.join(''));
  1010. },
  1011. asyncNode: function (setting, node, isSilent, callback) {
  1012. var i, l;
  1013. var isParent = data.nodeIsParent(setting, node);
  1014. if (node && !isParent) {
  1015. tools.apply(callback);
  1016. return false;
  1017. } else if (node && node.isAjaxing) {
  1018. return false;
  1019. } else if (tools.apply(setting.callback.beforeAsync, [setting.treeId, node], true) == false) {
  1020. tools.apply(callback);
  1021. return false;
  1022. }
  1023. if (node) {
  1024. node.isAjaxing = true;
  1025. var icoObj = $$(node, consts.id.ICON, setting);
  1026. icoObj.attr({"style": "", "class": consts.className.BUTTON + " " + consts.className.ICO_LOADING});
  1027. }
  1028. var tmpParam = {};
  1029. var autoParam = tools.apply(setting.async.autoParam, [setting.treeId, node], setting.async.autoParam);
  1030. for (i = 0, l = autoParam.length; node && i < l; i++) {
  1031. var pKey = autoParam[i].split("="), spKey = pKey;
  1032. if (pKey.length > 1) {
  1033. spKey = pKey[1];
  1034. pKey = pKey[0];
  1035. }
  1036. tmpParam[spKey] = node[pKey];
  1037. }
  1038. var otherParam = tools.apply(setting.async.otherParam, [setting.treeId, node], setting.async.otherParam);
  1039. if (tools.isArray(otherParam)) {
  1040. for (i = 0, l = otherParam.length; i < l; i += 2) {
  1041. tmpParam[otherParam[i]] = otherParam[i + 1];
  1042. }
  1043. } else {
  1044. for (var p in otherParam) {
  1045. tmpParam[p] = otherParam[p];
  1046. }
  1047. }
  1048. var _tmpV = data.getRoot(setting)._ver;
  1049. $.ajax({
  1050. contentType: setting.async.contentType,
  1051. cache: false,
  1052. type: setting.async.type,
  1053. url: tools.apply(setting.async.url, [setting.treeId, node], setting.async.url),
  1054. data: setting.async.contentType.indexOf('application/json') > -1 ? JSON.stringify(tmpParam) : tmpParam,
  1055. dataType: setting.async.dataType,
  1056. headers: setting.async.headers,
  1057. xhrFields: setting.async.xhrFields,
  1058. success: function (msg) {
  1059. if (_tmpV != data.getRoot(setting)._ver) {
  1060. return;
  1061. }
  1062. var newNodes = [];
  1063. try {
  1064. if (!msg || msg.length == 0) {
  1065. newNodes = [];
  1066. } else if (typeof msg == "string") {
  1067. newNodes = eval("(" + msg + ")");
  1068. } else {
  1069. newNodes = msg;
  1070. }
  1071. } catch (err) {
  1072. newNodes = msg;
  1073. }
  1074. if (node) {
  1075. node.isAjaxing = null;
  1076. node.zAsync = true;
  1077. }
  1078. view.setNodeLineIcos(setting, node);
  1079. if (newNodes && newNodes !== "") {
  1080. newNodes = tools.apply(setting.async.dataFilter, [setting.treeId, node, newNodes], newNodes);
  1081. view.addNodes(setting, node, -1, !!newNodes ? tools.clone(newNodes) : [], !!isSilent);
  1082. } else {
  1083. view.addNodes(setting, node, -1, [], !!isSilent);
  1084. }
  1085. setting.treeObj.trigger(consts.event.ASYNC_SUCCESS, [setting.treeId, node, msg]);
  1086. tools.apply(callback);
  1087. },
  1088. error: function (XMLHttpRequest, textStatus, errorThrown) {
  1089. if (_tmpV != data.getRoot(setting)._ver) {
  1090. return;
  1091. }
  1092. if (node) node.isAjaxing = null;
  1093. view.setNodeLineIcos(setting, node);
  1094. setting.treeObj.trigger(consts.event.ASYNC_ERROR, [setting.treeId, node, XMLHttpRequest, textStatus, errorThrown]);
  1095. }
  1096. });
  1097. return true;
  1098. },
  1099. cancelPreSelectedNode: function (setting, node, excludeNode) {
  1100. var list = data.getRoot(setting).curSelectedList,
  1101. i, n;
  1102. for (i = list.length - 1; i >= 0; i--) {
  1103. n = list[i];
  1104. if (node === n || (!node && (!excludeNode || excludeNode !== n))) {
  1105. $$(n, consts.id.A, setting).removeClass(consts.node.CURSELECTED);
  1106. if (node) {
  1107. data.removeSelectedNode(setting, node);
  1108. break;
  1109. } else {
  1110. list.splice(i, 1);
  1111. setting.treeObj.trigger(consts.event.UNSELECTED, [setting.treeId, n]);
  1112. }
  1113. }
  1114. }
  1115. },
  1116. createNodeCallback: function (setting) {
  1117. if (!!setting.callback.onNodeCreated || !!setting.view.addDiyDom) {
  1118. var root = data.getRoot(setting);
  1119. while (root.createdNodes.length > 0) {
  1120. var node = root.createdNodes.shift();
  1121. tools.apply(setting.view.addDiyDom, [setting.treeId, node]);
  1122. if (!!setting.callback.onNodeCreated) {
  1123. setting.treeObj.trigger(consts.event.NODECREATED, [setting.treeId, node]);
  1124. }
  1125. }
  1126. }
  1127. },
  1128. createNodes: function (setting, level, nodes, parentNode, index) {
  1129. if (!nodes || nodes.length == 0) return;
  1130. var root = data.getRoot(setting),
  1131. openFlag = !parentNode || parentNode.open || !!$$(data.nodeChildren(setting, parentNode)[0], setting).get(0);
  1132. root.createdNodes = [];
  1133. var zTreeHtml = view.appendNodes(setting, level, nodes, parentNode, index, true, openFlag),
  1134. parentObj, nextObj;
  1135. if (!parentNode) {
  1136. parentObj = setting.treeObj;
  1137. //setting.treeObj.append(zTreeHtml.join(''));
  1138. } else {
  1139. var ulObj = $$(parentNode, consts.id.UL, setting);
  1140. if (ulObj.get(0)) {
  1141. parentObj = ulObj;
  1142. //ulObj.append(zTreeHtml.join(''));
  1143. }
  1144. }
  1145. if (parentObj) {
  1146. if (index >= 0) {
  1147. nextObj = parentObj.children()[index];
  1148. }
  1149. if (index >= 0 && nextObj) {
  1150. $(nextObj).before(zTreeHtml.join(''));
  1151. } else {
  1152. parentObj.append(zTreeHtml.join(''));
  1153. }
  1154. }
  1155. view.createNodeCallback(setting);
  1156. },
  1157. destroy: function (setting) {
  1158. if (!setting) return;
  1159. data.initCache(setting);
  1160. data.initRoot(setting);
  1161. event.unbindTree(setting);
  1162. event.unbindEvent(setting);
  1163. setting.treeObj.empty();
  1164. delete settings[setting.treeId];
  1165. },
  1166. expandCollapseNode: function (setting, node, expandFlag, animateFlag, callback) {
  1167. var root = data.getRoot(setting);
  1168. var tmpCb, _callback;
  1169. if (!node) {
  1170. tools.apply(callback, []);
  1171. return;
  1172. }
  1173. var children = data.nodeChildren(setting, node);
  1174. var isParent = data.nodeIsParent(setting, node);
  1175. if (root.expandTriggerFlag) {
  1176. _callback = callback;
  1177. tmpCb = function () {
  1178. if (_callback) _callback();
  1179. if (node.open) {
  1180. setting.treeObj.trigger(consts.event.EXPAND, [setting.treeId, node]);
  1181. } else {
  1182. setting.treeObj.trigger(consts.event.COLLAPSE, [setting.treeId, node]);
  1183. }
  1184. };
  1185. callback = tmpCb;
  1186. root.expandTriggerFlag = false;
  1187. }
  1188. if (!node.open && isParent && ((!$$(node, consts.id.UL, setting).get(0)) || (children && children.length > 0 && !$$(children[0], setting).get(0)))) {
  1189. view.appendParentULDom(setting, node);
  1190. view.createNodeCallback(setting);
  1191. }
  1192. if (node.open == expandFlag) {
  1193. tools.apply(callback, []);
  1194. return;
  1195. }
  1196. var ulObj = $$(node, consts.id.UL, setting),
  1197. switchObj = $$(node, consts.id.SWITCH, setting),
  1198. icoObj = $$(node, consts.id.ICON, setting);
  1199. if (isParent) {
  1200. node.open = !node.open;
  1201. if (node.iconOpen && node.iconClose) {
  1202. icoObj.attr("style", view.makeNodeIcoStyle(setting, node));
  1203. }
  1204. if (node.open) {
  1205. view.replaceSwitchClass(node, switchObj, consts.folder.OPEN);
  1206. view.replaceIcoClass(node, icoObj, consts.folder.OPEN);
  1207. if (animateFlag == false || setting.view.expandSpeed == "") {
  1208. ulObj.show();
  1209. tools.apply(callback, []);
  1210. } else {
  1211. if (children && children.length > 0) {
  1212. ulObj.slideDown(setting.view.expandSpeed, callback);
  1213. } else {
  1214. ulObj.show();
  1215. tools.apply(callback, []);
  1216. }
  1217. }
  1218. } else {
  1219. view.replaceSwitchClass(node, switchObj, consts.folder.CLOSE);
  1220. view.replaceIcoClass(node, icoObj, consts.folder.CLOSE);
  1221. if (animateFlag == false || setting.view.expandSpeed == "" || !(children && children.length > 0)) {
  1222. ulObj.hide();
  1223. tools.apply(callback, []);
  1224. } else {
  1225. ulObj.slideUp(setting.view.expandSpeed, callback);
  1226. }
  1227. }
  1228. } else {
  1229. tools.apply(callback, []);
  1230. }
  1231. },
  1232. expandCollapseParentNode: function (setting, node, expandFlag, animateFlag, callback) {
  1233. if (!node) return;
  1234. if (!node.parentTId) {
  1235. view.expandCollapseNode(setting, node, expandFlag, animateFlag, callback);
  1236. return;
  1237. } else {
  1238. view.expandCollapseNode(setting, node, expandFlag, animateFlag);
  1239. }
  1240. if (node.parentTId) {
  1241. view.expandCollapseParentNode(setting, node.getParentNode(), expandFlag, animateFlag, callback);
  1242. }
  1243. },
  1244. expandCollapseSonNode: function (setting, node, expandFlag, animateFlag, callback) {
  1245. var root = data.getRoot(setting),
  1246. treeNodes = (node) ? data.nodeChildren(setting, node) : data.nodeChildren(setting, root),
  1247. selfAnimateSign = (node) ? false : animateFlag,
  1248. expandTriggerFlag = data.getRoot(setting).expandTriggerFlag;
  1249. data.getRoot(setting).expandTriggerFlag = false;
  1250. if (treeNodes) {
  1251. for (var i = 0, l = treeNodes.length; i < l; i++) {
  1252. if (treeNodes[i]) view.expandCollapseSonNode(setting, treeNodes[i], expandFlag, selfAnimateSign);
  1253. }
  1254. }
  1255. data.getRoot(setting).expandTriggerFlag = expandTriggerFlag;
  1256. view.expandCollapseNode(setting, node, expandFlag, animateFlag, callback);
  1257. },
  1258. isSelectedNode: function (setting, node) {
  1259. if (!node) {
  1260. return false;
  1261. }
  1262. var list = data.getRoot(setting).curSelectedList,
  1263. i;
  1264. for (i = list.length - 1; i >= 0; i--) {
  1265. if (node === list[i]) {
  1266. return true;
  1267. }
  1268. }
  1269. return false;
  1270. },
  1271. makeDOMNodeIcon: function (html, setting, node) {
  1272. var nameStr = data.nodeName(setting, node),
  1273. name = setting.view.nameIsHTML ? nameStr : nameStr.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
  1274. html.push("<span id='", node.tId, consts.id.ICON,
  1275. "' title='' treeNode", consts.id.ICON, " class='", view.makeNodeIcoClass(setting, node),
  1276. "' style='", view.makeNodeIcoStyle(setting, node), "'></span><span id='", node.tId, consts.id.SPAN,
  1277. "' class='", consts.className.NAME,
  1278. "'>", name, "</span>");
  1279. },
  1280. makeDOMNodeLine: function (html, setting, node) {
  1281. html.push("<span id='", node.tId, consts.id.SWITCH, "' title='' class='", view.makeNodeLineClass(setting, node), "' treeNode", consts.id.SWITCH, "></span>");
  1282. },
  1283. makeDOMNodeMainAfter: function (html, setting, node) {
  1284. html.push("</li>");
  1285. },
  1286. makeDOMNodeMainBefore: function (html, setting, node) {
  1287. html.push("<li id='", node.tId, "' class='", consts.className.LEVEL, node.level, "' tabindex='0' hidefocus='true' treenode>");
  1288. },
  1289. makeDOMNodeNameAfter: function (html, setting, node) {
  1290. html.push("</a>");
  1291. },
  1292. makeDOMNodeNameBefore: function (html, setting, node) {
  1293. var title = data.nodeTitle(setting, node),
  1294. url = view.makeNodeUrl(setting, node),
  1295. fontcss = view.makeNodeFontCss(setting, node),
  1296. fontStyle = [];
  1297. for (var f in fontcss) {
  1298. fontStyle.push(f, ":", fontcss[f], ";");
  1299. }
  1300. html.push("<a id='", node.tId, consts.id.A, "' class='", consts.className.LEVEL, node.level, "' treeNode", consts.id.A, " onclick=\"", (node.click || ''),
  1301. "\" ", ((url != null && url.length > 0) ? "href='" + url + "'" : ""), " target='", view.makeNodeTarget(node), "' style='", fontStyle.join(''),
  1302. "'");
  1303. if (tools.apply(setting.view.showTitle, [setting.treeId, node], setting.view.showTitle) && title) {
  1304. html.push("title='", title.replace(/'/g, "&#39;").replace(/</g, '&lt;').replace(/>/g, '&gt;'), "'");
  1305. }
  1306. html.push(">");
  1307. },
  1308. makeNodeFontCss: function (setting, node) {
  1309. var fontCss = tools.apply(setting.view.fontCss, [setting.treeId, node], setting.view.fontCss);
  1310. return (fontCss && ((typeof fontCss) != "function")) ? fontCss : {};
  1311. },
  1312. makeNodeIcoClass: function (setting, node) {
  1313. var icoCss = ["ico"];
  1314. if (!node.isAjaxing) {
  1315. var isParent = data.nodeIsParent(setting, node);
  1316. icoCss[0] = (node.iconSkin ? node.iconSkin + "_" : "") + icoCss[0];
  1317. if (isParent) {
  1318. icoCss.push(node.open ? consts.folder.OPEN : consts.folder.CLOSE);
  1319. } else {
  1320. icoCss.push(consts.folder.DOCU);
  1321. }
  1322. }
  1323. return consts.className.BUTTON + " " + icoCss.join('_');
  1324. },
  1325. makeNodeIcoStyle: function (setting, node) {
  1326. var icoStyle = [];
  1327. if (!node.isAjaxing) {
  1328. var isParent = data.nodeIsParent(setting, node);
  1329. var icon = (isParent && node.iconOpen && node.iconClose) ? (node.open ? node.iconOpen : node.iconClose) : node[setting.data.key.icon];
  1330. if (icon) icoStyle.push("background:url(", icon, ") 0 0 no-repeat;");
  1331. if (setting.view.showIcon == false || !tools.apply(setting.view.showIcon, [setting.treeId, node], true)) {
  1332. icoStyle.push("display:none;");
  1333. }
  1334. }
  1335. return icoStyle.join('');
  1336. },
  1337. makeNodeLineClass: function (setting, node) {
  1338. var lineClass = [];
  1339. if (setting.view.showLine) {
  1340. if (node.level == 0 && node.isFirstNode && node.isLastNode) {
  1341. lineClass.push(consts.line.ROOT);
  1342. } else if (node.level == 0 && node.isFirstNode) {
  1343. lineClass.push(consts.line.ROOTS);
  1344. } else if (node.isLastNode) {
  1345. lineClass.push(consts.line.BOTTOM);
  1346. } else {
  1347. lineClass.push(consts.line.CENTER);
  1348. }
  1349. } else {
  1350. lineClass.push(consts.line.NOLINE);
  1351. }
  1352. if (data.nodeIsParent(setting, node)) {
  1353. lineClass.push(node.open ? consts.folder.OPEN : consts.folder.CLOSE);
  1354. } else {
  1355. lineClass.push(consts.folder.DOCU);
  1356. }
  1357. return view.makeNodeLineClassEx(node) + lineClass.join('_');
  1358. },
  1359. makeNodeLineClassEx: function (node) {
  1360. return consts.className.BUTTON + " " + consts.className.LEVEL + node.level + " " + consts.className.SWITCH + " ";
  1361. },
  1362. makeNodeTarget: function (node) {
  1363. return (node.target || "_blank");
  1364. },
  1365. makeNodeUrl: function (setting, node) {
  1366. var urlKey = setting.data.key.url;
  1367. return node[urlKey] ? node[urlKey] : null;
  1368. },
  1369. makeUlHtml: function (setting, node, html, content) {
  1370. 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"), "'>");
  1371. html.push(content);
  1372. html.push("</ul>");
  1373. },
  1374. makeUlLineClass: function (setting, node) {
  1375. return ((setting.view.showLine && !node.isLastNode) ? consts.line.LINE : "");
  1376. },
  1377. removeChildNodes: function (setting, node) {
  1378. if (!node) return;
  1379. var nodes = data.nodeChildren(setting, node);
  1380. if (!nodes) return;
  1381. for (var i = 0, l = nodes.length; i < l; i++) {
  1382. data.removeNodeCache(setting, nodes[i]);
  1383. }
  1384. data.removeSelectedNode(setting);
  1385. delete node[setting.data.key.children];
  1386. if (!setting.data.keep.parent) {
  1387. data.nodeIsParent(setting, node, false);
  1388. node.open = false;
  1389. var tmp_switchObj = $$(node, consts.id.SWITCH, setting),
  1390. tmp_icoObj = $$(node, consts.id.ICON, setting);
  1391. view.replaceSwitchClass(node, tmp_switchObj, consts.folder.DOCU);
  1392. view.replaceIcoClass(node, tmp_icoObj, consts.folder.DOCU);
  1393. $$(node, consts.id.UL, setting).remove();
  1394. } else {
  1395. $$(node, consts.id.UL, setting).empty();
  1396. }
  1397. },
  1398. scrollIntoView: function (setting, dom) {
  1399. if (!dom) {
  1400. return;
  1401. }
  1402. // support IE 7 / 8
  1403. if (typeof Element === 'undefined' || typeof HTMLElement === 'undefined') {
  1404. var contRect = setting.treeObj.get(0).getBoundingClientRect(),
  1405. findMeRect = dom.getBoundingClientRect();
  1406. if (findMeRect.top < contRect.top || findMeRect.bottom > contRect.bottom
  1407. || findMeRect.right > contRect.right || findMeRect.left < contRect.left) {
  1408. dom.scrollIntoView();
  1409. }
  1410. return;
  1411. }
  1412. // CC-BY jocki84@googlemail.com, https://gist.github.com/jocki84/6ffafd003387179a988e
  1413. if (!Element.prototype.scrollIntoViewIfNeeded) {
  1414. Element.prototype.scrollIntoViewIfNeeded = function (centerIfNeeded) {
  1415. "use strict";
  1416. function makeRange(start, length) {
  1417. return {"start": start, "length": length, "end": start + length};
  1418. }
  1419. function coverRange(inner, outer) {
  1420. if (
  1421. false === centerIfNeeded ||
  1422. (outer.start < inner.end && inner.start < outer.end)
  1423. ) {
  1424. return Math.max(
  1425. inner.end - outer.length,
  1426. Math.min(outer.start, inner.start)
  1427. );
  1428. }
  1429. return (inner.start + inner.end - outer.length) / 2;
  1430. }
  1431. function makePoint(x, y) {
  1432. return {
  1433. "x": x,
  1434. "y": y,
  1435. "translate": function translate(dX, dY) {
  1436. return makePoint(x + dX, y + dY);
  1437. }
  1438. };
  1439. }
  1440. function absolute(elem, pt) {
  1441. while (elem) {
  1442. pt = pt.translate(elem.offsetLeft, elem.offsetTop);
  1443. elem = elem.offsetParent;
  1444. }
  1445. return pt;
  1446. }
  1447. var target = absolute(this, makePoint(0, 0)),
  1448. extent = makePoint(this.offsetWidth, this.offsetHeight),
  1449. elem = this.parentNode,
  1450. origin;
  1451. while (elem instanceof HTMLElement) {
  1452. // Apply desired scroll amount.
  1453. origin = absolute(elem, makePoint(elem.clientLeft, elem.clientTop));
  1454. elem.scrollLeft = coverRange(
  1455. makeRange(target.x - origin.x, extent.x),
  1456. makeRange(elem.scrollLeft, elem.clientWidth)
  1457. );
  1458. elem.scrollTop = coverRange(
  1459. makeRange(target.y - origin.y, extent.y),
  1460. makeRange(elem.scrollTop, elem.clientHeight)
  1461. );
  1462. // Determine actual scroll amount by reading back scroll properties.
  1463. target = target.translate(-elem.scrollLeft, -elem.scrollTop);
  1464. elem = elem.parentNode;
  1465. }
  1466. };
  1467. }
  1468. dom.scrollIntoViewIfNeeded();
  1469. },
  1470. setFirstNode: function (setting, parentNode) {
  1471. var children = data.nodeChildren(setting, parentNode);
  1472. if (children.length > 0) {
  1473. children[0].isFirstNode = true;
  1474. }
  1475. },
  1476. setLastNode: function (setting, parentNode) {
  1477. var children = data.nodeChildren(setting, parentNode);
  1478. if (children.length > 0) {
  1479. children[children.length - 1].isLastNode = true;
  1480. }
  1481. },
  1482. removeNode: function (setting, node) {
  1483. var root = data.getRoot(setting),
  1484. parentNode = (node.parentTId) ? node.getParentNode() : root;
  1485. node.isFirstNode = false;
  1486. node.isLastNode = false;
  1487. node.getPreNode = function () {
  1488. return null;
  1489. };
  1490. node.getNextNode = function () {
  1491. return null;
  1492. };
  1493. if (!data.getNodeCache(setting, node.tId)) {
  1494. return;
  1495. }
  1496. $$(node, setting).remove();
  1497. data.removeNodeCache(setting, node);
  1498. data.removeSelectedNode(setting, node);
  1499. var children = data.nodeChildren(setting, parentNode);
  1500. for (var i = 0, l = children.length; i < l; i++) {
  1501. if (children[i].tId == node.tId) {
  1502. children.splice(i, 1);
  1503. break;
  1504. }
  1505. }
  1506. view.setFirstNode(setting, parentNode);
  1507. view.setLastNode(setting, parentNode);
  1508. var tmp_ulObj, tmp_switchObj, tmp_icoObj,
  1509. childLength = children.length;
  1510. //repair nodes old parent
  1511. if (!setting.data.keep.parent && childLength == 0) {
  1512. //old parentNode has no child nodes
  1513. data.nodeIsParent(setting, parentNode, false);
  1514. parentNode.open = false;
  1515. delete parentNode[setting.data.key.children];
  1516. tmp_ulObj = $$(parentNode, consts.id.UL, setting);
  1517. tmp_switchObj = $$(parentNode, consts.id.SWITCH, setting);
  1518. tmp_icoObj = $$(parentNode, consts.id.ICON, setting);
  1519. view.replaceSwitchClass(parentNode, tmp_switchObj, consts.folder.DOCU);
  1520. view.replaceIcoClass(parentNode, tmp_icoObj, consts.folder.DOCU);
  1521. tmp_ulObj.css("display", "none");
  1522. } else if (setting.view.showLine && childLength > 0) {
  1523. //old parentNode has child nodes
  1524. var newLast = children[childLength - 1];
  1525. tmp_ulObj = $$(newLast, consts.id.UL, setting);
  1526. tmp_switchObj = $$(newLast, consts.id.SWITCH, setting);
  1527. tmp_icoObj = $$(newLast, consts.id.ICON, setting);
  1528. if (parentNode == root) {
  1529. if (children.length == 1) {
  1530. //node was root, and ztree has only one root after move node
  1531. view.replaceSwitchClass(newLast, tmp_switchObj, consts.line.ROOT);
  1532. } else {
  1533. var tmp_first_switchObj = $$(children[0], consts.id.SWITCH, setting);
  1534. view.replaceSwitchClass(children[0], tmp_first_switchObj, consts.line.ROOTS);
  1535. view.replaceSwitchClass(newLast, tmp_switchObj, consts.line.BOTTOM);
  1536. }
  1537. } else {
  1538. view.replaceSwitchClass(newLast, tmp_switchObj, consts.line.BOTTOM);
  1539. }
  1540. tmp_ulObj.removeClass(consts.line.LINE);
  1541. }
  1542. },
  1543. replaceIcoClass: function (node, obj, newName) {
  1544. if (!obj || node.isAjaxing) return;
  1545. var tmpName = obj.attr("class");
  1546. if (tmpName == undefined) return;
  1547. var tmpList = tmpName.split("_");
  1548. switch (newName) {
  1549. case consts.folder.OPEN:
  1550. case consts.folder.CLOSE:
  1551. case consts.folder.DOCU:
  1552. tmpList[tmpList.length - 1] = newName;
  1553. break;
  1554. }
  1555. obj.attr("class", tmpList.join("_"));
  1556. },
  1557. replaceSwitchClass: function (node, obj, newName) {
  1558. if (!obj) return;
  1559. var tmpName = obj.attr("class");
  1560. if (tmpName == undefined) return;
  1561. var tmpList = tmpName.split("_");
  1562. switch (newName) {
  1563. case consts.line.ROOT:
  1564. case consts.line.ROOTS:
  1565. case consts.line.CENTER:
  1566. case consts.line.BOTTOM:
  1567. case consts.line.NOLINE:
  1568. tmpList[0] = view.makeNodeLineClassEx(node) + newName;
  1569. break;
  1570. case consts.folder.OPEN:
  1571. case consts.folder.CLOSE:
  1572. case consts.folder.DOCU:
  1573. tmpList[1] = newName;
  1574. break;
  1575. }
  1576. obj.attr("class", tmpList.join("_"));
  1577. if (newName !== consts.folder.DOCU) {
  1578. obj.removeAttr("disabled");
  1579. } else {
  1580. obj.attr("disabled", "disabled");
  1581. }
  1582. },
  1583. selectNode: function (setting, node, addFlag) {
  1584. if (!addFlag) {
  1585. view.cancelPreSelectedNode(setting, null, node);
  1586. }
  1587. $$(node, consts.id.A, setting).addClass(consts.node.CURSELECTED);
  1588. data.addSelectedNode(setting, node);
  1589. setting.treeObj.trigger(consts.event.SELECTED, [setting.treeId, node]);
  1590. },
  1591. setNodeFontCss: function (setting, treeNode) {
  1592. var aObj = $$(treeNode, consts.id.A, setting),
  1593. fontCss = view.makeNodeFontCss(setting, treeNode);
  1594. if (fontCss) {
  1595. aObj.css(fontCss);
  1596. }
  1597. },
  1598. setNodeLineIcos: function (setting, node) {
  1599. if (!node) return;
  1600. var switchObj = $$(node, consts.id.SWITCH, setting),
  1601. ulObj = $$(node, consts.id.UL, setting),
  1602. icoObj = $$(node, consts.id.ICON, setting),
  1603. ulLine = view.makeUlLineClass(setting, node);
  1604. if (ulLine.length == 0) {
  1605. ulObj.removeClass(consts.line.LINE);
  1606. } else {
  1607. ulObj.addClass(ulLine);
  1608. }
  1609. switchObj.attr("class", view.makeNodeLineClass(setting, node));
  1610. if (data.nodeIsParent(setting, node)) {
  1611. switchObj.removeAttr("disabled");
  1612. } else {
  1613. switchObj.attr("disabled", "disabled");
  1614. }
  1615. icoObj.removeAttr("style");
  1616. icoObj.attr("style", view.makeNodeIcoStyle(setting, node));
  1617. icoObj.attr("class", view.makeNodeIcoClass(setting, node));
  1618. },
  1619. setNodeName: function (setting, node) {
  1620. var title = data.nodeTitle(setting, node),
  1621. nObj = $$(node, consts.id.SPAN, setting);
  1622. nObj.empty();
  1623. if (setting.view.nameIsHTML) {
  1624. nObj.html(data.nodeName(setting, node));
  1625. } else {
  1626. nObj.text(data.nodeName(setting, node));
  1627. }
  1628. if (tools.apply(setting.view.showTitle, [setting.treeId, node], setting.view.showTitle)) {
  1629. var aObj = $$(node, consts.id.A, setting);
  1630. aObj.attr("title", !title ? "" : title);
  1631. }
  1632. },
  1633. setNodeTarget: function (setting, node) {
  1634. var aObj = $$(node, consts.id.A, setting);
  1635. aObj.attr("target", view.makeNodeTarget(node));
  1636. },
  1637. setNodeUrl: function (setting, node) {
  1638. var aObj = $$(node, consts.id.A, setting),
  1639. url = view.makeNodeUrl(setting, node);
  1640. if (url == null || url.length == 0) {
  1641. aObj.removeAttr("href");
  1642. } else {
  1643. aObj.attr("href", url);
  1644. }
  1645. },
  1646. switchNode: function (setting, node) {
  1647. if (node.open || !tools.canAsync(setting, node)) {
  1648. view.expandCollapseNode(setting, node, !node.open);
  1649. } else if (setting.async.enable) {
  1650. if (!view.asyncNode(setting, node)) {
  1651. view.expandCollapseNode(setting, node, !node.open);
  1652. return;
  1653. }
  1654. } else if (node) {
  1655. view.expandCollapseNode(setting, node, !node.open);
  1656. }
  1657. }
  1658. };
  1659. // zTree defind
  1660. $.fn.zTree = {
  1661. consts: _consts,
  1662. _z: {
  1663. tools: tools,
  1664. view: view,
  1665. event: event,
  1666. data: data
  1667. },
  1668. getZTreeObj: function (treeId) {
  1669. var o = data.getZTreeTools(treeId);
  1670. return o ? o : null;
  1671. },
  1672. destroy: function (treeId) {
  1673. if (!!treeId && treeId.length > 0) {
  1674. view.destroy(data.getSetting(treeId));
  1675. } else {
  1676. for (var s in settings) {
  1677. view.destroy(settings[s]);
  1678. }
  1679. }
  1680. },
  1681. init: function (obj, zSetting, zNodes) {
  1682. var setting = tools.clone(_setting);
  1683. $.extend(true, setting, zSetting);
  1684. setting.treeId = obj.attr("id");
  1685. setting.treeObj = obj;
  1686. setting.treeObj.empty();
  1687. settings[setting.treeId] = setting;
  1688. //For some older browser,(e.g., ie6)
  1689. if (typeof document.body.style.maxHeight === "undefined") {
  1690. setting.view.expandSpeed = "";
  1691. }
  1692. data.initRoot(setting);
  1693. var root = data.getRoot(setting);
  1694. zNodes = zNodes ? tools.clone(tools.isArray(zNodes) ? zNodes : [zNodes]) : [];
  1695. if (setting.data.simpleData.enable) {
  1696. data.nodeChildren(setting, root, data.transformTozTreeFormat(setting, zNodes));
  1697. } else {
  1698. data.nodeChildren(setting, root, zNodes);
  1699. }
  1700. data.initCache(setting);
  1701. event.unbindTree(setting);
  1702. event.bindTree(setting);
  1703. event.unbindEvent(setting);
  1704. event.bindEvent(setting);
  1705. var zTreeTools = {
  1706. setting: setting,
  1707. addNodes: function (parentNode, index, newNodes, isSilent) {
  1708. if (!parentNode) parentNode = null;
  1709. var isParent = data.nodeIsParent(setting, parentNode);
  1710. if (parentNode && !isParent && setting.data.keep.leaf) return null;
  1711. var i = parseInt(index, 10);
  1712. if (isNaN(i)) {
  1713. isSilent = !!newNodes;
  1714. newNodes = index;
  1715. index = -1;
  1716. } else {
  1717. index = i;
  1718. }
  1719. if (!newNodes) return null;
  1720. var xNewNodes = tools.clone(tools.isArray(newNodes) ? newNodes : [newNodes]);
  1721. function addCallback() {
  1722. view.addNodes(setting, parentNode, index, xNewNodes, (isSilent == true));
  1723. }
  1724. if (tools.canAsync(setting, parentNode)) {
  1725. view.asyncNode(setting, parentNode, isSilent, addCallback);
  1726. } else {
  1727. addCallback();
  1728. }
  1729. return xNewNodes;
  1730. },
  1731. cancelSelectedNode: function (node) {
  1732. view.cancelPreSelectedNode(setting, node);
  1733. },
  1734. destroy: function () {
  1735. view.destroy(setting);
  1736. },
  1737. expandAll: function (expandFlag) {
  1738. expandFlag = !!expandFlag;
  1739. view.expandCollapseSonNode(setting, null, expandFlag, true);
  1740. return expandFlag;
  1741. },
  1742. expandNode: function (node, expandFlag, sonSign, focus, callbackFlag) {
  1743. if (!node || !data.nodeIsParent(setting, node)) return null;
  1744. if (expandFlag !== true && expandFlag !== false) {
  1745. expandFlag = !node.open;
  1746. }
  1747. callbackFlag = !!callbackFlag;
  1748. if (callbackFlag && expandFlag && (tools.apply(setting.callback.beforeExpand, [setting.treeId, node], true) == false)) {
  1749. return null;
  1750. } else if (callbackFlag && !expandFlag && (tools.apply(setting.callback.beforeCollapse, [setting.treeId, node], true) == false)) {
  1751. return null;
  1752. }
  1753. if (expandFlag && node.parentTId) {
  1754. view.expandCollapseParentNode(setting, node.getParentNode(), expandFlag, false);
  1755. }
  1756. if (expandFlag === node.open && !sonSign) {
  1757. return null;
  1758. }
  1759. data.getRoot(setting).expandTriggerFlag = callbackFlag;
  1760. if (!tools.canAsync(setting, node) && sonSign) {
  1761. view.expandCollapseSonNode(setting, node, expandFlag, true, showNodeFocus);
  1762. } else {
  1763. node.open = !expandFlag;
  1764. view.switchNode(this.setting, node);
  1765. showNodeFocus();
  1766. }
  1767. return expandFlag;
  1768. function showNodeFocus() {
  1769. var a = $$(node, setting).get(0);
  1770. if (a && focus !== false) {
  1771. view.scrollIntoView(setting, a);
  1772. }
  1773. }
  1774. },
  1775. getNodes: function () {
  1776. return data.getNodes(setting);
  1777. },
  1778. getNodeByParam: function (key, value, parentNode) {
  1779. if (!key) return null;
  1780. return data.getNodeByParam(setting, parentNode ? data.nodeChildren(setting, parentNode) : data.getNodes(setting), key, value);
  1781. },
  1782. getNodeByTId: function (tId) {
  1783. return data.getNodeCache(setting, tId);
  1784. },
  1785. getNodesByParam: function (key, value, parentNode) {
  1786. if (!key) return null;
  1787. return data.getNodesByParam(setting, parentNode ? data.nodeChildren(setting, parentNode) : data.getNodes(setting), key, value);
  1788. },
  1789. getNodesByParamFuzzy: function (key, value, parentNode) {
  1790. if (!key) return null;
  1791. return data.getNodesByParamFuzzy(setting, parentNode ? data.nodeChildren(setting, parentNode) : data.getNodes(setting), key, value);
  1792. },
  1793. getNodesByFilter: function (filter, isSingle, parentNode, invokeParam) {
  1794. isSingle = !!isSingle;
  1795. if (!filter || (typeof filter != "function")) return (isSingle ? null : []);
  1796. return data.getNodesByFilter(setting, parentNode ? data.nodeChildren(setting, parentNode) : data.getNodes(setting), filter, isSingle, invokeParam);
  1797. },
  1798. getNodeIndex: function (node) {
  1799. if (!node) return null;
  1800. var parentNode = (node.parentTId) ? node.getParentNode() : data.getRoot(setting);
  1801. var children = data.nodeChildren(setting, parentNode);
  1802. for (var i = 0, l = children.length; i < l; i++) {
  1803. if (children[i] == node) return i;
  1804. }
  1805. return -1;
  1806. },
  1807. getSelectedNodes: function () {
  1808. var r = [], list = data.getRoot(setting).curSelectedList;
  1809. for (var i = 0, l = list.length; i < l; i++) {
  1810. r.push(list[i]);
  1811. }
  1812. return r;
  1813. },
  1814. isSelectedNode: function (node) {
  1815. return data.isSelectedNode(setting, node);
  1816. },
  1817. reAsyncChildNodesPromise: function (parentNode, reloadType, isSilent) {
  1818. var promise = new Promise(function (resolve, reject) {
  1819. try {
  1820. zTreeTools.reAsyncChildNodes(parentNode, reloadType, isSilent, function () {
  1821. resolve(parentNode);
  1822. });
  1823. } catch (e) {
  1824. reject(e);
  1825. }
  1826. });
  1827. return promise;
  1828. },
  1829. reAsyncChildNodes: function (parentNode, reloadType, isSilent, callback) {
  1830. if (!this.setting.async.enable) return;
  1831. var isRoot = !parentNode;
  1832. if (isRoot) {
  1833. parentNode = data.getRoot(setting);
  1834. }
  1835. if (reloadType == "refresh") {
  1836. var children = data.nodeChildren(setting, parentNode);
  1837. for (var i = 0, l = children ? children.length : 0; i < l; i++) {
  1838. data.removeNodeCache(setting, children[i]);
  1839. }
  1840. data.removeSelectedNode(setting);
  1841. data.nodeChildren(setting, parentNode, []);
  1842. if (isRoot) {
  1843. this.setting.treeObj.empty();
  1844. } else {
  1845. var ulObj = $$(parentNode, consts.id.UL, setting);
  1846. ulObj.empty();
  1847. }
  1848. }
  1849. view.asyncNode(this.setting, isRoot ? null : parentNode, !!isSilent, callback);
  1850. },
  1851. refresh: function () {
  1852. this.setting.treeObj.empty();
  1853. var root = data.getRoot(setting),
  1854. nodes = data.nodeChildren(setting, root);
  1855. data.initRoot(setting);
  1856. data.nodeChildren(setting, root, nodes);
  1857. data.initCache(setting);
  1858. view.createNodes(setting, 0, data.nodeChildren(setting, root), null, -1);
  1859. },
  1860. removeChildNodes: function (node) {
  1861. if (!node) return null;
  1862. var nodes = data.nodeChildren(setting, node);
  1863. view.removeChildNodes(setting, node);
  1864. return nodes ? nodes : null;
  1865. },
  1866. removeNode: function (node, callbackFlag) {
  1867. if (!node) return;
  1868. callbackFlag = !!callbackFlag;
  1869. if (callbackFlag && tools.apply(setting.callback.beforeRemove, [setting.treeId, node], true) == false) return;
  1870. view.removeNode(setting, node);
  1871. if (callbackFlag) {
  1872. this.setting.treeObj.trigger(consts.event.REMOVE, [setting.treeId, node]);
  1873. }
  1874. },
  1875. selectNode: function (node, addFlag, isSilent) {
  1876. if (!node) return;
  1877. if (tools.uCanDo(setting)) {
  1878. addFlag = setting.view.selectedMulti && addFlag;
  1879. if (node.parentTId) {
  1880. view.expandCollapseParentNode(setting, node.getParentNode(), true, false, showNodeFocus);
  1881. } else if (!isSilent) {
  1882. try {
  1883. $$(node, setting).focus().blur();
  1884. } catch (e) {
  1885. }
  1886. }
  1887. view.selectNode(setting, node, addFlag);
  1888. }
  1889. function showNodeFocus() {
  1890. if (isSilent) {
  1891. return;
  1892. }
  1893. var a = $$(node, setting).get(0);
  1894. view.scrollIntoView(setting, a);
  1895. }
  1896. },
  1897. transformTozTreeNodes: function (simpleNodes) {
  1898. return data.transformTozTreeFormat(setting, simpleNodes);
  1899. },
  1900. transformToArray: function (nodes) {
  1901. return data.transformToArrayFormat(setting, nodes);
  1902. },
  1903. updateNode: function (node, checkTypeFlag) {
  1904. if (!node) return;
  1905. var nObj = $$(node, setting);
  1906. if (nObj.get(0) && tools.uCanDo(setting)) {
  1907. view.setNodeName(setting, node);
  1908. view.setNodeTarget(setting, node);
  1909. view.setNodeUrl(setting, node);
  1910. view.setNodeLineIcos(setting, node);
  1911. view.setNodeFontCss(setting, node);
  1912. }
  1913. }
  1914. };
  1915. root.treeTools = zTreeTools;
  1916. data.setZTreeTools(setting, zTreeTools);
  1917. var children = data.nodeChildren(setting, root);
  1918. if (children && children.length > 0) {
  1919. view.createNodes(setting, 0, children, null, -1);
  1920. } else if (setting.async.enable && setting.async.url && setting.async.url !== '') {
  1921. view.asyncNode(setting);
  1922. }
  1923. return zTreeTools;
  1924. }
  1925. };
  1926. var zt = $.fn.zTree,
  1927. $$ = tools.$,
  1928. consts = zt.consts;
  1929. })(jQuery);
  1930. /*
  1931. * JQuery zTree excheck
  1932. * v3.5.42
  1933. * http://treejs.cn/
  1934. *
  1935. * Copyright (c) 2010 Hunter.z
  1936. *
  1937. * Licensed same as jquery - MIT License
  1938. * http://www.opensource.org/licenses/mit-license.php
  1939. *
  1940. * Date: 2020-01-19
  1941. */
  1942. (function ($) {
  1943. //default consts of excheck
  1944. var _consts = {
  1945. event: {
  1946. CHECK: "ztree_check"
  1947. },
  1948. id: {
  1949. CHECK: "_check"
  1950. },
  1951. checkbox: {
  1952. STYLE: "checkbox",
  1953. DEFAULT: "chk",
  1954. DISABLED: "disable",
  1955. FALSE: "false",
  1956. TRUE: "true",
  1957. FULL: "full",
  1958. PART: "part",
  1959. FOCUS: "focus"
  1960. },
  1961. radio: {
  1962. STYLE: "radio",
  1963. TYPE_ALL: "all",
  1964. TYPE_LEVEL: "level"
  1965. }
  1966. },
  1967. //default setting of excheck
  1968. _setting = {
  1969. check: {
  1970. enable: false,
  1971. autoCheckTrigger: false,
  1972. chkStyle: _consts.checkbox.STYLE,
  1973. nocheckInherit: false,
  1974. chkDisabledInherit: false,
  1975. radioType: _consts.radio.TYPE_LEVEL,
  1976. chkboxType: {
  1977. "Y": "ps",
  1978. "N": "ps"
  1979. }
  1980. },
  1981. data: {
  1982. key: {
  1983. checked: "checked"
  1984. }
  1985. },
  1986. callback: {
  1987. beforeCheck: null,
  1988. onCheck: null
  1989. }
  1990. },
  1991. //default root of excheck
  1992. _initRoot = function (setting) {
  1993. var r = data.getRoot(setting);
  1994. r.radioCheckedList = [];
  1995. },
  1996. //default cache of excheck
  1997. _initCache = function (treeId) {
  1998. },
  1999. //default bind event of excheck
  2000. _bindEvent = function (setting) {
  2001. var o = setting.treeObj,
  2002. c = consts.event;
  2003. o.bind(c.CHECK, function (event, srcEvent, treeId, node) {
  2004. event.srcEvent = srcEvent;
  2005. tools.apply(setting.callback.onCheck, [event, treeId, node]);
  2006. });
  2007. },
  2008. _unbindEvent = function (setting) {
  2009. var o = setting.treeObj,
  2010. c = consts.event;
  2011. o.unbind(c.CHECK);
  2012. },
  2013. //default event proxy of excheck
  2014. _eventProxy = function (e) {
  2015. var target = e.target,
  2016. setting = data.getSetting(e.data.treeId),
  2017. tId = "", node = null,
  2018. nodeEventType = "", treeEventType = "",
  2019. nodeEventCallback = null, treeEventCallback = null;
  2020. if (tools.eqs(e.type, "mouseover")) {
  2021. if (setting.check.enable && tools.eqs(target.tagName, "span") && target.getAttribute("treeNode" + consts.id.CHECK) !== null) {
  2022. tId = tools.getNodeMainDom(target).id;
  2023. nodeEventType = "mouseoverCheck";
  2024. }
  2025. } else if (tools.eqs(e.type, "mouseout")) {
  2026. if (setting.check.enable && tools.eqs(target.tagName, "span") && target.getAttribute("treeNode" + consts.id.CHECK) !== null) {
  2027. tId = tools.getNodeMainDom(target).id;
  2028. nodeEventType = "mouseoutCheck";
  2029. }
  2030. } else if (tools.eqs(e.type, "click")) {
  2031. if (setting.check.enable && tools.eqs(target.tagName, "span") && target.getAttribute("treeNode" + consts.id.CHECK) !== null) {
  2032. tId = tools.getNodeMainDom(target).id;
  2033. nodeEventType = "checkNode";
  2034. }
  2035. }
  2036. if (tId.length > 0) {
  2037. node = data.getNodeCache(setting, tId);
  2038. switch (nodeEventType) {
  2039. case "checkNode" :
  2040. nodeEventCallback = _handler.onCheckNode;
  2041. break;
  2042. case "mouseoverCheck" :
  2043. nodeEventCallback = _handler.onMouseoverCheck;
  2044. break;
  2045. case "mouseoutCheck" :
  2046. nodeEventCallback = _handler.onMouseoutCheck;
  2047. break;
  2048. }
  2049. }
  2050. var proxyResult = {
  2051. stop: nodeEventType === "checkNode",
  2052. node: node,
  2053. nodeEventType: nodeEventType,
  2054. nodeEventCallback: nodeEventCallback,
  2055. treeEventType: treeEventType,
  2056. treeEventCallback: treeEventCallback
  2057. };
  2058. return proxyResult
  2059. },
  2060. //default init node of excheck
  2061. _initNode = function (setting, level, n, parentNode, isFirstNode, isLastNode, openFlag) {
  2062. if (!n) return;
  2063. var checked = data.nodeChecked(setting, n);
  2064. n.checkedOld = checked;
  2065. if (typeof n.nocheck == "string") n.nocheck = tools.eqs(n.nocheck, "true");
  2066. n.nocheck = !!n.nocheck || (setting.check.nocheckInherit && parentNode && !!parentNode.nocheck);
  2067. if (typeof n.chkDisabled == "string") n.chkDisabled = tools.eqs(n.chkDisabled, "true");
  2068. n.chkDisabled = !!n.chkDisabled || (setting.check.chkDisabledInherit && parentNode && !!parentNode.chkDisabled);
  2069. if (typeof n.halfCheck == "string") n.halfCheck = tools.eqs(n.halfCheck, "true");
  2070. n.halfCheck = !!n.halfCheck;
  2071. n.check_Child_State = -1;
  2072. n.check_Focus = false;
  2073. n.getCheckStatus = function () {
  2074. return data.getCheckStatus(setting, n);
  2075. };
  2076. if (setting.check.chkStyle == consts.radio.STYLE && setting.check.radioType == consts.radio.TYPE_ALL && checked) {
  2077. var r = data.getRoot(setting);
  2078. r.radioCheckedList.push(n);
  2079. }
  2080. },
  2081. //add dom for check
  2082. _beforeA = function (setting, node, html) {
  2083. if (setting.check.enable) {
  2084. data.makeChkFlag(setting, node);
  2085. 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>");
  2086. }
  2087. },
  2088. //update zTreeObj, add method of check
  2089. _zTreeTools = function (setting, zTreeTools) {
  2090. zTreeTools.checkNode = function (node, checked, checkTypeFlag, callbackFlag) {
  2091. var nodeChecked = data.nodeChecked(setting, node);
  2092. if (node.chkDisabled === true) return;
  2093. if (checked !== true && checked !== false) {
  2094. checked = !nodeChecked;
  2095. }
  2096. callbackFlag = !!callbackFlag;
  2097. if (nodeChecked === checked && !checkTypeFlag) {
  2098. return;
  2099. } else if (callbackFlag && tools.apply(this.setting.callback.beforeCheck, [this.setting.treeId, node], true) == false) {
  2100. return;
  2101. }
  2102. if (tools.uCanDo(this.setting) && this.setting.check.enable && node.nocheck !== true) {
  2103. data.nodeChecked(setting, node, checked);
  2104. var checkObj = $$(node, consts.id.CHECK, this.setting);
  2105. if (checkTypeFlag || this.setting.check.chkStyle === consts.radio.STYLE) view.checkNodeRelation(this.setting, node);
  2106. view.setChkClass(this.setting, checkObj, node);
  2107. view.repairParentChkClassWithSelf(this.setting, node);
  2108. if (callbackFlag) {
  2109. this.setting.treeObj.trigger(consts.event.CHECK, [null, this.setting.treeId, node]);
  2110. }
  2111. }
  2112. }
  2113. zTreeTools.checkAllNodes = function (checked) {
  2114. view.repairAllChk(this.setting, !!checked);
  2115. }
  2116. zTreeTools.getCheckedNodes = function (checked) {
  2117. checked = (checked !== false);
  2118. var children = data.nodeChildren(setting, data.getRoot(this.setting));
  2119. return data.getTreeCheckedNodes(this.setting, children, checked);
  2120. }
  2121. zTreeTools.getChangeCheckedNodes = function () {
  2122. var children = data.nodeChildren(setting, data.getRoot(this.setting));
  2123. return data.getTreeChangeCheckedNodes(this.setting, children);
  2124. }
  2125. zTreeTools.setChkDisabled = function (node, disabled, inheritParent, inheritChildren) {
  2126. disabled = !!disabled;
  2127. inheritParent = !!inheritParent;
  2128. inheritChildren = !!inheritChildren;
  2129. view.repairSonChkDisabled(this.setting, node, disabled, inheritChildren);
  2130. view.repairParentChkDisabled(this.setting, node.getParentNode(), disabled, inheritParent);
  2131. }
  2132. var _updateNode = zTreeTools.updateNode;
  2133. zTreeTools.updateNode = function (node, checkTypeFlag) {
  2134. if (_updateNode) _updateNode.apply(zTreeTools, arguments);
  2135. if (!node || !this.setting.check.enable) return;
  2136. var nObj = $$(node, this.setting);
  2137. if (nObj.get(0) && tools.uCanDo(this.setting)) {
  2138. var checkObj = $$(node, consts.id.CHECK, this.setting);
  2139. if (checkTypeFlag == true || this.setting.check.chkStyle === consts.radio.STYLE) view.checkNodeRelation(this.setting, node);
  2140. view.setChkClass(this.setting, checkObj, node);
  2141. view.repairParentChkClassWithSelf(this.setting, node);
  2142. }
  2143. }
  2144. },
  2145. //method of operate data
  2146. _data = {
  2147. getRadioCheckedList: function (setting) {
  2148. var checkedList = data.getRoot(setting).radioCheckedList;
  2149. for (var i = 0, j = checkedList.length; i < j; i++) {
  2150. if (!data.getNodeCache(setting, checkedList[i].tId)) {
  2151. checkedList.splice(i, 1);
  2152. i--;
  2153. j--;
  2154. }
  2155. }
  2156. return checkedList;
  2157. },
  2158. getCheckStatus: function (setting, node) {
  2159. if (!setting.check.enable || node.nocheck || node.chkDisabled) return null;
  2160. var checked = data.nodeChecked(setting, node),
  2161. r = {
  2162. checked: checked,
  2163. half: node.halfCheck ? node.halfCheck : (setting.check.chkStyle == consts.radio.STYLE ? (node.check_Child_State === 2) : (checked ? (node.check_Child_State > -1 && node.check_Child_State < 2) : (node.check_Child_State > 0)))
  2164. };
  2165. return r;
  2166. },
  2167. getTreeCheckedNodes: function (setting, nodes, checked, results) {
  2168. if (!nodes) return [];
  2169. var onlyOne = (checked && setting.check.chkStyle == consts.radio.STYLE && setting.check.radioType == consts.radio.TYPE_ALL);
  2170. results = !results ? [] : results;
  2171. for (var i = 0, l = nodes.length; i < l; i++) {
  2172. var node = nodes[i];
  2173. var children = data.nodeChildren(setting, node);
  2174. var nodeChecked = data.nodeChecked(setting, node);
  2175. if (node.nocheck !== true && node.chkDisabled !== true && nodeChecked == checked) {
  2176. results.push(node);
  2177. if (onlyOne) {
  2178. break;
  2179. }
  2180. }
  2181. data.getTreeCheckedNodes(setting, children, checked, results);
  2182. if (onlyOne && results.length > 0) {
  2183. break;
  2184. }
  2185. }
  2186. return results;
  2187. },
  2188. getTreeChangeCheckedNodes: function (setting, nodes, results) {
  2189. if (!nodes) return [];
  2190. results = !results ? [] : results;
  2191. for (var i = 0, l = nodes.length; i < l; i++) {
  2192. var node = nodes[i];
  2193. var children = data.nodeChildren(setting, node);
  2194. var nodeChecked = data.nodeChecked(setting, node);
  2195. if (node.nocheck !== true && node.chkDisabled !== true && nodeChecked != node.checkedOld) {
  2196. results.push(node);
  2197. }
  2198. data.getTreeChangeCheckedNodes(setting, children, results);
  2199. }
  2200. return results;
  2201. },
  2202. makeChkFlag: function (setting, node) {
  2203. if (!node) return;
  2204. var chkFlag = -1;
  2205. var children = data.nodeChildren(setting, node);
  2206. if (children) {
  2207. for (var i = 0, l = children.length; i < l; i++) {
  2208. var cNode = children[i];
  2209. var nodeChecked = data.nodeChecked(setting, cNode);
  2210. var tmp = -1;
  2211. if (setting.check.chkStyle == consts.radio.STYLE) {
  2212. if (cNode.nocheck === true || cNode.chkDisabled === true) {
  2213. tmp = cNode.check_Child_State;
  2214. } else if (cNode.halfCheck === true) {
  2215. tmp = 2;
  2216. } else if (nodeChecked) {
  2217. tmp = 2;
  2218. } else {
  2219. tmp = cNode.check_Child_State > 0 ? 2 : 0;
  2220. }
  2221. if (tmp == 2) {
  2222. chkFlag = 2;
  2223. break;
  2224. } else if (tmp == 0) {
  2225. chkFlag = 0;
  2226. }
  2227. } else if (setting.check.chkStyle == consts.checkbox.STYLE) {
  2228. if (cNode.nocheck === true || cNode.chkDisabled === true) {
  2229. tmp = cNode.check_Child_State;
  2230. } else if (cNode.halfCheck === true) {
  2231. tmp = 1;
  2232. } else if (nodeChecked) {
  2233. tmp = (cNode.check_Child_State === -1 || cNode.check_Child_State === 2) ? 2 : 1;
  2234. } else {
  2235. tmp = (cNode.check_Child_State > 0) ? 1 : 0;
  2236. }
  2237. if (tmp === 1) {
  2238. chkFlag = 1;
  2239. break;
  2240. } else if (tmp === 2 && chkFlag > -1 && i > 0 && tmp !== chkFlag) {
  2241. chkFlag = 1;
  2242. break;
  2243. } else if (chkFlag === 2 && tmp > -1 && tmp < 2) {
  2244. chkFlag = 1;
  2245. break;
  2246. } else if (tmp > -1) {
  2247. chkFlag = tmp;
  2248. }
  2249. }
  2250. }
  2251. }
  2252. node.check_Child_State = chkFlag;
  2253. }
  2254. },
  2255. //method of event proxy
  2256. _event = {},
  2257. //method of event handler
  2258. _handler = {
  2259. onCheckNode: function (event, node) {
  2260. if (node.chkDisabled === true) return false;
  2261. var setting = data.getSetting(event.data.treeId);
  2262. if (tools.apply(setting.callback.beforeCheck, [setting.treeId, node], true) == false) return true;
  2263. var nodeChecked = data.nodeChecked(setting, node);
  2264. data.nodeChecked(setting, node, !nodeChecked);
  2265. view.checkNodeRelation(setting, node);
  2266. var checkObj = $$(node, consts.id.CHECK, setting);
  2267. view.setChkClass(setting, checkObj, node);
  2268. view.repairParentChkClassWithSelf(setting, node);
  2269. setting.treeObj.trigger(consts.event.CHECK, [event, setting.treeId, node]);
  2270. return true;
  2271. },
  2272. onMouseoverCheck: function (event, node) {
  2273. if (node.chkDisabled === true) return false;
  2274. var setting = data.getSetting(event.data.treeId),
  2275. checkObj = $$(node, consts.id.CHECK, setting);
  2276. node.check_Focus = true;
  2277. view.setChkClass(setting, checkObj, node);
  2278. return true;
  2279. },
  2280. onMouseoutCheck: function (event, node) {
  2281. if (node.chkDisabled === true) return false;
  2282. var setting = data.getSetting(event.data.treeId),
  2283. checkObj = $$(node, consts.id.CHECK, setting);
  2284. node.check_Focus = false;
  2285. view.setChkClass(setting, checkObj, node);
  2286. return true;
  2287. }
  2288. },
  2289. //method of tools for zTree
  2290. _tools = {},
  2291. //method of operate ztree dom
  2292. _view = {
  2293. checkNodeRelation: function (setting, node) {
  2294. var pNode, i, l,
  2295. r = consts.radio;
  2296. var nodeChecked = data.nodeChecked(setting, node);
  2297. if (setting.check.chkStyle == r.STYLE) {
  2298. var checkedList = data.getRadioCheckedList(setting);
  2299. if (nodeChecked) {
  2300. if (setting.check.radioType == r.TYPE_ALL) {
  2301. for (i = checkedList.length - 1; i >= 0; i--) {
  2302. pNode = checkedList[i];
  2303. var pNodeChecked = data.nodeChecked(setting, pNode);
  2304. if (pNodeChecked && pNode != node) {
  2305. data.nodeChecked(setting, pNode, false);
  2306. checkedList.splice(i, 1);
  2307. view.setChkClass(setting, $$(pNode, consts.id.CHECK, setting), pNode);
  2308. if (pNode.parentTId != node.parentTId) {
  2309. view.repairParentChkClassWithSelf(setting, pNode);
  2310. }
  2311. }
  2312. }
  2313. checkedList.push(node);
  2314. } else {
  2315. var parentNode = (node.parentTId) ? node.getParentNode() : data.getRoot(setting);
  2316. var children = data.nodeChildren(setting, parentNode);
  2317. for (i = 0, l = children.length; i < l; i++) {
  2318. pNode = children[i];
  2319. var pNodeChecked = data.nodeChecked(setting, pNode);
  2320. if (pNodeChecked && pNode != node) {
  2321. data.nodeChecked(setting, pNode, false);
  2322. view.setChkClass(setting, $$(pNode, consts.id.CHECK, setting), pNode);
  2323. }
  2324. }
  2325. }
  2326. } else if (setting.check.radioType == r.TYPE_ALL) {
  2327. for (i = 0, l = checkedList.length; i < l; i++) {
  2328. if (node == checkedList[i]) {
  2329. checkedList.splice(i, 1);
  2330. break;
  2331. }
  2332. }
  2333. }
  2334. } else {
  2335. var children = data.nodeChildren(setting, node);
  2336. if (nodeChecked && (!children || children.length == 0 || setting.check.chkboxType.Y.indexOf("s") > -1)) {
  2337. view.setSonNodeCheckBox(setting, node, true);
  2338. }
  2339. if (!nodeChecked && (!children || children.length == 0 || setting.check.chkboxType.N.indexOf("s") > -1)) {
  2340. view.setSonNodeCheckBox(setting, node, false);
  2341. }
  2342. if (nodeChecked && setting.check.chkboxType.Y.indexOf("p") > -1) {
  2343. view.setParentNodeCheckBox(setting, node, true);
  2344. }
  2345. if (!nodeChecked && setting.check.chkboxType.N.indexOf("p") > -1) {
  2346. view.setParentNodeCheckBox(setting, node, false);
  2347. }
  2348. }
  2349. },
  2350. makeChkClass: function (setting, node) {
  2351. var c = consts.checkbox, r = consts.radio,
  2352. fullStyle = "";
  2353. var nodeChecked = data.nodeChecked(setting, node);
  2354. if (node.chkDisabled === true) {
  2355. fullStyle = c.DISABLED;
  2356. } else if (node.halfCheck) {
  2357. fullStyle = c.PART;
  2358. } else if (setting.check.chkStyle == r.STYLE) {
  2359. fullStyle = (node.check_Child_State < 1) ? c.FULL : c.PART;
  2360. } else {
  2361. fullStyle = nodeChecked ? ((node.check_Child_State === 2 || node.check_Child_State === -1) ? c.FULL : c.PART) : ((node.check_Child_State < 1) ? c.FULL : c.PART);
  2362. }
  2363. var chkName = setting.check.chkStyle + "_" + (nodeChecked ? c.TRUE : c.FALSE) + "_" + fullStyle;
  2364. chkName = (node.check_Focus && node.chkDisabled !== true) ? chkName + "_" + c.FOCUS : chkName;
  2365. return consts.className.BUTTON + " " + c.DEFAULT + " " + chkName;
  2366. },
  2367. repairAllChk: function (setting, checked) {
  2368. if (setting.check.enable && setting.check.chkStyle === consts.checkbox.STYLE) {
  2369. var root = data.getRoot(setting);
  2370. var children = data.nodeChildren(setting, root);
  2371. for (var i = 0, l = children.length; i < l; i++) {
  2372. var node = children[i];
  2373. if (node.nocheck !== true && node.chkDisabled !== true) {
  2374. data.nodeChecked(setting, node, checked);
  2375. }
  2376. view.setSonNodeCheckBox(setting, node, checked);
  2377. }
  2378. }
  2379. },
  2380. repairChkClass: function (setting, node) {
  2381. if (!node) return;
  2382. data.makeChkFlag(setting, node);
  2383. if (node.nocheck !== true) {
  2384. var checkObj = $$(node, consts.id.CHECK, setting);
  2385. view.setChkClass(setting, checkObj, node);
  2386. }
  2387. },
  2388. repairParentChkClass: function (setting, node) {
  2389. if (!node || !node.parentTId) return;
  2390. var pNode = node.getParentNode();
  2391. view.repairChkClass(setting, pNode);
  2392. view.repairParentChkClass(setting, pNode);
  2393. },
  2394. repairParentChkClassWithSelf: function (setting, node) {
  2395. if (!node) return;
  2396. var children = data.nodeChildren(setting, node);
  2397. if (children && children.length > 0) {
  2398. view.repairParentChkClass(setting, children[0]);
  2399. } else {
  2400. view.repairParentChkClass(setting, node);
  2401. }
  2402. },
  2403. repairSonChkDisabled: function (setting, node, chkDisabled, inherit) {
  2404. if (!node) return;
  2405. if (node.chkDisabled != chkDisabled) {
  2406. node.chkDisabled = chkDisabled;
  2407. }
  2408. view.repairChkClass(setting, node);
  2409. var children = data.nodeChildren(setting, node);
  2410. if (children && inherit) {
  2411. for (var i = 0, l = children.length; i < l; i++) {
  2412. var sNode = children[i];
  2413. view.repairSonChkDisabled(setting, sNode, chkDisabled, inherit);
  2414. }
  2415. }
  2416. },
  2417. repairParentChkDisabled: function (setting, node, chkDisabled, inherit) {
  2418. if (!node) return;
  2419. if (node.chkDisabled != chkDisabled && inherit) {
  2420. node.chkDisabled = chkDisabled;
  2421. }
  2422. view.repairChkClass(setting, node);
  2423. view.repairParentChkDisabled(setting, node.getParentNode(), chkDisabled, inherit);
  2424. },
  2425. setChkClass: function (setting, obj, node) {
  2426. if (!obj) return;
  2427. if (node.nocheck === true) {
  2428. obj.hide();
  2429. } else {
  2430. obj.show();
  2431. }
  2432. obj.attr('class', view.makeChkClass(setting, node));
  2433. },
  2434. setParentNodeCheckBox: function (setting, node, value, srcNode) {
  2435. var checkObj = $$(node, consts.id.CHECK, setting);
  2436. if (!srcNode) srcNode = node;
  2437. data.makeChkFlag(setting, node);
  2438. if (node.nocheck !== true && node.chkDisabled !== true) {
  2439. data.nodeChecked(setting, node, value);
  2440. view.setChkClass(setting, checkObj, node);
  2441. if (setting.check.autoCheckTrigger && node != srcNode) {
  2442. setting.treeObj.trigger(consts.event.CHECK, [null, setting.treeId, node]);
  2443. }
  2444. }
  2445. if (node.parentTId) {
  2446. var pSign = true;
  2447. if (!value) {
  2448. var pNodes = data.nodeChildren(setting, node.getParentNode());
  2449. for (var i = 0, l = pNodes.length; i < l; i++) {
  2450. var pNode = pNodes[i];
  2451. var nodeChecked = data.nodeChecked(setting, pNode);
  2452. if ((pNode.nocheck !== true && pNode.chkDisabled !== true && nodeChecked)
  2453. || ((pNode.nocheck === true || pNode.chkDisabled === true) && pNode.check_Child_State > 0)) {
  2454. pSign = false;
  2455. break;
  2456. }
  2457. }
  2458. }
  2459. if (pSign) {
  2460. view.setParentNodeCheckBox(setting, node.getParentNode(), value, srcNode);
  2461. }
  2462. }
  2463. },
  2464. setSonNodeCheckBox: function (setting, node, value, srcNode) {
  2465. if (!node) return;
  2466. var checkObj = $$(node, consts.id.CHECK, setting);
  2467. if (!srcNode) srcNode = node;
  2468. var hasDisable = false;
  2469. var children = data.nodeChildren(setting, node);
  2470. if (children) {
  2471. for (var i = 0, l = children.length; i < l; i++) {
  2472. var sNode = children[i];
  2473. view.setSonNodeCheckBox(setting, sNode, value, srcNode);
  2474. if (sNode.chkDisabled === true) hasDisable = true;
  2475. }
  2476. }
  2477. if (node != data.getRoot(setting) && node.chkDisabled !== true) {
  2478. if (hasDisable && node.nocheck !== true) {
  2479. data.makeChkFlag(setting, node);
  2480. }
  2481. if (node.nocheck !== true && node.chkDisabled !== true) {
  2482. data.nodeChecked(setting, node, value);
  2483. if (!hasDisable) node.check_Child_State = (children && children.length > 0) ? (value ? 2 : 0) : -1;
  2484. } else {
  2485. node.check_Child_State = -1;
  2486. }
  2487. view.setChkClass(setting, checkObj, node);
  2488. if (setting.check.autoCheckTrigger && node != srcNode && node.nocheck !== true && node.chkDisabled !== true) {
  2489. setting.treeObj.trigger(consts.event.CHECK, [null, setting.treeId, node]);
  2490. }
  2491. }
  2492. }
  2493. },
  2494. _z = {
  2495. tools: _tools,
  2496. view: _view,
  2497. event: _event,
  2498. data: _data
  2499. };
  2500. $.extend(true, $.fn.zTree.consts, _consts);
  2501. $.extend(true, $.fn.zTree._z, _z);
  2502. var zt = $.fn.zTree,
  2503. tools = zt._z.tools,
  2504. consts = zt.consts,
  2505. view = zt._z.view,
  2506. data = zt._z.data,
  2507. event = zt._z.event,
  2508. $$ = tools.$;
  2509. data.nodeChecked = function (setting, node, newChecked) {
  2510. if (!node) {
  2511. return false;
  2512. }
  2513. var key = setting.data.key.checked;
  2514. if (typeof newChecked !== 'undefined') {
  2515. if (typeof newChecked === "string") {
  2516. newChecked = tools.eqs(newChecked, "true");
  2517. }
  2518. newChecked = !!newChecked;
  2519. node[key] = newChecked;
  2520. } else if (typeof node[key] == "string"){
  2521. node[key] = tools.eqs(node[key], "true");
  2522. } else {
  2523. node[key] = !!node[key];
  2524. }
  2525. return node[key];
  2526. };
  2527. data.exSetting(_setting);
  2528. data.addInitBind(_bindEvent);
  2529. data.addInitUnBind(_unbindEvent);
  2530. data.addInitCache(_initCache);
  2531. data.addInitNode(_initNode);
  2532. data.addInitProxy(_eventProxy, true);
  2533. data.addInitRoot(_initRoot);
  2534. data.addBeforeA(_beforeA);
  2535. data.addZTreeTools(_zTreeTools);
  2536. var _createNodes = view.createNodes;
  2537. view.createNodes = function (setting, level, nodes, parentNode, index) {
  2538. if (_createNodes) _createNodes.apply(view, arguments);
  2539. if (!nodes) return;
  2540. view.repairParentChkClassWithSelf(setting, parentNode);
  2541. }
  2542. var _removeNode = view.removeNode;
  2543. view.removeNode = function (setting, node) {
  2544. var parentNode = node.getParentNode();
  2545. if (_removeNode) _removeNode.apply(view, arguments);
  2546. if (!node || !parentNode) return;
  2547. view.repairChkClass(setting, parentNode);
  2548. view.repairParentChkClass(setting, parentNode);
  2549. }
  2550. var _appendNodes = view.appendNodes;
  2551. view.appendNodes = function (setting, level, nodes, parentNode, index, initFlag, openFlag) {
  2552. var html = "";
  2553. if (_appendNodes) {
  2554. html = _appendNodes.apply(view, arguments);
  2555. }
  2556. if (parentNode) {
  2557. data.makeChkFlag(setting, parentNode);
  2558. }
  2559. return html;
  2560. }
  2561. })(jQuery);
  2562. /*
  2563. * JQuery zTree exedit
  2564. * v3.5.42
  2565. * http://treejs.cn/
  2566. *
  2567. * Copyright (c) 2010 Hunter.z
  2568. *
  2569. * Licensed same as jquery - MIT License
  2570. * http://www.opensource.org/licenses/mit-license.php
  2571. *
  2572. * Date: 2020-01-19
  2573. */
  2574. (function ($) {
  2575. //default consts of exedit
  2576. var _consts = {
  2577. event: {
  2578. DRAG: "ztree_drag",
  2579. DROP: "ztree_drop",
  2580. RENAME: "ztree_rename",
  2581. DRAGMOVE: "ztree_dragmove"
  2582. },
  2583. id: {
  2584. EDIT: "_edit",
  2585. INPUT: "_input",
  2586. REMOVE: "_remove"
  2587. },
  2588. move: {
  2589. TYPE_INNER: "inner",
  2590. TYPE_PREV: "prev",
  2591. TYPE_NEXT: "next"
  2592. },
  2593. node: {
  2594. CURSELECTED_EDIT: "curSelectedNode_Edit",
  2595. TMPTARGET_TREE: "tmpTargetzTree",
  2596. TMPTARGET_NODE: "tmpTargetNode"
  2597. }
  2598. },
  2599. //default setting of exedit
  2600. _setting = {
  2601. edit: {
  2602. enable: false,
  2603. editNameSelectAll: false,
  2604. showRemoveBtn: true,
  2605. showRenameBtn: true,
  2606. removeTitle: "remove",
  2607. renameTitle: "rename",
  2608. drag: {
  2609. autoExpandTrigger: false,
  2610. isCopy: true,
  2611. isMove: true,
  2612. prev: true,
  2613. next: true,
  2614. inner: true,
  2615. minMoveSize: 5,
  2616. borderMax: 10,
  2617. borderMin: -5,
  2618. maxShowNodeNum: 5,
  2619. autoOpenTime: 500
  2620. }
  2621. },
  2622. view: {
  2623. addHoverDom: null,
  2624. removeHoverDom: null
  2625. },
  2626. callback: {
  2627. beforeDrag: null,
  2628. beforeDragOpen: null,
  2629. beforeDrop: null,
  2630. beforeEditName: null,
  2631. beforeRename: null,
  2632. onDrag: null,
  2633. onDragMove: null,
  2634. onDrop: null,
  2635. onRename: null
  2636. }
  2637. },
  2638. //default root of exedit
  2639. _initRoot = function (setting) {
  2640. var r = data.getRoot(setting), rs = data.getRoots();
  2641. r.curEditNode = null;
  2642. r.curEditInput = null;
  2643. r.curHoverNode = null;
  2644. r.dragFlag = 0;
  2645. r.dragNodeShowBefore = [];
  2646. r.dragMaskList = new Array();
  2647. rs.showHoverDom = true;
  2648. },
  2649. //default cache of exedit
  2650. _initCache = function (treeId) {
  2651. },
  2652. //default bind event of exedit
  2653. _bindEvent = function (setting) {
  2654. var o = setting.treeObj;
  2655. var c = consts.event;
  2656. o.bind(c.RENAME, function (event, treeId, treeNode, isCancel) {
  2657. tools.apply(setting.callback.onRename, [event, treeId, treeNode, isCancel]);
  2658. });
  2659. o.bind(c.DRAG, function (event, srcEvent, treeId, treeNodes) {
  2660. tools.apply(setting.callback.onDrag, [srcEvent, treeId, treeNodes]);
  2661. });
  2662. o.bind(c.DRAGMOVE, function (event, srcEvent, treeId, treeNodes) {
  2663. tools.apply(setting.callback.onDragMove, [srcEvent, treeId, treeNodes]);
  2664. });
  2665. o.bind(c.DROP, function (event, srcEvent, treeId, treeNodes, targetNode, moveType, isCopy) {
  2666. tools.apply(setting.callback.onDrop, [srcEvent, treeId, treeNodes, targetNode, moveType, isCopy]);
  2667. });
  2668. },
  2669. _unbindEvent = function (setting) {
  2670. var o = setting.treeObj;
  2671. var c = consts.event;
  2672. o.unbind(c.RENAME);
  2673. o.unbind(c.DRAG);
  2674. o.unbind(c.DRAGMOVE);
  2675. o.unbind(c.DROP);
  2676. },
  2677. //default event proxy of exedit
  2678. _eventProxy = function (e) {
  2679. var target = e.target,
  2680. setting = data.getSetting(e.data.treeId),
  2681. relatedTarget = e.relatedTarget,
  2682. tId = "", node = null,
  2683. nodeEventType = "", treeEventType = "",
  2684. nodeEventCallback = null, treeEventCallback = null,
  2685. tmp = null;
  2686. if (tools.eqs(e.type, "mouseover")) {
  2687. tmp = tools.getMDom(setting, target, [{tagName: "a", attrName: "treeNode" + consts.id.A}]);
  2688. if (tmp) {
  2689. tId = tools.getNodeMainDom(tmp).id;
  2690. nodeEventType = "hoverOverNode";
  2691. }
  2692. } else if (tools.eqs(e.type, "mouseout")) {
  2693. tmp = tools.getMDom(setting, relatedTarget, [{tagName: "a", attrName: "treeNode" + consts.id.A}]);
  2694. if (!tmp) {
  2695. tId = "remove";
  2696. nodeEventType = "hoverOutNode";
  2697. }
  2698. } else if (tools.eqs(e.type, "mousedown")) {
  2699. tmp = tools.getMDom(setting, target, [{tagName: "a", attrName: "treeNode" + consts.id.A}]);
  2700. if (tmp) {
  2701. tId = tools.getNodeMainDom(tmp).id;
  2702. nodeEventType = "mousedownNode";
  2703. }
  2704. }
  2705. if (tId.length > 0) {
  2706. node = data.getNodeCache(setting, tId);
  2707. switch (nodeEventType) {
  2708. case "mousedownNode" :
  2709. nodeEventCallback = _handler.onMousedownNode;
  2710. break;
  2711. case "hoverOverNode" :
  2712. nodeEventCallback = _handler.onHoverOverNode;
  2713. break;
  2714. case "hoverOutNode" :
  2715. nodeEventCallback = _handler.onHoverOutNode;
  2716. break;
  2717. }
  2718. }
  2719. var proxyResult = {
  2720. stop: false,
  2721. node: node,
  2722. nodeEventType: nodeEventType,
  2723. nodeEventCallback: nodeEventCallback,
  2724. treeEventType: treeEventType,
  2725. treeEventCallback: treeEventCallback
  2726. };
  2727. return proxyResult
  2728. },
  2729. //default init node of exedit
  2730. _initNode = function (setting, level, n, parentNode, isFirstNode, isLastNode, openFlag) {
  2731. if (!n) return;
  2732. n.isHover = false;
  2733. n.editNameFlag = false;
  2734. },
  2735. //update zTreeObj, add method of edit
  2736. _zTreeTools = function (setting, zTreeTools) {
  2737. zTreeTools.cancelEditName = function (newName) {
  2738. var root = data.getRoot(this.setting);
  2739. if (!root.curEditNode) return;
  2740. view.cancelCurEditNode(this.setting, newName ? newName : null, true);
  2741. }
  2742. zTreeTools.copyNode = function (targetNode, node, moveType, isSilent) {
  2743. if (!node) return null;
  2744. var isParent = data.nodeIsParent(setting, targetNode);
  2745. if (targetNode && !isParent && this.setting.data.keep.leaf && moveType === consts.move.TYPE_INNER) return null;
  2746. var _this = this,
  2747. newNode = tools.clone(node);
  2748. if (!targetNode) {
  2749. targetNode = null;
  2750. moveType = consts.move.TYPE_INNER;
  2751. }
  2752. if (moveType == consts.move.TYPE_INNER) {
  2753. function copyCallback() {
  2754. view.addNodes(_this.setting, targetNode, -1, [newNode], isSilent);
  2755. }
  2756. if (tools.canAsync(this.setting, targetNode)) {
  2757. view.asyncNode(this.setting, targetNode, isSilent, copyCallback);
  2758. } else {
  2759. copyCallback();
  2760. }
  2761. } else {
  2762. view.addNodes(this.setting, targetNode.parentNode, -1, [newNode], isSilent);
  2763. view.moveNode(this.setting, targetNode, newNode, moveType, false, isSilent);
  2764. }
  2765. return newNode;
  2766. }
  2767. zTreeTools.editName = function (node) {
  2768. if (!node || !node.tId || node !== data.getNodeCache(this.setting, node.tId)) return;
  2769. if (node.parentTId) view.expandCollapseParentNode(this.setting, node.getParentNode(), true);
  2770. view.editNode(this.setting, node)
  2771. }
  2772. zTreeTools.moveNode = function (targetNode, node, moveType, isSilent) {
  2773. if (!node) return node;
  2774. var isParent = data.nodeIsParent(setting, targetNode);
  2775. if (targetNode && !isParent && this.setting.data.keep.leaf && moveType === consts.move.TYPE_INNER) {
  2776. return null;
  2777. } else if (targetNode && ((node.parentTId == targetNode.tId && moveType == consts.move.TYPE_INNER) || $$(node, this.setting).find("#" + targetNode.tId).length > 0)) {
  2778. return null;
  2779. } else if (!targetNode) {
  2780. targetNode = null;
  2781. }
  2782. var _this = this;
  2783. function moveCallback() {
  2784. view.moveNode(_this.setting, targetNode, node, moveType, false, isSilent);
  2785. }
  2786. if (tools.canAsync(this.setting, targetNode) && moveType === consts.move.TYPE_INNER) {
  2787. view.asyncNode(this.setting, targetNode, isSilent, moveCallback);
  2788. } else {
  2789. moveCallback();
  2790. }
  2791. return node;
  2792. }
  2793. zTreeTools.setEditable = function (editable) {
  2794. this.setting.edit.enable = editable;
  2795. return this.refresh();
  2796. }
  2797. },
  2798. //method of operate data
  2799. _data = {
  2800. setSonNodeLevel: function (setting, parentNode, node) {
  2801. if (!node) return;
  2802. var children = data.nodeChildren(setting, node);
  2803. node.level = (parentNode) ? parentNode.level + 1 : 0;
  2804. if (!children) return;
  2805. for (var i = 0, l = children.length; i < l; i++) {
  2806. if (children[i]) data.setSonNodeLevel(setting, node, children[i]);
  2807. }
  2808. }
  2809. },
  2810. //method of event proxy
  2811. _event = {},
  2812. //method of event handler
  2813. _handler = {
  2814. onHoverOverNode: function (event, node) {
  2815. var setting = data.getSetting(event.data.treeId),
  2816. root = data.getRoot(setting);
  2817. if (root.curHoverNode != node) {
  2818. _handler.onHoverOutNode(event);
  2819. }
  2820. root.curHoverNode = node;
  2821. view.addHoverDom(setting, node);
  2822. },
  2823. onHoverOutNode: function (event, node) {
  2824. var setting = data.getSetting(event.data.treeId),
  2825. root = data.getRoot(setting);
  2826. if (root.curHoverNode && !data.isSelectedNode(setting, root.curHoverNode)) {
  2827. view.removeTreeDom(setting, root.curHoverNode);
  2828. root.curHoverNode = null;
  2829. }
  2830. },
  2831. onMousedownNode: function (eventMouseDown, _node) {
  2832. var i, l,
  2833. setting = data.getSetting(eventMouseDown.data.treeId),
  2834. root = data.getRoot(setting), roots = data.getRoots();
  2835. //right click can't drag & drop
  2836. if (eventMouseDown.button == 2 || !setting.edit.enable || (!setting.edit.drag.isCopy && !setting.edit.drag.isMove)) return true;
  2837. //input of edit node name can't drag & drop
  2838. var target = eventMouseDown.target,
  2839. _nodes = data.getRoot(setting).curSelectedList,
  2840. nodes = [];
  2841. if (!data.isSelectedNode(setting, _node)) {
  2842. nodes = [_node];
  2843. } else {
  2844. for (i = 0, l = _nodes.length; i < l; i++) {
  2845. if (_nodes[i].editNameFlag && tools.eqs(target.tagName, "input") && target.getAttribute("treeNode" + consts.id.INPUT) !== null) {
  2846. return true;
  2847. }
  2848. nodes.push(_nodes[i]);
  2849. if (nodes[0].parentTId !== _nodes[i].parentTId) {
  2850. nodes = [_node];
  2851. break;
  2852. }
  2853. }
  2854. }
  2855. view.editNodeBlur = true;
  2856. view.cancelCurEditNode(setting);
  2857. var doc = $(setting.treeObj.get(0).ownerDocument),
  2858. body = $(setting.treeObj.get(0).ownerDocument.body), curNode, tmpArrow, tmpTarget,
  2859. isOtherTree = false,
  2860. targetSetting = setting,
  2861. sourceSetting = setting,
  2862. preNode, nextNode,
  2863. preTmpTargetNodeId = null,
  2864. preTmpMoveType = null,
  2865. tmpTargetNodeId = null,
  2866. moveType = consts.move.TYPE_INNER,
  2867. mouseDownX = eventMouseDown.clientX,
  2868. mouseDownY = eventMouseDown.clientY,
  2869. startTime = (new Date()).getTime();
  2870. if (tools.uCanDo(setting)) {
  2871. doc.bind("mousemove", _docMouseMove);
  2872. }
  2873. function _docMouseMove(event) {
  2874. //avoid start drag after click node
  2875. if (root.dragFlag == 0 && Math.abs(mouseDownX - event.clientX) < setting.edit.drag.minMoveSize
  2876. && Math.abs(mouseDownY - event.clientY) < setting.edit.drag.minMoveSize) {
  2877. return true;
  2878. }
  2879. var i, l, tmpNode, tmpDom, tmpNodes;
  2880. body.css("cursor", "pointer");
  2881. if (root.dragFlag == 0) {
  2882. if (tools.apply(setting.callback.beforeDrag, [setting.treeId, nodes], true) == false) {
  2883. _docMouseUp(event);
  2884. return true;
  2885. }
  2886. for (i = 0, l = nodes.length; i < l; i++) {
  2887. if (i == 0) {
  2888. root.dragNodeShowBefore = [];
  2889. }
  2890. tmpNode = nodes[i];
  2891. if (data.nodeIsParent(setting, tmpNode) && tmpNode.open) {
  2892. view.expandCollapseNode(setting, tmpNode, !tmpNode.open);
  2893. root.dragNodeShowBefore[tmpNode.tId] = true;
  2894. } else {
  2895. root.dragNodeShowBefore[tmpNode.tId] = false;
  2896. }
  2897. }
  2898. root.dragFlag = 1;
  2899. roots.showHoverDom = false;
  2900. tools.showIfameMask(setting, true);
  2901. //sort
  2902. var isOrder = true, lastIndex = -1;
  2903. if (nodes.length > 1) {
  2904. var pNodes = nodes[0].parentTId ? data.nodeChildren(setting, nodes[0].getParentNode()) : data.getNodes(setting);
  2905. tmpNodes = [];
  2906. for (i = 0, l = pNodes.length; i < l; i++) {
  2907. if (root.dragNodeShowBefore[pNodes[i].tId] !== undefined) {
  2908. if (isOrder && lastIndex > -1 && (lastIndex + 1) !== i) {
  2909. isOrder = false;
  2910. }
  2911. tmpNodes.push(pNodes[i]);
  2912. lastIndex = i;
  2913. }
  2914. if (nodes.length === tmpNodes.length) {
  2915. nodes = tmpNodes;
  2916. break;
  2917. }
  2918. }
  2919. }
  2920. if (isOrder) {
  2921. preNode = nodes[0].getPreNode();
  2922. nextNode = nodes[nodes.length - 1].getNextNode();
  2923. }
  2924. //set node in selected
  2925. curNode = $$("<ul class='zTreeDragUL'></ul>", setting);
  2926. for (i = 0, l = nodes.length; i < l; i++) {
  2927. tmpNode = nodes[i];
  2928. tmpNode.editNameFlag = false;
  2929. view.selectNode(setting, tmpNode, i > 0);
  2930. view.removeTreeDom(setting, tmpNode);
  2931. if (i > setting.edit.drag.maxShowNodeNum - 1) {
  2932. continue;
  2933. }
  2934. tmpDom = $$("<li id='" + tmpNode.tId + "_tmp'></li>", setting);
  2935. tmpDom.append($$(tmpNode, consts.id.A, setting).clone());
  2936. tmpDom.css("padding", "0");
  2937. tmpDom.children("#" + tmpNode.tId + consts.id.A).removeClass(consts.node.CURSELECTED);
  2938. curNode.append(tmpDom);
  2939. if (i == setting.edit.drag.maxShowNodeNum - 1) {
  2940. tmpDom = $$("<li id='" + tmpNode.tId + "_moretmp'><a> ... </a></li>", setting);
  2941. curNode.append(tmpDom);
  2942. }
  2943. }
  2944. curNode.attr("id", nodes[0].tId + consts.id.UL + "_tmp");
  2945. curNode.addClass(setting.treeObj.attr("class"));
  2946. curNode.appendTo(body);
  2947. tmpArrow = $$("<span class='tmpzTreeMove_arrow'></span>", setting);
  2948. tmpArrow.attr("id", "zTreeMove_arrow_tmp");
  2949. tmpArrow.appendTo(body);
  2950. setting.treeObj.trigger(consts.event.DRAG, [event, setting.treeId, nodes]);
  2951. }
  2952. if (root.dragFlag == 1) {
  2953. if (tmpTarget && tmpArrow.attr("id") == event.target.id && tmpTargetNodeId && (event.clientX + doc.scrollLeft() + 2) > ($("#" + tmpTargetNodeId + consts.id.A, tmpTarget).offset().left)) {
  2954. var xT = $("#" + tmpTargetNodeId + consts.id.A, tmpTarget);
  2955. event.target = (xT.length > 0) ? xT.get(0) : event.target;
  2956. } else if (tmpTarget) {
  2957. tmpTarget.removeClass(consts.node.TMPTARGET_TREE);
  2958. if (tmpTargetNodeId) $("#" + tmpTargetNodeId + consts.id.A, tmpTarget).removeClass(consts.node.TMPTARGET_NODE + "_" + consts.move.TYPE_PREV)
  2959. .removeClass(consts.node.TMPTARGET_NODE + "_" + _consts.move.TYPE_NEXT).removeClass(consts.node.TMPTARGET_NODE + "_" + _consts.move.TYPE_INNER);
  2960. }
  2961. tmpTarget = null;
  2962. tmpTargetNodeId = null;
  2963. //judge drag & drop in multi ztree
  2964. isOtherTree = false;
  2965. targetSetting = setting;
  2966. var settings = data.getSettings();
  2967. for (var s in settings) {
  2968. if (settings[s].treeId && settings[s].edit.enable && settings[s].treeId != setting.treeId
  2969. && (event.target.id == settings[s].treeId || $(event.target).parents("#" + settings[s].treeId).length > 0)) {
  2970. isOtherTree = true;
  2971. targetSetting = settings[s];
  2972. }
  2973. }
  2974. var docScrollTop = doc.scrollTop(),
  2975. docScrollLeft = doc.scrollLeft(),
  2976. treeOffset = targetSetting.treeObj.offset(),
  2977. scrollHeight = targetSetting.treeObj.get(0).scrollHeight,
  2978. scrollWidth = targetSetting.treeObj.get(0).scrollWidth,
  2979. dTop = (event.clientY + docScrollTop - treeOffset.top),
  2980. dBottom = (targetSetting.treeObj.height() + treeOffset.top - event.clientY - docScrollTop),
  2981. dLeft = (event.clientX + docScrollLeft - treeOffset.left),
  2982. dRight = (targetSetting.treeObj.width() + treeOffset.left - event.clientX - docScrollLeft),
  2983. isTop = (dTop < setting.edit.drag.borderMax && dTop > setting.edit.drag.borderMin),
  2984. isBottom = (dBottom < setting.edit.drag.borderMax && dBottom > setting.edit.drag.borderMin),
  2985. isLeft = (dLeft < setting.edit.drag.borderMax && dLeft > setting.edit.drag.borderMin),
  2986. isRight = (dRight < setting.edit.drag.borderMax && dRight > setting.edit.drag.borderMin),
  2987. isTreeInner = dTop > setting.edit.drag.borderMin && dBottom > setting.edit.drag.borderMin && dLeft > setting.edit.drag.borderMin && dRight > setting.edit.drag.borderMin,
  2988. isTreeTop = (isTop && targetSetting.treeObj.scrollTop() <= 0),
  2989. isTreeBottom = (isBottom && (targetSetting.treeObj.scrollTop() + targetSetting.treeObj.height() + 10) >= scrollHeight),
  2990. isTreeLeft = (isLeft && targetSetting.treeObj.scrollLeft() <= 0),
  2991. isTreeRight = (isRight && (targetSetting.treeObj.scrollLeft() + targetSetting.treeObj.width() + 10) >= scrollWidth);
  2992. if (event.target && tools.isChildOrSelf(event.target, targetSetting.treeId)) {
  2993. //get node <li> dom
  2994. var targetObj = event.target;
  2995. while (targetObj && targetObj.tagName && !tools.eqs(targetObj.tagName, "li") && targetObj.id != targetSetting.treeId) {
  2996. targetObj = targetObj.parentNode;
  2997. }
  2998. var canMove = true;
  2999. //don't move to self or children of self
  3000. for (i = 0, l = nodes.length; i < l; i++) {
  3001. tmpNode = nodes[i];
  3002. if (targetObj.id === tmpNode.tId) {
  3003. canMove = false;
  3004. break;
  3005. } else if ($$(tmpNode, setting).find("#" + targetObj.id).length > 0) {
  3006. canMove = false;
  3007. break;
  3008. }
  3009. }
  3010. if (canMove && event.target && tools.isChildOrSelf(event.target, targetObj.id + consts.id.A)) {
  3011. tmpTarget = $(targetObj);
  3012. tmpTargetNodeId = targetObj.id;
  3013. }
  3014. }
  3015. //the mouse must be in zTree
  3016. tmpNode = nodes[0];
  3017. if (isTreeInner && tools.isChildOrSelf(event.target, targetSetting.treeId)) {
  3018. //judge mouse move in root of ztree
  3019. if (!tmpTarget && (event.target.id == targetSetting.treeId || isTreeTop || isTreeBottom || isTreeLeft || isTreeRight) && (isOtherTree || (!isOtherTree && tmpNode.parentTId))) {
  3020. tmpTarget = targetSetting.treeObj;
  3021. }
  3022. //auto scroll top
  3023. if (isTop) {
  3024. targetSetting.treeObj.scrollTop(targetSetting.treeObj.scrollTop() - 10);
  3025. } else if (isBottom) {
  3026. targetSetting.treeObj.scrollTop(targetSetting.treeObj.scrollTop() + 10);
  3027. }
  3028. if (isLeft) {
  3029. targetSetting.treeObj.scrollLeft(targetSetting.treeObj.scrollLeft() - 10);
  3030. } else if (isRight) {
  3031. targetSetting.treeObj.scrollLeft(targetSetting.treeObj.scrollLeft() + 10);
  3032. }
  3033. //auto scroll left
  3034. if (tmpTarget && tmpTarget != targetSetting.treeObj && tmpTarget.offset().left < targetSetting.treeObj.offset().left) {
  3035. targetSetting.treeObj.scrollLeft(targetSetting.treeObj.scrollLeft() + tmpTarget.offset().left - targetSetting.treeObj.offset().left);
  3036. }
  3037. }
  3038. curNode.css({
  3039. "top": (event.clientY + docScrollTop + 3) + "px",
  3040. "left": (event.clientX + docScrollLeft + 3) + "px"
  3041. });
  3042. var dX = 0;
  3043. var dY = 0;
  3044. if (tmpTarget && tmpTarget.attr("id") != targetSetting.treeId) {
  3045. var tmpTargetNode = tmpTargetNodeId == null ? null : data.getNodeCache(targetSetting, tmpTargetNodeId),
  3046. isCopy = ((event.ctrlKey || event.metaKey) && setting.edit.drag.isMove && setting.edit.drag.isCopy) || (!setting.edit.drag.isMove && setting.edit.drag.isCopy),
  3047. isPrev = !!(preNode && tmpTargetNodeId === preNode.tId),
  3048. isNext = !!(nextNode && tmpTargetNodeId === nextNode.tId),
  3049. isInner = (tmpNode.parentTId && tmpNode.parentTId == tmpTargetNodeId),
  3050. canPrev = (isCopy || !isNext) && tools.apply(targetSetting.edit.drag.prev, [targetSetting.treeId, nodes, tmpTargetNode], !!targetSetting.edit.drag.prev),
  3051. canNext = (isCopy || !isPrev) && tools.apply(targetSetting.edit.drag.next, [targetSetting.treeId, nodes, tmpTargetNode], !!targetSetting.edit.drag.next),
  3052. canInner = (isCopy || !isInner) && !(targetSetting.data.keep.leaf && !data.nodeIsParent(setting, tmpTargetNode)) && tools.apply(targetSetting.edit.drag.inner, [targetSetting.treeId, nodes, tmpTargetNode], !!targetSetting.edit.drag.inner);
  3053. function clearMove() {
  3054. tmpTarget = null;
  3055. tmpTargetNodeId = "";
  3056. moveType = consts.move.TYPE_INNER;
  3057. tmpArrow.css({
  3058. "display": "none"
  3059. });
  3060. if (window.zTreeMoveTimer) {
  3061. clearTimeout(window.zTreeMoveTimer);
  3062. window.zTreeMoveTargetNodeTId = null
  3063. }
  3064. }
  3065. if (!canPrev && !canNext && !canInner) {
  3066. clearMove();
  3067. } else {
  3068. var tmpTargetA = $("#" + tmpTargetNodeId + consts.id.A, tmpTarget),
  3069. tmpNextA = tmpTargetNode.isLastNode ? null : $("#" + tmpTargetNode.getNextNode().tId + consts.id.A, tmpTarget.next()),
  3070. tmpTop = tmpTargetA.offset().top,
  3071. tmpLeft = tmpTargetA.offset().left,
  3072. prevPercent = canPrev ? (canInner ? 0.25 : (canNext ? 0.5 : 1)) : -1,
  3073. nextPercent = canNext ? (canInner ? 0.75 : (canPrev ? 0.5 : 0)) : -1,
  3074. dY_percent = (event.clientY + docScrollTop - tmpTop) / tmpTargetA.height();
  3075. if ((prevPercent == 1 || dY_percent <= prevPercent && dY_percent >= -.2) && canPrev) {
  3076. dX = 1 - tmpArrow.width();
  3077. dY = tmpTop - tmpArrow.height() / 2;
  3078. moveType = consts.move.TYPE_PREV;
  3079. } else if ((nextPercent == 0 || dY_percent >= nextPercent && dY_percent <= 1.2) && canNext) {
  3080. dX = 1 - tmpArrow.width();
  3081. dY = (tmpNextA == null || (data.nodeIsParent(setting, tmpTargetNode) && tmpTargetNode.open)) ? (tmpTop + tmpTargetA.height() - tmpArrow.height() / 2) : (tmpNextA.offset().top - tmpArrow.height() / 2);
  3082. moveType = consts.move.TYPE_NEXT;
  3083. } else if (canInner) {
  3084. dX = 5 - tmpArrow.width();
  3085. dY = tmpTop;
  3086. moveType = consts.move.TYPE_INNER;
  3087. } else {
  3088. clearMove();
  3089. }
  3090. if (tmpTarget) {
  3091. tmpArrow.css({
  3092. "display": "block",
  3093. "top": dY + "px",
  3094. "left": (tmpLeft + dX) + "px"
  3095. });
  3096. tmpTargetA.addClass(consts.node.TMPTARGET_NODE + "_" + moveType);
  3097. if (preTmpTargetNodeId != tmpTargetNodeId || preTmpMoveType != moveType) {
  3098. startTime = (new Date()).getTime();
  3099. }
  3100. if (tmpTargetNode && data.nodeIsParent(setting, tmpTargetNode) && moveType == consts.move.TYPE_INNER) {
  3101. var startTimer = true;
  3102. if (window.zTreeMoveTimer && window.zTreeMoveTargetNodeTId !== tmpTargetNode.tId) {
  3103. clearTimeout(window.zTreeMoveTimer);
  3104. window.zTreeMoveTargetNodeTId = null;
  3105. } else if (window.zTreeMoveTimer && window.zTreeMoveTargetNodeTId === tmpTargetNode.tId) {
  3106. startTimer = false;
  3107. }
  3108. if (startTimer) {
  3109. window.zTreeMoveTimer = setTimeout(function () {
  3110. if (moveType != consts.move.TYPE_INNER) return;
  3111. if (tmpTargetNode && data.nodeIsParent(setting, tmpTargetNode) && !tmpTargetNode.open && (new Date()).getTime() - startTime > targetSetting.edit.drag.autoOpenTime
  3112. && tools.apply(targetSetting.callback.beforeDragOpen, [targetSetting.treeId, tmpTargetNode], true)) {
  3113. view.switchNode(targetSetting, tmpTargetNode);
  3114. if (targetSetting.edit.drag.autoExpandTrigger) {
  3115. targetSetting.treeObj.trigger(consts.event.EXPAND, [targetSetting.treeId, tmpTargetNode]);
  3116. }
  3117. }
  3118. }, targetSetting.edit.drag.autoOpenTime + 50);
  3119. window.zTreeMoveTargetNodeTId = tmpTargetNode.tId;
  3120. }
  3121. }
  3122. }
  3123. }
  3124. } else {
  3125. moveType = consts.move.TYPE_INNER;
  3126. if (tmpTarget && tools.apply(targetSetting.edit.drag.inner, [targetSetting.treeId, nodes, null], !!targetSetting.edit.drag.inner)) {
  3127. tmpTarget.addClass(consts.node.TMPTARGET_TREE);
  3128. } else {
  3129. tmpTarget = null;
  3130. }
  3131. tmpArrow.css({
  3132. "display": "none"
  3133. });
  3134. if (window.zTreeMoveTimer) {
  3135. clearTimeout(window.zTreeMoveTimer);
  3136. window.zTreeMoveTargetNodeTId = null;
  3137. }
  3138. }
  3139. preTmpTargetNodeId = tmpTargetNodeId;
  3140. preTmpMoveType = moveType;
  3141. setting.treeObj.trigger(consts.event.DRAGMOVE, [event, setting.treeId, nodes]);
  3142. }
  3143. return false;
  3144. }
  3145. doc.bind("mouseup", _docMouseUp);
  3146. function _docMouseUp(event) {
  3147. if (window.zTreeMoveTimer) {
  3148. clearTimeout(window.zTreeMoveTimer);
  3149. window.zTreeMoveTargetNodeTId = null;
  3150. }
  3151. preTmpTargetNodeId = null;
  3152. preTmpMoveType = null;
  3153. doc.unbind("mousemove", _docMouseMove);
  3154. doc.unbind("mouseup", _docMouseUp);
  3155. doc.unbind("selectstart", _docSelect);
  3156. body.css("cursor", "");
  3157. if (tmpTarget) {
  3158. tmpTarget.removeClass(consts.node.TMPTARGET_TREE);
  3159. if (tmpTargetNodeId) $("#" + tmpTargetNodeId + consts.id.A, tmpTarget).removeClass(consts.node.TMPTARGET_NODE + "_" + consts.move.TYPE_PREV)
  3160. .removeClass(consts.node.TMPTARGET_NODE + "_" + _consts.move.TYPE_NEXT).removeClass(consts.node.TMPTARGET_NODE + "_" + _consts.move.TYPE_INNER);
  3161. }
  3162. tools.showIfameMask(setting, false);
  3163. roots.showHoverDom = true;
  3164. if (root.dragFlag == 0) return;
  3165. root.dragFlag = 0;
  3166. var i, l, tmpNode;
  3167. for (i = 0, l = nodes.length; i < l; i++) {
  3168. tmpNode = nodes[i];
  3169. if (data.nodeIsParent(setting, tmpNode) && root.dragNodeShowBefore[tmpNode.tId] && !tmpNode.open) {
  3170. view.expandCollapseNode(setting, tmpNode, !tmpNode.open);
  3171. delete root.dragNodeShowBefore[tmpNode.tId];
  3172. }
  3173. }
  3174. if (curNode) curNode.remove();
  3175. if (tmpArrow) tmpArrow.remove();
  3176. var isCopy = ((event.ctrlKey || event.metaKey) && setting.edit.drag.isMove && setting.edit.drag.isCopy) || (!setting.edit.drag.isMove && setting.edit.drag.isCopy);
  3177. if (!isCopy && tmpTarget && tmpTargetNodeId && nodes[0].parentTId && tmpTargetNodeId == nodes[0].parentTId && moveType == consts.move.TYPE_INNER) {
  3178. tmpTarget = null;
  3179. }
  3180. if (tmpTarget) {
  3181. var dragTargetNode = tmpTargetNodeId == null ? null : data.getNodeCache(targetSetting, tmpTargetNodeId);
  3182. if (tools.apply(setting.callback.beforeDrop, [targetSetting.treeId, nodes, dragTargetNode, moveType, isCopy], true) == false) {
  3183. view.selectNodes(sourceSetting, nodes);
  3184. return;
  3185. }
  3186. var newNodes = isCopy ? tools.clone(nodes) : nodes;
  3187. function dropCallback() {
  3188. if (isOtherTree) {
  3189. if (!isCopy) {
  3190. for (var i = 0, l = nodes.length; i < l; i++) {
  3191. view.removeNode(setting, nodes[i]);
  3192. }
  3193. }
  3194. if (moveType == consts.move.TYPE_INNER) {
  3195. view.addNodes(targetSetting, dragTargetNode, -1, newNodes);
  3196. } else {
  3197. view.addNodes(targetSetting, dragTargetNode.getParentNode(), moveType == consts.move.TYPE_PREV ? dragTargetNode.getIndex() : dragTargetNode.getIndex() + 1, newNodes);
  3198. }
  3199. } else {
  3200. if (isCopy && moveType == consts.move.TYPE_INNER) {
  3201. view.addNodes(targetSetting, dragTargetNode, -1, newNodes);
  3202. } else if (isCopy) {
  3203. view.addNodes(targetSetting, dragTargetNode.getParentNode(), moveType == consts.move.TYPE_PREV ? dragTargetNode.getIndex() : dragTargetNode.getIndex() + 1, newNodes);
  3204. } else {
  3205. if (moveType != consts.move.TYPE_NEXT) {
  3206. for (i = 0, l = newNodes.length; i < l; i++) {
  3207. view.moveNode(targetSetting, dragTargetNode, newNodes[i], moveType, false);
  3208. }
  3209. } else {
  3210. for (i = -1, l = newNodes.length - 1; i < l; l--) {
  3211. view.moveNode(targetSetting, dragTargetNode, newNodes[l], moveType, false);
  3212. }
  3213. }
  3214. }
  3215. }
  3216. view.selectNodes(targetSetting, newNodes);
  3217. var a = $$(newNodes[0], setting).get(0);
  3218. view.scrollIntoView(setting, a);
  3219. setting.treeObj.trigger(consts.event.DROP, [event, targetSetting.treeId, newNodes, dragTargetNode, moveType, isCopy]);
  3220. }
  3221. if (moveType == consts.move.TYPE_INNER && tools.canAsync(targetSetting, dragTargetNode)) {
  3222. view.asyncNode(targetSetting, dragTargetNode, false, dropCallback);
  3223. } else {
  3224. dropCallback();
  3225. }
  3226. } else {
  3227. view.selectNodes(sourceSetting, nodes);
  3228. setting.treeObj.trigger(consts.event.DROP, [event, setting.treeId, nodes, null, null, null]);
  3229. }
  3230. }
  3231. doc.bind("selectstart", _docSelect);
  3232. function _docSelect() {
  3233. return false;
  3234. }
  3235. // 2018-03-30 FireFox has fixed this issue.
  3236. //Avoid FireFox's Bug
  3237. //If zTree Div CSS set 'overflow', so drag node outside of zTree, and event.target is error.
  3238. // if(eventMouseDown.preventDefault) {
  3239. // eventMouseDown.preventDefault();
  3240. // }
  3241. return true;
  3242. }
  3243. },
  3244. //method of tools for zTree
  3245. _tools = {
  3246. getAbs: function (obj) {
  3247. var oRect = obj.getBoundingClientRect(),
  3248. scrollTop = document.body.scrollTop + document.documentElement.scrollTop,
  3249. scrollLeft = document.body.scrollLeft + document.documentElement.scrollLeft;
  3250. return [oRect.left + scrollLeft, oRect.top + scrollTop];
  3251. },
  3252. inputFocus: function (inputObj) {
  3253. if (inputObj.get(0)) {
  3254. inputObj.focus();
  3255. tools.setCursorPosition(inputObj.get(0), inputObj.val().length);
  3256. }
  3257. },
  3258. inputSelect: function (inputObj) {
  3259. if (inputObj.get(0)) {
  3260. inputObj.focus();
  3261. inputObj.select();
  3262. }
  3263. },
  3264. setCursorPosition: function (obj, pos) {
  3265. if (obj.setSelectionRange) {
  3266. obj.focus();
  3267. obj.setSelectionRange(pos, pos);
  3268. } else if (obj.createTextRange) {
  3269. var range = obj.createTextRange();
  3270. range.collapse(true);
  3271. range.moveEnd('character', pos);
  3272. range.moveStart('character', pos);
  3273. range.select();
  3274. }
  3275. },
  3276. showIfameMask: function (setting, showSign) {
  3277. var root = data.getRoot(setting);
  3278. //clear full mask
  3279. while (root.dragMaskList.length > 0) {
  3280. root.dragMaskList[0].remove();
  3281. root.dragMaskList.shift();
  3282. }
  3283. if (showSign) {
  3284. //show mask
  3285. var iframeList = $$("iframe", setting);
  3286. for (var i = 0, l = iframeList.length; i < l; i++) {
  3287. var obj = iframeList.get(i),
  3288. r = tools.getAbs(obj),
  3289. 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);
  3290. dragMask.appendTo($$("body", setting));
  3291. root.dragMaskList.push(dragMask);
  3292. }
  3293. }
  3294. }
  3295. },
  3296. //method of operate ztree dom
  3297. _view = {
  3298. addEditBtn: function (setting, node) {
  3299. if (node.editNameFlag || $$(node, consts.id.EDIT, setting).length > 0) {
  3300. return;
  3301. }
  3302. if (!tools.apply(setting.edit.showRenameBtn, [setting.treeId, node], setting.edit.showRenameBtn)) {
  3303. return;
  3304. }
  3305. var aObj = $$(node, consts.id.A, setting),
  3306. 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>";
  3307. aObj.append(editStr);
  3308. $$(node, consts.id.EDIT, setting).bind('click',
  3309. function () {
  3310. if (!tools.uCanDo(setting) || tools.apply(setting.callback.beforeEditName, [setting.treeId, node], true) == false) return false;
  3311. view.editNode(setting, node);
  3312. return false;
  3313. }
  3314. ).show();
  3315. },
  3316. addRemoveBtn: function (setting, node) {
  3317. if (node.editNameFlag || $$(node, consts.id.REMOVE, setting).length > 0) {
  3318. return;
  3319. }
  3320. if (!tools.apply(setting.edit.showRemoveBtn, [setting.treeId, node], setting.edit.showRemoveBtn)) {
  3321. return;
  3322. }
  3323. var aObj = $$(node, consts.id.A, setting),
  3324. 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>";
  3325. aObj.append(removeStr);
  3326. $$(node, consts.id.REMOVE, setting).bind('click',
  3327. function () {
  3328. if (!tools.uCanDo(setting) || tools.apply(setting.callback.beforeRemove, [setting.treeId, node], true) == false) return false;
  3329. view.removeNode(setting, node);
  3330. setting.treeObj.trigger(consts.event.REMOVE, [setting.treeId, node]);
  3331. return false;
  3332. }
  3333. ).bind('mousedown',
  3334. function (eventMouseDown) {
  3335. return true;
  3336. }
  3337. ).show();
  3338. },
  3339. addHoverDom: function (setting, node) {
  3340. if (data.getRoots().showHoverDom) {
  3341. node.isHover = true;
  3342. if (setting.edit.enable) {
  3343. view.addEditBtn(setting, node);
  3344. view.addRemoveBtn(setting, node);
  3345. }
  3346. tools.apply(setting.view.addHoverDom, [setting.treeId, node]);
  3347. }
  3348. },
  3349. cancelCurEditNode: function (setting, forceName, isCancel) {
  3350. var root = data.getRoot(setting),
  3351. node = root.curEditNode;
  3352. if (node) {
  3353. var inputObj = root.curEditInput,
  3354. newName = forceName ? forceName : (isCancel ? data.nodeName(setting, node) : inputObj.val());
  3355. if (tools.apply(setting.callback.beforeRename, [setting.treeId, node, newName, isCancel], true) === false) {
  3356. return false;
  3357. }
  3358. data.nodeName(setting, node, newName);
  3359. var aObj = $$(node, consts.id.A, setting);
  3360. aObj.removeClass(consts.node.CURSELECTED_EDIT);
  3361. inputObj.unbind();
  3362. view.setNodeName(setting, node);
  3363. node.editNameFlag = false;
  3364. root.curEditNode = null;
  3365. root.curEditInput = null;
  3366. view.selectNode(setting, node, false);
  3367. setting.treeObj.trigger(consts.event.RENAME, [setting.treeId, node, isCancel]);
  3368. }
  3369. root.noSelection = true;
  3370. return true;
  3371. },
  3372. editNode: function (setting, node) {
  3373. var root = data.getRoot(setting);
  3374. view.editNodeBlur = false;
  3375. if (data.isSelectedNode(setting, node) && root.curEditNode == node && node.editNameFlag) {
  3376. setTimeout(function () {
  3377. tools.inputFocus(root.curEditInput);
  3378. }, 0);
  3379. return;
  3380. }
  3381. node.editNameFlag = true;
  3382. view.removeTreeDom(setting, node);
  3383. view.cancelCurEditNode(setting);
  3384. view.selectNode(setting, node, false);
  3385. $$(node, consts.id.SPAN, setting).html("<input type=text class='rename' id='" + node.tId + consts.id.INPUT + "' treeNode" + consts.id.INPUT + " >");
  3386. var inputObj = $$(node, consts.id.INPUT, setting);
  3387. inputObj.attr("value", data.nodeName(setting, node));
  3388. if (setting.edit.editNameSelectAll) {
  3389. tools.inputSelect(inputObj);
  3390. } else {
  3391. tools.inputFocus(inputObj);
  3392. }
  3393. inputObj.bind('blur', function (event) {
  3394. if (!view.editNodeBlur) {
  3395. view.cancelCurEditNode(setting);
  3396. }
  3397. }).bind('keydown', function (event) {
  3398. if (event.keyCode == "13") {
  3399. view.editNodeBlur = true;
  3400. view.cancelCurEditNode(setting);
  3401. } else if (event.keyCode == "27") {
  3402. view.cancelCurEditNode(setting, null, true);
  3403. }
  3404. }).bind('click', function (event) {
  3405. return false;
  3406. }).bind('dblclick', function (event) {
  3407. return false;
  3408. });
  3409. $$(node, consts.id.A, setting).addClass(consts.node.CURSELECTED_EDIT);
  3410. root.curEditInput = inputObj;
  3411. root.noSelection = false;
  3412. root.curEditNode = node;
  3413. },
  3414. moveNode: function (setting, targetNode, node, moveType, animateFlag, isSilent) {
  3415. var root = data.getRoot(setting);
  3416. if (targetNode == node) return;
  3417. if (setting.data.keep.leaf && targetNode && !data.nodeIsParent(setting, targetNode) && moveType == consts.move.TYPE_INNER) return;
  3418. var oldParentNode = (node.parentTId ? node.getParentNode() : root),
  3419. targetNodeIsRoot = (targetNode === null || targetNode == root);
  3420. if (targetNodeIsRoot && targetNode === null) targetNode = root;
  3421. if (targetNodeIsRoot) moveType = consts.move.TYPE_INNER;
  3422. var targetParentNode = (targetNode.parentTId ? targetNode.getParentNode() : root);
  3423. if (moveType != consts.move.TYPE_PREV && moveType != consts.move.TYPE_NEXT) {
  3424. moveType = consts.move.TYPE_INNER;
  3425. }
  3426. if (moveType == consts.move.TYPE_INNER) {
  3427. if (targetNodeIsRoot) {
  3428. //parentTId of root node is null
  3429. node.parentTId = null;
  3430. } else {
  3431. if (!data.nodeIsParent(setting, targetNode)) {
  3432. data.nodeIsParent(setting, targetNode, true);
  3433. targetNode.open = !!targetNode.open;
  3434. view.setNodeLineIcos(setting, targetNode);
  3435. }
  3436. node.parentTId = targetNode.tId;
  3437. }
  3438. }
  3439. //move node Dom
  3440. var targetObj, target_ulObj;
  3441. if (targetNodeIsRoot) {
  3442. targetObj = setting.treeObj;
  3443. target_ulObj = targetObj;
  3444. } else {
  3445. if (!isSilent && moveType == consts.move.TYPE_INNER) {
  3446. view.expandCollapseNode(setting, targetNode, true, false);
  3447. } else if (!isSilent) {
  3448. view.expandCollapseNode(setting, targetNode.getParentNode(), true, false);
  3449. }
  3450. targetObj = $$(targetNode, setting);
  3451. target_ulObj = $$(targetNode, consts.id.UL, setting);
  3452. if (!!targetObj.get(0) && !target_ulObj.get(0)) {
  3453. var ulstr = [];
  3454. view.makeUlHtml(setting, targetNode, ulstr, '');
  3455. targetObj.append(ulstr.join(''));
  3456. }
  3457. target_ulObj = $$(targetNode, consts.id.UL, setting);
  3458. }
  3459. var nodeDom = $$(node, setting);
  3460. if (!nodeDom.get(0)) {
  3461. nodeDom = view.appendNodes(setting, node.level, [node], null, -1, false, true).join('');
  3462. } else if (!targetObj.get(0)) {
  3463. nodeDom.remove();
  3464. }
  3465. if (target_ulObj.get(0) && moveType == consts.move.TYPE_INNER) {
  3466. target_ulObj.append(nodeDom);
  3467. } else if (targetObj.get(0) && moveType == consts.move.TYPE_PREV) {
  3468. targetObj.before(nodeDom);
  3469. } else if (targetObj.get(0) && moveType == consts.move.TYPE_NEXT) {
  3470. targetObj.after(nodeDom);
  3471. }
  3472. //repair the data after move
  3473. var i, l,
  3474. tmpSrcIndex = -1,
  3475. tmpTargetIndex = 0,
  3476. oldNeighbor = null,
  3477. newNeighbor = null,
  3478. oldLevel = node.level;
  3479. var oldChildren = data.nodeChildren(setting, oldParentNode);
  3480. var targetParentChildren = data.nodeChildren(setting, targetParentNode);
  3481. var targetChildren = data.nodeChildren(setting, targetNode);
  3482. if (node.isFirstNode) {
  3483. tmpSrcIndex = 0;
  3484. if (oldChildren.length > 1) {
  3485. oldNeighbor = oldChildren[1];
  3486. oldNeighbor.isFirstNode = true;
  3487. }
  3488. } else if (node.isLastNode) {
  3489. tmpSrcIndex = oldChildren.length - 1;
  3490. oldNeighbor = oldChildren[tmpSrcIndex - 1];
  3491. oldNeighbor.isLastNode = true;
  3492. } else {
  3493. for (i = 0, l = oldChildren.length; i < l; i++) {
  3494. if (oldChildren[i].tId == node.tId) {
  3495. tmpSrcIndex = i;
  3496. break;
  3497. }
  3498. }
  3499. }
  3500. if (tmpSrcIndex >= 0) {
  3501. oldChildren.splice(tmpSrcIndex, 1);
  3502. }
  3503. if (moveType != consts.move.TYPE_INNER) {
  3504. for (i = 0, l = targetParentChildren.length; i < l; i++) {
  3505. if (targetParentChildren[i].tId == targetNode.tId) tmpTargetIndex = i;
  3506. }
  3507. }
  3508. if (moveType == consts.move.TYPE_INNER) {
  3509. if (!targetChildren) {
  3510. targetChildren = data.nodeChildren(setting, targetNode, []);
  3511. }
  3512. if (targetChildren.length > 0) {
  3513. newNeighbor = targetChildren[targetChildren.length - 1];
  3514. newNeighbor.isLastNode = false;
  3515. }
  3516. targetChildren.splice(targetChildren.length, 0, node);
  3517. node.isLastNode = true;
  3518. node.isFirstNode = (targetChildren.length == 1);
  3519. } else if (targetNode.isFirstNode && moveType == consts.move.TYPE_PREV) {
  3520. targetParentChildren.splice(tmpTargetIndex, 0, node);
  3521. newNeighbor = targetNode;
  3522. newNeighbor.isFirstNode = false;
  3523. node.parentTId = targetNode.parentTId;
  3524. node.isFirstNode = true;
  3525. node.isLastNode = false;
  3526. } else if (targetNode.isLastNode && moveType == consts.move.TYPE_NEXT) {
  3527. targetParentChildren.splice(tmpTargetIndex + 1, 0, node);
  3528. newNeighbor = targetNode;
  3529. newNeighbor.isLastNode = false;
  3530. node.parentTId = targetNode.parentTId;
  3531. node.isFirstNode = false;
  3532. node.isLastNode = true;
  3533. } else {
  3534. if (moveType == consts.move.TYPE_PREV) {
  3535. targetParentChildren.splice(tmpTargetIndex, 0, node);
  3536. } else {
  3537. targetParentChildren.splice(tmpTargetIndex + 1, 0, node);
  3538. }
  3539. node.parentTId = targetNode.parentTId;
  3540. node.isFirstNode = false;
  3541. node.isLastNode = false;
  3542. }
  3543. data.fixPIdKeyValue(setting, node);
  3544. data.setSonNodeLevel(setting, node.getParentNode(), node);
  3545. //repair node what been moved
  3546. view.setNodeLineIcos(setting, node);
  3547. view.repairNodeLevelClass(setting, node, oldLevel);
  3548. //repair node's old parentNode dom
  3549. if (!setting.data.keep.parent && oldChildren.length < 1) {
  3550. //old parentNode has no child nodes
  3551. data.nodeIsParent(setting, oldParentNode, false);
  3552. oldParentNode.open = false;
  3553. var tmp_ulObj = $$(oldParentNode, consts.id.UL, setting),
  3554. tmp_switchObj = $$(oldParentNode, consts.id.SWITCH, setting),
  3555. tmp_icoObj = $$(oldParentNode, consts.id.ICON, setting);
  3556. view.replaceSwitchClass(oldParentNode, tmp_switchObj, consts.folder.DOCU);
  3557. view.replaceIcoClass(oldParentNode, tmp_icoObj, consts.folder.DOCU);
  3558. tmp_ulObj.css("display", "none");
  3559. } else if (oldNeighbor) {
  3560. //old neigbor node
  3561. view.setNodeLineIcos(setting, oldNeighbor);
  3562. }
  3563. //new neigbor node
  3564. if (newNeighbor) {
  3565. view.setNodeLineIcos(setting, newNeighbor);
  3566. }
  3567. //repair checkbox / radio
  3568. if (!!setting.check && setting.check.enable && view.repairChkClass) {
  3569. view.repairChkClass(setting, oldParentNode);
  3570. view.repairParentChkClassWithSelf(setting, oldParentNode);
  3571. if (oldParentNode != node.parent)
  3572. view.repairParentChkClassWithSelf(setting, node);
  3573. }
  3574. //expand parents after move
  3575. if (!isSilent) {
  3576. view.expandCollapseParentNode(setting, node.getParentNode(), true, animateFlag);
  3577. }
  3578. },
  3579. removeEditBtn: function (setting, node) {
  3580. $$(node, consts.id.EDIT, setting).unbind().remove();
  3581. },
  3582. removeRemoveBtn: function (setting, node) {
  3583. $$(node, consts.id.REMOVE, setting).unbind().remove();
  3584. },
  3585. removeTreeDom: function (setting, node) {
  3586. node.isHover = false;
  3587. view.removeEditBtn(setting, node);
  3588. view.removeRemoveBtn(setting, node);
  3589. tools.apply(setting.view.removeHoverDom, [setting.treeId, node]);
  3590. },
  3591. repairNodeLevelClass: function (setting, node, oldLevel) {
  3592. if (oldLevel === node.level) return;
  3593. var liObj = $$(node, setting),
  3594. aObj = $$(node, consts.id.A, setting),
  3595. ulObj = $$(node, consts.id.UL, setting),
  3596. oldClass = consts.className.LEVEL + oldLevel,
  3597. newClass = consts.className.LEVEL + node.level;
  3598. liObj.removeClass(oldClass);
  3599. liObj.addClass(newClass);
  3600. aObj.removeClass(oldClass);
  3601. aObj.addClass(newClass);
  3602. ulObj.removeClass(oldClass);
  3603. ulObj.addClass(newClass);
  3604. },
  3605. selectNodes: function (setting, nodes) {
  3606. for (var i = 0, l = nodes.length; i < l; i++) {
  3607. view.selectNode(setting, nodes[i], i > 0);
  3608. }
  3609. }
  3610. },
  3611. _z = {
  3612. tools: _tools,
  3613. view: _view,
  3614. event: _event,
  3615. data: _data
  3616. };
  3617. $.extend(true, $.fn.zTree.consts, _consts);
  3618. $.extend(true, $.fn.zTree._z, _z);
  3619. var zt = $.fn.zTree,
  3620. tools = zt._z.tools,
  3621. consts = zt.consts,
  3622. view = zt._z.view,
  3623. data = zt._z.data,
  3624. event = zt._z.event,
  3625. $$ = tools.$;
  3626. data.exSetting(_setting);
  3627. data.addInitBind(_bindEvent);
  3628. data.addInitUnBind(_unbindEvent);
  3629. data.addInitCache(_initCache);
  3630. data.addInitNode(_initNode);
  3631. data.addInitProxy(_eventProxy);
  3632. data.addInitRoot(_initRoot);
  3633. data.addZTreeTools(_zTreeTools);
  3634. var _cancelPreSelectedNode = view.cancelPreSelectedNode;
  3635. view.cancelPreSelectedNode = function (setting, node) {
  3636. var list = data.getRoot(setting).curSelectedList;
  3637. for (var i = 0, j = list.length; i < j; i++) {
  3638. if (!node || node === list[i]) {
  3639. view.removeTreeDom(setting, list[i]);
  3640. if (node) break;
  3641. }
  3642. }
  3643. if (_cancelPreSelectedNode) _cancelPreSelectedNode.apply(view, arguments);
  3644. }
  3645. var _createNodes = view.createNodes;
  3646. view.createNodes = function (setting, level, nodes, parentNode, index) {
  3647. if (_createNodes) {
  3648. _createNodes.apply(view, arguments);
  3649. }
  3650. if (!nodes) return;
  3651. if (view.repairParentChkClassWithSelf) {
  3652. view.repairParentChkClassWithSelf(setting, parentNode);
  3653. }
  3654. }
  3655. var _makeNodeUrl = view.makeNodeUrl;
  3656. view.makeNodeUrl = function (setting, node) {
  3657. return setting.edit.enable ? null : (_makeNodeUrl.apply(view, arguments));
  3658. }
  3659. var _removeNode = view.removeNode;
  3660. view.removeNode = function (setting, node) {
  3661. var root = data.getRoot(setting);
  3662. if (root.curEditNode === node) root.curEditNode = null;
  3663. if (_removeNode) {
  3664. _removeNode.apply(view, arguments);
  3665. }
  3666. }
  3667. var _selectNode = view.selectNode;
  3668. view.selectNode = function (setting, node, addFlag) {
  3669. var root = data.getRoot(setting);
  3670. if (data.isSelectedNode(setting, node) && root.curEditNode == node && node.editNameFlag) {
  3671. return false;
  3672. }
  3673. if (_selectNode) _selectNode.apply(view, arguments);
  3674. view.addHoverDom(setting, node);
  3675. return true;
  3676. }
  3677. var _uCanDo = tools.uCanDo;
  3678. tools.uCanDo = function (setting, e) {
  3679. var root = data.getRoot(setting);
  3680. if (e && (tools.eqs(e.type, "mouseover") || tools.eqs(e.type, "mouseout") || tools.eqs(e.type, "mousedown") || tools.eqs(e.type, "mouseup"))) {
  3681. return true;
  3682. }
  3683. if (root.curEditNode) {
  3684. view.editNodeBlur = false;
  3685. root.curEditInput.focus();
  3686. }
  3687. return (!root.curEditNode) && (_uCanDo ? _uCanDo.apply(view, arguments) : true);
  3688. }
  3689. })(jQuery);