wdDrag.js 82 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165
  1. var wd = wd || {};
  2. wd.drag = wd.drag || {};
  3. var ismousedown = functionKeyDown = false;
  4. var setDrag, DM, itemid = 0, readyMouseIcoLen = 12;
  5. function isEventTargetIsEditable(event) {
  6. var tg = event.target;
  7. return tg.nodeName == 'textarea' || (tg.nodeName == '#text' && $(tg).parent("[contenteditable]").length > 0) || isContenteditable(tg);
  8. };
  9. function isContenteditable(ele) {
  10. return $(ele).is("[contenteditable]");
  11. };
  12. function clearMouseIcon() {
  13. for (var iii = 1; iii <= readyMouseIcoLen; iii++) {
  14. $(".cursor-timing" + iii).removeClass("cursor-timing" + iii);
  15. }
  16. }
  17. function docMouseDown(event) {
  18. ismousedown = true;
  19. if (!isEventTargetIsEditable(event || window.event)) {
  20. $("[ssObjId] [editable]").removeAttr("contenteditable"); // ("[wdObjectId] [。Lin
  21. }
  22. }
  23. function docMouseMove(event) {
  24. // clearSlct();
  25. var panel = DM.dragingPanel;
  26. var currentdrager = DM.currentDrager;
  27. var flist = (currentdrager || {}).focusedList;
  28. if (currentdrager && !currentdrager.editGroup && !currentdrager.editOrder && currentdrager.getLists().length < 2) { }
  29. else if (ismousedown && (panel || (currentdrager && flist && flist.currentMouseDownItem))) { //拖动中
  30. if ((panel = DM.dragingPanel) == null) {
  31. var ci = flist.currentMouseDownItem;
  32. var tcx = event.clientX;
  33. var tcy = event.clientY;
  34. var cx = ci.cx || tcx;
  35. var cy = ci.cy || tcy;
  36. var xdiff = cx - tcx; // 计算两个点的横坐标之差
  37. var ydiff = cy - tcy; // 计算两个点的纵坐标之差
  38. if (Math.pow((xdiff * xdiff + ydiff * ydiff), 0.5) < 10) {
  39. return;
  40. }
  41. panel = DM.dragingPanel = new wd.drag.DragPanel();
  42. document.body.appendChild(panel.element);
  43. }
  44. return;
  45. }
  46. }
  47. function docMouseUp(event) {
  48. ismousedown = false;
  49. currentMouseDownItem = null;
  50. DM.dragingPanel != null && DM.dragingPanel.destroy();
  51. clearMouseIcon();
  52. }
  53. wd.drag.DragerManager = function () {
  54. console.log("new DragerManager");
  55. try {
  56. $("body").append("<link id='dragcss' rel='stylesheet' href='/ss/js/drag.css' />");
  57. $("head").append("<style>.subList .hLine-warning{width: calc(100% - 56px);float: right;} .vLine-warning{ display:inline-block;float:left;height:20px;position:unset;height:35px} .subList{min-height: 40px;}</style>");
  58. } catch (e) { }
  59. /**
  60. * 清除选中的文字
  61. */
  62. var clearSlct = "getSelection" in window ? function () {
  63. window.getSelection().removeAllRanges();
  64. }
  65. :
  66. function () {
  67. document.selection.empty();
  68. };
  69. // /**
  70. // *
  71. // * @param {Object} event
  72. // */
  73. // document.onselectstart = function (event) {
  74. // return false;
  75. // };
  76. /**
  77. *
  78. * @param {Object} event
  79. */
  80. document.addEventListener("mousedown", docMouseDown);
  81. /**
  82. *
  83. * @param {Object} event
  84. */
  85. document.addEventListener("mousemove", docMouseMove);
  86. /**
  87. * 触发移动时候的item的进出事件
  88. * @param {Object} dragList
  89. * @param {Object} panel
  90. * @param {Object} haschild
  91. * @param {Object} event
  92. */
  93. function eachListItem(dragList, panel, haschild, event) {
  94. return;
  95. var ghost = panel.ghost;
  96. var dr = dragList.drager;
  97. // var visibleItem=
  98. dragList.each(/*dragList.getItems()*/ dragList.visibleElements, function () {
  99. var location = this.isMouseOver(event);
  100. dr = this.drager;
  101. /*触发进出事件*/
  102. if (location > 0) { //这里触发item的鼠标进出事件,以后可能会调整,同时这里的逻辑有点问题但是能用,以后处理
  103. !this.isEnter && this.trigger("mouseover");
  104. this.isEnter && this.trigger("mousemove");
  105. this.isEnter = true; //进来了
  106. DM.dragingPanel.currentHoverItem = this;
  107. } else {
  108. this.isEnter && this.trigger("mouseleave");
  109. this.isEnter = false; //出去了
  110. }
  111. if (location > 0 && (this.drager.editGroup || this.drager.editOrder) && this.isExpand && !this.getDragList().isChild) { //鼠标在展开的group上面
  112. if (haschild) {
  113. panel.notAllowDrop();
  114. } else if (this.dragList.isMouseOver(event) > 0) {
  115. ghost.getDragList() != this.dragList && this.dragList.append(ghost);
  116. eachListItem(this.dragList, panel, haschild, event);
  117. }
  118. }
  119. ghost.lineMode();
  120. });
  121. !dr.editGroup && !dr.editOrder && (dragList.element.scrollTop = dragList.element.scrollHeight);
  122. };
  123. /**
  124. *
  125. * @param {Object} event
  126. */
  127. document.addEventListener("mouseup", docMouseUp);
  128. /**
  129. *
  130. * @param {Object} event
  131. */
  132. document.addEventListener("keydown", function (event) {
  133. functionKeyDown = event.ctrlKey || event.altKey || event.shiftKey;
  134. event.ctrlKey && event.keyCode === 65 && DM.currentDrager.focusedList != null && DM.currentDrager.focusedList.selectAll();
  135. });
  136. /**
  137. *
  138. * @param {Object} event
  139. */
  140. document.addEventListener("keyup", function (event) {
  141. functionKeyDown = event.ctrlKey || event.altKey || event.shiftKey;
  142. });
  143. };
  144. wd.drag.DragerManager.prototype = {
  145. constVars: {
  146. editOrder: "editOrder",
  147. editGroup: "editGroup"
  148. },
  149. instances: {},
  150. utils: {
  151. contains: function (arr, val) {
  152. if (typeof arr == 'object' && (arr instanceof Array || arr instanceof NodeList)) {
  153. for (var i = 0; i < arr.length; i++) {
  154. if (arr[i] == val) {
  155. return true;
  156. }
  157. }
  158. }
  159. return false;
  160. },
  161. parseForm2Url: function (form) {
  162. var arr = [];
  163. var action_ = form.getAttribute("action");
  164. var param = (action_ || "?").split("?");
  165. arr = arr.concat((param[1] || "").split("&"));
  166. var elements = form.querySelectorAll("input,select,textarea");
  167. for (var i = 0; i < elements; i++) {
  168. var feled = elements[i];
  169. switch (feled.type) {
  170. case undefined:
  171. case 'button':
  172. case 'file':
  173. case 'reset':
  174. case 'submit':
  175. break;
  176. case 'checkbox':
  177. case 'radio':
  178. if (!feled.checked) {
  179. break;
  180. }
  181. default:
  182. if (feled.value != null && feled.value != '' && feled.name != null && !feled.disabled) {
  183. arr.push(feled.name + "=" + feled.value);
  184. }
  185. }
  186. }
  187. return param[0] + "?" + arr.join("&");
  188. },
  189. containsKey: function (obj, key) {
  190. for (var key_ in obj) {
  191. if (key_ == key) {
  192. return true;
  193. }
  194. }
  195. return false;
  196. }
  197. },
  198. getDrager: function (name) {
  199. if (name) {
  200. return this.instances[name];
  201. }
  202. for (var key in this.instances) {
  203. return this.instances[key];
  204. }
  205. return
  206. },
  207. getCurrentFocusList: function () {
  208. return (this.currentDrager || {}).focusedList;
  209. },
  210. getCurrentSelectedItems: function () {
  211. if (this.getCurrentFocusList()) {
  212. return this.getCurrentFocusList().getSelectedItems();
  213. }
  214. },
  215. addItem: function (id, item, index, isCover) {
  216. return this.getDrager().addItem(id, item, index, isCover);
  217. },
  218. drager: function (name, group, functions, baseOptions) {
  219. this.itemSelector = "div[ssObjId]"; // [wdObjectID]。是 wdObjectID,不是 wdObjectId。Lin
  220. this.name = name;
  221. this.imgleft = 30;
  222. this.dragerManager = this;
  223. this.items = {};
  224. this.name = name;
  225. this.getItems = function () {
  226. var tmp = [];
  227. this.selectedList != null && (tmp = tmp.concat(this.selectedList.getAllItems()));
  228. this.optionList != null && (tmp = tmp.concat(this.optionList.getAllItems()));
  229. return tmp;
  230. }
  231. this.destroy = function () {
  232. this.selectedList && this.selectedList.destroy();
  233. this.optionList && this.optionList.destroy();
  234. delete DM.instances[this.name];
  235. }
  236. this.getLists = function () {
  237. var arr = [];
  238. this.selectedList && arr.push(this.selectedList);
  239. this.optionList && arr.push(this.optionList);
  240. return arr;
  241. }
  242. this.getSelectedResult = function () {
  243. return this.selectedList.getResult();
  244. }
  245. this.addItem = function (id, element, index, isCover) {
  246. return this.addItemTo(id, element, this.selectedList, index);
  247. }
  248. this.addItemToFocusedList = function (id, element, index, isCover) {
  249. this.addItemTo(id, element, this.focusedList, index, isCover);
  250. }
  251. this.addItemTo = function (id, element, list, index, isCover) {
  252. if (list == this.focusedList) { }
  253. else if (this.focusedList.isChild && this.focusedList.thisItem.getDragList() == list) {
  254. list = this.focusedList;
  255. }
  256. return list.insertItemByHtml(id, element, index, isCover);
  257. }
  258. this.init = function () {
  259. var this_ = this;
  260. for (var key in baseOptions) {
  261. this_[key] = baseOptions[key];
  262. }
  263. //处理functions
  264. this_.functions = functions || [];
  265. this_.group = group == true || group == "true";
  266. this_.editOrder = this_.functions.indexOf(DM.constVars.editOrder) > -1;
  267. this_.editGroup = this_.functions.indexOf(DM.constVars.editGroup) > -1;
  268. //获取查询表单
  269. /* 再改,"ddpSelectedId" 改为 "ddpSelId" -- 规范 ddp 命名。Lin
  270. var form = document.getElementsByName(name + "OptionForm")[0] || document.getElementById(name + "OptionForm");
  271. */ const form = document.getElementsByName(name + "OptForm")[0] || document.getElementById(name + "OptForm")
  272. || document.getElementsByName(name + "OptionForm")[0] || document.getElementById(name + "OptionForm");
  273. if (form) {
  274. this_.form = new wd.drag.Form(form);
  275. this_.form.drager = this;
  276. }
  277. var selectedList = document.getElementById(name +"Sel") || document.getElementById(name + "Selected"); // 兼容旧页面 id。
  278. if (selectedList) {
  279. var list = new wd.drag.DragList(name, selectedList);
  280. list.isSelectedList = true;
  281. /* 再改,"ddpSelectedId" 改为 "ddpSelId" -- 规范 ddp 命名。Lin
  282. var input = document.getElementsByName(name + "SelectedId")[0];
  283. input = input || document.getElementsByName(name + "SelectedId")[0]
  284. input = input || document.createElement("input");
  285. input.type = "hidden";
  286. input.name = name + "SelectedId";
  287. */
  288. let input = document.getElementsByName(name + "SelId")[0]
  289. || document.getElementsByName(name + "SelectedId")[0];
  290. input = input || document.createElement("input");
  291. input.type = "hidden";
  292. input.name = name +"SelId";
  293. list.before(input);
  294. list.result_input = input;
  295. list.init();
  296. list.alignMode = this.selectedListAlignMode || this.alignMode || "vertical";
  297. this.selectedList = list;
  298. } else {
  299. console.log("没有找到selectedList")
  300. }
  301. var optionList = document.getElementById(name + "Opt") || document.getElementById(name + "Option"); // 兼容旧页面 id。
  302. if (optionList) {
  303. var list = new wd.drag.DragList(name, optionList);
  304. list.isOptionList = true;
  305. list.init();
  306. // list.functions = this.functions || [];
  307. // if(this.optionFunctions)
  308. // list.functions = list.functions.concat(this.optionFunctions);
  309. list.alignMode = this.optionListAlignMode || this.alignMode || "vertical";
  310. this.optionList = list;
  311. }
  312. //获取按钮区域
  313. function moveEnd(items) {
  314. DM.getDrager(name).optionList.updateInfo();
  315. DM.getDrager(name).optionList.clearSelect();
  316. DM.getDrager(name).optionList.trigger("dragend");
  317. DM.getDrager(name).selectedList.updateInfo();
  318. DM.getDrager(name).selectedList.clearSelect();
  319. DM.getDrager(name).selectedList.trigger("dragend");
  320. if (DM.getDrager(name).dragend) {
  321. var doms = [];
  322. $.each(items, function () {
  323. doms.push(this.element);
  324. });
  325. DM.getDrager(name).dragend.call(this, doms);
  326. };
  327. }
  328. var moveButtons = {
  329. 'PickAll': function () {
  330. var items = DM.getDrager(name).optionList.getSelectedItems();
  331. if (items.length < 1) {
  332. items = $(DM.getDrager(name).optionList.element).children("[ssObjId]:not(:hidden)"); // [wdObjectId]:。Lin
  333. }
  334. $.each(items, function () {
  335. var eee = this.confs ? this : this.element;
  336. if (eee && $(eee).not(":hidden")) {
  337. DM.getDrager(name).selectedList.append(eee);
  338. }
  339. });
  340. moveEnd(items);
  341. },
  342. 'DropAll': function () {
  343. var items = DM.getDrager(name).selectedList.getSelectedItems();
  344. if (items.length < 1) {
  345. items = $(DM.getDrager(name).selectedList.element).children("[ssObjId]:not(:hidden)"); // [wdObjectId]:。Lin
  346. }
  347. $.each(items, function () {
  348. var eee = this.confs ? this : this.element;
  349. if (eee && $(eee).not(":hidden")) {
  350. DM.getDrager(name).optionList.append(eee);
  351. }
  352. });
  353. moveEnd(items);
  354. }
  355. };
  356. for (var key in moveButtons) {
  357. console.log("#" + name + key)
  358. $("#" + name + key).click(moveButtons[key]);
  359. }
  360. this.getLists().length < 1 && console.info("没找到要初始化的Draglist\"" + name + "\"");
  361. }
  362. },
  363. getInstance: function (name, group, functions, baseOptions) {
  364. baseOptions = baseOptions || {};
  365. var this_ = this;
  366. return DM.instances[name] || function () {
  367. /* 再去掉,只支持一种写法 -- 不需要在页面写 <script>var isWriteOut=true;</script> 了。Lin
  368. if (typeof (isWriteOut) == "undefined") {
  369. alert("注意下,这是旧的写法,以后不再自动初始化拖拽了,\n记得新的拖拽需要通过commonwrite输出^_^");
  370. return;
  371. }
  372. */
  373. var drager = DM.instances[name] = new this_.drager(name, group, functions, baseOptions);
  374. drager.init();
  375. return drager
  376. }
  377. (name, group, functions, baseOptions);
  378. }
  379. };
  380. wd.drag.Shadow = function (element) {
  381. wd.drag.Base.call(this);
  382. this.drager = element.confs.drager;
  383. var clone = this.element = element.cloneNode(true);
  384. clone.confs = this;
  385. this.src = element;
  386. this.isShadow = true;
  387. // clone.style.opacity = "0.5";
  388. this.addClass("shadow");
  389. element.confs.isSelected() && this.removeClass(element.confs.getTopDragList({}).wdSelectedClass);
  390. $(this.element).find(".icon-checked").addClass('icon-unchecked').removeClass('icon-checked');
  391. this.getTopDragList = function (emptyObj) {
  392. if (!this.exist())
  393. return emptyObj;
  394. var list = this.getDragList();
  395. list.isChild && (list = list.thisItem.getDragList());
  396. return list;
  397. };
  398. this.getDragList = function () {
  399. return (this.element.parentNode || {}).confs;
  400. }
  401. };
  402. wd.drag.Base = function (element) {
  403. this.bindedEvent = (element || {}).bindedEvent = (element || {}).bindedEvent || {};
  404. this.isConfs = true;
  405. this.isshow = true;
  406. this.element = element;
  407. this.exist = function () {
  408. return $.contains(document.body, this.element);
  409. };
  410. this.getScrollInfo = function () {
  411. var scrollinfo = {
  412. left: 0,
  413. top: 0
  414. }
  415. getScroll(this.element);
  416. return scrollinfo;
  417. function getScroll(node) {
  418. // 非Element 终止递归
  419. if (!node) {
  420. return
  421. }
  422. if (node.nodeType !== 1) {
  423. return;
  424. }
  425. if (node.parentNode && node.parentNode.tagName == "body") {
  426. getScroll(node.parentNode);
  427. return;
  428. }
  429. scrollinfo.top += node.scrollTop;
  430. scrollinfo.left += node.scrollLeft; // position = fixed: 获取值后退出递归
  431. if (node.parentNode)
  432. getScroll(node.parentNode);
  433. }
  434. };
  435. this.offset = function () { /* 摘自jquery */
  436. var docElem,
  437. win,
  438. box = {
  439. top: 0,
  440. left: 0
  441. },
  442. elem = this.element,
  443. doc = elem && elem.ownerDocument;
  444. if (!doc) {
  445. return;
  446. }
  447. docElem = doc.documentElement;
  448. if (!DM.utils.contains(document.querySelectorAll("*"), this.element)) {
  449. return box;
  450. }
  451. if (typeof elem.getBoundingClientRect !== typeof undefined) {
  452. box = elem.getBoundingClientRect();
  453. }
  454. function getWindow(elem) {
  455. return (elem && elem == elem.window) ?
  456. elem :
  457. elem.nodeType === 9 ?
  458. elem.defaultView || elem.parentWindow :
  459. false;
  460. }
  461. win = getWindow(doc);
  462. return {
  463. top: box.top + (win.pageYOffset || docElem.scrollTop) - (docElem.clientTop || 0),
  464. left: box.left + (win.pageXOffset || docElem.scrollLeft) - (docElem.clientLeft || 0)
  465. };
  466. };
  467. this.hide = function () {
  468. $(this.element).hide();
  469. this.isshow = false;
  470. };
  471. this.show = function () {
  472. $(this.element).show();
  473. this.isshow = true;
  474. };
  475. this.find = function (selector) {
  476. return this.element.querySelectorAll(selector);
  477. };
  478. this.children = function (selector) {
  479. selector = selector || "*"
  480. var children = []
  481. $(this.element).children(selector).each(function () {
  482. children.push(this.confs == null ? new wd.drag.Base(this) : this.confs);
  483. });
  484. return children
  485. };
  486. this.is = function (selector) {
  487. return $(this.element).is(selector);
  488. };
  489. this.isDom = function (obj) {
  490. return typeof HTMLElement === 'object' ?
  491. obj instanceof HTMLElement :
  492. obj && typeof obj === 'object' && obj.nodeType === 1 && typeof obj.nodeName === 'string';
  493. };
  494. this.prev = function () {
  495. var ele = this.element.previousSibling;
  496. while (ele != null && ele.nodeType == 3) {
  497. ele = ele.previousSibling;
  498. }
  499. return ele == null ? null : (ele.confs || new wd.drag.Base(ele));
  500. };
  501. this.next = function () {
  502. var ele = this.element.nextSibling;
  503. while (ele != null && ele.nodeType == 3) {
  504. ele = ele.nextSibling;
  505. }
  506. return ele == null ? null : (ele.confs || new wd.drag.Base(ele));
  507. };
  508. this.prevAll = function (selector) {
  509. selector = selector || "*"
  510. var pe = this.element.parentNode;
  511. // var cs = pe.children;
  512. var cs = new wd.drag.Base(pe).children(selector);
  513. var arr = [];
  514. for (var i = 0; i < cs.length; i++) {
  515. var csi = cs[i];
  516. if (csi.element == this.element) {
  517. break;
  518. }
  519. arr.push(csi);
  520. }
  521. return arr;
  522. };
  523. this.nextAll = function (selector) {
  524. selector = selector || "*"
  525. var pe = this.element.parentNode;
  526. // var cs = pe.children;
  527. var cs = new wd.drag.Base(pe).children(selector);
  528. var arr = [];
  529. for (var i = cs.length - 1; i >= 0; i--) {
  530. var csi = cs[i];
  531. if (csi.element == this.element) {
  532. break;
  533. }
  534. arr.unshift(csi);
  535. }
  536. return arr;
  537. };
  538. this.remove = function () {
  539. if (this.bindedEvent) {
  540. for (var key in this.bindedEvent) {
  541. this.off(key);
  542. }
  543. }
  544. this.element.parentNode.removeChild(this.element);
  545. };
  546. this.isMouseOver = function (event) {
  547. event = event || window.event;
  548. var target = this.element;
  549. if (this.is("#ghost"))
  550. return 0;
  551. var sizeInfo = this.getSize();
  552. var result = 0;
  553. var cx = event.clientX;
  554. var cy = event.clientY;
  555. var left = sizeInfo.left;
  556. var top = sizeInfo.top;
  557. var width = sizeInfo.width;
  558. var height = sizeInfo.height;
  559. try {
  560. (cx >= left) && (cx <= (left + width)) && (cy >= top) && (cy <= (top + height)) && (result = 1);
  561. if (result == 0)
  562. return 0;
  563. if (cx >= left && cx <= parseInt(left + width / 2)) {
  564. result *= 1; //左边
  565. } else if (cx > parseInt(left + width / 2) && cx <= parseInt(left + width)) {
  566. result *= 2; //右边
  567. } else {
  568. result *= 0; //不在上面
  569. }
  570. if (cy >= top && cy <= parseInt(top + height / 3 * 2)) {
  571. result *= 3; //上半部分
  572. } else if (cy > parseInt(top + height / 3 * 2) && cy <= parseInt(top + height)) {
  573. result *= 4; //下半部分
  574. } else {
  575. result *= 0; //不在上面
  576. }
  577. } catch (e) {
  578. console.error(e)
  579. return 0;
  580. }
  581. //左上1*3=3,右上2*3=6,左下1*4=4,右下2*4=8,不在0*0
  582. return result;
  583. };
  584. this.isChildOf = function (b) {
  585. return this.isDom(b) && $.contains(b, this.element);
  586. };
  587. this.getStyles = function () {
  588. var _style;
  589. if (!this.exist()) {
  590. console.warn("注意,该节点不在文档里面,无法获取元素相关信息");
  591. offset = {
  592. top: this.element.offsetTop,
  593. left: this.element.offsetLeft
  594. }
  595. _style = this.element.style;
  596. } else {
  597. _style = window.getComputedStyle(this.element)
  598. offset = this.offset();
  599. }
  600. return _style;
  601. };
  602. this.getSize = function () {
  603. var offset,
  604. _style;
  605. if (!this.exist()) {
  606. console.warn("注意,该节点不在文档里面,无法获取元素相关信息");
  607. offset = {
  608. top: this.element.offsetTop,
  609. left: this.element.offsetLeft
  610. }
  611. } else {
  612. offset = this.offset();
  613. }
  614. _style = this.getStyles();
  615. var scrollinfo = this.getScrollInfo();
  616. var ele = this.element,
  617. sizeInfo = {},
  618. marginTop = parseInt(_style.marginTop.replace("px", "")) || 0,
  619. marginRight = parseInt(_style.marginRight.replace("px", "")) || 0,
  620. marginBottom = parseInt(_style.marginBottom.replace("px", "")) || 0,
  621. marginLeft = parseInt(_style.marginLeft.replace("px", "")) || 0,
  622. width = parseInt(_style.width.replace("px", "")) || 0,
  623. height = parseInt(_style.height.replace("px", "")) || 0,
  624. scrollleft = scrollinfo.left || document.documentElement.scrollLeft || document.body.scrollLeft || 0,
  625. scrolltop = scrollinfo.top || document.documentElement.scrollTop || document.body.scrollTop ||
  626. 0;
  627. // offset = $(this.element).offset();
  628. if (offset) {
  629. sizeInfo.top = offset.top - (document.documentElement.offsetTop || document.body.scrollTop); // 距离body的top
  630. sizeInfo.left = offset.left - (document.documentElement.offsetLeft || document.body.offsetLeft); // 距离body的left
  631. sizeInfo.width = width + marginLeft + marginRight; // 宽
  632. sizeInfo.height = height + marginTop + marginBottom; // 高
  633. sizeInfo.scrollleft = scrollleft;
  634. sizeInfo.scrolltop = scrolltop;
  635. }
  636. return sizeInfo;
  637. };
  638. this.each = $.each;
  639. this.off = function (eventNames, fn) {
  640. var ele = this.element;
  641. var enl = eventNames.split(" ");
  642. for (var i = 0; i < enl.length; i++) {
  643. var eventName = enl[i]
  644. if (this.bindedEvent[eventName]) {
  645. var fnNameL = this.bindedEvent[eventName];
  646. if (!fnNameL || fnNameL.length > 0) {
  647. this.each(fnNameL, function () {
  648. ele.removeEventListener && ele.removeEventListener(eventName, eval(this.toString()));
  649. ele.detachEvent && ele.detachEvent("on" + eventName, eval(this.toString()));
  650. window[this.toString()] == null;
  651. })
  652. if (fn) {
  653. fn.call(this, window.event);
  654. }
  655. }
  656. }
  657. }
  658. this.element && (this.element.bindedEvent = this.bindedEvent);
  659. return this;
  660. };
  661. this.trigger = function (eventNames) {
  662. var enl = eventNames.split(" ");
  663. for (var i = 0; i < enl.length; i++) {
  664. var eventName = enl[i];
  665. if (this.bindedEvent[eventName]) {
  666. var events = this.bindedEvent[eventName];
  667. this.each(events, function () {
  668. try {
  669. window[this.toString()].call(this, window.event);
  670. } catch (e) {
  671. console.error(e)
  672. }
  673. });
  674. }
  675. }
  676. return this;
  677. };
  678. this.on = function (eventNames, fn) {
  679. var ele = this.element;
  680. var this_ = this;
  681. var enl = eventNames.split(/\s+/i);
  682. for (var i = 0; i < enl.length; i++) {
  683. var eventName = enl[i];
  684. if (eventName == "")
  685. continue;
  686. var fnl = this.bindedEvent[eventName];
  687. if (!fnl) {
  688. fnl = this.bindedEvent[eventName] = [];
  689. }
  690. var fnName = "event_" + (this.id || "_") + "_" + new Date().getTime() + "_" + eventName + "_" + fnl.length;
  691. fnName = fnName.split(/\W+/).join("_");
  692. fnl.push(fnName);
  693. window[fnName] = function () {
  694. var event = window.event;
  695. if (fn.call(this_, event) === false) {
  696. event.preventDefault && event.preventDefault();
  697. event.stopPropagation && event.stopPropagation();
  698. event.cancelBubble && (event.cancelBubble = true);
  699. }
  700. };
  701. ele.addEventListener && ele.addEventListener(eventName, eval(fnName), false);
  702. ele.attachEvent && ele.attachEvent("on" + eventName, eval(fnName));
  703. }
  704. this.element && (this.element.bindedEvent = this.bindedEvent);
  705. return this;
  706. };
  707. this.addClass = function (name) {
  708. $(this.element).addClass(name);
  709. return this;
  710. };
  711. this.toggleClass = function (name) {
  712. if (!name) {
  713. return;
  714. }
  715. if (this.hasClass(name)) {
  716. this.removeClass(name);
  717. } else {
  718. this.addClass(name);
  719. }
  720. return this
  721. };
  722. this.hasClass = function (name) {
  723. return name && this.element.className.indexOf(name) > -1;
  724. };
  725. this.append = function (ele) {
  726. var e;
  727. if (this.isDom(ele)) {
  728. e = ele;
  729. } else if (this.isConfs) {
  730. e = ele.element;
  731. }
  732. $(this.element).append(e);
  733. };
  734. this.before = function (item) {
  735. if (!item) {
  736. return
  737. } else if (this.isDom(item)) {
  738. this.element.parentNode.insertBefore(item, this.element);
  739. } else if (item.isConfs) {
  740. this.element.parentNode.insertBefore(item.element, this.element);
  741. } else {
  742. console.log("??")
  743. }
  744. };
  745. this.after = function (item) {
  746. if (!item) {
  747. return
  748. } else if (this.isDom(item)) {
  749. this.element.parentNode.insertBefore(item, this.element.nextSibling);
  750. } else if (item.isConfs) {
  751. this.element.parentNode.insertBefore(item.element, this.element.nextSibling);
  752. }
  753. };
  754. this.removeClass = function (name) {
  755. $(this.element).removeClass(name);
  756. return this;
  757. };
  758. if (element && (element.confs || element.isConfs)) {
  759. var con = element.isConfs ? element : element.confs
  760. for (var key in con) {
  761. this.element.confs[key] = con[key];
  762. }
  763. // return;
  764. }
  765. };
  766. var dragCursor = ["cursor-vDragMultiple", "cursor-vDrag", "cursor-timing", "cursor-hDragMultiple", "cursor-hDrag", "cursor-timing"];
  767. wd.drag.DragPanel = function () {
  768. wd.drag.Base.call(this);
  769. var dragList = DM.currentDrager.focusedList;
  770. var ghost = this.ghost = new wd.drag.Ghost(dragList.currentMouseDownItem.element);
  771. dragList.element.appendChild(ghost.element);
  772. if (dragList.alignMode != "vertical") {
  773. // $(ghost.element).removeClass("hLine-warning").addClass("vLine-warning");
  774. // $(ghost.element).css({
  775. // "display": "inline-block",
  776. // "float": "left",
  777. // "height": "20px",
  778. // "position": "unset",
  779. // "height": "35px"
  780. // });
  781. }
  782. var box = this.element = dragList.element.cloneNode();
  783. // var styles = document.querySelectorAll("style");
  784. // this.each(styles, function () {
  785. // box.appendChild(this.cloneNode(true));
  786. // });
  787. // styles = document.querySelectorAll("link");
  788. // this.each(styles, function () {
  789. // box.appendChild(this.cloneNode(true));
  790. // });
  791. // styles = document.querySelectorAll("LINK");
  792. // this.each(styles, function () {
  793. // box.appendChild(this.cloneNode(true));
  794. // });
  795. box.confs = this;
  796. this.drager = dragList.drager;
  797. this.sizeInfo = dragList.currentMouseDownItem.getSize();
  798. this.left = dragList.currentMouseDownItem.cx - this.sizeInfo.left;
  799. this.top = dragList.currentMouseDownItem.cy - this.sizeInfo.top;
  800. box.style.zIndex = "9999";
  801. box.style.background = "white";
  802. box.style.border = "1px dashed black";
  803. box.style.borderRadius = ".3em";
  804. box.style.position = "fixed";
  805. box.style.padding = ".3em";
  806. box.id = "list";
  807. this.notAllowDrop = function () {
  808. this.isAllowDrop = false;
  809. this.mask.cursor_old = DM.dragingPanel.mask.style.cursor
  810. this.mask.style.cursor = "not-allowed";
  811. this.ghost.hide();
  812. };
  813. this.allowDrop = function () {
  814. this.isAllowDrop = true;
  815. this.mask.style.cursor = this.mask.cursor_old || "move";
  816. this.mask.cursor_old = null;
  817. this.ghost.show();
  818. };
  819. var items = this.items = [];
  820. var shadows = this.shadows = [];
  821. var count = 0;
  822. var its = dragList.getSelectedItems();
  823. its[0].hideDragList();
  824. var ss = its[0].getSize();
  825. this.each(its, function () {
  826. var item = this;
  827. var shadow = item.createShadow();
  828. if (item.isExpand)
  829. item.hideDragList();
  830. item.shadow = shadow;
  831. items.push(item);
  832. shadows.push(shadow);
  833. item.removeClass(item.getTopDragList({}).wdSelectedClass);
  834. $(item.element).find('.icon-checked').addClass('icon-unchecked').removeClass('icon-checked');
  835. // item.removeClass(item.getTopDragList({}).wdNormalClass);
  836. item.removeClass(item.getTopDragList({}).wdHoverClass);
  837. box.appendChild(item.element);
  838. });
  839. box.style.width = ss.width + 10 + "px";
  840. box.style.height = ss.height * its.length + "px";
  841. dragList.selectedItems = {};
  842. dragList.updateVisibleElements();
  843. dragList.trigger("mouseup");
  844. dragList.currentMouseDownItem = null;
  845. this.move = function (event) {
  846. var ele = this.element;
  847. ele.style.left = (event.clientX - this.left) + "px";
  848. ele.style.top = (event.clientY - this.top) + "px";
  849. };
  850. this.getDragList = function () {
  851. return (this.ghost.element.parentNode || {}).confs;
  852. };
  853. this.hasChild = function () {
  854. for (var i = 0; i < items.length; i++) {
  855. if (items[i].dragList && items[i].dragList.getItems().length > 0) {
  856. return true;
  857. }
  858. }
  859. return false;
  860. };
  861. var t = this.getDragList().alignMode != "vertical" ? 3 : 0;
  862. var c = items.length > 1 ? dragCursor[0 + t] : dragCursor[1 + t];
  863. this.destroy = function () {
  864. this.drager.selectedList && this.drager.selectedList.updateVisibleElements();
  865. this.drager.optionList && this.drager.optionList.updateVisibleElements();
  866. $("body,html").removeClass(dragCursor.join(" "));
  867. $(".notallow_item").removeClass("notallow_item");
  868. var this_ = this;
  869. var list = this.getDragList();
  870. this.each(this_.items, function () {
  871. try {
  872. var item__ = list.getItemById(this.id);
  873. if (item__.isGhost || item__.isShadow || item__ == this) { }
  874. else {
  875. item__.remove();
  876. console.log("找到重复的ID“" + this.id + "”,覆盖")
  877. }
  878. } catch (e) { }
  879. if (this_.ghost.isshow) {
  880. this_.ghost.before(this);
  881. this.select();
  882. } else {
  883. this.shadow.before(this)
  884. }
  885. })
  886. this.each(this_.shadows, function () {
  887. this.remove();
  888. })
  889. this.each(this.drager.getLists(), function () {
  890. var this_ = this;
  891. setTimeout(function () {
  892. this_.trigger("dragend");
  893. }, 1)
  894. });
  895. this.each(this.items, function () {
  896. var this_ = this;
  897. setTimeout(function () {
  898. this_.trigger("dragend");
  899. })
  900. });
  901. this.each(this.drager.getLists(), function () {
  902. this.clearSelect();
  903. });
  904. this.each(items, function () {
  905. this.select();
  906. });
  907. if (this.drager.dragend) {
  908. var doms = [];
  909. this.each(items, function () {
  910. doms.push(this.element);
  911. });
  912. this.drager.dragend.call(this, doms, this.ghost.element);
  913. };
  914. this.ghost.getDragList().focus();
  915. this.ghost.destroy();
  916. this.remove();
  917. DM.dragingPanel = null;
  918. };
  919. var mask = this.mask = $("<div style='clear:both;position:absolute;top:-1em;left:-1em;right:-1em;bottom:-1em;z-index:110000' class='panel'/>")[0];
  920. new wd.drag.Base(mask).on("mousewheel DOMMouseScroll", function (e) {
  921. function isCanScroll(obj) {
  922. if (obj) {
  923. var of = window.getComputedStyle(obj)["overflow-y"];
  924. return ("scroll|auto".indexOf(of) > -1) && (obj.scrollHeight > 0);
  925. } else {
  926. return false
  927. }
  928. };
  929. function findObjScrollParent(obj, i) {
  930. i = i || 0;
  931. i++;
  932. var par = obj.parentNode;
  933. if (obj.tagName == "HTML") {
  934. return obj.querySelector("body");
  935. }
  936. if (isCanScroll(par)) {
  937. return par;
  938. } else {
  939. return findObjScrollParent(par, i);
  940. }
  941. };
  942. var delta = (e.wheelDelta && (e.wheelDelta > 0 ? 1 : -1)) || // chrome & ie
  943. (e.detail && (e.detail > 0 ? -1 : 1)); // firefox
  944. findObjScrollParent(ghost.element).scrollTop -= delta * 35;
  945. ghost.getDragList().updateVisibleElements();
  946. });
  947. $("body,html").addClass(c);
  948. if (this.hasChild()) {
  949. $.each(this.drager.getLists(), function () {
  950. $(this.element).children(this.drager.itemSelector).addClass("notallow_item");
  951. });
  952. }
  953. box.appendChild(mask);
  954. document.body.appendChild(box);
  955. box.style.display = "none";
  956. DM.justEnd = true;
  957. };
  958. wd.drag.DragList = function (name, element) {
  959. wd.drag.Base.call(this);
  960. var drager = this.drager = DM.getInstance(name);
  961. this.visibleElements = [];
  962. this.wdNormalClass = element.getAttribute("ssNormClazz") || ""; // ("wdNormalClass")。Lin
  963. this.wdHoverClass = element.getAttribute("ssHovClazz") || ""; // ("wdHoverClass")。Lin
  964. this.wdSelectedClass = element.getAttribute("ssSelClazz") || ""; // ("wdSelectedClass")。Lin
  965. this.wdSelectedParentClass = element.getAttribute("wdSelectedParentClass") || "";
  966. this.element = element.isConfs ? element.element : element;
  967. this.isChild = false;
  968. this.isDragList = true;
  969. this.dragerName = name;
  970. this.id = this.element.id;
  971. this.element.confs = this;
  972. this.unfocus = function () {
  973. this.removeClass(this.wdSelectedParentClass);
  974. this.clearSelect();
  975. this.drager.focusedList = null;
  976. DM.currentDrager = null;
  977. };
  978. this.focus = function () {
  979. if (drager.focusedList && this != drager.focusedList) {
  980. drager.focusedList.clearSelect();
  981. drager.focusedList.unfocus();
  982. }
  983. drager.focusedList = this;
  984. DM.currentDrager = this.drager;
  985. DM.currentDrager.focusedList = this;
  986. this.addClass(this.wdSelectedParentClass);
  987. };
  988. this.empty = function () {
  989. this.each(this.getItems(), function () {
  990. this.remove();
  991. });
  992. this.element.innerHTML = '';
  993. this.trigger("dragend");
  994. };
  995. this.selectAll = function () {
  996. this.each(this.element.children, function () {
  997. this.confs && this.confs.select && this.confs.select();
  998. });
  999. };
  1000. this.clearSelect = function () {
  1001. this.each(this.element.children, function () {
  1002. if (this.confs && this.confs.exist() && !this.confs.isShadow && this.confs.isGhost != true) {
  1003. this.confs.unselect();
  1004. this.hasDragList && this.dragList && this.dragList.clearSelect();
  1005. }
  1006. });
  1007. this.selectedItems = {};
  1008. };
  1009. this.destroy = function () {
  1010. this.off("mousedown mouseup click dragend");
  1011. this.element.confs = null;
  1012. this.each(this.getItems(), function () {
  1013. this.destroy();
  1014. });
  1015. }
  1016. this.reload = function (fn) {
  1017. var this_ = this;
  1018. console.time()
  1019. this.init();
  1020. console.timeEnd();
  1021. this.each(this.drager.getLists(), function () {
  1022. this.each(this.getAllItems(), function () {
  1023. this.drager.items[this.id] = this;
  1024. })
  1025. });
  1026. fn && typeof fn == 'function' && fn();
  1027. }
  1028. this.shiftSelect = function () {
  1029. this.each(this.shiftSelectStartItem.nextAll(this.drager.itemSelector), function () {
  1030. this instanceof wd.drag.Item && this.select();
  1031. });
  1032. this.each(this.currentMouseDownItem.nextAll(this.drager.itemSelector), function () {
  1033. if (this instanceof wd.drag.Item)
  1034. if (this.isSelected()) {
  1035. this.unselect()
  1036. } else {
  1037. this.select();
  1038. }
  1039. });
  1040. this.shiftSelectStartItem.select();
  1041. this.currentMouseDownItem.select();
  1042. };
  1043. this.insertItemByHtml = function (objectid, html, index, isCover) {
  1044. var element = html;
  1045. !this.isDom(element) && (element = $(element)[0]);
  1046. objectid != null && element.setAttribute("ssObjId", objectid); // ("wdObjectID",。是 wdObjectID,不是 wdObjectId。Lin
  1047. var item = new wd.drag.Item(this.drager.name, element);
  1048. objectid && (item.id = objectid);
  1049. return this.insertItem(item, index, isCover);
  1050. };
  1051. this.insertItem = function (item, index, isCover) {
  1052. index = (index != null && index > -1) ? index : (this.getSelectedItems().length < 1 ? this.getItems().length : this.getSelectedItems()[0].getIndex());
  1053. this.drager.items[item.id] = item;
  1054. var items = this.getItems();
  1055. var old = this.getItemById(item.id)
  1056. if (old) {
  1057. console.log("找到重复的id:\"" + old.id + "\",覆盖(默认覆盖)?:" + ((isCover != false || isCover != "false") ? "覆盖" : "不覆盖"))
  1058. if (isCover != false || isCover != "false") {
  1059. old.remove();
  1060. } else {
  1061. console.warn("不覆盖,跳过处理")
  1062. return null;
  1063. }
  1064. }
  1065. var bool = false;
  1066. this.each(items, function () {
  1067. if (this.getIndex() == index) {
  1068. this.after(item);
  1069. bool = true;
  1070. return false;
  1071. }
  1072. });
  1073. !bool && this.append(item);
  1074. item.init();
  1075. item.trigger("dragend");
  1076. return item;
  1077. };
  1078. this.getSelectedItems = function () {
  1079. var arr = [];
  1080. for (var key in this.selectedItems) {
  1081. arr.push(this.selectedItems[key]);
  1082. }
  1083. return arr;
  1084. };
  1085. this.distnict = function () {
  1086. var ids = [];
  1087. this.each(this.getItems(), function () { });
  1088. };
  1089. this.updateInfo = function () {
  1090. this.each(this.getItems(), function () {
  1091. this.updateInfo();
  1092. });
  1093. };
  1094. this.getResult = function () {
  1095. this.updateInfo();
  1096. var result = [];
  1097. this.each(this.element.children, function () {
  1098. if (this.isGhost || this.isShadow || this.confs == null)
  1099. return;
  1100. var itemdata = {
  1101. ID: this.confs.id,
  1102. PID: this.confs.parentid || null
  1103. };
  1104. itemdata.PID == null && delete itemdata.PID;
  1105. itemdata.ID != null && result.push(itemdata);
  1106. if (this.confs.hasDragList && this.confs.dragList) {
  1107. this.confs.each(this.confs.dragList.getResult(), function () {
  1108. result.push(this);
  1109. });
  1110. }
  1111. });
  1112. return result;
  1113. };
  1114. this.getAllItems = function () {
  1115. var thisitems = this.getItems();
  1116. var tmp = [];
  1117. this.each(thisitems, function () {
  1118. this.hasDragList && this.dragList && (tmp = tmp.concat(this.dragList.getItems()));
  1119. });
  1120. return thisitems.concat(tmp);
  1121. }
  1122. this.getItemByIndex = function (index) {
  1123. if (this.getItems()[index])
  1124. return this.getItems()[index];
  1125. else
  1126. return null;
  1127. };
  1128. this.getItemListObj = function () {
  1129. var obj = {};
  1130. this.each(this.getItems(), function () {
  1131. obj[this.id] = this;
  1132. });
  1133. return obj;
  1134. }
  1135. this.getItemById = function (id) {
  1136. var result;
  1137. this.each(this.getItems(), function () {
  1138. if (this.id == id) {
  1139. result = this;
  1140. return false;
  1141. }
  1142. });
  1143. return result;
  1144. };
  1145. this.updateVisibleElements = function () {
  1146. if (this.alignMode == "vertical") {
  1147. this.visibleElements = this.getItems();
  1148. } else {
  1149. var start = this.getScrollInfo().top - 15;
  1150. var end = this.getSize().height + start + 15;
  1151. this.visibleElements = [];
  1152. while (start++ <= end) {
  1153. try {
  1154. this.visibleElements.push(this.element.querySelector("[ssObjId][tp='" + start + "']").confs); // ("[wdObjectID][。是 wdObjectID,不是 wdObjectId。Lin
  1155. } catch (e) { }
  1156. }
  1157. }
  1158. };
  1159. this.getItems = function () {
  1160. var result = [];
  1161. this.each(this.children(this.drager.itemSelector), function () {
  1162. (this.isItem || this.isShadow) && this.isConfs && result.push(this);
  1163. });
  1164. return result;
  1165. };
  1166. this.init = function () {
  1167. this.selectedItems = {};
  1168. var this_ = this;
  1169. var t = {};
  1170. this.on("selectstart", function (event) {
  1171. if (isEventTargetIsEditable(event)) {
  1172. return true;
  1173. }
  1174. event.preventDefault();
  1175. event.stopPropagation();
  1176. return false;
  1177. });
  1178. this.on("mousewheel DOMMouseScroll", function () {
  1179. this.updateVisibleElements();
  1180. })
  1181. this.on("mouseover", function (event) {
  1182. var panel = DM.dragingPanel;
  1183. if (panel && panel.drager == this.drager && !$.contains(this.element, panel.ghost.element)) {
  1184. this.append(panel.ghost.element);
  1185. }
  1186. return false;
  1187. });
  1188. this.each(this.children(this_.drager.itemSelector), function (index) {
  1189. // if(new wd.drag.Base(this).is(this_.drager.itemSelector)) {
  1190. var item = this.isItem ? this : new wd.drag.Item(name, this);
  1191. var id = item.id;
  1192. if (t[id] == null) {
  1193. t[id] = item;
  1194. item.init();
  1195. this_.drager.items[item.id] = item;
  1196. } else {
  1197. console.log("找到重复的ID“" + id + "”,删除")
  1198. item.remove();
  1199. }
  1200. if (item.id != null && !this_.isSelectedList && this_.drager.selectedList && this_.drager.selectedList.getItemById(item.id) != null) {
  1201. item.remove();
  1202. }
  1203. // }
  1204. });
  1205. if (drager.group) {
  1206. //判断是否存在环
  1207. var tmp = {};
  1208. this.each(this.getItems(), function () {
  1209. var t = tmp[this.id] = tmp[this.id] || {
  1210. id: this.id
  1211. };
  1212. if (this.parentid) {
  1213. tmp[this.parentid] = tmp[this.parentid] || {};
  1214. tmp[this.parentid].child = t;
  1215. }
  1216. });
  1217. try {
  1218. var items = this.getItemListObj();
  1219. JSON.stringify(tmp);
  1220. for (var key in items) {
  1221. if (items[key].parentid && this_.drager.items[items[key].parentid]) {
  1222. this_.drager.items[items[key].parentid].dragList.insertItem(items[key]);
  1223. }
  1224. }
  1225. } catch (e) {
  1226. console.log(items)
  1227. console.error("错误:上下级关系存在环,不进行分组放置处理");
  1228. }
  1229. } else {
  1230. this.each(this.find("[ssObjId]"), function () { // ("[wdObjectID]"),。是 wdObjectID,不是 wdObjectId。Lin
  1231. this_.append(this);
  1232. });
  1233. }
  1234. if (this.isChild || this.thisItem) {
  1235. this.element.id = this.thisItem.id + new Date().getTime();
  1236. this.isChild = true;
  1237. }
  1238. this.on("dragend", function () {
  1239. var its = this.getItems();
  1240. var l = 30; //个一组
  1241. var ii = 0;
  1242. while (ii < its.length) {
  1243. (function (arr) {
  1244. setTimeout(function () {
  1245. for (var i = 0; i < arr.length; i++) {
  1246. arr[i] && arr[i].trigger("dragend");
  1247. }
  1248. });
  1249. })(its.slice(ii, ii += l));
  1250. }
  1251. if (this.result_input) {
  1252. this.result_input.value = JSON.stringify(this.getResult());
  1253. }
  1254. this.updateInfo();
  1255. });
  1256. this.off("mousedown").on("mousedown", function (event) {
  1257. if (isEventTargetIsEditable(event)) {
  1258. return;
  1259. }
  1260. this.focus();
  1261. event.stopPropagation();
  1262. return false;
  1263. });
  1264. this.off("mouseup").on("mouseup", function () {
  1265. // event.stopPropagation();
  1266. // return false;
  1267. });
  1268. this.off("click").on("click", function (event) {
  1269. event.stopPropagation();
  1270. return false;
  1271. });
  1272. this.trigger("dragend");
  1273. this.updateVisibleElements();
  1274. };
  1275. };
  1276. /* 改,改用 .list-color -- 原 .list 增加了来自列表行外层的 <div style=。Lin
  1277. var textWrapperClass = ["list", "list", "list-highlight", "list-highlight"];
  1278. */
  1279. /* 再去掉,去掉列表行的文字样式区分 -- 图标区分了。Lin
  1280. var textWrapperClass = ["list-color", "list-color", "list-highlight", "list-highlight"];
  1281. */
  1282. var iconClassName = ["icon-doc", "icon-point", "icon-openFolder", "icon-folder"];
  1283. wd.drag.ShowBtn = function (itemelement) {
  1284. wd.drag.Base.call(this);
  1285. var element = this.element = $("<span>&nbsp;</span>")[0];
  1286. element.confs = this;
  1287. // element.style.cursor = 'pointer';
  1288. var itemEle = this.itemEle = itemelement;
  1289. this.init = function () {
  1290. // this.element.style.display = "inline-block";
  1291. // this.element.style.width = this.itemEle.confs.drager.imgleft + "px";
  1292. // this.element.style.background = "url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAQAAAC1+jfqAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAADoSURBVBgZBcExblNBGAbA2ceegTRBuIKOgiihSZNTcC5LUHAihNJR0kGKCDcYJY6D3/77MdOinTvzAgCw8ysThIvn/VojIyMjIyPP+bS1sUQIV2s95pBDDvmbP/mdkft83tpYguZq5Jh/OeaYh+yzy8hTHvNlaxNNczm+la9OTlar1UdA/+C2A4trRCnD3jS8BB1obq2Gk6GU6QbQAS4BUaYSQAf4bhhKKTFdAzrAOwAxEUAH+KEM01SY3gM6wBsEAQB0gJ+maZoC3gI6iPYaAIBJsiRmHU0AALOeFC3aK2cWAACUXe7+AwO0lc9eTHYTAAAAAElFTkSuQmCC) no-repeat right ";
  1293. // this.element.style.backgroundSize = 'auto 100%';
  1294. }
  1295. this.destroy = function () {
  1296. this.remove();
  1297. }
  1298. this.initEvent = function () {
  1299. this.on("click", function () {
  1300. if (functionKeyDown)
  1301. return;
  1302. var cfs = itemEle.confs
  1303. if ((cfs.dragList && cfs.isExpand) || (!cfs.drager.group || (cfs.dragList && cfs.dragList.getItems().length == 0))) {
  1304. cfs.hideDragList()
  1305. } else {
  1306. cfs.showDragList();
  1307. }
  1308. event.stopPropagation();
  1309. return false;
  1310. });
  1311. }
  1312. this.switchImg = function () {
  1313. var cfs = itemEle.confs;
  1314. if (!cfs.drager.group || (cfs.dragList && cfs.dragList.getItems() == 0)) { //不是分组,也没有子内容
  1315. this.fileStyle();
  1316. } else {
  1317. if (cfs.isExpand) {
  1318. this.expandFolderStyle();
  1319. } else {
  1320. this.normalFolderStyle();
  1321. }
  1322. }
  1323. };
  1324. this.toggleIcon = function (state) {
  1325. $(this.element).removeClass(iconClassName.join(" ")).addClass(iconClassName[state]);
  1326. /* 再去掉,去掉列表行的文字样式区分 -- 图标区分了。Lin
  1327. $(this.element.textwrapper).removeClass(textWrapperClass.join(" ")).addClass(textWrapperClass[state]);
  1328. */
  1329. var cn = this.itemEle.confs;
  1330. if (state > 1) { //文件夹样式
  1331. cn.addClass("filelist");
  1332. } else {
  1333. cn.removeClass("filelist");
  1334. }
  1335. }
  1336. this.expandFolderStyle = function () {
  1337. this.toggleIcon(2)
  1338. };
  1339. this.normalFolderStyle = function () {
  1340. this.toggleIcon(3);
  1341. };
  1342. this.fileStyle = function () {
  1343. if (itemEle.confs.getDragList().isChild) {
  1344. this.toggleIcon(1);
  1345. } else {
  1346. this.toggleIcon(0);
  1347. }
  1348. };
  1349. itemEle.insertBefore(element, itemEle.childNodes[0]);
  1350. this.init();
  1351. return this;
  1352. };
  1353. wd.drag.Item = function (name, element) {
  1354. wd.drag.Base.call(this);
  1355. this.element = element.isConfs ? element.element : element;
  1356. this.element.confs = this;
  1357. this.isItem = true;
  1358. this.id = (this.element.getAttribute("ssObjId") || (itemid++) + "").split("#").join("").split(".").join(""); // ("wdObjectID")。是 wdObjectID,不是 wdObjectId。Lin
  1359. this.parentid = (this.element.getAttribute("ssPobjId") || "").split("#").join("").split(".").join(""); // ("wdParentObjectID")。是 wdParentObjectID,不是 wdParentObjectId。Lin
  1360. var drager = this.drager = DM.getInstance(name);
  1361. this.hasDragList = false;
  1362. this.createShadow = function () {
  1363. var clone = new wd.drag.Shadow(this.element);
  1364. this.element.parentNode.insertBefore(clone.element, this.element);
  1365. this.shadow = clone;
  1366. return clone;
  1367. };
  1368. this.isSelected = function () {
  1369. return this.hasClass(this.getTopDragList({}).wdSelectedClass);
  1370. };
  1371. this.getTopDragList = function (emptyObj) {
  1372. if (!this.exist())
  1373. console.log("!!!")
  1374. var list = this.getDragList();
  1375. if (list.isChild)
  1376. list = list.thisItem.getDragList();
  1377. return list;
  1378. }
  1379. this.select = function () {
  1380. if (!this.drager.editGroup && !this.drager.editOrder && this.drager.getLists().length < 2) { }
  1381. else {
  1382. this.isFunctionKeyDown = functionKeyDown || event.ctrlKey || event.altKey || event.shiftKey;
  1383. this.getDragList().selectedItems[this.id] = this;
  1384. this.addClass(this.getTopDragList({}).wdSelectedClass);
  1385. $(this.element).find(".icon-unchecked").addClass('icon-checked').removeClass('icon-unchecked');
  1386. }
  1387. };
  1388. this.unselect = function () {
  1389. this.isFunctionKeyDown = false;
  1390. delete this.getDragList().selectedItems[this.id];
  1391. this.removeClass(this.getTopDragList({}).wdSelectedClass);
  1392. $(this.element).find(".icon-checked").addClass('icon-unchecked').removeClass('icon-checked');
  1393. };
  1394. this.getParentItem = function () {
  1395. var list = this.getDragList();
  1396. if (list && list.isChild) {
  1397. return list.thisItem;
  1398. } else {
  1399. return null;
  1400. }
  1401. };
  1402. this.getDragList = function () {
  1403. return (this.element.parentNode || {}).confs;
  1404. };
  1405. this.hideDragList = function () {
  1406. this.isExpand = false;
  1407. if (this.getDragList() && !this.drager.group)
  1408. return;
  1409. if (this.getDragList().isChild && this.imgBtn) {
  1410. this.dragList.hide();
  1411. // this.dragList.element.style.height = "auto";
  1412. } else if (!this.getDragList().isChild && this.imgBtn) {
  1413. this.dragList.hide();
  1414. // this.dragList.element.style.height = "auto";
  1415. }
  1416. if (this.imgBtn)
  1417. this.imgBtn.switchImg();
  1418. this.getDragList().focus();
  1419. };
  1420. this.showDragList = function () {
  1421. if (!this.drager.group)
  1422. return;
  1423. if (DM.dragingPanel && DM.dragingPanel.hasChild())
  1424. return;
  1425. if (this.getDragList().isChild /*|| !(this.getDragList()instanceof wd.drag.DragList)*/)
  1426. return;
  1427. if (this.imgBtn) {
  1428. this.isExpand = true;
  1429. if (this.dragList.getItems().length > 0) {
  1430. this.dragList.element.style.height = "auto";
  1431. } else if (this.dragList.getSize().height == 0) {
  1432. this.dragList.element.style.minHeight = this.getSize().height + "px";
  1433. }
  1434. this.dragList.show();
  1435. this.dragList.focus();
  1436. this.imgBtn.switchImg();
  1437. }
  1438. };
  1439. this.getIndex = function () {
  1440. this.index = this.prevAll().length;
  1441. return this.index;
  1442. };
  1443. this.updateInfo = function () {
  1444. this.parentid = this.getDragList().thisItem == null ? null : this.getDragList().thisItem.id;
  1445. if (this.parentid) // 增加,不输出 ssPobjId="null"。Lin
  1446. this.element.setAttribute("ssPobjId", this.parentid); // ("wdParentObjectID",。是 wdParentObjectID,不是 wdParentObjectId。Lin
  1447. this.index = this.prevAll().length;
  1448. if (!this.getDragList().isChild && this.dragList) {
  1449. this.dragList.isChild = true;
  1450. if (this.imgBtn) {
  1451. var len = this.dragList.children().length;
  1452. this.imgBtn.element.innerText = len > 0 ? len : "";
  1453. }
  1454. } else if (this.dragList) {
  1455. this.dragList.isChild = false;
  1456. }
  1457. if (this.dragList && this.dragList.getItems().length == 0) {
  1458. this.hideDragList();
  1459. }
  1460. if (this.imgBtn)
  1461. this.imgBtn.switchImg();
  1462. };
  1463. this.destroy = function () {
  1464. this.off("dblclick selectedClick click dragend mousedown mouseup mousemove mouseover mouseout mouseleave");
  1465. this.off("dblclick selectedClick click dragend mousedown mouseup mousemove mouseover mouseout mouseleave");
  1466. this.imgBtn && this.imgBtn.destroy();
  1467. this.hasDragList && this.dragList && (this.drager.functions.indexOf('group') > -1) && this.dragList.destroy();
  1468. this.element.confs = null;
  1469. }
  1470. this.init = function () {
  1471. var me = this;
  1472. this.isExpand = false;
  1473. if (this.drager.group) {
  1474. //初始化第二层,包住
  1475. var $div = $("<div>");
  1476. $div.attr("id", "wrapper_" + this.id);
  1477. $div.append($(this.element.childNodes));
  1478. $(this.element).append($div);
  1479. this.imgBtn = this.imgBtn || new wd.drag.ShowBtn(this.element);
  1480. this.imgBtn.element.textwrapper = $div[0];
  1481. this.dragList = new wd.drag.DragList(name, document.createElement("div"));
  1482. this.append(this.dragList.element);
  1483. this.dragList.thisItem = this;
  1484. this.dragList.addClass("subList");
  1485. this.dragList.hide();
  1486. this.imgBtn.initEvent();
  1487. this.hasDragList = true;
  1488. };
  1489. var _checkbox = this.checkbox = document.createElement("span");
  1490. // _checkbox.innerHTML = "";
  1491. // _checkbox.className='dragcheckbox';
  1492. // _checkbox.style.width="15px";
  1493. // _checkbox.style.border='1px dashed black';
  1494. /* 再改,把 style= 移到新加的 .list .icon { -- 不在 js 里写样式属性。Lin
  1495. _checkbox.style.cssText = 'display: inline-block; width: 28px;height: 40px;float: left;';
  1496. _checkbox.className = "icon-unchecked";
  1497. */ _checkbox.className = "icon icon-unchecked";
  1498. _checkbox.onmousedown = _checkbox.onmouseup = function (e) {
  1499. e.stopPropagation();
  1500. }
  1501. _checkbox.onclick = function (e) {
  1502. if (!me.isSelected()) {
  1503. me.select();
  1504. } else {
  1505. me.unselect();
  1506. }
  1507. e.stopPropagation();
  1508. }
  1509. /* 再改,增加 .icon 了 -- 把 style= 移到新加的 .list .icon { -- 不在 js 里写样式属性。Lin
  1510. * 同时拥有 icon 和 icon-unchecked 两个 class 的同一个元素,要写为 .find(".icon.icon-unchecked") -- 中间无空格
  1511. * 原来只有一个样式,这样写 .find("." + _checkbox.className) 没问题
  1512. * 两个样式,就变为 .find(".icon icon-unchecked") 了
  1513. $(this.element).find("." + _checkbox.className).length < 1 && $(this.element).prepend(_checkbox);
  1514. */ $(this.element).find(".icon.icon-unchecked").length < 1 && $(this.element).prepend(_checkbox);
  1515. this.element.styleinfo = this.getStyles();
  1516. // this.element.style.position = "relative";
  1517. this.addClass(this.getTopDragList({}).wdNormalClass);
  1518. var this_ = this;
  1519. this_.element.setAttribute("tp", this.element.offsetTop);
  1520. this.off("dblclick").on("dblclick", function () {
  1521. if (this.imgBtn) {
  1522. this.imgBtn.trigger("click");
  1523. }
  1524. if (this.drager.onDblClick) {
  1525. this.drager.onDblClick.call(this);
  1526. }
  1527. });
  1528. this.off("selectedClick").on("selectedClick", function (event) {
  1529. this_.drager.selectedClick && this_.drager.selectedClick.call(this, this.element);
  1530. })
  1531. this.off("click").on("click", function (event) {
  1532. if (isEventTargetIsEditable(event)) {
  1533. return;
  1534. }
  1535. this.triggerSelectedClick && this.trigger("selectedClick");
  1536. this_.drager.itemClick && this_.drager.itemClick.call(this, this.element);
  1537. });
  1538. this.off("dragend").on("dragend", function () {
  1539. this.hasDragList && this.getDragList() && !this.getDragList().isChild && this.dragList.trigger("dragend");
  1540. if (this.getDragList() && this.getDragList().isChild) {
  1541. this.hideDragList();
  1542. } else if (this.isExpand) {
  1543. this.showDragList();
  1544. } else {
  1545. this.hideDragList();
  1546. }
  1547. if (this.getTopDragList({}).isSelectedList) {
  1548. this.each(this.find('[wdSelected="true"]'), function () {
  1549. this.style.display = "";
  1550. });
  1551. this.each(this.find('[wdOption="true"]'), function () {
  1552. this.display = this.style.display;
  1553. this.style.display = 'none';
  1554. });
  1555. } else if (this.getTopDragList({}).isOptionList) {
  1556. this.each(this.find('[wdOption="true"]'), function () {
  1557. this.style.display = "";
  1558. });
  1559. this.each(this.find('[wdSelected="true"]'), function () {
  1560. this.display = this.style.display;
  1561. this.style.display = 'none';
  1562. });
  1563. }
  1564. this.addClass(this.getTopDragList({}).wdNormalClass);
  1565. this.updateInfo();
  1566. });
  1567. this.off("mousedown").on("mousedown", function (event) {
  1568. if (isEventTargetIsEditable(event)) {
  1569. return;
  1570. }
  1571. $("[ssObjId] [editable][contenteditable]").blur().removeAttr("contenteditable"); // ("[wdObjectId] [。Lin
  1572. DM.justEnd = false;
  1573. this.cx = event.clientX;
  1574. this.cy = event.clientY;
  1575. this.getDragList().focus();
  1576. var selected = this.selected = this.isSelected();
  1577. this.isFunctionKeyDown = functionKeyDown || this.isFunctionKeyDown;
  1578. this.getDragList().currentMouseDownItem = this;
  1579. if (event.shiftKey) {
  1580. var s = this.getDragList().shiftSelectStartItem;
  1581. if (s) {
  1582. if (this.isChildOf(s.getDragList().element)) {
  1583. this.getDragList().shiftSelect();
  1584. } else {
  1585. this.getDragList().currentMouseDownItem = null;
  1586. return false;
  1587. }
  1588. }
  1589. } else {
  1590. this.getDragList().shiftSelectStartItem = null;
  1591. }
  1592. this.select();
  1593. if (selected) { //第二次或以上选中
  1594. this.triggerSelectedClick = true;
  1595. } else { //第一次选中
  1596. this.triggerSelectedClick = false;
  1597. }
  1598. this.getDragList().focus();
  1599. dragItemDown = true;
  1600. if (this.drager.list != null) {
  1601. return false;
  1602. }
  1603. dragStartPoint = {
  1604. x: event.clientX,
  1605. y: event.clientY
  1606. };
  1607. event.stopPropagation();
  1608. docMouseDown();
  1609. return false;
  1610. });
  1611. this.off("mouseup").on("mouseup", function (event) {
  1612. docMouseUp();
  1613. var isSelected = this.isSelected();
  1614. this.getDragList().shiftSelectStartItem = this.getDragList().shiftSelectStartItem || this;
  1615. this.getDragList().currentMouseDownItem = null;
  1616. if (!(event.ctrlKey || event.shiftKey)) {
  1617. this.getDragList().clearSelect();
  1618. this.select();
  1619. }
  1620. this.selected && event.ctrlKey && this.unselect();
  1621. event.stopPropagation();
  1622. return false;
  1623. });
  1624. this.off("mouseleave").on("mouseleave", function (event) {
  1625. if (isEventTargetIsEditable(event)) {
  1626. return;
  1627. }
  1628. this.addClass(this.getTopDragList({}).wdNormalClass);
  1629. this.removeClass(this.getTopDragList({}).wdHoverClass);
  1630. // this.element.style.border = "";
  1631. if (this.intervalid) {
  1632. clearInterval(this.intervalid);
  1633. this.intervalid = null;
  1634. }
  1635. if (this.timeoutid) {
  1636. clearTimeout(this.timeoutid);
  1637. this.timeoutid = null
  1638. }
  1639. clearMouseIcon();
  1640. this.isEnter = false;
  1641. // this.element.style.border = "";
  1642. });
  1643. this.off("mouseover").on("mouseover", function () {
  1644. this.addClass(this.getTopDragList({}).wdHoverClass);
  1645. itemMouseEvent.call(this, event);
  1646. this.isEnter = true;
  1647. return false;
  1648. });
  1649. // this.off("mousemove").on("mousemove", function () {
  1650. // !this.isEnter && itemMouseEvent.call(this, event);
  1651. // });
  1652. this.element.setAttribute("ssObjId", this.id); // ("wdObjectID",。是 wdObjectID,不是 wdObjectId。Lin
  1653. if (this.parentid) // 增加,不输出 ssPobjId="null"。Lin
  1654. this.element.setAttribute("ssPobjId", this.parentid); // ("wdParentObjectID",。是 wdParentObjectID,不是 wdParentObjectId。Lin
  1655. this.drager.functions && this.drager.group && this.dragList && this.dragList.init();
  1656. var $editable = $(this.element).find("[editable]");
  1657. $editable.click(function (event) {
  1658. if (isContenteditable(this)) {
  1659. event.stopPropagation();
  1660. return false;
  1661. } else if (this_.triggerSelectedClick) {
  1662. if ($(event.target).is("[editable]")) {
  1663. $(event.target).attr("contenteditable", true);
  1664. event.target.focus();
  1665. }
  1666. }
  1667. });
  1668. var keyAction=function (event) {
  1669. var e = event || window.event;
  1670. var keycode = e.charCode || e.keyCode;
  1671. if (keycode == 13) {
  1672. if (window.event) {
  1673. window.event.returnValue = false;
  1674. } else {
  1675. e.preventDefault(); //for firefox
  1676. }
  1677. e.stopPropagation();
  1678. return false;
  1679. } else if (isContenteditable(this)) {
  1680. this.realContent = this.innerHtml;
  1681. try {
  1682. this_.drager.onItemInput && this_.drager.onItemInput.apply(this, [event,this_]);
  1683. } catch (e) {
  1684. console.error(e);
  1685. }
  1686. }
  1687. }
  1688. $editable.keyup(keyAction);
  1689. // $editable.keydown(keyAction);
  1690. $editable.each(function () {
  1691. this.commonHeight = $(this).height();
  1692. });
  1693. $editable.blur(function () {
  1694. this.realContent = this.innerHTML;
  1695. this.setAttribute("title",this.realContent);
  1696. console.log(this.realContent);
  1697. var content = wd.display.ellipsisContent(this, this.commonHeight);
  1698. this.innerHTML = content;
  1699. console.log("blur")
  1700. });
  1701. $editable.focus(function () {
  1702. if (!isContenteditable(this)) {
  1703. return;
  1704. }
  1705. console.log(this.realContent);
  1706. var content = this.realContent;
  1707. if (content) {
  1708. this.innerHTML = content;
  1709. console.log(content)
  1710. }
  1711. })
  1712. }
  1713. };
  1714. wd.drag.Form = function (element) {
  1715. wd.drag.Base.call(this);
  1716. this.element = element;
  1717. this.parseForm2Url = function () {
  1718. var form = this.element;
  1719. var arr = [];
  1720. var action_ = form.getAttribute("action");
  1721. var param = (action_ || "?").split("?");
  1722. arr = arr.concat((param[1] || "").split("&"));
  1723. var elements = form.querySelectorAll("input,select,textarea");
  1724. for (var i = 0; i < elements; i++) {
  1725. var feled = elements[i];
  1726. switch (feled.type) {
  1727. case undefined:
  1728. case 'button':
  1729. case 'file':
  1730. case 'reset':
  1731. case 'submit':
  1732. break;
  1733. case 'checkbox':
  1734. case 'radio':
  1735. if (!feled.checked) {
  1736. break;
  1737. }
  1738. default:
  1739. if (feled.value != null && feled.value != '' && feled.name != null && !feled.disabled) {
  1740. arr.push(feled.name + "=" + feled.value);
  1741. }
  1742. }
  1743. }
  1744. return param[0] + "?" + arr.join("&");
  1745. };
  1746. this.parseFormData = function () {
  1747. var form = this.element;
  1748. var params = {};
  1749. var elements = form.querySelectorAll("input,select,textarea");
  1750. for (var i = 0; i < elements.length; i++) {
  1751. var feled = elements[i];
  1752. console.log(feled.name, feled.value)
  1753. switch (feled.type) {
  1754. case undefined:
  1755. case 'button':
  1756. case 'file':
  1757. case 'reset':
  1758. case 'submit':
  1759. break;
  1760. case 'checkbox':
  1761. case 'radio':
  1762. if (!feled.checked) {
  1763. break;
  1764. }
  1765. default:
  1766. feled.value != null && feled.value != '' && feled.name != null && !feled.disabled && (params[feled.name] = feled.value);
  1767. }
  1768. }
  1769. console.log(params)
  1770. return params;
  1771. };
  1772. this.submit = function () {
  1773. var data = this.parseFormData(),
  1774. url = this.element.getAttribute("action"),
  1775. this_ = this,
  1776. meWin = window,
  1777. drager = this_.drager
  1778. wd.c.wdAjax({
  1779. url: url,
  1780. type: "post",
  1781. data: data,
  1782. async: false,
  1783. success: function (data) {
  1784. /// 增加,把 &lt;、&gt; 转为 <、> -- 解决 .querySelectorAll() 取不到 Dom 的问题。Lin
  1785. /* 再去掉,&lt;、&gt; 已经在上层转为 <、> 了 -- 再转,就成了 "\n\n\n\n学员文件人员班级部门初始岗位单位生产任务初始部门初始人员项目岗位来访校区专业\n\n\n"。Lin
  1786. var temp = document.createElement("div");
  1787. temp.innerHTML = data;
  1788. var output = temp.innerText;
  1789. temp = null;
  1790. */
  1791. ///
  1792. var resultdiv = document.createElement("div");
  1793. resultdiv.style.display = "none";
  1794. resultdiv.id = new Date().getTime();
  1795. /* 再改回,去掉 output 了 -- 见上面。Lin
  1796. resultdiv.innerHTML = output; // = data。Lin
  1797. */ resultdiv.innerHTML = data;
  1798. doms = resultdiv.querySelectorAll(drager.itemSelector);
  1799. drager.optionList.empty();
  1800. $.each(doms, function () {
  1801. drager.optionList.append(this);
  1802. });
  1803. var scripts = resultdiv.querySelectorAll("script");
  1804. for (var i = 0; i < scripts.length; i++) {
  1805. var s = scripts[i];
  1806. if (s.innerHTML != null /*&& s.innerHTML.indexOf(tokenCleanser) > -1*/) {
  1807. try {
  1808. meWin.eval(s.innerHTML);
  1809. } catch (e) {
  1810. console.error(e)
  1811. }
  1812. } else {
  1813. //$(s).remove();
  1814. }
  1815. }
  1816. drager.optionList.reload();
  1817. }
  1818. });
  1819. };
  1820. //? 再增加,增加支持直接调用新加的 wdDrag.js > wrDdpOptList( -- 不写 <form name="ddpOptionForm" action=,不绕圈!Lin
  1821. /*? 移到顶层。Lin
  1822. this.wrDdpOptList = function (optList) {
  1823. console.log("wrDdpOptList:"+ optList);
  1824. };
  1825. ?*/
  1826. this.init = function () {
  1827. console.log(this.element.tagName)
  1828. this.element.tagName.toLowerCase() == "form" && (this.element.tagName = "div");
  1829. var this_ = this,
  1830. btn = this.element.querySelector("input[type='submit']");
  1831. this.on("submit onsubmit", function () {
  1832. this.submit();
  1833. });
  1834. this.element.submit = function () {
  1835. this_.submit();
  1836. };
  1837. if (btn != null) {
  1838. this.submitBtn = new wd.drag.Base(btn);
  1839. this.submitBtn.on("click", function (event) {
  1840. this_.trigger("submit");
  1841. event.stopPropagation();
  1842. event.preventDefault();
  1843. return false;
  1844. });
  1845. }
  1846. };
  1847. this.init();
  1848. };
  1849. wd.drag.Ghost = function (element) {
  1850. wd.drag.Base.call(this);
  1851. this.drager = element.confs.drager;
  1852. this.isGhost = true;
  1853. var sizeInfo = this.sizeInfo = element.confs.getSize();
  1854. var ele = this.element = document.createElement(element.tagName);
  1855. ele.className = element.className;
  1856. ele.confs = this;
  1857. ele.setAttribute("class", "" /*"hLine-warning"*/)
  1858. ele.style.cssText = "";
  1859. ele.innerHTML = "";
  1860. ele.id = "ghost";
  1861. this.dashMode = function () {
  1862. // ele.style.width = sizeInfo.width + "px";
  1863. // ele.style.height = sizeInfo.height + "px";
  1864. // ele.style.border = "1px dashed red";
  1865. // ele.style.borderRadius = "5px";
  1866. // ele.style.background = "white";
  1867. };
  1868. this.getDragList = function () {
  1869. return (this.element.parentNode || {}).confs;
  1870. };
  1871. this.getTopDragList = function () {
  1872. var list = this.getDragList();
  1873. if (list.isChild)
  1874. list = list.thisItem.getDragList();
  1875. return list;
  1876. };
  1877. this.lineMode = function () {
  1878. // ele.style.borderRadius = "0";
  1879. // ele.style.margin = 0;
  1880. // ele.style.background = "padding-box red";
  1881. // ele.style.borderStyle = "solid";
  1882. // ele.style.borderWidth = "2px";
  1883. // ele.style.padding = '0';
  1884. // if (this.getDragList() && this.getTopDragList({}).alignMode == 'vertical') {
  1885. // ele.style.width = "2px";
  1886. // ele.style.height = sizeInfo.height + "px";
  1887. // ele.style.minWidth = "0px";
  1888. // ele.style.borderColor = "red transparent";
  1889. // } else {
  1890. // ele.style.width = "auto";
  1891. // ele.style.height = "2px";
  1892. // ele.style.minHeight = "0px";
  1893. // ele.style.borderColor = "transparent red";
  1894. // }
  1895. }
  1896. this.destroy = function () {
  1897. this.interval && clearInterval(this.interval);
  1898. this.remove();
  1899. }
  1900. this.init = function () {
  1901. var this_ = this;
  1902. this.interval = setInterval(function () {
  1903. var allow = true;
  1904. if (DM.dragingPanel == null)
  1905. clearInterval(this_.interval);
  1906. if (DM.dragingPanel.isAllowDrop == false) {
  1907. allow = false;
  1908. } else if (this_.drager != this_.getDragList().drager) {
  1909. allow = false;
  1910. } else if (this_.drager.editGroup) { //最多功能的
  1911. allow = true;
  1912. } else if (this_.drager.editOrder) { //只能同级拖拽
  1913. } else { //不能上下拖拽
  1914. }
  1915. allow && DM.dragingPanel.allowDrop();
  1916. !allow && DM.dragingPanel.notAllowDrop();
  1917. }, 5);
  1918. this.hide();
  1919. }
  1920. this.init();
  1921. this.lineMode();
  1922. };
  1923. function itemMouseEvent(event) {
  1924. var panel = DM.dragingPanel;
  1925. if (panel != null) {
  1926. var item = this;
  1927. var location = item.isMouseOver(event);
  1928. var dragList = item.getDragList();
  1929. var ghost = panel.ghost;
  1930. if (item.drager.editOrder || item.drager.editGroup) {
  1931. ghost.addClass("ghost");
  1932. if (location && item.getTopDragList({}).alignMode != "horizontal") { //如果不是水平分布,就上下拖动排序
  1933. ghost.removeClass("vLine-warning").addClass("hLine-warning");
  1934. switch (location) {
  1935. case 3: //左上
  1936. case 6: //右上
  1937. item.before(ghost);
  1938. break;
  1939. case 4:
  1940. case 8:
  1941. item.after(ghost);
  1942. break;
  1943. }
  1944. } else if (location) { //不然就左右分布
  1945. ghost.removeClass("hLine-warning").addClass("vLine-warning");
  1946. switch (location) {
  1947. case 3: //左上
  1948. case 4: //左下
  1949. item.before(ghost);
  1950. break;
  1951. case 6: //右上
  1952. case 8: //右下
  1953. item.after(ghost);
  1954. break;
  1955. }
  1956. }
  1957. if (!item.drager.editGroup) { //只能同级拖拽
  1958. var allow = true;
  1959. item.each(panel.shadows, function () {
  1960. var shadow = this;
  1961. if (
  1962. (shadow.getDragList() != ghost.getDragList() && shadow.getTopDragList({}) == ghost.getTopDragList({})) //同列表不同级
  1963. ||
  1964. (shadow.getDragList().isChild && shadow.getTopDragList({}) != ghost.getTopDragList({})) //不同列表不同级
  1965. ) {
  1966. allow = false;
  1967. return false;
  1968. }
  1969. });
  1970. if (item.isShadow || item.isGhost) { }
  1971. else if (item.isExpand) { //展开了的
  1972. if (!allow) { }
  1973. else if (item.dragList.isMouseOver(event) && panel.hasChild()) {
  1974. allow = false;
  1975. } else {
  1976. allow = true;
  1977. }
  1978. } else {
  1979. //没展开但是不是editgroup不作处理
  1980. }
  1981. allow && DM.dragingPanel.allowDrop();
  1982. !allow && DM.dragingPanel.notAllowDrop();
  1983. } else { // editGroup的情况
  1984. if (item.isShadow || item.isGhost) { }
  1985. else if (!item.isExpand) { //没展开的
  1986. !item.getDragList().isChild && !panel.hasChild();
  1987. if (item.timeoutid == null) {
  1988. delay = 1000;
  1989. if (item.intervalid == null)
  1990. item.intervalid = setInterval(function () { //切换鼠标,达到gif效果
  1991. item.ri = item.ri || 0;
  1992. item.addClass("cursor-timing" + ((item.ri++) % readyMouseIcoLen + 1));
  1993. }, delay / readyMouseIcoLen);
  1994. var id = setTimeout(function () { //清除动画
  1995. item.drager.editGroup && item.showDragList && !item.getDragList().isChild && item.showDragList() && item.hasDragList && item.dragList.append(ghost);
  1996. clearInterval(item.intervalid);
  1997. item.timeoutid = null;
  1998. item.intervalid = null;
  1999. clearMouseIcon();
  2000. }, delay);
  2001. item.timeoutid = id;
  2002. }
  2003. panel.allowDrop();
  2004. }
  2005. }
  2006. } else { //既不是editorder也不是editgroup
  2007. var allow = true;
  2008. ghost.each(panel.shadows, function () {
  2009. var shadow = this;
  2010. if (ghost.getTopDragList() == shadow.getTopDragList()) {
  2011. allow = false;
  2012. return false;
  2013. }
  2014. });
  2015. allow && DM.dragingPanel.allowDrop();
  2016. !allow && DM.dragingPanel.notAllowDrop();
  2017. }
  2018. }
  2019. return false;
  2020. }
  2021. //绑定document的事件
  2022. var DM = window.DM = wd.drag.DM = DM || new wd.drag.DragerManager();
  2023. setDrag = function (name, group, functions, options, _window) {
  2024. return DM.getInstance(name, group, functions, options, _window);
  2025. };
  2026. // 再增加,增加支持直接调用新加的 wdDrag.js > wrDdpOptList( -- 不写 <form name="ddpOptionForm" action=,不绕圈!Lin
  2027. /* 再去掉,new wd.drag.Form() 会抛出错误 -- Cannot read properties of undefined (reading 'tagName')。Lin
  2028. * wd.drag.Form = function (element) { > this.init = function () { 里,this.element.tagName 时,this.element 没有值
  2029. var Form = window.Form = wd.drag.Form = Form || new wd.drag.Form();
  2030. wrDdpOptList = function (optList) {
  2031. return Form.wrDdpOptList(optList);
  2032. };
  2033. */
  2034. // 再增加,增加支持直接提交纯备选记录到这,不绕圈 <form -- 不写 <form name="ddpOptionForm" action=。Lin
  2035. // 抄自 wd.drag.Form = function (element) { > this.submit = function () { > success: function (data) { 里的
  2036. wrDdpOptList = function (optList) {
  2037. // console.log("wrDdpOptList:"+ optList);
  2038. /* 重写,改为纯备选记录 optList 了。Lin
  2039. var resultdiv = document.createElement("div");
  2040. resultdiv.style.display = "none";
  2041. resultdiv.id = new Date().getTime();
  2042. resultdiv.innerHTML = data;
  2043. doms = resultdiv.querySelectorAll(drager.itemSelector);
  2044. drager.optionList.empty();
  2045. $.each(doms, function () {
  2046. drager.optionList.append(this);
  2047. });
  2048. var scripts = resultdiv.querySelectorAll("script");
  2049. for (var i = 0; i < scripts.length; i++) {
  2050. var s = scripts[i];
  2051. if (s.innerHTML != null) {
  2052. try {
  2053. meWin.eval(s.innerHTML);
  2054. } catch (e) {
  2055. console.error(e)
  2056. }
  2057. } else {
  2058. //$(s).remove();
  2059. }
  2060. }
  2061. drager.optionList.reload();
  2062. */
  2063. const optionList = DM.getDrager().optionList;
  2064. optionList.empty();
  2065. optList.forEach(function (opt) {
  2066. const optDiv = document.createElement("div");
  2067. optDiv.setAttribute("ssObjId", opt.ddpid);
  2068. /* 改,去掉 .list-background,.list 改为 .ddp-list -- 再,不改名了 -- 老的 .list 还有好多样式。老 UI,将就。Lin
  2069. * .list-background 老 UI 没有定义,也没有作用
  2070. * 把原来的 <div style= 合并到原来的 .list 里
  2071. optDiv.classList.add("list-background list");
  2072. optDiv.style.cssText = "min-height: 41px;line-height: 41px;width: calc(100% - 4px);box-sizing: border-box;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;";
  2073. */ optDiv.classList.add("list");
  2074. const optSpan = document.createElement("span");
  2075. optSpan.textContent = opt.ddpdesc;
  2076. optDiv.appendChild(optSpan);
  2077. optionList.append(optDiv);
  2078. });
  2079. optionList.reload();
  2080. };
  2081. // 再增加,增加支持直接提交纯已选记录到这 -- 抄自 wrDdpOptList(optList)。Lin
  2082. // 去掉页面里写的
  2083. // <div ssObjId="${item.ddpid}" class="list-background list" style="min-height: 41px;line-height: 41px;width: calc(100% - 4px);box-sizing: border-box;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;">
  2084. // <span><ss:txt val='${item.ddpdesc}'/></span>
  2085. // </div>
  2086. // .list-background 老 UI 没有定义,也没有作用
  2087. // 把原来的 <div style= 合并到原来的 .list 里
  2088. wrDdpSelList = function (selList) {
  2089. const selectedList = DM.getDrager().selectedList;
  2090. selectedList.empty();
  2091. selList.forEach(function (opt) {
  2092. const optDiv = document.createElement("div");
  2093. optDiv.setAttribute("ssObjId", opt.ddpid);
  2094. optDiv.classList.add("list");
  2095. const optSpan = document.createElement("span");
  2096. optSpan.textContent = opt.ddpdesc;
  2097. optDiv.appendChild(optSpan);
  2098. selectedList.append(optDiv);
  2099. });
  2100. selectedList.reload();
  2101. };