| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044 |
- var wd = wd || {};
- wd.drag = wd.drag || {};
- var ismousedown = functionKeyDown = false;
- var setDrag, DM, itemid = 0, readyMouseIcoLen = 12;
- function isEventTargetIsEditable(event) {
- var tg = event.target;
- return tg.nodeName == 'textarea' || (tg.nodeName == '#text' && $(tg).parent("[contenteditable]").length > 0) || isContenteditable(tg);
- };
- function isContenteditable(ele) {
- return $(ele).is("[contenteditable]");
- };
- function clearMouseIcon() {
- for (var iii = 1; iii <= readyMouseIcoLen; iii++) {
- $(".cursor-timing" + iii).removeClass("cursor-timing" + iii);
- }
- }
- function docMouseDown(event) {
- ismousedown = true;
- if (!isEventTargetIsEditable(event || window.event)) {
- $("[ssObjId] [editable]").removeAttr("contenteditable"); // ("[wdObjectId] [。Lin
- }
- }
- function docMouseMove(event) {
- // clearSlct();
- var panel = DM.dragingPanel;
- var currentdrager = DM.currentDrager;
- var flist = (currentdrager || {}).focusedList;
- if (currentdrager && !currentdrager.editGroup && !currentdrager.editOrder && currentdrager.getLists().length < 2) { }
- else if (ismousedown && (panel || (currentdrager && flist && flist.currentMouseDownItem))) { //拖动中
- if ((panel = DM.dragingPanel) == null) {
- var ci = flist.currentMouseDownItem;
- var tcx = event.clientX;
- var tcy = event.clientY;
- var cx = ci.cx || tcx;
- var cy = ci.cy || tcy;
- var xdiff = cx - tcx; // 计算两个点的横坐标之差
- var ydiff = cy - tcy; // 计算两个点的纵坐标之差
- if (Math.pow((xdiff * xdiff + ydiff * ydiff), 0.5) < 10) {
- return;
- }
- panel = DM.dragingPanel = new wd.drag.DragPanel();
- document.body.appendChild(panel.element);
- }
- return;
- }
- }
- function docMouseUp(event) {
- ismousedown = false;
- currentMouseDownItem = null;
- DM.dragingPanel != null && DM.dragingPanel.destroy();
- clearMouseIcon();
- }
- wd.drag.DragerManager = function () {
- console.log("new DragerManager");
- try {
- $("body").append("<link id='dragcss' rel='stylesheet' href='/ss/js/drag.css' />");
- $("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>");
- } catch (e) { }
- /**
- * 清除选中的文字
- */
- var clearSlct = "getSelection" in window ? function () {
- window.getSelection().removeAllRanges();
- }
- :
- function () {
- document.selection.empty();
- };
- // /**
- // *
- // * @param {Object} event
- // */
- // document.onselectstart = function (event) {
- // return false;
- // };
- /**
- *
- * @param {Object} event
- */
- document.addEventListener("mousedown", docMouseDown);
- /**
- *
- * @param {Object} event
- */
- document.addEventListener("mousemove", docMouseMove);
- /**
- * 触发移动时候的item的进出事件
- * @param {Object} dragList
- * @param {Object} panel
- * @param {Object} haschild
- * @param {Object} event
- */
- function eachListItem(dragList, panel, haschild, event) {
- return;
- var ghost = panel.ghost;
- var dr = dragList.drager;
- // var visibleItem=
- dragList.each(/*dragList.getItems()*/ dragList.visibleElements, function () {
- var location = this.isMouseOver(event);
- dr = this.drager;
- /*触发进出事件*/
- if (location > 0) { //这里触发item的鼠标进出事件,以后可能会调整,同时这里的逻辑有点问题但是能用,以后处理
- !this.isEnter && this.trigger("mouseover");
- this.isEnter && this.trigger("mousemove");
- this.isEnter = true; //进来了
- DM.dragingPanel.currentHoverItem = this;
- } else {
- this.isEnter && this.trigger("mouseleave");
- this.isEnter = false; //出去了
- }
- if (location > 0 && (this.drager.editGroup || this.drager.editOrder) && this.isExpand && !this.getDragList().isChild) { //鼠标在展开的group上面
- if (haschild) {
- panel.notAllowDrop();
- } else if (this.dragList.isMouseOver(event) > 0) {
- ghost.getDragList() != this.dragList && this.dragList.append(ghost);
- eachListItem(this.dragList, panel, haschild, event);
- }
- }
- ghost.lineMode();
- });
- !dr.editGroup && !dr.editOrder && (dragList.element.scrollTop = dragList.element.scrollHeight);
- };
- /**
- *
- * @param {Object} event
- */
- document.addEventListener("mouseup", docMouseUp);
- /**
- *
- * @param {Object} event
- */
- document.addEventListener("keydown", function (event) {
- functionKeyDown = event.ctrlKey || event.altKey || event.shiftKey;
- event.ctrlKey && event.keyCode === 65 && DM.currentDrager.focusedList != null && DM.currentDrager.focusedList.selectAll();
- });
- /**
- *
- * @param {Object} event
- */
- document.addEventListener("keyup", function (event) {
- functionKeyDown = event.ctrlKey || event.altKey || event.shiftKey;
- });
- };
- wd.drag.DragerManager.prototype = {
- constVars: {
- editOrder: "editOrder",
- editGroup: "editGroup"
- },
- instances: {},
- utils: {
- contains: function (arr, val) {
- if (typeof arr == 'object' && (arr instanceof Array || arr instanceof NodeList)) {
- for (var i = 0; i < arr.length; i++) {
- if (arr[i] == val) {
- return true;
- }
- }
- }
- return false;
- },
- parseForm2Url: function (form) {
- var arr = [];
- var action_ = form.getAttribute("action");
- var param = (action_ || "?").split("?");
- arr = arr.concat((param[1] || "").split("&"));
- var elements = form.querySelectorAll("input,select,textarea");
- for (var i = 0; i < elements; i++) {
- var feled = elements[i];
- switch (feled.type) {
- case undefined:
- case 'button':
- case 'file':
- case 'reset':
- case 'submit':
- break;
- case 'checkbox':
- case 'radio':
- if (!feled.checked) {
- break;
- }
- default:
- if (feled.value != null && feled.value != '' && feled.name != null && !feled.disabled) {
- arr.push(feled.name + "=" + feled.value);
- }
- }
- }
- return param[0] + "?" + arr.join("&");
- },
- containsKey: function (obj, key) {
- for (var key_ in obj) {
- if (key_ == key) {
- return true;
- }
- }
- return false;
- }
- },
- getDrager: function (name) {
- if (name) {
- return this.instances[name];
- }
- for (var key in this.instances) {
- return this.instances[key];
- }
- return
- },
- getCurrentFocusList: function () {
- return (this.currentDrager || {}).focusedList;
- },
- getCurrentSelectedItems: function () {
- if (this.getCurrentFocusList()) {
- return this.getCurrentFocusList().getSelectedItems();
- }
- },
- addItem: function (id, item, index, isCover) {
- return this.getDrager().addItem(id, item, index, isCover);
- },
- drager: function (name, group, functions, baseOptions) {
- this.itemSelector = "div[ssObjId]"; // [wdObjectID]。是 wdObjectID,不是 wdObjectId。Lin
- this.name = name;
- this.imgleft = 30;
- this.dragerManager = this;
- this.items = {};
- this.name = name;
- this.getItems = function () {
- var tmp = [];
- this.selectedList != null && (tmp = tmp.concat(this.selectedList.getAllItems()));
- this.optionList != null && (tmp = tmp.concat(this.optionList.getAllItems()));
- return tmp;
- }
- this.destroy = function () {
- this.selectedList && this.selectedList.destroy();
- this.optionList && this.optionList.destroy();
- delete DM.instances[this.name];
- }
- this.getLists = function () {
- var arr = [];
- this.selectedList && arr.push(this.selectedList);
- this.optionList && arr.push(this.optionList);
- return arr;
- }
- this.getSelectedResult = function () {
- return this.selectedList.getResult();
- }
- this.addItem = function (id, element, index, isCover) {
- return this.addItemTo(id, element, this.selectedList, index);
- }
- this.addItemToFocusedList = function (id, element, index, isCover) {
- this.addItemTo(id, element, this.focusedList, index, isCover);
- }
- this.addItemTo = function (id, element, list, index, isCover) {
- if (list == this.focusedList) { }
- else if (this.focusedList.isChild && this.focusedList.thisItem.getDragList() == list) {
- list = this.focusedList;
- }
- return list.insertItemByHtml(id, element, index, isCover);
- }
- this.init = function () {
- var this_ = this;
- for (var key in baseOptions) {
- this_[key] = baseOptions[key];
- }
- //处理functions
- this_.functions = functions || [];
- this_.group = group == true || group == "true";
- this_.editOrder = this_.functions.indexOf(DM.constVars.editOrder) > -1;
- this_.editGroup = this_.functions.indexOf(DM.constVars.editGroup) > -1;
- //获取查询表单
- var form = document.getElementsByName(name + "OptionForm")[0] || document.getElementById(name + "OptionForm");
- if (form) {
- this_.form = new wd.drag.Form(form);
- this_.form.drager = this;
- }
- var selectedList = document.getElementById(name + "Selected");
- if (selectedList) {
- var list = new wd.drag.DragList(name, selectedList);
- list.isSelectedList = true;
- var input = document.getElementsByName(name + "SelectedId")[0];
- input = input || document.getElementsByName(name + "SelectedId")[0]
- input = input || document.createElement("input");
- input.type = "hidden";
- input.name = name + "SelectedId";
- list.before(input);
- list.result_input = input;
- list.init();
- list.alignMode = this.selectedListAlignMode || this.alignMode || "vertical";
- this.selectedList = list;
- } else {
- console.log("没有找到selectedList")
- }
- var optionList = document.getElementById(name + "Option");
- if (optionList) {
- var list = new wd.drag.DragList(name, optionList);
- list.isOptionList = true;
- list.init();
- // list.functions = this.functions || [];
- // if(this.optionFunctions)
- // list.functions = list.functions.concat(this.optionFunctions);
- list.alignMode = this.optionListAlignMode || this.alignMode || "vertical";
- this.optionList = list;
- }
- //获取按钮区域
- function moveEnd(items) {
- DM.getDrager(name).optionList.updateInfo();
- DM.getDrager(name).optionList.clearSelect();
- DM.getDrager(name).optionList.trigger("dragend");
- DM.getDrager(name).selectedList.updateInfo();
- DM.getDrager(name).selectedList.clearSelect();
- DM.getDrager(name).selectedList.trigger("dragend");
- if (DM.getDrager(name).dragend) {
- var doms = [];
- $.each(items, function () {
- doms.push(this.element);
- });
- DM.getDrager(name).dragend.call(this, doms);
- };
- }
- var moveButtons = {
- 'PickAll': function () {
- var items = DM.getDrager(name).optionList.getSelectedItems();
- if (items.length < 1) {
- items = $(DM.getDrager(name).optionList.element).children("[ssObjId]:not(:hidden)"); // [wdObjectId]:。Lin
- }
- $.each(items, function () {
- var eee = this.confs ? this : this.element;
- if (eee && $(eee).not(":hidden")) {
- DM.getDrager(name).selectedList.append(eee);
- }
- });
- moveEnd(items);
- },
- 'DropAll': function () {
- var items = DM.getDrager(name).selectedList.getSelectedItems();
- if (items.length < 1) {
- items = $(DM.getDrager(name).selectedList.element).children("[ssObjId]:not(:hidden)"); // [wdObjectId]:。Lin
- }
- $.each(items, function () {
- var eee = this.confs ? this : this.element;
- if (eee && $(eee).not(":hidden")) {
- DM.getDrager(name).optionList.append(eee);
- }
- });
- moveEnd(items);
- }
- };
- for (var key in moveButtons) {
- console.log("#" + name + key)
- $("#" + name + key).click(moveButtons[key]);
- }
- this.getLists().length < 1 && console.info("没找到要初始化的Draglist\"" + name + "\"");
- }
- },
- getInstance: function (name, group, functions, baseOptions) {
- baseOptions = baseOptions || {};
- var this_ = this;
- return DM.instances[name] || function () {
- if (typeof (isWriteOut) == "undefined") {
- alert("注意下,这是旧的写法,以后不再自动初始化拖拽了,\n记得新的拖拽需要通过commonwrite输出^_^");
- return;
- }
- var drager = DM.instances[name] = new this_.drager(name, group, functions, baseOptions);
- drager.init();
- return drager
- }
- (name, group, functions, baseOptions);
- }
- };
- wd.drag.Shadow = function (element) {
- wd.drag.Base.call(this);
- this.drager = element.confs.drager;
- var clone = this.element = element.cloneNode(true);
- clone.confs = this;
- this.src = element;
- this.isShadow = true;
- // clone.style.opacity = "0.5";
- this.addClass("shadow");
- element.confs.isSelected() && this.removeClass(element.confs.getTopDragList({}).wdSelectedClass);
- $(this.element).find(".icon-checked").addClass('icon-unchecked').removeClass('icon-checked');
- this.getTopDragList = function (emptyObj) {
- if (!this.exist())
- return emptyObj;
- var list = this.getDragList();
- list.isChild && (list = list.thisItem.getDragList());
- return list;
- };
- this.getDragList = function () {
- return (this.element.parentNode || {}).confs;
- }
- };
- wd.drag.Base = function (element) {
- this.bindedEvent = (element || {}).bindedEvent = (element || {}).bindedEvent || {};
- this.isConfs = true;
- this.isshow = true;
- this.element = element;
- this.exist = function () {
- return $.contains(document.body, this.element);
- };
- this.getScrollInfo = function () {
- var scrollinfo = {
- left: 0,
- top: 0
- }
- getScroll(this.element);
- return scrollinfo;
- function getScroll(node) {
- // 非Element 终止递归
- if (!node) {
- return
- }
- if (node.nodeType !== 1) {
- return;
- }
- if (node.parentNode && node.parentNode.tagName == "body") {
- getScroll(node.parentNode);
- return;
- }
- scrollinfo.top += node.scrollTop;
- scrollinfo.left += node.scrollLeft; // position = fixed: 获取值后退出递归
- if (node.parentNode)
- getScroll(node.parentNode);
- }
- };
- this.offset = function () { /* 摘自jquery */
- var docElem,
- win,
- box = {
- top: 0,
- left: 0
- },
- elem = this.element,
- doc = elem && elem.ownerDocument;
- if (!doc) {
- return;
- }
- docElem = doc.documentElement;
- if (!DM.utils.contains(document.querySelectorAll("*"), this.element)) {
- return box;
- }
- if (typeof elem.getBoundingClientRect !== typeof undefined) {
- box = elem.getBoundingClientRect();
- }
- function getWindow(elem) {
- return (elem && elem == elem.window) ?
- elem :
- elem.nodeType === 9 ?
- elem.defaultView || elem.parentWindow :
- false;
- }
- win = getWindow(doc);
- return {
- top: box.top + (win.pageYOffset || docElem.scrollTop) - (docElem.clientTop || 0),
- left: box.left + (win.pageXOffset || docElem.scrollLeft) - (docElem.clientLeft || 0)
- };
- };
- this.hide = function () {
- $(this.element).hide();
- this.isshow = false;
- };
- this.show = function () {
- $(this.element).show();
- this.isshow = true;
- };
- this.find = function (selector) {
- return this.element.querySelectorAll(selector);
- };
- this.children = function (selector) {
- selector = selector || "*"
- var children = []
- $(this.element).children(selector).each(function () {
- children.push(this.confs == null ? new wd.drag.Base(this) : this.confs);
- });
- return children
- };
- this.is = function (selector) {
- return $(this.element).is(selector);
- };
- this.isDom = function (obj) {
- return typeof HTMLElement === 'object' ?
- obj instanceof HTMLElement :
- obj && typeof obj === 'object' && obj.nodeType === 1 && typeof obj.nodeName === 'string';
- };
- this.prev = function () {
- var ele = this.element.previousSibling;
- while (ele != null && ele.nodeType == 3) {
- ele = ele.previousSibling;
- }
- return ele == null ? null : (ele.confs || new wd.drag.Base(ele));
- };
- this.next = function () {
- var ele = this.element.nextSibling;
- while (ele != null && ele.nodeType == 3) {
- ele = ele.nextSibling;
- }
- return ele == null ? null : (ele.confs || new wd.drag.Base(ele));
- };
- this.prevAll = function (selector) {
- selector = selector || "*"
- var pe = this.element.parentNode;
- // var cs = pe.children;
- var cs = new wd.drag.Base(pe).children(selector);
- var arr = [];
- for (var i = 0; i < cs.length; i++) {
- var csi = cs[i];
- if (csi.element == this.element) {
- break;
- }
- arr.push(csi);
- }
- return arr;
- };
- this.nextAll = function (selector) {
- selector = selector || "*"
- var pe = this.element.parentNode;
- // var cs = pe.children;
- var cs = new wd.drag.Base(pe).children(selector);
- var arr = [];
- for (var i = cs.length - 1; i >= 0; i--) {
- var csi = cs[i];
- if (csi.element == this.element) {
- break;
- }
- arr.unshift(csi);
- }
- return arr;
- };
- this.remove = function () {
- if (this.bindedEvent) {
- for (var key in this.bindedEvent) {
- this.off(key);
- }
- }
- this.element.parentNode.removeChild(this.element);
- };
- this.isMouseOver = function (event) {
- event = event || window.event;
- var target = this.element;
- if (this.is("#ghost"))
- return 0;
- var sizeInfo = this.getSize();
- var result = 0;
- var cx = event.clientX;
- var cy = event.clientY;
- var left = sizeInfo.left;
- var top = sizeInfo.top;
- var width = sizeInfo.width;
- var height = sizeInfo.height;
- try {
- (cx >= left) && (cx <= (left + width)) && (cy >= top) && (cy <= (top + height)) && (result = 1);
- if (result == 0)
- return 0;
- if (cx >= left && cx <= parseInt(left + width / 2)) {
- result *= 1; //左边
- } else if (cx > parseInt(left + width / 2) && cx <= parseInt(left + width)) {
- result *= 2; //右边
- } else {
- result *= 0; //不在上面
- }
- if (cy >= top && cy <= parseInt(top + height / 3 * 2)) {
- result *= 3; //上半部分
- } else if (cy > parseInt(top + height / 3 * 2) && cy <= parseInt(top + height)) {
- result *= 4; //下半部分
- } else {
- result *= 0; //不在上面
- }
- } catch (e) {
- console.error(e)
- return 0;
- }
- //左上1*3=3,右上2*3=6,左下1*4=4,右下2*4=8,不在0*0
- return result;
- };
- this.isChildOf = function (b) {
- return this.isDom(b) && $.contains(b, this.element);
- };
- this.getStyles = function () {
- var _style;
- if (!this.exist()) {
- console.warn("注意,该节点不在文档里面,无法获取元素相关信息");
- offset = {
- top: this.element.offsetTop,
- left: this.element.offsetLeft
- }
- _style = this.element.style;
- } else {
- _style = window.getComputedStyle(this.element)
- offset = this.offset();
- }
- return _style;
- };
- this.getSize = function () {
- var offset,
- _style;
- if (!this.exist()) {
- console.warn("注意,该节点不在文档里面,无法获取元素相关信息");
- offset = {
- top: this.element.offsetTop,
- left: this.element.offsetLeft
- }
- } else {
- offset = this.offset();
- }
- _style = this.getStyles();
- var scrollinfo = this.getScrollInfo();
- var ele = this.element,
- sizeInfo = {},
- marginTop = parseInt(_style.marginTop.replace("px", "")) || 0,
- marginRight = parseInt(_style.marginRight.replace("px", "")) || 0,
- marginBottom = parseInt(_style.marginBottom.replace("px", "")) || 0,
- marginLeft = parseInt(_style.marginLeft.replace("px", "")) || 0,
- width = parseInt(_style.width.replace("px", "")) || 0,
- height = parseInt(_style.height.replace("px", "")) || 0,
- scrollleft = scrollinfo.left || document.documentElement.scrollLeft || document.body.scrollLeft || 0,
- scrolltop = scrollinfo.top || document.documentElement.scrollTop || document.body.scrollTop ||
- 0;
- // offset = $(this.element).offset();
- if (offset) {
- sizeInfo.top = offset.top - (document.documentElement.offsetTop || document.body.scrollTop); // 距离body的top
- sizeInfo.left = offset.left - (document.documentElement.offsetLeft || document.body.offsetLeft); // 距离body的left
- sizeInfo.width = width + marginLeft + marginRight; // 宽
- sizeInfo.height = height + marginTop + marginBottom; // 高
- sizeInfo.scrollleft = scrollleft;
- sizeInfo.scrolltop = scrolltop;
- }
- return sizeInfo;
- };
- this.each = $.each;
- this.off = function (eventNames, fn) {
- var ele = this.element;
- var enl = eventNames.split(" ");
- for (var i = 0; i < enl.length; i++) {
- var eventName = enl[i]
- if (this.bindedEvent[eventName]) {
- var fnNameL = this.bindedEvent[eventName];
- if (!fnNameL || fnNameL.length > 0) {
- this.each(fnNameL, function () {
- ele.removeEventListener && ele.removeEventListener(eventName, eval(this.toString()));
- ele.detachEvent && ele.detachEvent("on" + eventName, eval(this.toString()));
- window[this.toString()] == null;
- })
- if (fn) {
- fn.call(this, window.event);
- }
- }
- }
- }
- this.element && (this.element.bindedEvent = this.bindedEvent);
- return this;
- };
- this.trigger = function (eventNames) {
- var enl = eventNames.split(" ");
- for (var i = 0; i < enl.length; i++) {
- var eventName = enl[i];
- if (this.bindedEvent[eventName]) {
- var events = this.bindedEvent[eventName];
- this.each(events, function () {
- try {
- window[this.toString()].call(this, window.event);
- } catch (e) {
- console.error(e)
- }
- });
- }
- }
- return this;
- };
- this.on = function (eventNames, fn) {
- var ele = this.element;
- var this_ = this;
- var enl = eventNames.split(/\s+/i);
- for (var i = 0; i < enl.length; i++) {
- var eventName = enl[i];
- if (eventName == "")
- continue;
- var fnl = this.bindedEvent[eventName];
- if (!fnl) {
- fnl = this.bindedEvent[eventName] = [];
- }
- var fnName = "event_" + (this.id || "_") + "_" + new Date().getTime() + "_" + eventName + "_" + fnl.length;
- fnName = fnName.split(/\W+/).join("_");
- fnl.push(fnName);
- window[fnName] = function () {
- var event = window.event;
- if (fn.call(this_, event) === false) {
- event.preventDefault && event.preventDefault();
- event.stopPropagation && event.stopPropagation();
- event.cancelBubble && (event.cancelBubble = true);
- }
- };
- ele.addEventListener && ele.addEventListener(eventName, eval(fnName), false);
- ele.attachEvent && ele.attachEvent("on" + eventName, eval(fnName));
- }
- this.element && (this.element.bindedEvent = this.bindedEvent);
- return this;
- };
- this.addClass = function (name) {
- $(this.element).addClass(name);
- return this;
- };
- this.toggleClass = function (name) {
- if (!name) {
- return;
- }
- if (this.hasClass(name)) {
- this.removeClass(name);
- } else {
- this.addClass(name);
- }
- return this
- };
- this.hasClass = function (name) {
- return name && this.element.className.indexOf(name) > -1;
- };
- this.append = function (ele) {
- var e;
- if (this.isDom(ele)) {
- e = ele;
- } else if (this.isConfs) {
- e = ele.element;
- }
- $(this.element).append(e);
- };
- this.before = function (item) {
- if (!item) {
- return
- } else if (this.isDom(item)) {
- this.element.parentNode.insertBefore(item, this.element);
- } else if (item.isConfs) {
- this.element.parentNode.insertBefore(item.element, this.element);
- } else {
- console.log("??")
- }
- };
- this.after = function (item) {
- if (!item) {
- return
- } else if (this.isDom(item)) {
- this.element.parentNode.insertBefore(item, this.element.nextSibling);
- } else if (item.isConfs) {
- this.element.parentNode.insertBefore(item.element, this.element.nextSibling);
- }
- };
- this.removeClass = function (name) {
- $(this.element).removeClass(name);
- return this;
- };
- if (element && (element.confs || element.isConfs)) {
- var con = element.isConfs ? element : element.confs
- for (var key in con) {
- this.element.confs[key] = con[key];
- }
- // return;
- }
- };
- var dragCursor = ["cursor-vDragMultiple", "cursor-vDrag", "cursor-timing", "cursor-hDragMultiple", "cursor-hDrag", "cursor-timing"];
- wd.drag.DragPanel = function () {
- wd.drag.Base.call(this);
- var dragList = DM.currentDrager.focusedList;
- var ghost = this.ghost = new wd.drag.Ghost(dragList.currentMouseDownItem.element);
- dragList.element.appendChild(ghost.element);
- if (dragList.alignMode != "vertical") {
- // $(ghost.element).removeClass("hLine-warning").addClass("vLine-warning");
- // $(ghost.element).css({
- // "display": "inline-block",
- // "float": "left",
- // "height": "20px",
- // "position": "unset",
- // "height": "35px"
- // });
- }
- var box = this.element = dragList.element.cloneNode();
- // var styles = document.querySelectorAll("style");
- // this.each(styles, function () {
- // box.appendChild(this.cloneNode(true));
- // });
- // styles = document.querySelectorAll("link");
- // this.each(styles, function () {
- // box.appendChild(this.cloneNode(true));
- // });
- // styles = document.querySelectorAll("LINK");
- // this.each(styles, function () {
- // box.appendChild(this.cloneNode(true));
- // });
- box.confs = this;
- this.drager = dragList.drager;
- this.sizeInfo = dragList.currentMouseDownItem.getSize();
- this.left = dragList.currentMouseDownItem.cx - this.sizeInfo.left;
- this.top = dragList.currentMouseDownItem.cy - this.sizeInfo.top;
- box.style.zIndex = "9999";
- box.style.background = "white";
- box.style.border = "1px dashed black";
- box.style.borderRadius = ".3em";
- box.style.position = "fixed";
- box.style.padding = ".3em";
- box.id = "list";
- this.notAllowDrop = function () {
- this.isAllowDrop = false;
- this.mask.cursor_old = DM.dragingPanel.mask.style.cursor
- this.mask.style.cursor = "not-allowed";
- this.ghost.hide();
- };
- this.allowDrop = function () {
- this.isAllowDrop = true;
- this.mask.style.cursor = this.mask.cursor_old || "move";
- this.mask.cursor_old = null;
- this.ghost.show();
- };
- var items = this.items = [];
- var shadows = this.shadows = [];
- var count = 0;
- var its = dragList.getSelectedItems();
- its[0].hideDragList();
- var ss = its[0].getSize();
- this.each(its, function () {
- var item = this;
- var shadow = item.createShadow();
- if (item.isExpand)
- item.hideDragList();
- item.shadow = shadow;
- items.push(item);
- shadows.push(shadow);
- item.removeClass(item.getTopDragList({}).wdSelectedClass);
- $(item.element).find('.icon-checked').addClass('icon-unchecked').removeClass('icon-checked');
- // item.removeClass(item.getTopDragList({}).wdNormalClass);
- item.removeClass(item.getTopDragList({}).wdHoverClass);
- box.appendChild(item.element);
- });
- box.style.width = ss.width + 10 + "px";
- box.style.height = ss.height * its.length + "px";
- dragList.selectedItems = {};
- dragList.updateVisibleElements();
- dragList.trigger("mouseup");
- dragList.currentMouseDownItem = null;
- this.move = function (event) {
- var ele = this.element;
- ele.style.left = (event.clientX - this.left) + "px";
- ele.style.top = (event.clientY - this.top) + "px";
- };
- this.getDragList = function () {
- return (this.ghost.element.parentNode || {}).confs;
- };
- this.hasChild = function () {
- for (var i = 0; i < items.length; i++) {
- if (items[i].dragList && items[i].dragList.getItems().length > 0) {
- return true;
- }
- }
- return false;
- };
- var t = this.getDragList().alignMode != "vertical" ? 3 : 0;
- var c = items.length > 1 ? dragCursor[0 + t] : dragCursor[1 + t];
- this.destroy = function () {
- this.drager.selectedList && this.drager.selectedList.updateVisibleElements();
- this.drager.optionList && this.drager.optionList.updateVisibleElements();
- $("body,html").removeClass(dragCursor.join(" "));
- $(".notallow_item").removeClass("notallow_item");
- var this_ = this;
- var list = this.getDragList();
- this.each(this_.items, function () {
- try {
- var item__ = list.getItemById(this.id);
- if (item__.isGhost || item__.isShadow || item__ == this) { }
- else {
- item__.remove();
- console.log("找到重复的ID“" + this.id + "”,覆盖")
- }
- } catch (e) { }
- if (this_.ghost.isshow) {
- this_.ghost.before(this);
- this.select();
- } else {
- this.shadow.before(this)
- }
- })
- this.each(this_.shadows, function () {
- this.remove();
- })
- this.each(this.drager.getLists(), function () {
- var this_ = this;
- setTimeout(function () {
- this_.trigger("dragend");
- }, 1)
- });
- this.each(this.items, function () {
- var this_ = this;
- setTimeout(function () {
- this_.trigger("dragend");
- })
- });
- this.each(this.drager.getLists(), function () {
- this.clearSelect();
- });
- this.each(items, function () {
- this.select();
- });
- if (this.drager.dragend) {
- var doms = [];
- this.each(items, function () {
- doms.push(this.element);
- });
- this.drager.dragend.call(this, doms, this.ghost.element);
- };
- this.ghost.getDragList().focus();
- this.ghost.destroy();
- this.remove();
- DM.dragingPanel = null;
- };
- var mask = this.mask = $("<div style='clear:both;position:absolute;top:-1em;left:-1em;right:-1em;bottom:-1em;z-index:110000' class='panel'/>")[0];
- new wd.drag.Base(mask).on("mousewheel DOMMouseScroll", function (e) {
- function isCanScroll(obj) {
- if (obj) {
- var of = window.getComputedStyle(obj)["overflow-y"];
- return ("scroll|auto".indexOf(of) > -1) && (obj.scrollHeight > 0);
- } else {
- return false
- }
- };
- function findObjScrollParent(obj, i) {
- i = i || 0;
- i++;
- var par = obj.parentNode;
- if (obj.tagName == "HTML") {
- return obj.querySelector("body");
- }
- if (isCanScroll(par)) {
- return par;
- } else {
- return findObjScrollParent(par, i);
- }
- };
- var delta = (e.wheelDelta && (e.wheelDelta > 0 ? 1 : -1)) || // chrome & ie
- (e.detail && (e.detail > 0 ? -1 : 1)); // firefox
- findObjScrollParent(ghost.element).scrollTop -= delta * 35;
- ghost.getDragList().updateVisibleElements();
- });
- $("body,html").addClass(c);
- if (this.hasChild()) {
- $.each(this.drager.getLists(), function () {
- $(this.element).children(this.drager.itemSelector).addClass("notallow_item");
- });
- }
- box.appendChild(mask);
- document.body.appendChild(box);
- box.style.display = "none";
- DM.justEnd = true;
- };
- wd.drag.DragList = function (name, element) {
- wd.drag.Base.call(this);
- var drager = this.drager = DM.getInstance(name);
- this.visibleElements = [];
- this.wdNormalClass = element.getAttribute("ssNormClazz") || ""; // ("wdNormalClass")。Lin
- this.wdHoverClass = element.getAttribute("ssHovClazz") || ""; // ("wdHoverClass")。Lin
- this.wdSelectedClass = element.getAttribute("ssSelClazz") || ""; // ("wdSelectedClass")。Lin
- this.wdSelectedParentClass = element.getAttribute("wdSelectedParentClass") || "";
- this.element = element.isConfs ? element.element : element;
- this.isChild = false;
- this.isDragList = true;
- this.dragerName = name;
- this.id = this.element.id;
- this.element.confs = this;
- this.unfocus = function () {
- this.removeClass(this.wdSelectedParentClass);
- this.clearSelect();
- this.drager.focusedList = null;
- DM.currentDrager = null;
- };
- this.focus = function () {
- if (drager.focusedList && this != drager.focusedList) {
- drager.focusedList.clearSelect();
- drager.focusedList.unfocus();
- }
- drager.focusedList = this;
- DM.currentDrager = this.drager;
- DM.currentDrager.focusedList = this;
- this.addClass(this.wdSelectedParentClass);
- };
- this.empty = function () {
- this.each(this.getItems(), function () {
- this.remove();
- });
- this.element.innerHTML = '';
- this.trigger("dragend");
- };
- this.selectAll = function () {
- this.each(this.element.children, function () {
- this.confs && this.confs.select && this.confs.select();
- });
- };
- this.clearSelect = function () {
- this.each(this.element.children, function () {
- if (this.confs && this.confs.exist() && !this.confs.isShadow && this.confs.isGhost != true) {
- this.confs.unselect();
- this.hasDragList && this.dragList && this.dragList.clearSelect();
- }
- });
- this.selectedItems = {};
- };
- this.destroy = function () {
- this.off("mousedown mouseup click dragend");
- this.element.confs = null;
- this.each(this.getItems(), function () {
- this.destroy();
- });
- }
- this.reload = function (fn) {
- var this_ = this;
- console.time()
- this.init();
- console.timeEnd();
- this.each(this.drager.getLists(), function () {
- this.each(this.getAllItems(), function () {
- this.drager.items[this.id] = this;
- })
- });
- fn && typeof fn == 'function' && fn();
- }
- this.shiftSelect = function () {
- this.each(this.shiftSelectStartItem.nextAll(this.drager.itemSelector), function () {
- this instanceof wd.drag.Item && this.select();
- });
- this.each(this.currentMouseDownItem.nextAll(this.drager.itemSelector), function () {
- if (this instanceof wd.drag.Item)
- if (this.isSelected()) {
- this.unselect()
- } else {
- this.select();
- }
- });
- this.shiftSelectStartItem.select();
- this.currentMouseDownItem.select();
- };
- this.insertItemByHtml = function (objectid, html, index, isCover) {
- var element = html;
- !this.isDom(element) && (element = $(element)[0]);
- objectid != null && element.setAttribute("ssObjId", objectid); // ("wdObjectID",。是 wdObjectID,不是 wdObjectId。Lin
- var item = new wd.drag.Item(this.drager.name, element);
- objectid && (item.id = objectid);
- return this.insertItem(item, index, isCover);
- };
- this.insertItem = function (item, index, isCover) {
- index = (index != null && index > -1) ? index : (this.getSelectedItems().length < 1 ? this.getItems().length : this.getSelectedItems()[0].getIndex());
- this.drager.items[item.id] = item;
- var items = this.getItems();
- var old = this.getItemById(item.id)
- if (old) {
- console.log("找到重复的id:\"" + old.id + "\",覆盖(默认覆盖)?:" + ((isCover != false || isCover != "false") ? "覆盖" : "不覆盖"))
- if (isCover != false || isCover != "false") {
- old.remove();
- } else {
- console.warn("不覆盖,跳过处理")
- return null;
- }
- }
- var bool = false;
- this.each(items, function () {
- if (this.getIndex() == index) {
- this.after(item);
- bool = true;
- return false;
- }
- });
- !bool && this.append(item);
- item.init();
- item.trigger("dragend");
- return item;
- };
- this.getSelectedItems = function () {
- var arr = [];
- for (var key in this.selectedItems) {
- arr.push(this.selectedItems[key]);
- }
- return arr;
- };
- this.distnict = function () {
- var ids = [];
- this.each(this.getItems(), function () { });
- };
- this.updateInfo = function () {
- this.each(this.getItems(), function () {
- this.updateInfo();
- });
- };
- this.getResult = function () {
- this.updateInfo();
- var result = [];
- this.each(this.element.children, function () {
- if (this.isGhost || this.isShadow || this.confs == null)
- return;
- var itemdata = {
- ID: this.confs.id,
- PID: this.confs.parentid || null
- };
- itemdata.PID == null && delete itemdata.PID;
- itemdata.ID != null && result.push(itemdata);
- if (this.confs.hasDragList && this.confs.dragList) {
- this.confs.each(this.confs.dragList.getResult(), function () {
- result.push(this);
- });
- }
- });
- return result;
- };
- this.getAllItems = function () {
- var thisitems = this.getItems();
- var tmp = [];
- this.each(thisitems, function () {
- this.hasDragList && this.dragList && (tmp = tmp.concat(this.dragList.getItems()));
- });
- return thisitems.concat(tmp);
- }
- this.getItemByIndex = function (index) {
- if (this.getItems()[index])
- return this.getItems()[index];
- else
- return null;
- };
- this.getItemListObj = function () {
- var obj = {};
- this.each(this.getItems(), function () {
- obj[this.id] = this;
- });
- return obj;
- }
- this.getItemById = function (id) {
- var result;
- this.each(this.getItems(), function () {
- if (this.id == id) {
- result = this;
- return false;
- }
- });
- return result;
- };
- this.updateVisibleElements = function () {
- if (this.alignMode == "vertical") {
- this.visibleElements = this.getItems();
- } else {
- var start = this.getScrollInfo().top - 15;
- var end = this.getSize().height + start + 15;
- this.visibleElements = [];
- while (start++ <= end) {
- try {
- this.visibleElements.push(this.element.querySelector("[ssObjId][tp='" + start + "']").confs); // ("[wdObjectID][。是 wdObjectID,不是 wdObjectId。Lin
- } catch (e) { }
- }
- }
- };
- this.getItems = function () {
- var result = [];
- this.each(this.children(this.drager.itemSelector), function () {
- (this.isItem || this.isShadow) && this.isConfs && result.push(this);
- });
- return result;
- };
- this.init = function () {
- this.selectedItems = {};
- var this_ = this;
- var t = {};
- this.on("selectstart", function (event) {
- if (isEventTargetIsEditable(event)) {
- return true;
- }
- event.preventDefault();
- event.stopPropagation();
- return false;
- });
- this.on("mousewheel DOMMouseScroll", function () {
- this.updateVisibleElements();
- })
- this.on("mouseover", function (event) {
- var panel = DM.dragingPanel;
- if (panel && panel.drager == this.drager && !$.contains(this.element, panel.ghost.element)) {
- this.append(panel.ghost.element);
- }
- return false;
- });
- this.each(this.children(this_.drager.itemSelector), function (index) {
- // if(new wd.drag.Base(this).is(this_.drager.itemSelector)) {
- var item = this.isItem ? this : new wd.drag.Item(name, this);
- var id = item.id;
- if (t[id] == null) {
- t[id] = item;
- item.init();
- this_.drager.items[item.id] = item;
- } else {
- console.log("找到重复的ID“" + id + "”,删除")
- item.remove();
- }
- if (item.id != null && !this_.isSelectedList && this_.drager.selectedList && this_.drager.selectedList.getItemById(item.id) != null) {
- item.remove();
- }
- // }
- });
- if (drager.group) {
- //判断是否存在环
- var tmp = {};
- this.each(this.getItems(), function () {
- var t = tmp[this.id] = tmp[this.id] || {
- id: this.id
- };
- if (this.parentid) {
- tmp[this.parentid] = tmp[this.parentid] || {};
- tmp[this.parentid].child = t;
- }
- });
- try {
- var items = this.getItemListObj();
- JSON.stringify(tmp);
- for (var key in items) {
- if (items[key].parentid && this_.drager.items[items[key].parentid]) {
- this_.drager.items[items[key].parentid].dragList.insertItem(items[key]);
- }
- }
- } catch (e) {
- console.log(items)
- console.error("错误:上下级关系存在环,不进行分组放置处理");
- }
- } else {
- this.each(this.find("[ssObjId]"), function () { // ("[wdObjectID]"),。是 wdObjectID,不是 wdObjectId。Lin
- this_.append(this);
- });
- }
- if (this.isChild || this.thisItem) {
- this.element.id = this.thisItem.id + new Date().getTime();
- this.isChild = true;
- }
- this.on("dragend", function () {
- var its = this.getItems();
- var l = 30; //个一组
- var ii = 0;
- while (ii < its.length) {
- (function (arr) {
- setTimeout(function () {
- for (var i = 0; i < arr.length; i++) {
- arr[i] && arr[i].trigger("dragend");
- }
- });
- })(its.slice(ii, ii += l));
- }
- if (this.result_input) {
- this.result_input.value = JSON.stringify(this.getResult());
- }
- this.updateInfo();
- });
- this.off("mousedown").on("mousedown", function (event) {
- if (isEventTargetIsEditable(event)) {
- return;
- }
- this.focus();
- event.stopPropagation();
- return false;
- });
- this.off("mouseup").on("mouseup", function () {
- // event.stopPropagation();
- // return false;
- });
- this.off("click").on("click", function (event) {
- event.stopPropagation();
- return false;
- });
- this.trigger("dragend");
- this.updateVisibleElements();
- };
- };
- var textWrapperClass = ["list", "list", "list-highlight", "list-highlight"];
- var iconClassName = ["icon-doc", "icon-point", "icon-openFolder", "icon-folder"];
- wd.drag.ShowBtn = function (itemelement) {
- wd.drag.Base.call(this);
- var element = this.element = $("<span> </span>")[0];
- element.confs = this;
- // element.style.cursor = 'pointer';
- var itemEle = this.itemEle = itemelement;
- this.init = function () {
- // this.element.style.display = "inline-block";
- // this.element.style.width = this.itemEle.confs.drager.imgleft + "px";
- // 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 ";
- // this.element.style.backgroundSize = 'auto 100%';
- }
- this.destroy = function () {
- this.remove();
- }
- this.initEvent = function () {
- this.on("click", function () {
- if (functionKeyDown)
- return;
- var cfs = itemEle.confs
- if ((cfs.dragList && cfs.isExpand) || (!cfs.drager.group || (cfs.dragList && cfs.dragList.getItems().length == 0))) {
- cfs.hideDragList()
- } else {
- cfs.showDragList();
- }
- event.stopPropagation();
- return false;
- });
- }
- this.switchImg = function () {
- var cfs = itemEle.confs;
- if (!cfs.drager.group || (cfs.dragList && cfs.dragList.getItems() == 0)) { //不是分组,也没有子内容
- this.fileStyle();
- } else {
- if (cfs.isExpand) {
- this.expandFolderStyle();
- } else {
- this.normalFolderStyle();
- }
- }
- };
- this.toggleIcon = function (state) {
- $(this.element).removeClass(iconClassName.join(" ")).addClass(iconClassName[state]);
- $(this.element.textwrapper).removeClass(textWrapperClass.join(" ")).addClass(textWrapperClass[state]);
- var cn = this.itemEle.confs;
- if (state > 1) { //文件夹样式
- cn.addClass("filelist");
- } else {
- cn.removeClass("filelist");
- }
- }
- this.expandFolderStyle = function () {
- this.toggleIcon(2)
- };
- this.normalFolderStyle = function () {
- this.toggleIcon(3);
- };
- this.fileStyle = function () {
- if (itemEle.confs.getDragList().isChild) {
- this.toggleIcon(1);
- } else {
- this.toggleIcon(0);
- }
- };
- itemEle.insertBefore(element, itemEle.childNodes[0]);
- this.init();
- return this;
- };
- wd.drag.Item = function (name, element) {
- wd.drag.Base.call(this);
- this.element = element.isConfs ? element.element : element;
- this.element.confs = this;
- this.isItem = true;
- this.id = (this.element.getAttribute("ssObjId") || (itemid++) + "").split("#").join("").split(".").join(""); // ("wdObjectID")。是 wdObjectID,不是 wdObjectId。Lin
- this.parentid = (this.element.getAttribute("ssPobjId") || "").split("#").join("").split(".").join(""); // ("wdParentObjectID")。是 wdParentObjectID,不是 wdParentObjectId。Lin
- var drager = this.drager = DM.getInstance(name);
- this.hasDragList = false;
- this.createShadow = function () {
- var clone = new wd.drag.Shadow(this.element);
- this.element.parentNode.insertBefore(clone.element, this.element);
- this.shadow = clone;
- return clone;
- };
- this.isSelected = function () {
- return this.hasClass(this.getTopDragList({}).wdSelectedClass);
- };
- this.getTopDragList = function (emptyObj) {
- if (!this.exist())
- console.log("!!!")
- var list = this.getDragList();
- if (list.isChild)
- list = list.thisItem.getDragList();
- return list;
- }
- this.select = function () {
- if (!this.drager.editGroup && !this.drager.editOrder && this.drager.getLists().length < 2) { }
- else {
- this.isFunctionKeyDown = functionKeyDown || event.ctrlKey || event.altKey || event.shiftKey;
- this.getDragList().selectedItems[this.id] = this;
- this.addClass(this.getTopDragList({}).wdSelectedClass);
- $(this.element).find(".icon-unchecked").addClass('icon-checked').removeClass('icon-unchecked');
- }
- };
- this.unselect = function () {
- this.isFunctionKeyDown = false;
- delete this.getDragList().selectedItems[this.id];
- this.removeClass(this.getTopDragList({}).wdSelectedClass);
- $(this.element).find(".icon-checked").addClass('icon-unchecked').removeClass('icon-checked');
- };
- this.getParentItem = function () {
- var list = this.getDragList();
- if (list && list.isChild) {
- return list.thisItem;
- } else {
- return null;
- }
- };
- this.getDragList = function () {
- return (this.element.parentNode || {}).confs;
- };
- this.hideDragList = function () {
- this.isExpand = false;
- if (this.getDragList() && !this.drager.group)
- return;
- if (this.getDragList().isChild && this.imgBtn) {
- this.dragList.hide();
- // this.dragList.element.style.height = "auto";
- } else if (!this.getDragList().isChild && this.imgBtn) {
- this.dragList.hide();
- // this.dragList.element.style.height = "auto";
- }
- if (this.imgBtn)
- this.imgBtn.switchImg();
- this.getDragList().focus();
- };
- this.showDragList = function () {
- if (!this.drager.group)
- return;
- if (DM.dragingPanel && DM.dragingPanel.hasChild())
- return;
- if (this.getDragList().isChild /*|| !(this.getDragList()instanceof wd.drag.DragList)*/)
- return;
- if (this.imgBtn) {
- this.isExpand = true;
- if (this.dragList.getItems().length > 0) {
- this.dragList.element.style.height = "auto";
- } else if (this.dragList.getSize().height == 0) {
- this.dragList.element.style.minHeight = this.getSize().height + "px";
- }
- this.dragList.show();
- this.dragList.focus();
- this.imgBtn.switchImg();
- }
- };
- this.getIndex = function () {
- this.index = this.prevAll().length;
- return this.index;
- };
- this.updateInfo = function () {
- this.parentid = this.getDragList().thisItem == null ? null : this.getDragList().thisItem.id;
- this.element.setAttribute("ssPobjId", this.parentid); // ("wdParentObjectID",。是 wdParentObjectID,不是 wdParentObjectId。Lin
- this.index = this.prevAll().length;
- if (!this.getDragList().isChild && this.dragList) {
- this.dragList.isChild = true;
- if (this.imgBtn) {
- var len = this.dragList.children().length;
- this.imgBtn.element.innerText = len > 0 ? len : "";
- }
- } else if (this.dragList) {
- this.dragList.isChild = false;
- }
- if (this.dragList && this.dragList.getItems().length == 0) {
- this.hideDragList();
- }
- if (this.imgBtn)
- this.imgBtn.switchImg();
- };
- this.destroy = function () {
- this.off("dblclick selectedClick click dragend mousedown mouseup mousemove mouseover mouseout mouseleave");
- this.off("dblclick selectedClick click dragend mousedown mouseup mousemove mouseover mouseout mouseleave");
- this.imgBtn && this.imgBtn.destroy();
- this.hasDragList && this.dragList && (this.drager.functions.indexOf('group') > -1) && this.dragList.destroy();
- this.element.confs = null;
- }
- this.init = function () {
- var me = this;
- this.isExpand = false;
- if (this.drager.group) {
- //初始化第二层,包住
- var $div = $("<div>");
- $div.attr("id", "wrapper_" + this.id);
- $div.append($(this.element.childNodes));
- $(this.element).append($div);
- this.imgBtn = this.imgBtn || new wd.drag.ShowBtn(this.element);
- this.imgBtn.element.textwrapper = $div[0];
- this.dragList = new wd.drag.DragList(name, document.createElement("div"));
- this.append(this.dragList.element);
- this.dragList.thisItem = this;
- this.dragList.addClass("subList");
- this.dragList.hide();
- this.imgBtn.initEvent();
- this.hasDragList = true;
- };
- var _checkbox = this.checkbox = document.createElement("span");
- // _checkbox.innerHTML = "";
- // _checkbox.className='dragcheckbox';
- // _checkbox.style.width="15px";
- // _checkbox.style.border='1px dashed black';
- _checkbox.style.cssText = 'display: inline-block; width: 28px;height: 40px;float: left;';
- _checkbox.className = "icon-unchecked";
- _checkbox.onmousedown = _checkbox.onmouseup = function (e) {
- e.stopPropagation();
- }
- _checkbox.onclick = function (e) {
- if (!me.isSelected()) {
- me.select();
- } else {
- me.unselect();
- }
- e.stopPropagation();
- }
- $(this.element).find("." + _checkbox.className).length < 1 && $(this.element).prepend(_checkbox);
- this.element.styleinfo = this.getStyles();
- // this.element.style.position = "relative";
- this.addClass(this.getTopDragList({}).wdNormalClass);
- var this_ = this;
- this_.element.setAttribute("tp", this.element.offsetTop);
- this.off("dblclick").on("dblclick", function () {
- if (this.imgBtn) {
- this.imgBtn.trigger("click");
- }
- if (this.drager.onDblClick) {
- this.drager.onDblClick.call(this);
- }
- });
- this.off("selectedClick").on("selectedClick", function (event) {
- this_.drager.selectedClick && this_.drager.selectedClick.call(this, this.element);
- })
- this.off("click").on("click", function (event) {
- if (isEventTargetIsEditable(event)) {
- return;
- }
- this.triggerSelectedClick && this.trigger("selectedClick");
- this_.drager.itemClick && this_.drager.itemClick.call(this, this.element);
- });
- this.off("dragend").on("dragend", function () {
- this.hasDragList && this.getDragList() && !this.getDragList().isChild && this.dragList.trigger("dragend");
- if (this.getDragList() && this.getDragList().isChild) {
- this.hideDragList();
- } else if (this.isExpand) {
- this.showDragList();
- } else {
- this.hideDragList();
- }
- if (this.getTopDragList({}).isSelectedList) {
- this.each(this.find('[wdSelected="true"]'), function () {
- this.style.display = "";
- });
- this.each(this.find('[wdOption="true"]'), function () {
- this.display = this.style.display;
- this.style.display = 'none';
- });
- } else if (this.getTopDragList({}).isOptionList) {
- this.each(this.find('[wdOption="true"]'), function () {
- this.style.display = "";
- });
- this.each(this.find('[wdSelected="true"]'), function () {
- this.display = this.style.display;
- this.style.display = 'none';
- });
- }
- this.addClass(this.getTopDragList({}).wdNormalClass);
- this.updateInfo();
- });
- this.off("mousedown").on("mousedown", function (event) {
- if (isEventTargetIsEditable(event)) {
- return;
- }
- $("[ssObjId] [editable][contenteditable]").blur().removeAttr("contenteditable"); // ("[wdObjectId] [。Lin
- DM.justEnd = false;
- this.cx = event.clientX;
- this.cy = event.clientY;
- this.getDragList().focus();
- var selected = this.selected = this.isSelected();
- this.isFunctionKeyDown = functionKeyDown || this.isFunctionKeyDown;
- this.getDragList().currentMouseDownItem = this;
- if (event.shiftKey) {
- var s = this.getDragList().shiftSelectStartItem;
- if (s) {
- if (this.isChildOf(s.getDragList().element)) {
- this.getDragList().shiftSelect();
- } else {
- this.getDragList().currentMouseDownItem = null;
- return false;
- }
- }
- } else {
- this.getDragList().shiftSelectStartItem = null;
- }
- this.select();
- if (selected) { //第二次或以上选中
- this.triggerSelectedClick = true;
- } else { //第一次选中
- this.triggerSelectedClick = false;
- }
- this.getDragList().focus();
- dragItemDown = true;
- if (this.drager.list != null) {
- return false;
- }
- dragStartPoint = {
- x: event.clientX,
- y: event.clientY
- };
- event.stopPropagation();
- docMouseDown();
- return false;
- });
- this.off("mouseup").on("mouseup", function (event) {
- docMouseUp();
- var isSelected = this.isSelected();
- this.getDragList().shiftSelectStartItem = this.getDragList().shiftSelectStartItem || this;
- this.getDragList().currentMouseDownItem = null;
- if (!(event.ctrlKey || event.shiftKey)) {
- this.getDragList().clearSelect();
- this.select();
- }
- this.selected && event.ctrlKey && this.unselect();
- event.stopPropagation();
- return false;
- });
- this.off("mouseleave").on("mouseleave", function (event) {
- if (isEventTargetIsEditable(event)) {
- return;
- }
- this.addClass(this.getTopDragList({}).wdNormalClass);
- this.removeClass(this.getTopDragList({}).wdHoverClass);
- // this.element.style.border = "";
- if (this.intervalid) {
- clearInterval(this.intervalid);
- this.intervalid = null;
- }
- if (this.timeoutid) {
- clearTimeout(this.timeoutid);
- this.timeoutid = null
- }
- clearMouseIcon();
- this.isEnter = false;
- // this.element.style.border = "";
- });
- this.off("mouseover").on("mouseover", function () {
- this.addClass(this.getTopDragList({}).wdHoverClass);
- itemMouseEvent.call(this, event);
- this.isEnter = true;
- return false;
- });
- // this.off("mousemove").on("mousemove", function () {
- // !this.isEnter && itemMouseEvent.call(this, event);
- // });
- this.element.setAttribute("ssObjId", this.id); // ("wdObjectID",。是 wdObjectID,不是 wdObjectId。Lin
- this.element.setAttribute("ssPobjId", this.parentid); // ("wdParentObjectID",。是 wdParentObjectID,不是 wdParentObjectId。Lin
- this.drager.functions && this.drager.group && this.dragList && this.dragList.init();
- var $editable = $(this.element).find("[editable]");
- $editable.click(function (event) {
- if (isContenteditable(this)) {
- event.stopPropagation();
- return false;
- } else if (this_.triggerSelectedClick) {
- if ($(event.target).is("[editable]")) {
- $(event.target).attr("contenteditable", true);
- event.target.focus();
- }
- }
- });
- var keyAction=function (event) {
- var e = event || window.event;
- var keycode = e.charCode || e.keyCode;
- if (keycode == 13) {
- if (window.event) {
- window.event.returnValue = false;
- } else {
- e.preventDefault(); //for firefox
- }
- e.stopPropagation();
- return false;
- } else if (isContenteditable(this)) {
- this.realContent = this.innerHtml;
- try {
- this_.drager.onItemInput && this_.drager.onItemInput.apply(this, [event,this_]);
- } catch (e) {
- console.error(e);
- }
- }
- }
- $editable.keyup(keyAction);
- // $editable.keydown(keyAction);
- $editable.each(function () {
- this.commonHeight = $(this).height();
- });
- $editable.blur(function () {
- this.realContent = this.innerHTML;
- this.setAttribute("title",this.realContent);
- console.log(this.realContent);
- var content = wd.display.ellipsisContent(this, this.commonHeight);
- this.innerHTML = content;
- console.log("blur")
- });
- $editable.focus(function () {
- if (!isContenteditable(this)) {
- return;
- }
- console.log(this.realContent);
- var content = this.realContent;
- if (content) {
- this.innerHTML = content;
- console.log(content)
- }
- })
- }
- };
- wd.drag.Form = function (element) {
- wd.drag.Base.call(this);
- this.element = element;
- this.parseForm2Url = function () {
- var form = this.element;
- var arr = [];
- var action_ = form.getAttribute("action");
- var param = (action_ || "?").split("?");
- arr = arr.concat((param[1] || "").split("&"));
- var elements = form.querySelectorAll("input,select,textarea");
- for (var i = 0; i < elements; i++) {
- var feled = elements[i];
- switch (feled.type) {
- case undefined:
- case 'button':
- case 'file':
- case 'reset':
- case 'submit':
- break;
- case 'checkbox':
- case 'radio':
- if (!feled.checked) {
- break;
- }
- default:
- if (feled.value != null && feled.value != '' && feled.name != null && !feled.disabled) {
- arr.push(feled.name + "=" + feled.value);
- }
- }
- }
- return param[0] + "?" + arr.join("&");
- };
- this.parseFormData = function () {
- var form = this.element;
- var params = {};
- var elements = form.querySelectorAll("input,select,textarea");
- for (var i = 0; i < elements.length; i++) {
- var feled = elements[i];
- console.log(feled.name, feled.value)
- switch (feled.type) {
- case undefined:
- case 'button':
- case 'file':
- case 'reset':
- case 'submit':
- break;
- case 'checkbox':
- case 'radio':
- if (!feled.checked) {
- break;
- }
- default:
- feled.value != null && feled.value != '' && feled.name != null && !feled.disabled && (params[feled.name] = feled.value);
- }
- }
- console.log(params)
- return params;
- };
- this.submit = function () {
- var data = this.parseFormData(),
- url = this.element.getAttribute("action"),
- this_ = this,
- meWin = window,
- drager = this_.drager
- wd.c.wdAjax({
- url: url,
- type: "post",
- data: data,
- async: false,
- success: function (data) {
- /// 增加,把 <、> 转为 <、> -- 解决 .querySelectorAll() 取不到 Dom 的问题。Lin
- /* 再去掉,<、> 已经在上层转为 <、> 了 -- 再转,就成了 "\n\n\n\n学员文件人员班级部门初始岗位单位生产任务初始部门初始人员项目岗位来访校区专业\n\n\n"。Lin
- var temp = document.createElement("div");
- temp.innerHTML = data;
- var output = temp.innerText;
- temp = null;
- */
- ///
- var resultdiv = document.createElement("div");
- resultdiv.style.display = "none";
- resultdiv.id = new Date().getTime();
- /* 再改回,去掉 output 了 -- 见上面。Lin
- resultdiv.innerHTML = output; // = data。Lin
- */ resultdiv.innerHTML = data;
- doms = resultdiv.querySelectorAll(drager.itemSelector);
- drager.optionList.empty();
- $.each(doms, function () {
- drager.optionList.append(this);
- });
- var scripts = resultdiv.querySelectorAll("script");
- for (var i = 0; i < scripts.length; i++) {
- var s = scripts[i];
- if (s.innerHTML != null /*&& s.innerHTML.indexOf(tokenCleanser) > -1*/) {
- try {
- meWin.eval(s.innerHTML);
- } catch (e) {
- console.error(e)
- }
- } else {
- //$(s).remove();
- }
- }
- drager.optionList.reload();
- }
- });
- };
- this.init = function () {
- console.log(this.element.tagName)
- this.element.tagName.toLowerCase() == "form" && (this.element.tagName = "div");
- var this_ = this,
- btn = this.element.querySelector("input[type='submit']");
- this.on("submit onsubmit", function () {
- this.submit();
- });
- this.element.submit = function () {
- this_.submit();
- };
- if (btn != null) {
- this.submitBtn = new wd.drag.Base(btn);
- this.submitBtn.on("click", function (event) {
- this_.trigger("submit");
- event.stopPropagation();
- event.preventDefault();
- return false;
- });
- }
- };
- this.init();
- };
- wd.drag.Ghost = function (element) {
- wd.drag.Base.call(this);
- this.drager = element.confs.drager;
- this.isGhost = true;
- var sizeInfo = this.sizeInfo = element.confs.getSize();
- var ele = this.element = document.createElement(element.tagName);
- ele.className = element.className;
- ele.confs = this;
- ele.setAttribute("class", "" /*"hLine-warning"*/)
- ele.style.cssText = "";
- ele.innerHTML = "";
- ele.id = "ghost";
- this.dashMode = function () {
- // ele.style.width = sizeInfo.width + "px";
- // ele.style.height = sizeInfo.height + "px";
- // ele.style.border = "1px dashed red";
- // ele.style.borderRadius = "5px";
- // ele.style.background = "white";
- };
- this.getDragList = function () {
- return (this.element.parentNode || {}).confs;
- };
- this.getTopDragList = function () {
- var list = this.getDragList();
- if (list.isChild)
- list = list.thisItem.getDragList();
- return list;
- };
- this.lineMode = function () {
- // ele.style.borderRadius = "0";
- // ele.style.margin = 0;
- // ele.style.background = "padding-box red";
- // ele.style.borderStyle = "solid";
- // ele.style.borderWidth = "2px";
- // ele.style.padding = '0';
- // if (this.getDragList() && this.getTopDragList({}).alignMode == 'vertical') {
- // ele.style.width = "2px";
- // ele.style.height = sizeInfo.height + "px";
- // ele.style.minWidth = "0px";
- // ele.style.borderColor = "red transparent";
- // } else {
- // ele.style.width = "auto";
- // ele.style.height = "2px";
- // ele.style.minHeight = "0px";
- // ele.style.borderColor = "transparent red";
- // }
- }
- this.destroy = function () {
- this.interval && clearInterval(this.interval);
- this.remove();
- }
- this.init = function () {
- var this_ = this;
- this.interval = setInterval(function () {
- var allow = true;
- if (DM.dragingPanel == null)
- clearInterval(this_.interval);
- if (DM.dragingPanel.isAllowDrop == false) {
- allow = false;
- } else if (this_.drager != this_.getDragList().drager) {
- allow = false;
- } else if (this_.drager.editGroup) { //最多功能的
- allow = true;
- } else if (this_.drager.editOrder) { //只能同级拖拽
- } else { //不能上下拖拽
- }
- allow && DM.dragingPanel.allowDrop();
- !allow && DM.dragingPanel.notAllowDrop();
- }, 5);
- this.hide();
- }
- this.init();
- this.lineMode();
- };
- function itemMouseEvent(event) {
- var panel = DM.dragingPanel;
- if (panel != null) {
- var item = this;
- var location = item.isMouseOver(event);
- var dragList = item.getDragList();
- var ghost = panel.ghost;
- if (item.drager.editOrder || item.drager.editGroup) {
- ghost.addClass("ghost");
- if (location && item.getTopDragList({}).alignMode != "horizontal") { //如果不是水平分布,就上下拖动排序
- ghost.removeClass("vLine-warning").addClass("hLine-warning");
- switch (location) {
- case 3: //左上
- case 6: //右上
- item.before(ghost);
- break;
- case 4:
- case 8:
- item.after(ghost);
- break;
- }
- } else if (location) { //不然就左右分布
- ghost.removeClass("hLine-warning").addClass("vLine-warning");
- switch (location) {
- case 3: //左上
- case 4: //左下
- item.before(ghost);
- break;
- case 6: //右上
- case 8: //右下
- item.after(ghost);
- break;
- }
- }
- if (!item.drager.editGroup) { //只能同级拖拽
- var allow = true;
- item.each(panel.shadows, function () {
- var shadow = this;
- if (
- (shadow.getDragList() != ghost.getDragList() && shadow.getTopDragList({}) == ghost.getTopDragList({})) //同列表不同级
- ||
- (shadow.getDragList().isChild && shadow.getTopDragList({}) != ghost.getTopDragList({})) //不同列表不同级
- ) {
- allow = false;
- return false;
- }
- });
- if (item.isShadow || item.isGhost) { }
- else if (item.isExpand) { //展开了的
- if (!allow) { }
- else if (item.dragList.isMouseOver(event) && panel.hasChild()) {
- allow = false;
- } else {
- allow = true;
- }
- } else {
- //没展开但是不是editgroup不作处理
- }
- allow && DM.dragingPanel.allowDrop();
- !allow && DM.dragingPanel.notAllowDrop();
- } else { // editGroup的情况
- if (item.isShadow || item.isGhost) { }
- else if (!item.isExpand) { //没展开的
- !item.getDragList().isChild && !panel.hasChild();
- if (item.timeoutid == null) {
- delay = 1000;
- if (item.intervalid == null)
- item.intervalid = setInterval(function () { //切换鼠标,达到gif效果
- item.ri = item.ri || 0;
- item.addClass("cursor-timing" + ((item.ri++) % readyMouseIcoLen + 1));
- }, delay / readyMouseIcoLen);
- var id = setTimeout(function () { //清除动画
- item.drager.editGroup && item.showDragList && !item.getDragList().isChild && item.showDragList() && item.hasDragList && item.dragList.append(ghost);
- clearInterval(item.intervalid);
- item.timeoutid = null;
- item.intervalid = null;
- clearMouseIcon();
- }, delay);
- item.timeoutid = id;
- }
- panel.allowDrop();
- }
- }
- } else { //既不是editorder也不是editgroup
- var allow = true;
- ghost.each(panel.shadows, function () {
- var shadow = this;
- if (ghost.getTopDragList() == shadow.getTopDragList()) {
- allow = false;
- return false;
- }
- });
- allow && DM.dragingPanel.allowDrop();
- !allow && DM.dragingPanel.notAllowDrop();
- }
- }
- return false;
- };
- //绑定document的事件
- var DM = window.DM = wd.drag.DM = DM || new wd.drag.DragerManager();
- setDrag = function (name, group, functions, options, _window) {
- return DM.getInstance(name, group, functions, options, _window);
- };
|