a6e9b2996b8024c278d345d8302c10ec456f728f
[moodle.git] / lib / yui / build / moodle-core-dock / moodle-core-dock-min.js
1 YUI.add("moodle-core-dock",function(e,t){var n="moodle-core-dock",r=e.one(e.config.doc.body),i={dock:"dock",dockspacer:"dockspacer",controls:"controls",body:"has_dock",buttonscontainer:"buttons_container",dockeditem:"dockeditem",dockeditemcontainer:"dockeditem_container",dockedtitle:"dockedtitle",activeitem:"activeitem",dockonload:"dock_on_load"},s={dockableblock:".block[data-instanceid][data-dockable]",blockmoveto:".block[data-instanceid][data-dockable] .moveto",panelmoveto:"#dockeditempanel .commands a.moveto",dockonload:".block."+i.dockonload,blockregion:"[data-blockregion]"},o,u,a,f,l;M.core=M.core||{},M.core.dock=M.core.dock||{},M.core.dock._dock=null,M.core.dock._dockableblocks={},M.core.dock.init=function(){e.all(s.dockableblock).each(M.core.dock.registerDockableBlock),e.Global.on(M.core.globalEvents.BLOCK_CONTENT_UPDATED,function(e){M.core.dock.notifyBlockChange(e.instanceid)},this),r.delegate("click",M.core.dock.dockBlock,s.blockmoveto),r.delegate("key",M.core.dock.dockBlock,s.blockmoveto,"enter")},M.core.dock.get=function(){return this._dock===null&&(this._dock=new o),this._dock},M.core.dock.registerDockableBlock=function(e){typeof e=="object"&&typeof e.getData=="function"&&(e=e.getData("instanceid")),M.core.dock._dockableblocks[e]=new f({id:e})},M.core.dock.dockBlock=function(e){typeof e=="object"&&e.target!=="undefined"&&(e=e.target);if(typeof e=="object"){e.test(s.dockableblock)||(e=e.ancestor(s.dockableblock));if(typeof e!="object"||typeof e.getData!="function"||!!e.ancestor("."+i.dock))return;e=e.getData("instanceid")}var t=M.core.dock._dockableblocks[e];t&&t.moveToDock()},M.core.dock.fixTitleOrientation=function(t,n){var i=M.core.dock.get(),s="11px",o="rotate(270deg)",u,a,f,l,c=M.util.get_string("thisdirectionvertical","langconfig");t=e.one(t);if(i.get("orientation")!=="vertical")return t.set("innerHTML",n),t;e.UA.ie>0&&e.UA.ie<8&&(c="ver");switch(c){case"ver":return t.set("innerHTML",n.split("").join("<br />"));case"ttb":o="rotate(90deg)";break;case"btt":}return e.UA.ie===8?(t.set("innerHTML",n),t.setAttribute("style","writing-mode: tb-rl; filter: flipV flipH;display:inline;"),t.addClass("filterrotate"),t):(u=e.Node.create('<h2 class="transform-test-heading"><span class="transform-test-node" style="font-size:'+s+';">'+n+"</span></h2>"),r.insert(u,0),a=u.one("span").get("offsetWidth")*1.2,f=u.one("span").get("offsetHeight"),u.remove(),t.set("innerHTML",n),t.addClass("css3transform"),t.setStyles({position:"relative",fontSize:s,width:a,top:(a-f)/2}),window.right_to_left()?t.setStyle("left",a/2-f):t.setStyle("right",a/2-f),t.setStyles({transform:o,"-ms-transform":o,"-moz-transform":o,"-webkit-transform":o,"-o-transform":o}),l=e.Node.create("<div></div>"),l.append(t),l.setStyles({height:a+a/4,position:"relative"}),l)},M.core.dock.notifyBlockChange=function(e){if(this._dock!==null){var t=M.core.dock.get(),n=t.getActiveItem();n&&n.get("blockinstanceid")===parseInt(e,10)&&t.resizePanelIfRequired()}},o=function(){o.superclass.constructor.apply(this,arguments)},o.prototype={tabheightmanager:null,preventevent:null,delayedevent:null,dockeditems:[],dockdrawn:!1,count:0,totalcount:0,holdingareanode:null,initializer:function(){this.publish("dock:starting",{prefix:"dock",broadcast:2,emitFacade:!0,fireOnce:!0}),this.publish("dock:initialised",{prefix:"dock",broadcast:2,emitFacade:!0,fireOnce:!0}),this.publish("dock:beforedraw",{prefix:"dock",fireOnce:!0}),this.publish("dock:beforeshow",{prefix:"dock"}),this.publish("dock:shown",{prefix:"dock",broadcast:2}),this.publish("dock:hidden",{prefix:"dock",broadcast:2}),this.publish("dock:itemadded",{prefix:"dock"}),this.publish("dock:itemremoved",{prefix:"dock"}),this.publish("dock:itemschanged",{prefix:"dock",broadcast:2}),this.publish("dock:panelgenerated",{prefix:"dock",fireOnce:!0}),this.publish("dock:panelresizestart",{prefix:"dock"}),this.publish("dock:resizepanelcomplete",{prefix:"dock"}),this._applyThemeCustomisation(),this.fire("dock:starting"),this._ensureDockDrawn(),this.fire("dock:initialised")},_ensureDockDrawn:function(){if(this.dockdrawn===!0)return!0;var t=this._initialiseDockNode(),n={cssselector:"."+i.dockedtitle,delay:0},o={cssselector:"."+i.dockedtitle,delay:.5,iscontained:!0,preventevent:"click",preventdelay:3};return e.UA.ie>0&&e.UA.ie<7&&t.setStyle("height",t.get("winHeight")+"px"),this.fire("dock:beforedraw"),this._initialiseDockControls(),this.tabheightmanager=new a({dock:this}),e.delegate("click",this.handleEvent,this.get("dockNode"),"."+i.dockedtitle,this,n),e.delegate("mouseenter",this.handleEvent,this.get("dockNode"),"."+i.dockedtitle,this,o),this.get("dockNode").on("mouseleave",this.handleEvent,this,{cssselector:"#dock",delay:.5,iscontained:!1}),e.delegate("click",this.handleReturnToBlock,this.get("dockNode"),s.panelmoveto,this),e.delegate("dock:actionkey",this.handleDockedItemEvent,this.get("dockNode"),"."+i.dockeditem,this),r.on("click",this.handleEvent,this,{cssselector:"body",delay:0}),this.on("dock:itemschanged",this.resizeBlockSpace,this),this.on("dock:itemschanged",this.checkDockVisibility,this),this.on("dock:itemschanged",this.resetFirstItem,this),this.dockdrawn=!0,!0},handleDockedItemEvent:function(e){if(e.type!=="dock:actionkey")return!1;var t=e.target,n="."+i.dockeditem;t.test(n)||(t=t.ancestor(n));if(!t)return!1;e.halt(),this.dockeditems[t.getAttribute("rel")].toggle(e.action)},_applyThemeCustomisation:function(){if(typeof customise_dock_for_theme=="function"){M.core_dock=this,M.core_dock.cfg={buffer:null,orientation:null,position:null,spacebeforefirstitem:null,removeallicon:null},M.core_dock.css={dock:null,dockspacer:null,controls:null,body:null,buttonscontainer:null,dockeditem:null,dockeditemcontainer:null,dockedtitle:null,activeitem:null};try{window.customise_dock_for_theme(this)}catch(t){}var n,r,s=!1,o={buffer:"bufferPanel",orientation:"orientation",position:"position",spacebeforefirstitem:"bufferBeforeFirstItem",removeallicon:"undockAllIconUrl"};for(n in M.core_dock.cfg)if(e.Lang.isString(n)&&o[n]){
2 r=M.core_dock.cfg[n];if(r===null)continue;s||(s=!0),this.set(o[n],r)}for(n in M.core_dock.css)if(e.Lang.isString(n)){r=M.core_dock.css[n];if(r===null)continue;s||(s=!0),i[n]=r}}},_initialiseDockNode:function(){var t=this.get("dockNode"),n=i.dock+"_"+this.get("position")+"_"+this.get("orientation"),o=e.Node.create("<div></div>").setStyles({display:"none"}),u=this.get("buttonsNode"),a=this.get("itemContainerNode");return t||(t=e.one("#"+i.dock)),t||(t=e.Node.create('<div id="'+i.dock+'"></div>'),r.append(t)),t.setAttribute("role","menubar").addClass(n),e.all(s.dockonload).size()===0?t.addClass("nothingdocked"):(n=i.body+"_"+this.get("position")+"_"+this.get("orientation"),r.addClass(i.body).addClass()),u||(u=t.one("."+i.buttonscontainer)),u||(u=e.Node.create('<div class="'+i.buttonscontainer+'"></div>'),t.append(u)),a||(a=t.one("."+i.dockeditemcontainer)),a||(a=e.Node.create('<div class="'+i.dockeditemcontainer+'"></div>'),u.append(a)),r.append(o),this.holdingareanode=o,this.set("dockNode",t),this.set("buttonsNode",u),this.set("itemContainerNode",a),t},_initialiseDockControls:function(){var t=e.Node.create('<img alt="'+M.util.get_string("undockall","block")+'" tabindex="0" />');t.setAttribute("src",this.get("undockAllIconUrl")),t.on("removeall|click",this.removeAll,this),t.on("dock:actionkey",this.removeAll,this,{actions:{enter:!0}}),this.get("buttonsNode").append(e.Node.create('<div class="'+i.controls+'"></div>').append(t))},getPanel:function(){var t=this.get("panel");return t||(t=new u({dock:this}),t.on("panel:visiblechange",this.resize,this),e.on("windowresize",this.resize,this),this.set("panel",t),this.fire("dock:panelgenerated")),t},resizePanelIfRequired:function(){this.resize();var e=this.get("panel");e&&e.correctWidth()},handleEvent:function(e,t){var n=this.getActiveItem(),r,i,s=/^dock_item_(\d+)_title$/,o=this;if(t.cssselector==="body")this.get("dockNode").contains(e.target)||n&&n.hide();else{e.target.test(t.cssselector)?r=e.target:r=e.target.ancestor(t.cssselector);if(!r)return!0;if(this.preventevent!==null&&e.type===this.preventevent)return!0;t.preventevent&&(this.preventevent=t.preventevent,t.preventdelay&&setTimeout(function(){o.preventevent=null},t.preventdelay*1e3)),this.delayedevent&&this.delayedevent.timeout&&(clearTimeout(this.delayedevent.timeout),this.delayedevent.event.detach(),this.delayedevent=null);if(t.delay>0)return this.delayEvent(e,t,r);i=r.get("id"),i.match(s)?(n=this.dockeditems[i.replace(s,"$1")],n.active?n.hide():n.show()):n&&n.hide()}return!0},delayEvent:function(e,t,n){var i=this;return i.delayedevent=function(){return{target:n,event:r.on("mousemove",function(e){i.delayedevent.target=e.target}),timeout:null}}(i),i.delayedevent.timeout=setTimeout(function(){i.delayedevent.timeout=null,i.delayedevent.event.detach(),t.iscontained===i.get("dockNode").contains(i.delayedevent.target)&&i.handleEvent(e,{cssselector:t.cssselector,delay:0,iscontained:t.iscontained})},t.delay*1e3),!0},resizeBlockSpace:function(){if(e.all(s.dockonload).size()>0)return;var t=0,n=[],i=[],o=!1,u=[],a=!1,f=[],l=[];e.all(s.blockregion).each(function(e){var r=e.getData("blockregion");e.all(".block").size()>0?(n.push(r),t++):e.all(".block_dock_placeholder").size()>0&&i.push(r)}),e.all(".block-region").each(function(e){if(e.test(s.blockregion))return;a=!0;var n=e.get("id").replace(/^region\-/,"side-"),r=e.all(".block").size()>0;r?(u.push(n),t++):l.push(n+"-only")}),r.hasClass("blocks-moving")&&(o=!0),e.each(i,function(e){f.push("empty-region-"+e,"docked-region-"+e),l.push("used-region-"+e,e+"-only")},this),e.each(n,function(e){f.push("used-region-"+e),l.push("empty-region-"+e,"docked-region-"+e),t===1&&o===!1?f.push(e+"-only"):l.push(e+"-only")},this),a&&(o||t!==1?e.each(u,function(e){l.push(e+"-only")}):e.each(u,function(e){f.push(e+"-only")})),r.hasClass("has-region-content")||(t===0&&o===!1?f.push("content-only"):l.push("content-only")),e.each(l,function(e){r.removeClass(e)}),e.each(f,function(e){r.addClass(e)})},add:function(e){e.set("id",this.totalcount),this.count++,this.totalcount++,this.dockeditems[e.get("id")]=e,this.dockeditems[e.get("id")].draw(),this.fire("dock:itemadded",e),this.fire("dock:itemschanged",e)},append:function(e){this.get("itemContainerNode").append(e)},handleReturnToBlock:function(e){e.halt(),this.remove(this.getActiveItem().get("id"))},remove:function(e){return this.dockeditems[e]?(this.dockeditems[e].remove(),delete this.dockeditems[e],this.count--,this.fire("dock:itemremoved",e),this.fire("dock:itemschanged",e),!0):!1},resetFirstItem:function(){this.get("dockNode").all("."+i.dockeditem+".firstdockitem").removeClass("firstdockitem"),this.get("dockNode").one("."+i.dockeditem)&&this.get("dockNode").one("."+i.dockeditem).addClass("firstdockitem")},removeAll:function(){var t;for(t in this.dockeditems)(e.Lang.isNumber(t)||e.Lang.isString(t))&&this.remove(t);return!0},hideActive:function(){var e=this.getActiveItem();e&&e.hide()},checkDockVisibility:function(){var e=i.body+"_"+this.get("position")+"_"+this.get("orientation");this.count?(this.fire("dock:beforeshow"),this.get("dockNode").removeClass("nothingdocked"),r.addClass(i.body).addClass(e),this.fire("dock:shown")):(this.get("dockNode").addClass("nothingdocked"),r.removeClass(i.body).removeClass(),this.fire("dock:hidden"))},resize:function(){var t=this.getPanel(),n=this.getActiveItem(),i,s,o,u,a,f,l,c,h,p;return!t.get("visible")||!n?!0:(this.fire("dock:panelresizestart"),this.get("orientation")==="vertical"&&(i=this.get("bufferPanel"),s=parseInt(r.get("winHeight"),10)-i*2,o=this.get("dockNode").getY(),u=n.get("dockTitleNode").getY()-o-i,a=this.get("itemContainerNode").getY(),f=a-o+this.get("buttonsNode").get("offsetHeight"),l=t.get("bodyNode").get("scrollTop"),t.get("bodyNode").setStyle("height","auto"),t.get("node").removeClass("oversized_content"),c=t.get("node").get("offsetHeight"),e.UA.ie>0&&e.UA.ie<7?t.setTop(n.get("dockTitleNode").getY()):c>s?(t.setTop(i-f),t.get("bodyNode").setStyle("height",s-t.get("headerNode"
3 ).get("offsetHeight")+"px"),t.get("node").addClass("oversized_content")):c>s-(u-i)?t.setTop(u-f-(c-(s-u))+i):t.setTop(u-f+i),l&&t.get("bodyNode").set("scrollTop",l)),this.get("position")==="right"?t.get("node").setStyle("left","-"+t.get("node").get("offsetWidth")+"px"):this.get("position")==="top"&&(h=this.get("dockNode").getX(),p=n.get("dockTitleNode").getX()-h,t.get("node").setStyle("left",p+"px")),this.fire("dock:resizepanelcomplete"),!0)},getActiveItem:function(){var e;for(e in this.dockeditems)if(this.dockeditems[e].active)return this.dockeditems[e];return!1},addToHoldingArea:function(e){this.holdingareanode.append(e)}},e.extend(o,e.Base,o.prototype,{NAME:"moodle-core-dock",ATTRS:{dockNode:{writeOnce:!0},panel:{writeOnce:!0},buttonsNode:{writeOnce:!0},itemContainerNode:{writeOnce:!0},bufferPanel:{value:10,validator:e.Lang.isNumber},position:{value:"left",validator:e.Lang.isString},orientation:{value:"vertical",validator:e.Lang.isString,setter:function(e){return e.match(/^vertical$/i)?"vertical":"horizontal"}},bufferBeforeFirstItem:{value:10,validator:e.Lang.isNumber},undockAllIconUrl:{value:M.util.image_url(window.right_to_left()?"t/dock_to_block_rtl":"t/dock_to_block","moodle"),validator:e.Lang.isString}}}),e.augment(o,e.EventTarget),u=function(){u.superclass.constructor.apply(this,arguments)},u.prototype={created:!1,initializer:function(){this.publish("dockpanel:beforeshow",{prefix:"dockpanel"}),this.publish("dockpanel:shown",{prefix:"dockpanel"}),this.publish("dockpanel:beforehide",{prefix:"dockpanel"}),this.publish("dockpanel:hidden",{prefix:"dockpanel"}),this.publish("dockpanel:visiblechange",{prefix:"dockpanel"})},create:function(){if(this.created)return!0;this.created=!0;var t=this.get("dock"),n=t.get("dockNode");this.set("node",e.Node.create('<div id="dockeditempanel" class="dockitempanel_hidden"></div>')),this.set("contentNode",e.Node.create('<div class="dockeditempanel_content"></div>')),this.set("headerNode",e.Node.create('<div class="dockeditempanel_hd"></div>')),this.set("bodyNode",e.Node.create('<div class="dockeditempanel_bd"></div>')),n.append(this.get("node").append(this.get("contentNode").append(this.get("headerNode")).append(this.get("bodyNode"))))},show:function(){this.create(),this.fire("dockpanel:beforeshow"),this.set("visible",!0),this.get("node").removeClass("dockitempanel_hidden"),this.fire("dockpanel:shown"),this.fire("dockpanel:visiblechange")},hide:function(){this.fire("dockpanel:beforehide"),this.set("visible",!1),this.get("node").addClass("dockitempanel_hidden"),this.fire("dockpanel:hidden"),this.fire("dockpanel:visiblechange")},setHeader:function(t){this.create();var n=this.get("headerNode"),r;n.setContent(t);if(arguments.length>1)for(r=1;r<arguments.length;r++)(e.Lang.isNumber(r)||e.Lang.isString(r))&&n.append(arguments[r])},setBody:function(e){this.create(),this.get("bodyNode").setContent(e)},setTop:function(t){e.UA.ie>0&&e.UA.ie<7?this.get("node").setY(t):this.get("node").setStyle("top",t.toString()+"px")},correctWidth:function(){var e=this.get("bodyNode"),t=e.get("clientWidth"),n=e.get("scrollWidth"),r=e.get("offsetWidth"),i=t,s=Math.round(e.get("winWidth")*.8);n>t&&(i=t+(n-t)+(r-t)*2+10),i>s&&(i=s),i>r&&this.get("node").setStyle("width",i+"px")}},e.extend(u,e.Base,u.prototype,{NAME:"moodle-core-dock-panel",ATTRS:{dock:{writeOnce:"initOnly"},node:{value:null},contentNode:{value:null},headerNode:{value:null},bodyNode:{value:null},visible:{value:!1}}}),e.augment(u,e.EventTarget),a=function(){a.superclass.constructor.apply(this,arguments)},a.prototype={initializer:function(){var t=this.get("dock");t.on("dock:itemschanged",this.checkSizing,this),e.on("windowresize",this.checkSizing,this)},checkSizing:function(){var t=this.get("dock"),n=t.get("dockNode"),r=t.dockeditems,s=parseInt(n.one(".dockeditem_container").getStyle("marginTop").replace("/[^0-9]+$/",""),10),o=n.get("offsetHeight")-s,u=n.one(".controls").get("offsetHeight"),a=t.get("bufferPanel")*3,f=o-u-a-r.length*2,l=0,c,h;if(r.length>0){for(c in r)if(e.Lang.isNumber(c)||e.Lang.isString(c))h=e.one(r[c].get("title")).ancestor("."+i.dockedtitle),h&&(this.get("enabled")&&h.setStyle("height","auto"),l+=h.get("offsetHeight")||0);l>f&&this.enable(f)}},enable:function(t){var n=this.get("dock"),r=n.dockeditems,s=n.count,o=0,u=0,a,f,l,c;this.set("enabled",!0);for(a in r)if(e.Lang.isNumber(a)||e.Lang.isString(a)){f=e.one(r[a].get("title")).ancestor("."+i.dockedtitle);if(!f)continue;l=Math.floor((t-u)/(s-o)),c=f.get("offsetHeight"),f.setStyle("overflow","hidden"),c>l?(f.setStyle("height",l+"px"),u+=l):u+=c,o++}}},e.extend(a,e.Base,a.prototype,{NAME:"moodle-core-tabheightmanager",ATTRS:{dock:{writeOnce:"initOnly"},enabled:{value:!1}}}),e.Event.define("dock:actionkey",{_event:e.UA.webkit||e.UA.ie?"keydown":"keypress",_keys:{37:"collapse",39:"expand",32:"toggle",13:"enter"},_keyHandler:function(e,t,n){var r;n.actions?r=n.actions:r={collapse:!0,expand:!0,toggle:!0,enter:!0},this._keys[e.keyCode]&&r[this._keys[e.keyCode]]&&(e.action=this._keys[e.keyCode],t.fire(e))},on:function(e,t,n){t.args===null?t._detacher=e.on(this._event,this._keyHandler,this,n,{actions:!1}):t._detacher=e.on(this._event,this._keyHandler,this,n,t.args[0])},detach:function(e,t){t._detacher.detach()},delegate:function(e,t,n,r){t.args===null?t._delegateDetacher=e.delegate(this._event,this._keyHandler,r,this,n,{actions:!1}):t._delegateDetacher=e.delegate(this._event,this._keyHandler,r,this,n,t.args[0])},detachDelegate:function(e,t){t._delegateDetacher.detach()}}),f=function(){f.superclass.constructor.apply(this,arguments)},f.prototype={contentplaceholder:null,contentskipanchor:null,cachedcontentnode:null,skipsetposition:!0,dockitem:null,initializer:function(){var t=e.one("#inst"+this.get("id"));return t?(M.core.dock.ensureMoveToIconExists(t),t.hasClass(i.dockonload)&&(t.removeClass(i.dockonload),this.moveToDock()),this.skipsetposition=!1,!0):!1},_getBlockClass:function(t){var n=t.getData("block"),r,i;return e.Lang.isString(n)&&n!==""?n:(r=t.getAttribute
4 ("className").toString(),i=/(^| )block_([^ ]+)/.exec(r),i?i[2]:i)},moveToDock:function(t){t&&t.halt(!0);var n=M.core.dock.get(),r=this.get("id"),i=e.one("#inst"+r).one(".content"),s=window.right_to_left()?"t/dock_to_block_rtl":"t/dock_to_block",o=location.href.match(/\?/)?"&":"?",u,a,f,c;if(!i)return;this.recordBlockState(),u=this.cachedcontentnode.one(".title h2").cloneNode(!0),a=this.cachedcontentnode.one(".title .commands"),a?a=a.cloneNode(!0):a=e.Node.create('<div class="commands"></div>'),f=e.Node.create("<img />").setAttrs({alt:e.Escape.html(M.util.get_string("undockitem","block")),title:e.Escape.html(M.util.get_string("undockblock","block",u.get("innerHTML"))),src:M.util.image_url(s,"moodle")}),c=e.Node.create('<a class="moveto customcommand requiresjs"></a>').setAttrs({href:e.config.win.location.href+o+"dock="+r}),c.append(f),a.append(c.append(f)),this.dockitem=new l({block:this,dock:n,blockinstanceid:r,title:u,contents:i,commands:a,blockclass:this._getBlockClass(e.one("#inst"+r))}),n.add(this.dockitem),this.skipsetposition||M.util.set_user_preference("docked_block_instance_"+r,1),this.set("isDocked",!0)},recordBlockState:function(){var t=this.get("id"),n=M.core.dock.get(),r=e.one("#inst"+t),i=r.previous();i.hasClass("skip-block")&&(this.contentskipanchor=i,this.contentskipanchor.hide()),this.cachedcontentnode=r,this.contentplaceholder=e.Node.create('<div class="block_dock_placeholder"></div>'),r.replace(this.contentplaceholder),n.addToHoldingArea(r),r=null},returnToPage:function(){var e=this.get("id");return this.contentskipanchor&&this.contentskipanchor.show(),this.cachedcontentnode.one(".header")?this.cachedcontentnode.one(".header").insert(this.dockitem.get("contents"),"after"):this.cachedcontentnode.insert(this.dockitem.get("contents")),this.contentplaceholder.replace(this.cachedcontentnode),this.cachedcontentnode=null,M.util.set_user_preference("docked_block_instance_"+e,0),this.set("isDocked",!1),!0}},e.extend(f,e.Base,f.prototype,{NAME:"moodle-core-dock-block",ATTRS:{id:{writeOnce:"initOnly",setter:function(e){return parseInt(e,10)}},isDocked:{value:!1}}}),l=function(){l.superclass.constructor.apply(this,arguments)},l.prototype={active:!1,initializer:function(){var t=this.get("title"),n,r;this.publish("dockeditem:drawstart",{prefix:"dockeditem"}),this.publish("dockeditem:drawcomplete",{prefix:"dockeditem"}),this.publish("dockeditem:showstart",{prefix:"dockeditem"}),this.publish("dockeditem:showcomplete",{prefix:"dockeditem"}),this.publish("dockeditem:hidestart",{prefix:"dockeditem"}),this.publish("dockeditem:hidecomplete",{prefix:"dockeditem"}),this.publish("dockeditem:itemremoved",{prefix:"dockeditem"}),t&&(r=t.get("nodeName"),n=t.cloneNode(!0),t=e.Node.create("<"+r+"></"+r+">"),t=M.core.dock.fixTitleOrientation(t,n.get("text")),this.set("title",t),this.set("titlestring",n))},draw:function(){var t=e.Node.create,n=this.get("dock"),r=n.count,s,o,u,a,f=this.get("id");return this.fire("dockeditem:drawstart"),s=t('<div id="dock_item_'+f+'_title" role="menu" aria-haspopup="true" class="'+i.dockedtitle+'"></div>'),s.append(this.get("title")),o=t('<div id="dock_item_'+f+'" class="'+i.dockeditem+'" tabindex="0" rel="'+f+'"></div>'),r===1&&o.addClass("firstdockitem"),o.append(s),n.append(o),a=t('<img alt="'+M.util.get_string("hidepanel","block")+'" title="'+M.util.get_string("hidedockpanel","block")+'" />'),a.setAttribute("src",M.util.image_url("t/dockclose","moodle")),u=t('<span class="hidepanelicon" tabindex="0"></span>').append(a),u.on("forceclose|click",this.hide,this),u.on("dock:actionkey",this.hide,this,{actions:{enter:!0,toggle:!0}}),this.get("commands").append(u),this.set("dockTitleNode",s),this.set("dockItemNode",o),this.fire("dockeditem:drawcomplete"),!0},show:function(){var t=this.get("dock"),n=t.getPanel(),r=this.get("dockTitleNode");return t.hideActive(),this.fire("dockeditem:showstart"),n.setHeader(this.get("titlestring"),this.get("commands")),n.setBody(e.Node.create('<div class="block_'+this.get("blockclass")+' block_docked"></div>').append(this.get("contents"))),M.core.actionmenu!==undefined&&M.core.actionmenu.newDOMNode(n.get("node")),n.show(),n.correctWidth(),this.active=!0,r.addClass(i.activeitem),r.set("aria-expanded","true"),this.fire("dockeditem:showcomplete"),t.resize(),!0},hide:function(){this.fire("dockeditem:hidestart"),this.active&&(this.active=!1,this.get("dock").getPanel().hide()),this.get("dockTitleNode").removeClass(i.activeitem).set("aria-expanded","false"),this.fire("dockeditem:hidecomplete")},toggle:function(e){var t=this.get("dockTitleNode");t.hasClass(i.activeitem)&&e!=="expand"?this.hide():!t.hasClass(i.activeitem)&&e!=="collapse"&&this.show()},remove:function(){this.hide(),this.get("block").returnToPage(),this.get("dockItemNode").remove(),this.fire("dockeditem:itemremoved")},_getLogDescription:function(){return this.get("titlestring").get("innerHTML")+" ("+this.get("blockinstanceid")+")"}},e.extend(l,e.Base,l.prototype,{NAME:"moodle-core-dock-dockeditem",ATTRS:{block:{writeOnce:"initOnly"},dock:{writeOnce:"initOnly"},id:{},blockinstanceid:{writeOnce:"initOnly",setter:function(e){return parseInt(e,10)}},title:{value:null},titlestring:{value:null},contents:{writeOnce:"initOnly"},commands:{writeOnce:"initOnly"},blockclass:{writeOnce:"initOnly"},dockTitleNode:{value:null},dockItemNode:{value:null},dockcontainerNode:{value:null}}}),e.augment(l,e.EventTarget)},"@VERSION@",{requires:["base","node","event-custom","event-mouseenter","event-resize","escape","moodle-core-dock-loader","moodle-core-event"]});