refactor and add public updatePosition method
This commit is contained in:
parent
c36243d31c
commit
17f4c87439
1 changed files with 42 additions and 31 deletions
|
@ -587,6 +587,39 @@ Ox.Menu = function(options, self) {
|
|||
}
|
||||
}
|
||||
|
||||
function setCSS() {
|
||||
var offset = self.options.element.offset(),
|
||||
width = self.options.element.outerWidth(),
|
||||
height = self.options.element.outerHeight(),
|
||||
menuWidth = that.width(),
|
||||
windowWidth = Ox.$window.width(),
|
||||
windowHeight = Ox.$window.height(),
|
||||
left = offset.left + self.options.offset.left + (self.options.edge == 'bottom' ? 0 : width),
|
||||
top = offset.top + self.options.offset.top + (self.options.edge == 'bottom' ? height : 0),
|
||||
menuHeight = that.$content.outerHeight(), // fixme: why is outerHeight 0 when hidden?
|
||||
menuMaxHeight = Math.floor(Ox.$window.height() - top - 16);
|
||||
if (self.options.edge == 'bottom' && left + menuWidth > windowWidth) {
|
||||
left = offset.left + width - menuWidth;
|
||||
that.is('.OxRight') && that.removeClass('OxRight') && that.addClass('OxLeft');
|
||||
}
|
||||
if (self.options.parent) {
|
||||
if (menuHeight > menuMaxHeight) {
|
||||
top = Ox.limit(top - menuHeight + menuMaxHeight, self.options.parent.offset().top, top);
|
||||
menuMaxHeight = Math.floor(windowHeight - top - 16);
|
||||
}
|
||||
}
|
||||
that.css({
|
||||
left: left + 'px',
|
||||
top: top + 'px'
|
||||
});
|
||||
if (menuHeight > menuMaxHeight) {
|
||||
that.$container.height(menuMaxHeight - self.itemHeight - 8); // margin
|
||||
that.$scrollbars.down.show();
|
||||
} else {
|
||||
that.$container.height(menuHeight);
|
||||
}
|
||||
}
|
||||
|
||||
/*@
|
||||
addItem <f>
|
||||
@*/
|
||||
|
@ -639,6 +672,7 @@ Ox.Menu = function(options, self) {
|
|||
} else {
|
||||
that.submenus[ids.shift()].checkItem(ids.join('_'));
|
||||
}
|
||||
return that;
|
||||
};
|
||||
|
||||
/*@
|
||||
|
@ -647,6 +681,7 @@ Ox.Menu = function(options, self) {
|
|||
@*/
|
||||
that.clickItem = function(position, files) {
|
||||
clickItem(position, files);
|
||||
return that;
|
||||
};
|
||||
|
||||
/*@
|
||||
|
@ -793,37 +828,7 @@ Ox.Menu = function(options, self) {
|
|||
left: '-1000px',
|
||||
top: '-1000px'
|
||||
}).show();
|
||||
var offset = self.options.element.offset(),
|
||||
width = self.options.element.outerWidth(),
|
||||
height = self.options.element.outerHeight(),
|
||||
menuWidth = that.width(),
|
||||
windowWidth = Ox.$window.width(),
|
||||
windowHeight = Ox.$window.height(),
|
||||
left = offset.left + self.options.offset.left + (self.options.edge == 'bottom' ? 0 : width),
|
||||
right,
|
||||
top = offset.top + self.options.offset.top + (self.options.edge == 'bottom' ? height : 0),
|
||||
menuHeight = that.$content.outerHeight(), // fixme: why is outerHeight 0 when hidden?
|
||||
menuMaxHeight = Math.floor(Ox.$window.height() - top - 16);
|
||||
if (self.options.edge == 'bottom' && left + menuWidth > windowWidth) {
|
||||
left = offset.left + width - menuWidth;
|
||||
that.is('.OxRight') && that.removeClass('OxRight') && that.addClass('OxLeft');
|
||||
}
|
||||
if (self.options.parent) {
|
||||
if (menuHeight > menuMaxHeight) {
|
||||
top = Ox.limit(top - menuHeight + menuMaxHeight, self.options.parent.offset().top, top);
|
||||
menuMaxHeight = Math.floor(windowHeight - top - 16);
|
||||
}
|
||||
}
|
||||
that.css({
|
||||
left: left + 'px',
|
||||
top: top + 'px'
|
||||
});
|
||||
if (menuHeight > menuMaxHeight) {
|
||||
that.$container.height(menuMaxHeight - self.itemHeight - 8); // margin
|
||||
that.$scrollbars.down.show();
|
||||
} else {
|
||||
that.$container.height(menuHeight);
|
||||
}
|
||||
setCSS();
|
||||
if (!self.options.parent) {
|
||||
that.gainFocus();
|
||||
that.$layer = Ox.Layer({type: 'menu'})
|
||||
|
@ -848,6 +853,12 @@ Ox.Menu = function(options, self) {
|
|||
@*/
|
||||
that.uncheckItem = function(id) {
|
||||
that.checkItem(id, false);
|
||||
return that;
|
||||
};
|
||||
|
||||
that.updatePosition = function() {
|
||||
setCSS();
|
||||
return that;
|
||||
};
|
||||
|
||||
return that;
|
||||
|
|
Loading…
Reference in a new issue