You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

2 lines
7.1 KiB

YUI.add("moodle-core-dragdrop",function(e,t){var n={pix:"i/move_2d",largepix:"i/dragdrop",component:"moodle",cssclass:"moodle-core-dragdrop-draghandle"},r=function(){r.superclass.constructor.apply(this,arguments)};e.extend(r,e.Base,{goingup:null,absgoingup:null,samenodeclass:null,parentnodeclass:null,samenodelabel:null,parentnodelabel:null,groups:[],lastdroptarget:null,listeners:null,initializer:function(){this.listeners=[],this.listeners.push(e.DD.DDM.on("drag:start",this.global_drag_start,this)),this.listeners.push(e.DD.DDM.on("drag:end",this.global_drag_end,this)),this.listeners.push(e.DD.DDM.on("drag:drag",this.global_drag_drag,this)),this.listeners.push(e.DD.DDM.on("drop:over",this.global_drop_over,this)),this.listeners.push(e.DD.DDM.on("drop:hit",this.global_drop_hit,this)),this.listeners.push(e.DD.DDM.on("drag:dropmiss",this.global_drag_dropmiss,this)),this.listeners.push(e.one(e.config.doc.body).delegate("key",this.global_keydown,"down:32, enter, esc","."+n.cssclass,this)),this.listeners.push(e.one(e.config.doc.body).delegate("click",this.global_keydown,"."+n.cssclass,this))},destructor:function(){(new e.EventHandle(this.listeners)).detach()},get_drag_handle:function(t,r,i){var s=e.Node.create("<span></span>").addClass(r).setAttribute("title",t).setAttribute("tabIndex",0).setAttribute("data-draggroups",this.groups).setAttribute("role","button");return s.addClass(n.cssclass),window.require(["core/templates"],function(t){t.renderPix("i/move_2d","core").then(function(t){var n=e.Node.create(t);n.setStyle("cursor","move"),typeof i!="undefined"&&n.addClass(i),s.appendChild(n)})}),s},lock_drag_handle:function(e,t){e.removeHandle("."+t)},unlock_drag_handle:function(e,t){e.addHandle("."+t),e.get("activeHandle").focus()},ajax_failure:function(e){var t={name:e.status+" "+e.statusText,message:e.responseText};return new M.core.exception(t)},in_group:function(t){var n=!1;return e.each(this.groups,function(e){t._groups[e]&&(n=!0)},this),n},global_drag_start:function(e){var t=e.target;if(!this.in_group(t))return;this.originalstyle=t.get("node").getAttribute("style"),t.get("node").setStyle("opacity",".25"),t.get("dragNode").setStyles({opacity:".75",borderColor:t.get("node").getStyle("borderColor"),backgroundColor:t.get("node").getStyle("backgroundColor")}),t.get("dragNode").empty(),this.drag_start(e)},global_drag_end:function(e){var t=e.target;if(!this.in_group(t))return;t.get("node").setAttribute("style",this.originalstyle),this.drag_end(e)},global_drag_drag:function(e){var t=e.target,n=e.info;if(!this.in_group(t))return;n.start[1]<n.xy[1]?this.absgoingup=!0:n.start[1]>n.xy[1]&&(this.absgoingup=!1),n.delta[1]<0?this.goingup=!0:n.delta[1]>0&&(this.goingup=!1),this.drag_drag(e)},global_drop_over:function(e){if(!e.drop||!e.drop.inGroup(this.groups))return;var t=e.drag.get("node"),n=e.drop.get("node");this.lastdroptarget=e.drop;if(n.hasClass(this.samenodeclass)){var r;this.goingup?r="before":r="after",n.insert(t,r)}else(n.hasClass(this.parentnodeclass)||n.test('[data-droptarget="1"]'))&&!n.contains(t)&&(this.goingup?n.append(t):n.prepend(t));this.drop_over(e)},global_drag_dropmiss:function(e){e.drag=e.target,e.drop=this.lastdroptarget;if(!this.in_group(e.drag))return;if(!e.drop||!e.drop.inGroup(this.groups))return;this.drag_dropmiss(e)},global_drop_hit:function(e){if(!e.drop||!e.drop.inGroup(this.groups))return;this.drop_hit(e)},find_element_text:function(t){var n="";n=t.get("aria-label")||"";if(n.length>0)return n;var r=t.get("aria-labelledby");if(r){var i=e.one("#"+r);if(i&&i.get("text").length>0)return i.get("text")}var s=t.all("h2, h3, h4, h5, span:not(.actions):not(.menu-action-text), p, div.no-overflow, div.dimmed_text");return s.each(function(){n===""&&e.Lang.trim(this.get("text"))!==""&&(n=this.get("text"))}),n!==""?n:M.util.get_string("emptydragdropregion","moodle")},global_start_keyboard_drag:function(t,n,r){M.core.dragdrop.keydragcontainer=r,M.core.dragdrop.keydraghandle=n;var i=this.find_element_text(r),s=M.util.get_string("movecontent","moodle",i),o=e.Node.create("<ul></ul>");o.addClass("dragdrop-keyboard-drag");var u,a,f,l=e.all("."+this.samenodeclass+", ."+this.parentnodeclass);l.each(function(t){var n=!1,s=t,l=t.getAttribute("class").split(" ").join(", .");if(t.drop&&t.drop.inGroup(this.groups)&&t.drop.get("node")!==r&&t.next(l)!==r)n=!0;else{var c=t.getAttribute("data-draggroups").split(" "),h,p;for(h=0;h<c.length;h++){for(p=0;p<this.groups.length;p++)if(c[h]===this.groups[p]&&t!=r&&t.next(l)!==r&&t.get("children").item(0)!=r){n=!0,s=t.get("parentNode");break}if(n)break}}n&&(u=e.Node.create("<li></li>"),a=e.Node.create("<a></a>"),i=this.find_element_text(s),this.samenodelabel&&t.hasClass(this.samenodeclass)?f=M.util.get_string(this.samenodelabel.identifier,this.samenodelabel.component,i):this.parentnodelabel&&t.hasClass(this.parentnodeclass)?f=M.util.get_string(this.parentnodelabel.identifier,this.parentnodelabel.component,i):f=M.util.get_string("tocontent","moodle",i),a.setContent(f),a.setAttribute("data-drop-target",t.get("id")),a.setAttribute("tabindex","0"),a.on("click",this.global_keyboard_drop,this),a.on("key",this.global_keyboard_drop,"down:enter,32",this),u.append(a),o.append(u))},this),M.core.dragdrop.dropui=new M.core.dialogue({headerContent:s,bodyContent:o,draggable:!0,visible:!0,center:!0,modal:!0}),M.core.dragdrop.dropui.after("visibleChange",function(e){e.prevVal&&!e.newVal&&this.global_cancel_keyboard_drag()},this),o.one("a")&&o.one("a").focus()},simulated_drag_drop_event:function(e,t){var n=function(e){this.node=e};n.prototype.get=function(e){return e==="node"||e==="dragNode"||e==="dropNode"?this.node:e==="activeHandle"?this.node.one(".editing_move"):null},n.prototype.inGroup=function(){return!0},n.prototype.addHandle=function(){},n.prototype.removeHandle=function(){},this.drop=new n(t),this.drag=new n(e),this.target=this.drop},global_keyboard_drop:function(t){var n=M.core.dragdrop.keydragcontainer,r=e.one("#"+t.target.getAttribute("data-drop-target"));M.core.dragdrop
.dropui.hide(),t.preventDefault();var i=new this.simulated_drag_drop_event(n,n),s=new this.simulated_drag_drop_event(n,r);this.drag_start(i),this.global_drop_over(s),r.hasClass(this.parentnodeclass)&&r.contains(n)&&r.prepend(n),this.global_drop_hit(s)},global_cancel_keyboard_drag:function(){M.core.dragdrop.keydragcontainer&&(M.core.dragdrop.keydraghandle.focus(),M.core.dragdrop.keydragcontainer=null),M.core.dragdrop.dropui&&M.core.dragdrop.dropui.destroy()},global_keydown:function(e){var t=e.target.ancestor("."+n.cssclass,!0),r,i;if(t===null)return;if(e.keyCode===27){this.global_cancel_keyboard_drag(),e.preventDefault();return}if(!t.hasClass(n.cssclass))return;if(e.keyCode!==13&&e.keyCode!==32&&e.type!=="click")return;i=t.getAttribute("data-draggroups").split(" ");var s,o,u=!1;for(s=0;s<i.length;s++){for(o=0;o<this.groups.length;o++)if(i[s]===this.groups[o]){u=!0;break}if(u)break}if(!u)return;r=t.ancestor(".yui3-dd-drop"),this.global_start_keyboard_drag(e,t,r),e.preventDefault()},drag_start:function(){},drag_end:function(){},drag_drag:function(){},drag_dropmiss:function(){},drop_over:function(){},drop_hit:function(){}},{NAME:"dragdrop",ATTRS:{}}),M.core=M.core||{},M.core.dragdrop=r},"@VERSION@",{requires:["base","node","io","dom","dd","event-key","event-focus","moodle-core-notification"]});