AutorÃa | Ultima modificación | Ver Log |
YUI.add("moodle-core-actionmenu",function(e,t){var s=e.one(e.config.doc.body),o="action-menu-shown",a={CAN_RECEIVE_FOCUS_SELECTOR:'input:not([type="hidden"]), a[href], button, textarea, select, [tabindex]',MENU:".moodle-actionmenu[data-enhance=moodle-core-actionmenu]",MENUBAR:'[role="menubar"]',MENUITEM:'[role="menuitem"]',MENUCONTENT:".menu[data-rel=menu-content]",MENUCONTENTCHILD:"li a",MENUCHILD:".menu li a",TOGGLE:".toggle-display",KEEPOPEN:'[data-keepopen="1"]',MENUBARITEMS:['[role="menubar"] > [role="menuitem"]','[role="menubar"] > [role="presentation"] > [role="menuitem"]'],MENUITEMS:['> [role="menuitem"]','> [role="presentation"] > [role="menuitem"]']},n="tr",i="br",u=function(){u.superclass.constructor.apply(this,arguments)};e.extend(u,e.Base,u.prototype={dialogue:null,events:[],owner:null,menulink:null,menuChildren:null,firstMenuChild:null,lastMenuChild:null,initializer:function(){e.all(a.MENU).each(this.enhance,this),s.delegate("key",this.moveMenuItem,"down:37,39",a.MENUBARITEMS.join(","),this),s.
delegate("click",this.toggleMenu,a.MENU+" "+a.TOGGLE,this),s.delegate("key",this.showIfHidden,"down:enter,38,40",a.MENU+" "+a.TOGGLE,this),s.delegate("key",function(e){e.currentTarget.simulate("click"),e.preventDefault()},"down:32",a.MENUBARITEMS.join(","))},enhance:function(e){var t,n=e.one(a.MENUCONTENT);if(!n)return!1;t=n.getData("align")||this.get("align").join("-"),e.one(a.TOGGLE).set("aria-haspopup",!0),n.set("aria-hidden",!0),n.hasClass("align-"+t)||n.addClass("align-"+t),n.getDOMNode().childElementCount&&e.setAttribute("data-enhanced","1")},moveMenuItem:function(e){var t,n=e.target.ancestor(a.MENUITEM,!0);return 37===e.keyCode?t=this.getMenuItem(n,!0):39===e.keyCode&&(t=this.getMenuItem(n)),t&&t.focus(),this},getMenuItem:function(e,t){var n,i,s,o,u,h=e.ancestor(a.MENUBAR);if(!h)return null;if(!(n=h.all(a.MENUITEMS.join(","))))return null;if(1===(s=n.size()))return null;for(u=1,o=o=0;o<s&&n.item(o)!==e;o++);if(n.item(o)!==e)return null;for(t&&(u=-1);(i=n.item(o+=u))&&i.hasAttribute("hidden"););return
i},hideMenu:function(e){for(var t in this.dialogue&&(this.dialogue.removeClass("show"),this.dialogue.one(a.MENUCONTENT).set("aria-hidden",!0),this.dialogue=null),this.events)this.events[t].detach&&this.events[t].detach();this.events=[],this.owner&&(this.owner.removeClass(o),this.owner=null),this.menulink&&("click"!=e.type&&this.menulink.focus(),this.menulink=null)},showIfHidden:function(e){var t=e.target.ancestor(a.MENU);return t.hasClass("show")||(e.preventDefault(),this.showMenu(e,t)),this},toggleMenu:function(e){var t=e.target.ancestor(a.MENU),n=t.hasClass("show");e.halt(!0),this.hideMenu(e),n||this.showMenu(e,t)},handleKeyboardEvent:function(e){var t,n,i,s,o,u=function(e){e.preventDefault(),e.stopPropagation()};if(e.currentTarget.ancestor(a.TOGGLE,!0))return(40===e.keyCode||9===e.keyCode&&!e.shiftKey)&&this.firstMenuChild?(this.firstMenuChild.focus(),u(e)):38===e.keyCode&&this.lastMenuChild?(this.lastMenuChild.focus(),u(e)):9===e.keyCode&&e.shiftKey&&(this.hideMenu(e),u(e)),this;if(27===e.keyCode)this.hi
deMenu(e),u(e);else if(32===e.keyCode)u(e),e.currentTarget.simulate("click");else if(9===e.keyCode)e.target===this.firstMenuChild&&e.shiftKey?(this.hideMenu(e),u(e)):e.target!==this.lastMenuChild||e.shiftKey||this.hideMenu(e)&&(t=this.menulink.next(a.CAN_RECEIVE_FOCUS_SELECTOR))&&(t.focus(),u(e));else if(38===e.keyCode||40===e.keyCode){for(n=!1,s=1,o=i=0;!n&&i<this.menuChildren.size();)this.menuChildren.item(i)===e.currentTarget?n=!0:i++;if(n){for(38===e.keyCode&&(s=-1);(i+=s)<0?i=this.menuChildren.size()-1:i>=this.menuChildren.size()&&(i=0),t=this.menuChildren.item(i),++o<this.menuChildren.size()&&t!==e.currentTarget&&t.hasClass("hidden"););t&&(t.focus(),u(e))}}},hideIfOutside:function(e){e.target.ancestor(a.MENUCONTENT,!0)||this.hideMenu(e)},showMenu:function(e,t){var n=t.getData("owner"),i=t.one(a.MENUCONTENT);return this.owner=n?t.ancestor(n):null,(this.dialogue=t).addClass("show"),this.owner?(this.owner.addClass(o),this.menulink=this.owner.one(a.TOGGLE)):this.menulink=e.target.ancestor(a.TOGGLE,!0),this
.constrain(i.set("aria-hidden",!1)),this.menuChildren=this.dialogue.all(a.MENUCHILD),0<this.menuChildren.size()&&(this.firstMenuChild=this.menuChildren.item(0),this.lastMenuChild=this.menuChildren.item(this.menuChildren.size()-1),this.firstMenuChild.focus()),this.events.push(s.on("key",this.hideMenu,"esc",this)),this.events.push(s.on("click",this.hideIfOutside,this)),this.events.push(s.delegate("focus",this.hideIfOutside,"*",this)),this.events.push(t.delegate("key",this.handleKeyboardEvent,"down:9, 27, 38, 40, 32",a.MENUCHILD+", "+a.TOGGLE,this)),this.events.push(t.delegate("click",function(e){e.currentTarget.test(a.KEEPOPEN)||this.hideMenu(e)},a.MENUCHILD,this)),!0},constrain:function(e){var t,n,i,s=e.getData("constraint"),o=e.getX(),r=e.getY(),d=e.get("offsetWidth"),c=e.get("offsetHeight"),u=0,h=0,M="auto",m=null,f=null,a=null,l=null;if((s=s&&e.ancestor(s))?(t=s.get("offsetWidth"),n=s.get("offsetHeight"),u=s.getX(),h=s.getY(),M=s.getStyle("overflow")||"auto"):(t=e.get("docWidth"),n=e.get("docHeight")),t<d?
(m=d=t,a=o=u):o<u?a=o=u:u+t<=o+d&&(a=u+t-d),n<c&&"hidden"===M.toLowerCase()&&(f=c=n,e.setStyle("overflow","auto")),h<=r&&h+n<r+c){l=h+n-c;try{i=e.getStyle("boxShadow").replace(/.*? (\d+)px \d+px$/,"$1"),new RegExp(/^\d+$/).test(i)&&i<l-h&&(l-=i)}catch(E){}}null!==a&&e.setX(a),null!==l&&e.setY(l),null!==m&&e.setStyle("width",m.toString()+"px"),null!==f&&e.setStyle("height",f.toString()+"px")}},{NAME:"moodle-core-actionmenu",ATTRS:{align:{value:[n,i]}}}),M.core=M.core||{},M.core.actionmenu=M.core.actionmenu||{},M.core.actionmenu.instance=null,M.core.actionmenu.init=M.core.actionmenu.init||function(e){M.core.actionmenu.instance=M.core.actionmenu.instance||new u(e)},M.core.actionmenu.newDOMNode=function(e){if(null===M.core.actionmenu.instance)return!0;e.all(a.MENU).each(M.core.actionmenu.instance.enhance,M.core.actionmenu.instance)}},"@VERSION@",{requires:["base","event",
"node-event-simulate"]});