| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088 |
- 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 isPointInElement(element, event) {
- if (!element || !event) {
- return false;
- }
- var rect = element.getBoundingClientRect();
- return event.clientX >= rect.left && event.clientX <= rect.right
- && event.clientY >= rect.top && event.clientY <= rect.bottom;
- }
- function moveDragPanel(event) {
- var panel = DM.dragingPanel;
- var currentdrager = DM.currentDrager;
- if (!panel || !currentdrager || !panel.ghost) {
- return;
- }
- panel.show();
- panel.move(event);
- var hoveredItem = null;
- var hoveredList = null;
- currentdrager.getLists().forEach(function (list) {
- if (!isPointInElement(list.element, event)) {
- return;
- }
- hoveredList = list;
- var items = list.visibleElements || list.getAllItems();
- for (var i = 0; i < items.length; i++) {
- if (items[i].isMouseOver(event) > 0) {
- hoveredItem = items[i];
- hoveredList = items[i].getDragList();
- break;
- }
- }
- });
- if (hoveredItem) {
- itemMouseEvent.call(hoveredItem, event);
- } else if (hoveredList) {
- if (panel.ghost.element.parentNode !== hoveredList.element) {
- hoveredList.element.appendChild(panel.ghost.element);
- }
- panel.allowDrop();
- }
- }
- 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);
- }
- moveDragPanel(event);
- }
- }
- 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) {
- 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);
- };
|