wdDrag.js 77 KB

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