Permalink
Browse files

Merge pull request #22 from sfeast/master

Resize handler for menus & inheriting kinds (such as Picker) (ENYO-508)

Reviewed-By: Ben Combee (ben.combee@palm.com)
  • Loading branch information...
2 parents 7456721 + b6289a5 commit 66206eea1f3b1dfbcaf72306d828ad20a6fc57cb @unwiredben unwiredben committed Jun 20, 2012
Showing with 36 additions and 10 deletions.
  1. +32 −10 source/Menu.js
  2. +4 −0 source/Picker.js
View
@@ -19,16 +19,7 @@ enyo.kind({
},
showingChanged: function() {
this.inherited(arguments);
- if (this.showing && this.hasNode()) {
- this.removeClass("onyx-menu-up");
- var b = this.node.getBoundingClientRect();
- this.menuUp = b.top + b.height > window.innerHeight;
- this.addRemoveClass("onyx-menu-up", this.menuUp);
- if (this.floating && this.menuUp) {
- var r = this.activatorOffset;
- this.applyPosition({top: (r.top - b.height + r.height), bottom: "auto"});
- }
- }
+ this.adjustPosition(true);
},
requestMenuShow: function(inSender, inEvent) {
if (this.floating) {
@@ -52,5 +43,36 @@ enyo.kind({
// getBoundingClientRect returns top/left values which are relative to the viewport and not absolute
var r = inNode.getBoundingClientRect();
return {top: r.top + window.pageYOffset, left: r.left + window.pageXOffset, height: r.height, width: r.width};
+ },
+ //* @protected
+ /* Adjusts the menu position to fit inside the current window size.
+ belowActivator determines whether to position the top of the menu below or on top of the activator
+ */
+ adjustPosition: function(belowActivator) {
+ if (this.showing && this.hasNode()) {
+ this.removeClass("onyx-menu-up");
+ var b = this.node.getBoundingClientRect();
+ this.menuUp = b.top + b.height > window.innerHeight;
+ this.addRemoveClass("onyx-menu-up", this.menuUp);
+
+ if (this.floating) {
+ var r = this.activatorOffset;
+ //if the menu doesn't fit below the activator, move it up
+ if (this.menuUp) {
+ this.applyPosition({top: (r.top - b.height + r.height), bottom: "auto"});
+ }
+ else {
+ //if the top of the menu is above the top of the activator and there's room to move it down, do so
+ if ((b.top < r.top) && (r.top + (belowActivator ? r.height : 0) + b.height < window.innerHeight))
+ {
+ this.applyPosition({top: r.top + (this.showOnTop ? 0 : r.height), bottom: "auto"});
+ }
+ }
+ }
+ }
+ },
+ resizeHandler: function() {
+ this.inherited(arguments);
+ this.adjustPosition(true);
}
});
View
@@ -52,5 +52,9 @@ enyo.kind({
this.selected.addClass("selected");
this.doSelect({selected: this.selected, content: this.selected.content});
}
+ },
+ resizeHandler: function() {
+ this.inherited(arguments);
+ this.adjustPosition(false);
}
});

0 comments on commit 66206ee

Please sign in to comment.