wdDrag.js 37 KB

1
  1. window.ss=window.ss||{},window.ss.drag=window.ss.drag||{};var ismousedown=!1,functionKeyDown=!1,setDrag,DM,itemid=0,readyMouseIcoLen=12;function isEventTargetIsEditable(t){var e=t.target;return"textarea"==e.nodeName||"#text"==e.nodeName&&$(e).parent("[contenteditable]").length>0||isContenteditable(e)}function isContenteditable(t){return $(t).is("[contenteditable]")}function clearMouseIcon(){for(var t=1;t<=readyMouseIcoLen;t++)$(".cursor-timing"+t).removeClass("cursor-timing"+t)}function docMouseDown(t){ismousedown=!0,isEventTargetIsEditable(t||window.event)||$("[ssObjId] [editable]").removeAttr("contenteditable")}function docMouseMove(t){var e=DM.dragingPanel,i=DM.currentDrager,s=(i||{}).focusedList;if(i&&!i.editGroup&&!i.editOrder&&i.getLists().length<2);else if(ismousedown&&(e||i&&s&&s.currentMouseDownItem)){if(null==(e=DM.dragingPanel)){var n=s.currentMouseDownItem,r=t.clientX,o=t.clientY,a=(n.cx||r)-r,h=(n.cy||o)-o;if(Math.pow(a*a+h*h,.5)<10)return;e=DM.dragingPanel=new window.ss.drag.DragPanel,document.body.appendChild(e.element)}return}}function docMouseUp(t){ismousedown=!1,DM.currentMouseDownItem=null,null!=DM.dragingPanel&&DM.dragingPanel.destroy(),clearMouseIcon()}window.ss.drag.DragerManager=function(){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(t){}window;document.addEventListener("mousedown",docMouseDown),document.addEventListener("mousemove",docMouseMove),document.addEventListener("mouseup",docMouseUp),document.addEventListener("keydown",(function(t){functionKeyDown=t.ctrlKey||t.altKey||t.shiftKey,t.ctrlKey&&65===t.keyCode&&null!=DM.currentDrager.focusedList&&DM.currentDrager.focusedList.selectAll()})),document.addEventListener("keyup",(function(t){functionKeyDown=t.ctrlKey||t.altKey||t.shiftKey}))},window.ss.drag.DragerManager.prototype={constVars:{editOrder:"editOrder",editGroup:"editGroup"},instances:{},utils:{contains:function(t,e){if("object"==typeof t&&(t instanceof Array||t instanceof NodeList))for(var i=0;i<t.length;i++)if(t[i]==e)return!0;return!1},parseForm2Url:function(t){var e=[],i=(t.getAttribute("action")||"?").split("?");e=e.concat((i[1]||"").split("&"));for(var s=t.querySelectorAll("input,select,textarea"),n=0;n<s;n++){var r=s[n];switch(r.type){case void 0:case"button":case"file":case"reset":case"submit":break;case"checkbox":case"radio":if(!r.checked)break;default:null==r.value||""==r.value||null==r.name||r.disabled||e.push(r.name+"="+r.value)}}return i[0]+"?"+e.join("&")},containsKey:function(t,e){for(var i in t)if(i==e)return!0;return!1}},getDrager:function(t){if(t)return this.instances[t];for(var e in this.instances)return this.instances[e]},getCurrentFocusList:function(){return(this.currentDrager||{}).focusedList},getCurrentSelectedItems:function(){if(this.getCurrentFocusList())return this.getCurrentFocusList().getSelectedItems()},addItem:function(t,e,i,s){return this.getDrager().addItem(t,e,i,s)},drager:function(t,e,i,s){this.itemSelector="div[ssObjId]",this.name=t,this.imgleft=30,this.dragerManager=this,this.items={},this.name=t,this.getItems=function(){var t=[];return null!=this.selectedList&&(t=t.concat(this.selectedList.getAllItems())),null!=this.optionList&&(t=t.concat(this.optionList.getAllItems())),t},this.destroy=function(){this.selectedList&&this.selectedList.destroy(),this.optionList&&this.optionList.destroy(),delete DM.instances[this.name]},this.getLists=function(){var t=[];return this.selectedList&&t.push(this.selectedList),this.optionList&&t.push(this.optionList),t},this.getSelectedResult=function(){return this.selectedList.getResult()},this.addItem=function(t,e,i,s){return this.addItemTo(t,e,this.selectedList,i)},this.addItemToFocusedList=function(t,e,i,s){this.addItemTo(t,e,this.focusedList,i,s)},this.addItemTo=function(t,e,i,s,n){return i==this.focusedList||this.focusedList.isChild&&this.focusedList.thisItem.getDragList()==i&&(i=this.focusedList),i.insertItemByHtml(t,e,s,n)},this.init=function(){var n=this;for(var r in s)n[r]=s[r];n.functions=i||[],n.group=1==e||"true"==e,n.editOrder=n.functions.indexOf(DM.constVars.editOrder)>-1,n.editGroup=n.functions.indexOf(DM.constVars.editGroup)>-1;var o=document.getElementsByName(t+"OptionForm")[0]||document.getElementById(t+"OptionForm");o&&(n.form=new window.ss.drag.Form(o),n.form.drager=this);var a=document.getElementById(t+"Selected");if(a){(l=new window.ss.drag.DragList(t,a)).isSelectedList=!0;var h=document.getElementsByName(t+"SelectedId")[0];(h=(h=h||document.getElementsByName(t+"SelectedId")[0])||document.createElement("input")).type="hidden",h.name=t+"SelectedId",l.before(h),l.result_input=h,l.init(),l.alignMode=this.selectedListAlignMode||this.alignMode||"vertical",this.selectedList=l}var l,d=document.getElementById(t+"Option");d&&((l=new window.ss.drag.DragList(t,d)).isOptionList=!0,l.init(),l.alignMode=this.optionListAlignMode||this.alignMode||"vertical",this.optionList=l);function c(e){if(DM.getDrager(t).optionList.updateInfo(),DM.getDrager(t).optionList.clearSelect(),DM.getDrager(t).optionList.trigger("dragend"),DM.getDrager(t).selectedList.updateInfo(),DM.getDrager(t).selectedList.clearSelect(),DM.getDrager(t).selectedList.trigger("dragend"),DM.getDrager(t).dragend){var i=[];$.each(e,(function(){i.push(this.element)})),DM.getDrager(t).dragend.call(this,i)}}var u={PickAll:function(){var e=DM.getDrager(t).optionList.getSelectedItems();e.length<1&&(e=$(DM.getDrager(t).optionList.element).children("[ssObjId]:not(:hidden)")),$.each(e,(function(){var e=this.confs?this:this.element;e&&$(e).not(":hidden")&&DM.getDrager(t).selectedList.append(e)})),c(e)},DropAll:function(){var e=DM.getDrager(t).selectedList.getSelectedItems();e.length<1&&(e=$(DM.getDrager(t).selectedList.element).children("[ssObjId]:not(:hidden)")),$.each(e,(function(){var e=this.confs?this:this.element;e&&$(e).not(":hidden")&&DM.getDrager(t).optionList.append(e)})),c(e)}};for(var r in u)$("#"+t+r).click(u[r]);this.getLists().length}},getInstance:function(t,e,i,s){s=s||{};var n=this;return DM.instances[t]||function(){if(void 0!==this.isWriteOut){var r=DM.instances[t]=new n.drager(t,e,i,s);return r.init(),r}alert("注意下,这是旧的写法,以后不再自动初始化拖拽了,\n记得新的拖拽需要通过commonwrite输出^_^")}()}},window.ss.drag.Shadow=function(t){window.ss.drag.Base.call(this),this.drager=t.confs.drager,(this.element=t.cloneNode(!0)).confs=this,this.src=t,this.isShadow=!0,this.addClass("shadow"),t.confs.isSelected()&&this.removeClass(t.confs.getTopDragList({}).wdSelectedClass),$(this.element).find(".icon-checked").addClass("icon-unchecked").removeClass("icon-checked"),this.getTopDragList=function(t){if(!this.exist())return t;var e=this.getDragList();return e.isChild&&(e=e.thisItem.getDragList()),e},this.getDragList=function(){return(this.element.parentNode||{}).confs}},window.ss.drag.Base=function(element){if(this.bindedEvent=(element||{}).bindedEvent=(element||{}).bindedEvent||{},this.isConfs=!0,this.isshow=!0,this.element=element,this.exist=function(){return $.contains(document.body,this.element)},this.getScrollInfo=function(){var t={left:0,top:0};return function e(i){if(!i)return;if(1!==i.nodeType)return;if(i.parentNode&&"body"==i.parentNode.tagName)return void e(i.parentNode);t.top+=i.scrollTop,t.left+=i.scrollLeft,i.parentNode&&e(i.parentNode)}(this.element),t},this.offset=function(){var t,e,i={top:0,left:0},s=this.element,n=s&&s.ownerDocument;if(n)return t=n.documentElement,DM.utils.contains(document.querySelectorAll("*"),this.element)?(void 0!==s.getBoundingClientRect&&(i=s.getBoundingClientRect()),e=function(t){return t&&t==t.window?t:9===t.nodeType&&(t.defaultView||t.parentWindow)}(n),{top:i.top+(e.pageYOffset||t.scrollTop)-(t.clientTop||0),left:i.left+(e.pageXOffset||t.scrollLeft)-(t.clientLeft||0)}):i},this.hide=function(){$(this.element).hide(),this.isshow=!1},this.show=function(){$(this.element).show(),this.isshow=!0},this.find=function(t){return this.element.querySelectorAll(t)},this.children=function(t){t=t||"*";var e=[];return $(this.element).children(t).each((function(){e.push(null==this.confs?new window.ss.drag.Base(this):this.confs)})),e},this.is=function(t){return $(this.element).is(t)},this.isDom=function(t){return"object"==typeof HTMLElement?t instanceof HTMLElement:t&&"object"==typeof t&&1===t.nodeType&&"string"==typeof t.nodeName},this.prev=function(){for(var t=this.element.previousSibling;null!=t&&3==t.nodeType;)t=t.previousSibling;return null==t?null:t.confs||new window.ss.drag.Base(t)},this.next=function(){for(var t=this.element.nextSibling;null!=t&&3==t.nodeType;)t=t.nextSibling;return null==t?null:t.confs||new window.ss.drag.Base(t)},this.prevAll=function(t){t=t||"*";for(var e=this.element.parentNode,i=new window.ss.drag.Base(e).children(t),s=[],n=0;n<i.length;n++){var r=i[n];if(r.element==this.element)break;s.push(r)}return s},this.nextAll=function(t){t=t||"*";for(var e=this.element.parentNode,i=new window.ss.drag.Base(e).children(t),s=[],n=i.length-1;n>=0;n--){var r=i[n];if(r.element==this.element)break;s.unshift(r)}return s},this.remove=function(){if(this.bindedEvent)for(var t in this.bindedEvent)this.off(t);this.element.parentNode.removeChild(this.element)},this.isMouseOver=function(t){t=t||window.event;this.element;if(this.is("#ghost"))return 0;var e=this.getSize(),i=0,s=t.clientX,n=t.clientY,r=e.left,o=e.top,a=e.width,h=e.height;try{if(s>=r&&s<=r+a&&n>=o&&n<=o+h&&(i=1),0==i)return 0;s>=r&&s<=parseInt(r+a/2)?i*=1:s>parseInt(r+a/2)&&s<=parseInt(r+a)?i*=2:i*=0,n>=o&&n<=parseInt(o+h/3*2)?i*=3:n>parseInt(o+h/3*2)&&n<=parseInt(o+h)?i*=4:i*=0}catch(t){return 0}return i},this.isChildOf=function(t){return this.isDom(t)&&$.contains(t,this.element)},this.getStyles=function(){var t;if(this.exist())t=window.getComputedStyle(this.element),this.offset();else{this.element.offsetTop,this.element.offsetLeft;t=this.element.style}return t},this.getSize=function(){var t,e;t=this.exist()?this.offset():{top:this.element.offsetTop,left:this.element.offsetLeft},e=this.getStyles();var i=this.getScrollInfo(),s=(this.element,{top:0,left:0,width:0,height:0,scrollleft:0,scrolltop:0}),n=parseInt(e.marginTop.replace("px",""))||0,r=parseInt(e.marginRight.replace("px",""))||0,o=parseInt(e.marginBottom.replace("px",""))||0,a=parseInt(e.marginLeft.replace("px",""))||0,h=parseInt(e.width.replace("px",""))||0,l=parseInt(e.height.replace("px",""))||0,d=i.left||document.documentElement.scrollLeft||document.body.scrollLeft||0,c=i.top||document.documentElement.scrollTop||document.body.scrollTop||0;return t&&(s.top=t.top-(document.documentElement.offsetTop||document.body.scrollTop),s.left=t.left-(document.documentElement.offsetLeft||document.body.offsetLeft),s.width=h+a+r,s.height=l+n+o,s.scrollleft=d,s.scrolltop=c),s},this.each=$.each,this.off=function(eventNames,fn){for(var ele=this.element,enl=eventNames.split(" "),i=0;i<enl.length;i++){var eventName=enl[i];if(this.bindedEvent[eventName]){var fnNameL=this.bindedEvent[eventName];(!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()]})),fn&&fn.call(this,window.event))}}return this.element&&(this.element.bindedEvent=this.bindedEvent),this},this.trigger=function(t){for(var e=t.split(" "),i=0;i<e.length;i++){var s=e[i];if(this.bindedEvent[s]){var n=this.bindedEvent[s];this.each(n,(function(){try{window[this.toString()].call(this,window.event)}catch(t){}}))}}return this},this.on=function(eventNames,fn){for(var ele=this.element,this_=this,enl=eventNames.split(/\s+/i),i=0;i<enl.length;i++){var eventName=enl[i];if(""!=eventName){var fnl=this.bindedEvent[eventName];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 t=window.event;!1===fn.call(this_,t)&&(t.preventDefault&&t.preventDefault(),t.stopPropagation&&t.stopPropagation(),t.cancelBubble&&(t.cancelBubble=!0))},ele.addEventListener&&ele.addEventListener(eventName,eval(fnName),!1),ele.attachEvent&&ele.attachEvent("on"+eventName,eval(fnName))}}return this.element&&(this.element.bindedEvent=this.bindedEvent),this},this.addClass=function(t){return $(this.element).addClass(t),this},this.toggleClass=function(t){if(t)return this.hasClass(t)?this.removeClass(t):this.addClass(t),this},this.hasClass=function(t){return t&&this.element.className.indexOf(t)>-1},this.append=function(t){var e;this.isDom(t)?e=t:this.isConfs&&(e=t.element),$(this.element).append(e)},this.before=function(t){t&&(this.isDom(t)?this.element.parentNode.insertBefore(t,this.element):t.isConfs&&this.element.parentNode.insertBefore(t.element,this.element))},this.after=function(t){t&&(this.isDom(t)?this.element.parentNode.insertBefore(t,this.element.nextSibling):t.isConfs&&this.element.parentNode.insertBefore(t.element,this.element.nextSibling))},this.removeClass=function(t){return $(this.element).removeClass(t),this},element&&(element.confs||element.isConfs)){var con=element.isConfs?element:element.confs;for(var key in con)this.element.confs[key]=con[key]}};var dragCursor=["cursor-vDragMultiple","cursor-vDrag","cursor-timing","cursor-hDragMultiple","cursor-hDrag","cursor-timing"];window.ss.drag.DragPanel=function(){window.ss.drag.Base.call(this);var t=DM.currentDrager.focusedList,e=this.ghost=new window.ss.drag.Ghost(t.currentMouseDownItem.element);t.element.appendChild(e.element),t.alignMode;var i=this.element=t.element.cloneNode();i.confs=this,this.drager=t.drager,this.sizeInfo=t.currentMouseDownItem.getSize(),this.left=t.currentMouseDownItem.cx-this.sizeInfo.left,this.top=t.currentMouseDownItem.cy-this.sizeInfo.top,i.style.zIndex="9999",i.style.background="white",i.style.border="1px dashed black",i.style.borderRadius=".3em",i.style.position="fixed",i.style.padding=".3em",i.id="list",this.notAllowDrop=function(){this.isAllowDrop=!1,this.mask.cursor_old=DM.dragingPanel.mask.style.cursor,this.mask.style.cursor="not-allowed",this.ghost.hide()},this.allowDrop=function(){this.isAllowDrop=!0,this.mask.style.cursor=this.mask.cursor_old||"move",this.mask.cursor_old=null,this.ghost.show()};var s=this.items=[],n=this.shadows=[],r=t.getSelectedItems();r[0].hideDragList();var o=r[0].getSize();this.each(r,(function(){var t=this,e=t.createShadow();t.isExpand&&t.hideDragList(),t.shadow=e,s.push(t),n.push(e),t.removeClass(t.getTopDragList({}).wdSelectedClass),$(t.element).find(".icon-checked").addClass("icon-unchecked").removeClass("icon-checked"),t.removeClass(t.getTopDragList({}).wdHoverClass),i.appendChild(t.element)})),i.style.width=o.width+10+"px",i.style.height=o.height*r.length+"px",t.selectedItems={},t.updateVisibleElements(),t.trigger("mouseup"),t.currentMouseDownItem=null,this.move=function(t){var e=this.element;e.style.left=t.clientX-this.left+"px",e.style.top=t.clientY-this.top+"px"},this.getDragList=function(){return(this.ghost.element.parentNode||{}).confs},this.hasChild=function(){for(var t=0;t<s.length;t++)if(s[t].dragList&&s[t].dragList.getItems().length>0)return!0;return!1};var a="vertical"!=this.getDragList().alignMode?3:0,h=s.length>1?dragCursor[0+a]:dragCursor[1+a];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 t=this,e=this.getDragList();if(this.each(t.items,(function(){try{var i=e.getItemById(this.id);i.isGhost||i.isShadow||i==this||i.remove()}catch(t){}t.ghost.isshow?(t.ghost.before(this),this.select()):this.shadow.before(this)})),this.each(t.shadows,(function(){this.remove()})),this.each(this.drager.getLists(),(function(){var t=this;setTimeout((function(){t.trigger("dragend")}),1)})),this.each(this.items,(function(){var t=this;setTimeout((function(){t.trigger("dragend")}))})),this.each(this.drager.getLists(),(function(){this.clearSelect()})),this.each(s,(function(){this.select()})),this.drager.dragend){var i=[];this.each(s,(function(){i.push(this.element)})),this.drager.dragend.call(this,i,this.ghost.element)}this.ghost.getDragList().focus(),this.ghost.destroy(),this.remove(),DM.dragingPanel=null};var l=this.mask=$("<div style='clear:both;position:absolute;top:-1em;left:-1em;right:-1em;bottom:-1em;z-index:110000' class='panel'/>")[0];new window.ss.drag.Base(l).on("mousewheel DOMMouseScroll",(function(t){var i=t.wheelDelta&&(t.wheelDelta>0?1:-1)||t.detail&&(t.detail>0?-1:1);(function t(e,i){i=i||0,i++;var s=e.parentNode;return"HTML"==e.tagName?e.querySelector("body"):function(t){if(t){var e=window.getComputedStyle(t)["overflow-y"];return"scroll|auto".indexOf(e)>-1&&t.scrollHeight>0}return!1}(s)?s:t(s,i)}(e.element,0)).scrollTop-=35*i,e.getDragList().updateVisibleElements()})),$("body,html").addClass(h),this.hasChild()&&$.each(this.drager.getLists(),(function(){$(this.element).children(this.drager.itemSelector).addClass("notallow_item")})),i.appendChild(l),document.body.appendChild(i),i.style.display="none",DM.justEnd=!0},window.ss.drag.DragList=function(t,e){window.ss.drag.Base.call(this);var i=this.drager=DM.getInstance(t);this.visibleElements=[],this.wdNormalClass=e.getAttribute("ssNormClazz")||"",this.wdHoverClass=e.getAttribute("ssHovClazz")||"",this.wdSelectedClass=e.getAttribute("ssSelClazz")||"",this.wdSelectedParentClass=e.getAttribute("wdSelectedParentClass")||"",this.element=e.isConfs?e.element:e,this.isChild=!1,this.isDragList=!0,this.dragerName=t,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(){i.focusedList&&this!=i.focusedList&&(i.focusedList.clearSelect(),i.focusedList.unfocus()),i.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(){this.confs&&this.confs.exist()&&!this.confs.isShadow&&1!=this.confs.isGhost&&(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(t){this.init(),this.each(this.drager.getLists(),(function(){this.each(this.getAllItems(),(function(){this.drager.items[this.id]=this}))})),t&&"function"==typeof t&&t()},this.shiftSelect=function(){this.each(this.shiftSelectStartItem.nextAll(this.drager.itemSelector),(function(){this instanceof window.ss.drag.Item&&this.select()})),this.each(this.currentMouseDownItem.nextAll(this.drager.itemSelector),(function(){this instanceof window.ss.drag.Item&&(this.isSelected()?this.unselect():this.select())})),this.shiftSelectStartItem.select(),this.currentMouseDownItem.select()},this.insertItemByHtml=function(t,e,i,s){var n=e;!this.isDom(n)&&(n=$(n)[0]),null!=t&&n.setAttribute("ssObjId",t);var r=new window.ss.drag.Item(this.drager.name,n);return t&&(r.id=t),this.insertItem(r,i,s)},this.insertItem=function(t,e,i){e=null!=e&&e>-1?e:this.getSelectedItems().length<1?this.getItems().length:this.getSelectedItems()[0].getIndex(),this.drager.items[t.id]=t;var s=this.getItems(),n=this.getItemById(t.id);if(n){if(0==i&&"false"==i)return null;n.remove()}var r=!1;return this.each(s,(function(){if(this.getIndex()==e)return this.after(t),r=!0,!1})),!r&&this.append(t),t.init(),t.trigger("dragend"),t},this.getSelectedItems=function(){var t=[];for(var e in this.selectedItems)t.push(this.selectedItems[e]);return t},this.distnict=function(){this.each(this.getItems(),(function(){}))},this.updateInfo=function(){this.each(this.getItems(),(function(){this.updateInfo()}))},this.getResult=function(){this.updateInfo();var t=[];return this.each(this.element.children,(function(){if(!this.isGhost&&!this.isShadow&&null!=this.confs){var e={ID:this.confs.id,PID:this.confs.parentid||null};null==e.PID&&delete e.PID,null!=e.ID&&t.push(e),this.confs.hasDragList&&this.confs.dragList&&this.confs.each(this.confs.dragList.getResult(),(function(){t.push(this)}))}})),t},this.getAllItems=function(){var t=this.getItems(),e=[];return this.each(t,(function(){this.hasDragList&&this.dragList&&(e=e.concat(this.dragList.getItems()))})),t.concat(e)},this.getItemByIndex=function(t){return this.getItems()[t]?this.getItems()[t]:null},this.getItemListObj=function(){var t={};return this.each(this.getItems(),(function(){t[this.id]=this})),t},this.getItemById=function(t){var e;return this.each(this.getItems(),(function(){if(this.id==t)return e=this,!1})),e},this.updateVisibleElements=function(){if("vertical"==this.alignMode)this.visibleElements=this.getItems();else{var t=this.getScrollInfo().top-15,e=this.getSize().height+t+15;for(this.visibleElements=[];t++<=e;)try{this.visibleElements.push(this.element.querySelector("[ssObjId][tp='"+t+"']").confs)}catch(t){}}},this.getItems=function(){var t=[];return this.each(this.children(this.drager.itemSelector),(function(){(this.isItem||this.isShadow)&&this.isConfs&&t.push(this)})),t},this.init=function(){this.selectedItems={};var e=this,s={};if(this.on("selectstart",(function(t){return!!isEventTargetIsEditable(t)||(t.preventDefault(),t.stopPropagation(),!1)})),this.on("mousewheel DOMMouseScroll",(function(){this.updateVisibleElements()})),this.on("mouseover",(function(t){var e=DM.dragingPanel;return e&&e.drager==this.drager&&!$.contains(this.element,e.ghost.element)&&this.append(e.ghost.element),!1})),this.each(this.children(e.drager.itemSelector),(function(i){var n=this.isItem?this:new window.ss.drag.Item(t,this),r=n.id;null==s[r]?(s[r]=n,n.init(),e.drager.items[n.id]=n):n.remove(),null!=n.id&&!e.isSelectedList&&e.drager.selectedList&&null!=e.drager.selectedList.getItemById(n.id)&&n.remove()})),i.group){var n={};this.each(this.getItems(),(function(){var t=n[this.id]=n[this.id]||{id:this.id};this.parentid&&(n[this.parentid]=n[this.parentid]||{},n[this.parentid].child=t)}));try{var r=this.getItemListObj();for(var o in JSON.stringify(n),r)r[o].parentid&&e.drager.items[r[o].parentid]&&e.drager.items[r[o].parentid].dragList.insertItem(r[o])}catch(t){}}else this.each(this.find("[ssObjId]"),(function(){e.append(this)}));(this.isChild||this.thisItem)&&(this.element.id=this.thisItem.id+(new Date).getTime(),this.isChild=!0),this.on("dragend",(function(){for(var t=this.getItems(),e=0;e<t.length;)!function(t){setTimeout((function(){for(var e=0;e<t.length;e++)t[e]&&t[e].trigger("dragend")}))}(t.slice(e,e+=30));this.result_input&&(this.result_input.value=JSON.stringify(this.getResult())),this.updateInfo()})),this.off("mousedown").on("mousedown",(function(t){if(!isEventTargetIsEditable(t))return this.focus(),t.stopPropagation(),!1})),this.off("mouseup").on("mouseup",(function(){})),this.off("click").on("click",(function(t){return t.stopPropagation(),!1})),this.trigger("dragend"),this.updateVisibleElements()}};var textWrapperClass=["list","list","list-highlight","list-highlight"],iconClassName=["icon-doc","icon-point","icon-openFolder","icon-folder"];function itemMouseEvent(t){var e=DM.dragingPanel;if(null!=e){var i=this,s=i.isMouseOver(t),n=(i.getDragList(),e.ghost);if(i.drager.editOrder||i.drager.editGroup){if(n.addClass("ghost"),s&&"horizontal"!=i.getTopDragList({}).alignMode)switch(n.removeClass("vLine-warning").addClass("hLine-warning"),s){case 3:case 6:i.before(n);break;case 4:case 8:i.after(n)}else if(s)switch(n.removeClass("hLine-warning").addClass("vLine-warning"),s){case 3:case 4:i.before(n);break;case 6:case 8:i.after(n)}if(i.drager.editGroup){if(i.isShadow||i.isGhost);else if(!i.isExpand){if(!i.getDragList().isChild&&e.hasChild(),null==i.timeoutid){null==i.intervalid&&(i.intervalid=setInterval((function(){i.ri=i.ri||0,i.addClass("cursor-timing"+(i.ri++%readyMouseIcoLen+1))}),1e3/readyMouseIcoLen));var r=setTimeout((function(){i.drager.editGroup&&i.showDragList&&!i.getDragList().isChild&&i.showDragList()&&i.hasDragList&&i.dragList.append(n),clearInterval(i.intervalid),i.timeoutid=null,i.intervalid=null,clearMouseIcon()}),1e3);i.timeoutid=r}e.allowDrop()}}else{var o=!0;i.each(e.shadows,(function(){var t=this;if(t.getDragList()!=n.getDragList()&&t.getTopDragList({})==n.getTopDragList({})||t.getDragList().isChild&&t.getTopDragList({})!=n.getTopDragList({}))return o=!1,!1})),i.isShadow||i.isGhost||i.isExpand&&o&&(o=!i.dragList.isMouseOver(t)||!e.hasChild()),o&&DM.dragingPanel.allowDrop(),!o&&DM.dragingPanel.notAllowDrop()}}else{o=!0;n.each(e.shadows,(function(){if(n.getTopDragList()==this.getTopDragList())return o=!1,!1})),o&&DM.dragingPanel.allowDrop(),!o&&DM.dragingPanel.notAllowDrop()}}return!1}window.ss.drag.ShowBtn=function(t){window.ss.drag.Base.call(this);var e=this.element=$("<span>&nbsp;</span>")[0];e.confs=this;var i=this.itemEle=t;return this.commonHeight=0,this.init=function(){},this.destroy=function(){this.remove()},this.initEvent=function(){this.on("click",(function(){if(!functionKeyDown){var t=i.confs;return t.dragList&&t.isExpand||!t.drager.group||t.dragList&&0==t.dragList.getItems().length?t.hideDragList():t.showDragList(),event.stopPropagation(),!1}}))},this.switchImg=function(){var t=i.confs;!t.drager.group||t.dragList&&0==t.dragList.getItems()?this.fileStyle():t.isExpand?this.expandFolderStyle():this.normalFolderStyle()},this.toggleIcon=function(t){$(this.element).removeClass(iconClassName.join(" ")).addClass(iconClassName[t]),$(this.element.textwrapper).removeClass(textWrapperClass.join(" ")).addClass(textWrapperClass[t]);var e=this.itemEle.confs;t>1?e.addClass("filelist"):e.removeClass("filelist")},this.expandFolderStyle=function(){this.toggleIcon(2)},this.normalFolderStyle=function(){this.toggleIcon(3)},this.fileStyle=function(){i.confs.getDragList().isChild?this.toggleIcon(1):this.toggleIcon(0)},i.insertBefore(e,i.childNodes[0]),this.init(),this},window.ss.drag.Item=function(t,e){window.ss.drag.Base.call(this),this.element=e.isConfs?e.element:e,this.element.confs=this,this.isItem=!0,this.id=(this.element.getAttribute("ssObjId")||itemid+++"").split("#").join("").split(".").join(""),this.parentid=(this.element.getAttribute("ssPobjId")||"").split("#").join("").split(".").join("");this.drager=DM.getInstance(t);this.hasDragList=!1,this.createShadow=function(){var t=new window.ss.drag.Shadow(this.element);return this.element.parentNode.insertBefore(t.element,this.element),this.shadow=t,t},this.isSelected=function(){return this.hasClass(this.getTopDragList({}).wdSelectedClass)},this.getTopDragList=function(t){this.exist();var e=this.getDragList();return e.isChild&&(e=e.thisItem.getDragList()),e},this.select=function(){!this.drager.editGroup&&!this.drager.editOrder&&this.drager.getLists().length<2||(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=!1,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 t=this.getDragList();return t&&t.isChild?t.thisItem:null},this.getDragList=function(){return(this.element.parentNode||{}).confs},this.hideDragList=function(){this.isExpand=!1,this.getDragList()&&!this.drager.group||((this.getDragList().isChild&&this.imgBtn||!this.getDragList().isChild&&this.imgBtn)&&this.dragList.hide(),this.imgBtn&&this.imgBtn.switchImg(),this.getDragList().focus())},this.showDragList=function(){this.drager.group&&(DM.dragingPanel&&DM.dragingPanel.hasChild()||this.getDragList().isChild||this.imgBtn&&(this.isExpand=!0,this.dragList.getItems().length>0?this.dragList.element.style.height="auto":0==this.dragList.getSize().height&&(this.dragList.element.style.minHeight=this.getSize().height+"px"),this.dragList.show(),this.dragList.focus(),this.imgBtn.switchImg()))},this.getIndex=function(){return this.index=this.prevAll().length,this.index},this.updateInfo=function(){if(this.parentid=null==this.getDragList().thisItem?null:this.getDragList().thisItem.id,this.element.setAttribute("ssPobjId",this.parentid),this.index=this.prevAll().length,!this.getDragList().isChild&&this.dragList){if(this.dragList.isChild=!0,this.imgBtn){var t=this.dragList.children().length;this.imgBtn.element.innerText=t>0?t:""}}else this.dragList&&(this.dragList.isChild=!1);this.dragList&&0==this.dragList.getItems().length&&this.hideDragList(),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 e=this;if(this.isExpand=!1,this.drager.group){var i=$("<div>");i.attr("id","wrapper_"+this.id),i.append($(this.element.childNodes)),$(this.element).append(i),this.imgBtn=this.imgBtn||new window.ss.drag.ShowBtn(this.element),this.imgBtn.element.textwrapper=i[0],this.dragList=new window.ss.drag.DragList(t,document.createElement("div")),this.append(this.dragList.element),this.dragList.thisItem=this,this.dragList.addClass("subList"),this.dragList.hide(),this.imgBtn.initEvent(),this.hasDragList=!0}var s=this.checkbox=document.createElement("span");s.style.cssText="display: inline-block; width: 28px;height: 40px;float: left;",s.className="icon-unchecked",s.onmousedown=s.onmouseup=function(t){t.stopPropagation()},s.onclick=function(t){e.isSelected()?e.unselect():e.select(),t.stopPropagation()},$(this.element).find("."+s.className).length<1&&$(this.element).prepend(s),this.element.styleinfo=this.getStyles(),this.addClass(this.getTopDragList({}).wdNormalClass);var n=this;n.element.setAttribute("tp",this.element.offsetTop),this.off("dblclick").on("dblclick",(function(){this.imgBtn&&this.imgBtn.trigger("click"),this.drager.onDblClick&&this.drager.onDblClick.call(this)})),this.off("selectedClick").on("selectedClick",(function(t){n.drager.selectedClick&&n.drager.selectedClick.call(this,this.element)})),this.off("click").on("click",(function(t){isEventTargetIsEditable(t)||(this.triggerSelectedClick&&this.trigger("selectedClick"),n.drager.itemClick&&n.drager.itemClick.call(this,this.element))})),this.off("dragend").on("dragend",(function(){this.hasDragList&&this.getDragList()&&!this.getDragList().isChild&&this.dragList.trigger("dragend"),this.getDragList()&&this.getDragList().isChild?this.hideDragList():this.isExpand?this.showDragList():this.hideDragList(),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"}))):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(t){if(!isEventTargetIsEditable(t)){$("[ssObjId] [editable][contenteditable]").blur().removeAttr("contenteditable"),DM.justEnd=!1,this.cx=t.clientX,this.cy=t.clientY,this.getDragList().focus();var e=this.selected=this.isSelected();if(this.isFunctionKeyDown=functionKeyDown||t.ctrlKey||t.altKey||t.shiftKey,this.getDragList().currentMouseDownItem=this,t.shiftKey){var i=this.getDragList().shiftSelectStartItem;if(i){if(!this.isChildOf(i.getDragList().element))return this.getDragList().currentMouseDownItem=null,!1;this.getDragList().shiftSelect()}}else this.getDragList().shiftSelectStartItem=null;this.select(),this.triggerSelectedClick=!!e,this.getDragList().focus();if(null!=this.drager.list)return!1;t.clientX,t.clientY;return t.stopPropagation(),docMouseDown(t),!1}})),this.off("mouseup").on("mouseup",(function(t){docMouseUp(t);this.isSelected();return this.getDragList().shiftSelectStartItem=this.getDragList().shiftSelectStartItem||this,this.getDragList().currentMouseDownItem=null,t.ctrlKey||t.shiftKey||(this.getDragList().clearSelect(),this.select()),this.selected&&t.ctrlKey&&this.unselect(),t.stopPropagation(),!1})),this.off("mouseleave").on("mouseleave",(function(t){isEventTargetIsEditable(t)||(this.addClass(this.getTopDragList({}).wdNormalClass),this.removeClass(this.getTopDragList({}).wdHoverClass),this.intervalid&&(clearInterval(this.intervalid),this.intervalid=null),this.timeoutid&&(clearTimeout(this.timeoutid),this.timeoutid=null),clearMouseIcon(),this.isEnter=!1)})),this.off("mouseover").on("mouseover",(function(){return this.addClass(this.getTopDragList({}).wdHoverClass),itemMouseEvent.call(this,event),this.isEnter=!0,!1})),this.element.setAttribute("ssObjId",this.id),this.element.setAttribute("ssPobjId",this.parentid),this.drager.functions&&this.drager.group&&this.dragList&&this.dragList.init();var r=$(this.element).find("[editable]");r.click((function(t){if(isContenteditable(this))return t.stopPropagation(),!1;n.triggerSelectedClick&&$(t.target).is("[editable]")&&($(t.target).attr("contenteditable","true"),t.target.focus())}));r.keyup((function(t){var e=t||window.event;if(13==(e.charCode||e.keyCode))return window.event?window.event.returnValue=!1:e.preventDefault(),e.stopPropagation(),!1;if(isContenteditable(this)){this.realContent=this.innerHtml;try{n.drager.onItemInput&&n.drager.onItemInput.apply(this,[t,n])}catch(e){}}})),r.each((function(){this.commonHeight=$(this).height()})),r.blur((function(){this.realContent=this.innerHTML,this.setAttribute("title",this.realContent);var t=ss.display.ellipsisContent(this,this.commonHeight);this.innerHTML=t})),r.focus((function(){if(isContenteditable(this)){var t=this.realContent;t&&(this.innerHTML=t)}}))}},window.ss.drag.Form=function(t){window.ss.drag.Base.call(this),this.element=t,this.parseForm2Url=function(){var t=this.element,e=[],i=(t.getAttribute("action")||"?").split("?");e=e.concat((i[1]||"").split("&"));for(var s=t.querySelectorAll("input,select,textarea"),n=0;n<s;n++){var r=s[n];switch(r.type){case void 0:case"button":case"file":case"reset":case"submit":break;case"checkbox":case"radio":if(!r.checked)break;default:null==r.value||""==r.value||null==r.name||r.disabled||e.push(r.name+"="+r.value)}}return i[0]+"?"+e.join("&")},this.parseFormData=function(){for(var t={},e=this.element.querySelectorAll("input,select,textarea"),i=0;i<e.length;i++){var s=e[i];switch(s.type){case void 0:case"button":case"file":case"reset":case"submit":break;case"checkbox":case"radio":if(!s.checked)break;default:null!=s.value&&""!=s.value&&null!=s.name&&!s.disabled&&(t[s.name]=s.value)}}return t},this.submit=function(){var t=this.parseFormData(),e=this.element.getAttribute("action"),i=window,s=this.drager;ss.c.wdAjax({url:e,type:"post",data:t,async:!1,success:function(t){var e=document.createElement("div");e.style.display="none",e.id=(new Date).getTime().toString(),e.innerHTML=t;var n=e.querySelectorAll(s.itemSelector);s.optionList.empty(),$.each(n,(function(){s.optionList.append(this)}));for(var r=e.querySelectorAll("script"),o=0;o<r.length;o++){var a=r[o];if(null!=a.innerHTML)try{i.eval(a.innerHTML)}catch(t){}}s.optionList.reload()}})},this.init=function(){"form"==this.element.tagName.toLowerCase()&&(this.element.tagName="div");var t=this,e=this.element.querySelector("input[type='submit']");this.on("submit onsubmit",(function(){this.submit()})),this.element.submit=function(){t.submit()},null!=e&&(this.submitBtn=new window.ss.drag.Base(e),this.submitBtn.on("click",(function(e){return t.trigger("submit"),e.stopPropagation(),e.preventDefault(),!1})))},this.init()},window.ss.drag.Ghost=function(t){window.ss.drag.Base.call(this),this.drager=t.confs.drager,this.isGhost=!0;this.sizeInfo=t.confs.getSize();var e=this.element=document.createElement(t.tagName);e.className=t.className,e.confs=this,e.setAttribute("class",""),e.style.cssText="",e.innerHTML="",e.id="ghost",this.dashMode=function(){},this.getDragList=function(){return(this.element.parentNode||{}).confs},this.getTopDragList=function(){var t=this.getDragList();return t.isChild&&(t=t.thisItem.getDragList()),t},this.lineMode=function(){},this.destroy=function(){this.interval&&clearInterval(this.interval),this.remove()},this.init=function(){var t=this;this.interval=setInterval((function(){var e=!0;null==DM.dragingPanel&&clearInterval(t.interval),0==DM.dragingPanel.isAllowDrop||t.drager!=t.getDragList().drager?e=!1:t.drager.editGroup?e=!0:t.drager.editOrder,e&&DM.dragingPanel.allowDrop(),!e&&DM.dragingPanel.notAllowDrop()}),5),this.hide()},this.init(),this.lineMode()};var DM=window.DM=window.ss.drag.DM=DM||new window.ss.drag.DragerManager;setDrag=function(t,e,i,s,n){return DM.getInstance(t,e,i,s,n)};