MDL-42452 ActionMenu: Change constrains mechanism to show the entire menu
This commit is contained in:
committed by
Sam Hemelryk
parent
ae3fd8eb76
commit
d248b44c33
@@ -227,16 +227,8 @@ ACTIONMENU.prototype = {
|
||||
|
||||
// Constrain Y.
|
||||
// First up if the width is more than the constrain its easily full width + full height.
|
||||
if (nheight > cheight) {
|
||||
// The width of the constraint.
|
||||
newheight = nheight = cheight;
|
||||
// The constraints xpoint.
|
||||
newtop = ny = cy;
|
||||
} else {
|
||||
if (ny < cy) {
|
||||
// If ny is less than cy we need to move it right.
|
||||
newtop = ny = cy;
|
||||
} else if (ny + nheight > cy + cheight) {
|
||||
if (nheight <= cheight) {
|
||||
if (ny >= cy && ny + nheight > cy + cheight) {
|
||||
// The top right of the node is outside of the constraint, move it in.
|
||||
newtop = cy + cheight - nheight;
|
||||
}
|
||||
@@ -314,4 +306,5 @@ M.core.actionmenu.newDOMNode = function(node) {
|
||||
node.all(SELECTOR.MENU).each(M.core.actionmenu.instance.enhance, M.core.actionmenu.instance);
|
||||
};
|
||||
|
||||
|
||||
}, '@VERSION@', {"requires": ["base", "event"]});
|
||||
|
||||
@@ -1 +1 @@
|
||||
YUI.add("moodle-core-actionmenu",function(e,t){var n=e.one(e.config.doc.body),r={MENUSHOWN:"action-menu-shown"},i={MENU:".moodle-actionmenu[data-enhance=moodle-core-actionmenu]",MENUCONTENT:".menu[data-rel=menu-content]",TOGGLE:".toggle-display"},s,o={TL:"tl",TR:"tr",BL:"bl",BR:"br"};s=function(){s.superclass.constructor.apply(this,arguments)},s.prototype={dialogue:null,events:[],owner:null,initializer:function(){e.all(i.MENU).each(this.enhance,this),n.delegate("click",this.toggleMenu,i.MENU+" "+i.TOGGLE,this),n.delegate("key",this.toggleMenu,"enter,space",i.MENU+" "+i.TOGGLE,this)},enhance:function(e){var t=e.one(i.MENUCONTENT),n;if(!t)return!1;n=t.getData("align")||this.get("align").join("-"),e.one(i.TOGGLE).set("aria-haspopup",!0),t.set("aria-hidden",!0),t.hasClass("align-"+n)||t.addClass("align-"+n),t.hasChildNodes()&&e.setAttribute("data-enhanced","1")},hideMenu:function(){this.dialogue&&(this.dialogue.removeClass("show"),this.dialogue.one(i.MENUCONTENT).set("aria-hidden",!0),this.dialogue=null),this.owner&&(this.owner.removeClass(r.MENUSHOWN),this.owner=null);for(var e in this.events)this.events[e].detach&&this.events[e].detach();this.events=[]},toggleMenu:function(e){var t=e.target.ancestor(i.MENU),r=t.hasClass("show");e.halt(!0),this.hideMenu();if(r)return;this.showMenu(t),this.events.push(n.on("key",this.hideMenu,"esc",this)),this.events.push(n.on("click",this.hideIfOutside,this)),this.events.push(n.delegate("focus",this.hideIfOutside,"*",this))},hideIfOutside:function(e){!e.target.test(i.MENU)&&!e.target.ancestor(i.MENU)&&this.hideMenu()},showMenu:function(e){var t=e.getData("owner"),n=e.one(i.MENUCONTENT);return this.owner=t?e.ancestor(t):null,this.dialogue=e,e.addClass("show"),this.owner&&this.owner.addClass(r.MENUSHOWN),this.constrain(n.set("aria-hidden",!1)),!0},constrain:function(e){var t=e.getData("constraint"),n=e.getX(),r=e.getY(),i=e.get("offsetWidth"),s=e.get("offsetHeight"),o=0,u=0,a,f,l=null,c=null,h=null,p=null;t&&(t=e.ancestor(t)),t?(a=t.get("offsetWidth"),f=t.get("offsetHeight"),o=t.getX(),u=t.getY()):(a=e.get("docWidth"),f=e.get("docHeight")),i>a?(l=i=a,h=n=o):n<o?h=n=o:n+i>=o+a&&(h=o+a-i),s>f?(c=s=f,p=r=u):r<u?p=r=u:r+s>u+f&&(p=u+f-s),h!==null&&e.setX(h),p!==null&&e.setY(p),l!==null&&e.setStyle("width",l.toString()+"px"),c!==null&&e.setStyle("height",c.toString()+"px")}},e.extend(s,e.Base,s.prototype,{NAME:"moodle-core-actionmenu",ATTRS:{align:{value:[o.TR,o.BR]}}}),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 s(e)},M.core.actionmenu.newDOMNode=function(e){if(M.core.actionmenu.instance===null)return!0;e.all(i.MENU).each(M.core.actionmenu.instance.enhance,M.core.actionmenu.instance)}},"@VERSION@",{requires:["base","event"]});
|
||||
YUI.add("moodle-core-actionmenu",function(e,t){var n=e.one(e.config.doc.body),r={MENUSHOWN:"action-menu-shown"},i={MENU:".moodle-actionmenu[data-enhance=moodle-core-actionmenu]",MENUCONTENT:".menu[data-rel=menu-content]",TOGGLE:".toggle-display"},s,o={TL:"tl",TR:"tr",BL:"bl",BR:"br"};s=function(){s.superclass.constructor.apply(this,arguments)},s.prototype={dialogue:null,events:[],owner:null,initializer:function(){e.all(i.MENU).each(this.enhance,this),n.delegate("click",this.toggleMenu,i.MENU+" "+i.TOGGLE,this),n.delegate("key",this.toggleMenu,"enter,space",i.MENU+" "+i.TOGGLE,this)},enhance:function(e){var t=e.one(i.MENUCONTENT),n;if(!t)return!1;n=t.getData("align")||this.get("align").join("-"),e.one(i.TOGGLE).set("aria-haspopup",!0),t.set("aria-hidden",!0),t.hasClass("align-"+n)||t.addClass("align-"+n),t.hasChildNodes()&&e.setAttribute("data-enhanced","1")},hideMenu:function(){this.dialogue&&(this.dialogue.removeClass("show"),this.dialogue.one(i.MENUCONTENT).set("aria-hidden",!0),this.dialogue=null),this.owner&&(this.owner.removeClass(r.MENUSHOWN),this.owner=null);for(var e in this.events)this.events[e].detach&&this.events[e].detach();this.events=[]},toggleMenu:function(e){var t=e.target.ancestor(i.MENU),r=t.hasClass("show");e.halt(!0),this.hideMenu();if(r)return;this.showMenu(t),this.events.push(n.on("key",this.hideMenu,"esc",this)),this.events.push(n.on("click",this.hideIfOutside,this)),this.events.push(n.delegate("focus",this.hideIfOutside,"*",this))},hideIfOutside:function(e){!e.target.test(i.MENU)&&!e.target.ancestor(i.MENU)&&this.hideMenu()},showMenu:function(e){var t=e.getData("owner"),n=e.one(i.MENUCONTENT);return this.owner=t?e.ancestor(t):null,this.dialogue=e,e.addClass("show"),this.owner&&this.owner.addClass(r.MENUSHOWN),this.constrain(n.set("aria-hidden",!1)),!0},constrain:function(e){var t=e.getData("constraint"),n=e.getX(),r=e.getY(),i=e.get("offsetWidth"),s=e.get("offsetHeight"),o=0,u=0,a,f,l=null,c=null,h=null,p=null;t&&(t=e.ancestor(t)),t?(a=t.get("offsetWidth"),f=t.get("offsetHeight"),o=t.getX(),u=t.getY()):(a=e.get("docWidth"),f=e.get("docHeight")),i>a?(l=i=a,h=n=o):n<o?h=n=o:n+i>=o+a&&(h=o+a-i),s<=f&&r>=u&&r+s>u+f&&(p=u+f-s),h!==null&&e.setX(h),p!==null&&e.setY(p),l!==null&&e.setStyle("width",l.toString()+"px"),c!==null&&e.setStyle("height",c.toString()+"px")}},e.extend(s,e.Base,s.prototype,{NAME:"moodle-core-actionmenu",ATTRS:{align:{value:[o.TR,o.BR]}}}),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 s(e)},M.core.actionmenu.newDOMNode=function(e){if(M.core.actionmenu.instance===null)return!0;e.all(i.MENU).each(M.core.actionmenu.instance.enhance,M.core.actionmenu.instance)}},"@VERSION@",{requires:["base","event"]});
|
||||
|
||||
@@ -224,16 +224,8 @@ ACTIONMENU.prototype = {
|
||||
|
||||
// Constrain Y.
|
||||
// First up if the width is more than the constrain its easily full width + full height.
|
||||
if (nheight > cheight) {
|
||||
// The width of the constraint.
|
||||
newheight = nheight = cheight;
|
||||
// The constraints xpoint.
|
||||
newtop = ny = cy;
|
||||
} else {
|
||||
if (ny < cy) {
|
||||
// If ny is less than cy we need to move it right.
|
||||
newtop = ny = cy;
|
||||
} else if (ny + nheight > cy + cheight) {
|
||||
if (nheight <= cheight) {
|
||||
if (ny >= cy && ny + nheight > cy + cheight) {
|
||||
// The top right of the node is outside of the constraint, move it in.
|
||||
newtop = cy + cheight - nheight;
|
||||
}
|
||||
@@ -311,4 +303,5 @@ M.core.actionmenu.newDOMNode = function(node) {
|
||||
node.all(SELECTOR.MENU).each(M.core.actionmenu.instance.enhance, M.core.actionmenu.instance);
|
||||
};
|
||||
|
||||
|
||||
}, '@VERSION@', {"requires": ["base", "event"]});
|
||||
|
||||
+3
-11
@@ -225,16 +225,8 @@ ACTIONMENU.prototype = {
|
||||
|
||||
// Constrain Y.
|
||||
// First up if the width is more than the constrain its easily full width + full height.
|
||||
if (nheight > cheight) {
|
||||
// The width of the constraint.
|
||||
newheight = nheight = cheight;
|
||||
// The constraints xpoint.
|
||||
newtop = ny = cy;
|
||||
} else {
|
||||
if (ny < cy) {
|
||||
// If ny is less than cy we need to move it right.
|
||||
newtop = ny = cy;
|
||||
} else if (ny + nheight > cy + cheight) {
|
||||
if (nheight <= cheight) {
|
||||
if (ny >= cy && ny + nheight > cy + cheight) {
|
||||
// The top right of the node is outside of the constraint, move it in.
|
||||
newtop = cy + cheight - nheight;
|
||||
}
|
||||
@@ -310,4 +302,4 @@ M.core.actionmenu.newDOMNode = function(node) {
|
||||
return true;
|
||||
}
|
||||
node.all(SELECTOR.MENU).each(M.core.actionmenu.instance.enhance, M.core.actionmenu.instance);
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user