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.

3 lines
11 KiB

YUI.add("moodle-core-blocks",function(e,t){var n="/lib/ajax/blocks.php",r={BLOCK:"block",BLOCKREGION:"block-region",BLOCKADMINBLOCK:"block_adminblock",EDITINGMOVE:"editing_move",HEADER:"header",LIGHTBOX:"lightbox",REGIONCONTENT:"region-content",SKIPBLOCK:"skip-block",SKIPBLOCKTO:"skip-block-to",MYINDEX:"page-my-index",REGIONMAIN:"region-main",BLOCKSMOVING:"blocks-moving"},i={DRAGHANDLE:"."+r.HEADER+" .commands .moodle-core-dragdrop-draghandle"},s=function(){s.superclass.constructor.apply(this,arguments)};e.extend(s,M.core.dragdrop,{skipnodetop:null,skipnodebottom:null,dragsourceregion:null,initializer:function(){this.groups=["block"],this.samenodeclass=r.BLOCK,this.parentnodeclass=r.REGIONCONTENT;var t=e.Node.all("body#"+r.MYINDEX+" #"+r.REGIONMAIN+" > ."+r.REGIONCONTENT);if(t.size()>0){var n=t.item(0);n.addClass(r.BLOCKREGION),n.set("id",r.REGIONCONTENT),n.one("div").addClass(r.REGIONCONTENT)}var s=e.Node.all("div."+r.BLOCKREGION);if(s.size()===0)return!1;if(s.size()!==this.get("regions").length){var o=e.Node.create("<div></div>").addClass(r.BLOCKREGION),u=e.Node.create("<div></div>").addClass(r.REGIONCONTENT);o.appendChild(u);var a=s.filter("#region-pre"),f=s.filter("#region-post");a.size()===0&&f.size()===1?(o.setAttrs({id:"region-pre"}),f.item(0).insert(o,"before"),s.unshift(o)):f.size()===0&&a.size()===1&&(o.setAttrs({id:"region-post"}),a.item(0).insert(o,"after"),s.push(o))}s.each(function(t){new e.DD.Drop({node:t.one("div."+r.REGIONCONTENT),groups:this.groups,padding:"40 240 40 240"});var n=new e.DD.Delegate({container:t,nodes:"."+r.BLOCK,target:!0,handles:[i.DRAGHANDLE],invalid:".block-hider-hide, .block-hider-show, .moveto",dragConfig:{groups:this.groups}});n.dd.plug(e.Plugin.DDProxy,{moveOnEnd:!1}),n.dd.plug(e.Plugin.DDWinScroll);var s=t.all("."+r.BLOCK);s.each(function(e){var t=e.one("a."+r.EDITINGMOVE);t&&(t.replace(this.get_drag_handle(t.getAttribute("title"),"","iconsmall",!0)),e.one(i.DRAGHANDLE).setStyle("cursor","move"))},this)},this)},get_block_id:function(e){return Number(e.get("id").replace(/inst/i,""))},get_block_region:function(t){var n=t.ancestor("div."+r.BLOCKREGION).get("id").replace(/region-/i,"");return e.Array.indexOf(this.get("regions"),n)===-1?(window.right_to_left()&&(n==="post"?n="pre":n==="pre"&&(n="post")),"side-"+n):n},get_region_id:function(e){return e.get("id").replace(/region-/i,"")},drag_start:function(t){var n=t.target;this.dragsourceregion=n.get("node").ancestor("div."+r.BLOCKREGION),n.get("node").previous()&&n.get("node").previous().hasClass(r.SKIPBLOCK)&&(this.skipnodetop=n.get("node").previous()),n.get("node").next()&&n.get("node").next().hasClass(r.SKIPBLOCKTO)&&(this.skipnodebottom=n.get("node").next()),e.one("body").addClass(r.BLOCKSMOVING)},drop_over:function(t){var n=t.drag.get("node"),i=t.drop.get("node");i.hasClass(this.parentnodeclass)&&i.one("."+r.BLOCKADMINBLOCK)&&i.one("."+r.BLOCKADMINBLOCK).next("."+r.BLOCK)&&i.prepend(n);if(this.dragsourceregion.contains(i))return!1;var s=e.one("body"),o=this.get_region_id(this.dragsourceregion);s.hasClass("side-"+o+"-only")&&s.removeClass("side-"+o+"-only"),o=this.get_region_id(i.ancestor("div."+r.BLOCKREGION)),this.dragsourceregion.all("."+r.BLOCK).size()===0&&this.dragsourceregion.get("id").match(/(region-pre|region-post)/i)&&(s.hasClass("side-"+o+"-only")||s.addClass("side-"+o+"-only"))},drag_end:function(){this.skipnodetop=null,this.skipnodebottom=null,this.dragsourceregion=null,e.one("body").removeClass(r.BLOCKSMOVING)},drag_dropmiss:function(e){this.drop_hit(e)},drop_hit:function(t){var i=t.drag,s=i.get("node"),o=t.drop.get("node");s.previous()&&s.previous().hasClass(r.SKIPBLOCK)&&s.insert(s.previous(),"after"),this.skipnodetop&&s.insert(this.skipnodetop,"before"),this.skipnodebottom&&s.insert(this.skipnodebottom,"after");var u=M.util.add_lightbox(e,s),a={sesskey:M.cfg.sesskey,courseid:this.get("courseid"),pagelayout:this.get("pagelayout"),pagetype:this.get("pagetype"),subpage:this.get("subpage"),contextid:this.get("contextid"),action:"move",bui_moveid:this.get_block_id(s),bui_newregion:this.get_block_region(o)};this.get("c
,groups:this.groups,padding:"40 240 40 240"}),a=new e.DD.Delegate({container:s.get_droptarget(),nodes:"."+r.BLOCK,target:!0,handles:[i.DRAGHANDLE],invalid:".block-hider-hide, .block-hider-show, .moveto, .block_fake",dragConfig:{groups:this.groups}}),a.dd.plug(e.Plugin.DDProxy,{moveOnEnd:!1}),a.dd.plug(e.Plugin.DDWinScroll),e.DD.DDM.on("ddm:start",this.enable_all_regions,this),s.change_block_move_icons(this)},get_block_id:function(e){return Number(e.get("id").replace(/inst/i,""))},get_block_region:function(e){return e.test("[data-blockregion]")||(e=e.ancestor("[data-blockregion]")),e.getData("blockregion")},get_region_object:function(e){return this.regionobjects[this.get_block_region(e)]},enable_all_regions:function(){var t=e.DD.DDM.activeDrag.get("groups");if(!t||e.Array.indexOf(t,"block")===-1)return;var n;for(n in this.regionobjects){if(!this.regionobjects.hasOwnProperty(n))continue;this.regionobjects[n].enable()}},disable_regions_if_required:function(){var e=0;for(e in this.regionobjects)this.regionobjects[e].disable_if_required()},drag_start:function(e){var t=e.target;t.get("node").previous()&&t.get("node").previous().hasClass(r.SKIPBLOCK)&&(this.skipnodetop=t.get("node").previous()),t.get("node").next()&&t.get("node").next().hasClass(r.SKIPBLOCKTO)&&(this.skipnodebottom=t.get("node").next())},drop_over:function(e){var t=e.drag.get("node"),n=e.drop.get("node");n.hasClass(r.REGIONCONTENT)&&n.one("."+r.BLOCKADMINBLOCK)&&n.one("."+r.BLOCKADMINBLOCK).next("."+r.BLOCK)&&n.prepend(t)},drop_end:function(){this.skipnodetop=null,this.skipnodebottom=null,this.disable_regions_if_required()},drag_dropmiss:function(e){this.drop_hit(e)},drop_hit:function(t){var i=t.drag.get("node"),s=t.drop.get("node");i.previous()&&i.previous().hasClass(r.SKIPBLOCK)&&i.insert(i.previous(),"after"),this.skipnodetop&&i.insert(this.skipnodetop,"before"),this.skipnodebottom&&i.insert(this.skipnodebottom,"after");var o=M.util.add_lightbox(e,i),u={sesskey:M.cfg.sesskey,courseid:this.get("courseid"),pagelayout:this.get("pagelayout"),pagetype:this.get("pagetype"),subpage:this.get("subpage"),contextid:this.get("contextid"),action:"move",bui_moveid:this.get_block_id(i),bui_newregion:this.get_block_region(s)};this.get("cmid")&&(u.cmid=this.get("cmid")),i.next("."+r.BLOCK)&&!i.next("."+r.BLOCK).hasClass(r.BLOCKADMINBLOCK)&&(u.bui_beforeid=this.get_block_id(i.next("."+r.BLOCK))),e.io(M.cfg.wwwroot+n,{method:"POST",data:u,on:{start:function(){o.show()},success:function(t,n){window.setTimeout(function(){o.hide()},250);try{var r=e.JSON.parse(n.responseText);r.error&&new M.core.ajaxException(r)}catch(i){}},failure:function(e,t){this.ajax_failure(t),o.hide()},complete:function(){this.disable_regions_if_required()}},context:this})}},e.extend(o,M.core.dragdrop,o.prototype,{NAME:"core-blocks-dragdrop-manager",ATTRS:{courseid:{value:null},cmid:{value:null},contextid:{value:null},pagelayout:{value:null},pagetype:{value:null},subpage:{value:null},regions:{value:[]}}});var u=function(){u.superclass.constructor.apply(this,arguments)};u.prototype={initializer:function(){var t=this.get("node");t||(t=this.create_and_add_node());var n=e.one("body"),i=t.all("."+r.BLOCK).size()>0,s=this.get_has_region_class();this.set("hasblocks",i),n.hasClass(s)||n.addClass(s),n.addClass(i?this.get_used_region_class():this.get_empty_region_class()),n.removeClass(i?this.get_empty_region_class():this.get_used_region_class())},create_and_add_node:function(){var t=e.Node.create,n=this.get("region"),i=t('<div id="block-region-'+n+'" data-droptarget="1"></div>').addClass(r.BLOCKREGION).setData("blockregion",n),s=this.get("manager").get("regions"),o,u=!1,a=!1,f=!1,l,c;for(o in s)s[o].match(/(pre|left)/)?u=s[o]:s[o].match(/(post|right)/)&&(a=s[o]);return u!==!1&&a!==!1&&(n===u?(c=e.one("#block-region-"+a),c&&(c.insert(i,"before"),f=!0)):(l=e.one("#block-region-"+u),l&&(l.insert(i,"after"),f=!0))),f===!1&&e.one("body").append(i),this.set("node",i),i},change_block_move_icons:function(e){var t;this.get("node").all("."+r.BLOCK+" a."+r.EDITINGMOVE).each(function(n){n.setStyle("cursor","move"),t=e.get_drag