autocomplete, continued

This commit is contained in:
Rolux 2010-02-18 20:12:53 +05:30
parent 1037fa5e5c
commit f71f0ac5ee

View File

@ -1625,6 +1625,11 @@ requires
} }
} }
}, 50); }, 50);
/*
if (event.keyCode == 38 || event.keyCode == 40) {
return false;
}
*/
} }
function onClick(event, data) { function onClick(event, data) {
Ox.print("onClick", data) Ox.print("onClick", data)
@ -1632,7 +1637,7 @@ requires
self.menu.hideMenu(); self.menu.hideMenu();
} }
function onDeselect(event, data) { function onDeselect(event, data) {
that.val(""); that.val(self.value);
} }
function onSelect(event, data) { function onSelect(event, data) {
self.value = that.val().substr(0, selection()[0]); self.value = that.val().substr(0, selection()[0]);
@ -2623,38 +2628,46 @@ requires
}; };
that.showMenu = function() { that.showMenu = function() {
Ox.print("showMenu") Ox.print("showMenu");
if (!self.options.parent && !that.$layer.parent().length) { if (!self.options.parent && !that.$layer.parent().length) {
that.$layer.appendTo($body); that.$layer.appendTo($body);
} }
that.parent().length || that.appendTo($body); that.parent().length || that.appendTo($body);
that.css({
left: "-1000px",
top: "-1000px",
}).show();
var offset = self.options.element.offset(), var offset = self.options.element.offset(),
width = self.options.element.outerWidth(), width = self.options.element.outerWidth(),
height = self.options.element.outerHeight(), height = self.options.element.outerHeight(),
left = offset.left + self.options.offset.left + (self.options.side == "bottom" ? 0 : width), left = offset.left + self.options.offset.left + (self.options.side == "bottom" ? 0 : width),
top = offset.top + self.options.offset.top + (self.options.side == "bottom" ? height : 0), top = offset.top + self.options.offset.top + (self.options.side == "bottom" ? height : 0),
menuHeight = that.$content.outerHeight(); menuHeight = that.$content.outerHeight(); // fixme: why is outerHeight 0 when hidden?
menuMaxHeight = Math.floor($window.height() - top - 16), menuMaxHeight = Math.floor($window.height() - top - 16),
Ox.print("menuHeight", menuHeight, "menuMaxHeight", menuMaxHeight); Ox.print("menuHeight", menuHeight, "menuMaxHeight", menuMaxHeight, that.items.length);
if (self.options.parent) { if (self.options.parent) {
if (menuHeight > menuMaxHeight) { if (menuHeight > menuMaxHeight) {
top = Ox.limit(top - menuHeight + menuMaxHeight, self.options.parent.offset().top, top); top = Ox.limit(top - menuHeight + menuMaxHeight, self.options.parent.offset().top, top);
menuMaxHeight = Math.floor($window.height() - top - 16); menuMaxHeight = Math.floor($window.height() - top - 16);
} }
} }
/*
that.css({ that.css({
left: left + "px", left: left + "px",
top: top + "px" top: top + "px"
}).show(); }).show();
*/
that.css({
left: left + "px",
top: top + "px"
});
if (menuHeight > menuMaxHeight) { if (menuHeight > menuMaxHeight) {
that.$container.height(menuMaxHeight - itemHeight - 8); // margin that.$container.height(menuMaxHeight - itemHeight - 8); // margin
that.$scrollbars.down.show(); that.$scrollbars.down.show();
} else { } else {
that.$container.height(menuHeight); that.$container.height(menuHeight);
} }
if (!self.options.parent) { !self.options.parent && that.gainFocus();
that.gainFocus();
}
that.bindEvent({ that.bindEvent({
key_up: selectPreviousItem, key_up: selectPreviousItem,
key_down: selectNextItem, key_down: selectNextItem,