fixing bug in focus manager that would cause keyboard events to be bound twice
This commit is contained in:
parent
6c92221b50
commit
7000763be4
|
@ -212,23 +212,23 @@ requires
|
|||
}
|
||||
return {
|
||||
bind: function(id, event, callback) {
|
||||
Ox.print("a.l", arguments.length, id, event)
|
||||
if (arguments.length == 2) {
|
||||
callback = event;
|
||||
event = id;
|
||||
Ox.print("e,c", event, callback)
|
||||
}
|
||||
if (isKeyboardEvent(event)) {
|
||||
keyboardEvents[id] = keyboardEvents[id] || {};
|
||||
keyboardEvents[id][event] = callback;
|
||||
}
|
||||
if (!isKeyboardEvent(event) || Ox.Focus.focused() == id) {
|
||||
Ox.print("bind", id, event)
|
||||
$eventHandler.bind(event, callback);
|
||||
}
|
||||
},
|
||||
bindKeyboard: function(id) {
|
||||
$.each(keyboardEvents[id] || [], function(event, callback) {
|
||||
Ox.Event.bind(id, event, callback);
|
||||
//$eventHandler.bind(event, callback);
|
||||
});
|
||||
},
|
||||
trigger: function(event, data) {
|
||||
|
@ -244,17 +244,19 @@ requires
|
|||
}
|
||||
});
|
||||
}
|
||||
Ox.print("unbind", id, event)
|
||||
$eventHandler.unbind(event, callback);
|
||||
},
|
||||
unbindKeyboard: function(id) {
|
||||
$.each(keyboardEvents[id] || [], function(event, callback) {
|
||||
Ox.print("unbind", id, event)
|
||||
$eventHandler.unbind(event, callback);
|
||||
});
|
||||
}
|
||||
}
|
||||
}();
|
||||
|
||||
Ox.Event_ = function() {
|
||||
Ox.Event_ = function() { // unused
|
||||
var events = {};
|
||||
return {
|
||||
// make these bind, trigger, unbind
|
||||
|
@ -294,13 +296,13 @@ requires
|
|||
var stack = [];
|
||||
return {
|
||||
blur: function(id) {
|
||||
if (stack.indexOf(id) > -1) {
|
||||
if (stack.indexOf(id) == stack.length - 1) {
|
||||
$elements[Ox.Focus.focused()].removeClass("OxFocus");
|
||||
$(".OxFocus").removeClass("OxFocus"); // fixme: the above is better, and should work
|
||||
stack.splice(stack.length - 2, 0, stack.pop());
|
||||
Ox.Event.unbindKeyboard(id);
|
||||
Ox.Event.bindKeyboard(stack[stack.length - 1]);
|
||||
Ox.print("blur", stack);
|
||||
Ox.print("blur", id, stack);
|
||||
}
|
||||
},
|
||||
focus: function(id) {
|
||||
|
@ -314,7 +316,7 @@ requires
|
|||
stack.push(id);
|
||||
$elements[Ox.Focus.focused()].addClass("OxFocus");
|
||||
Ox.Event.bindKeyboard(id);
|
||||
Ox.print("focus", stack);
|
||||
Ox.print("focus", id, stack);
|
||||
},
|
||||
focused: function() {
|
||||
return stack[stack.length - 1];
|
||||
|
@ -2341,6 +2343,7 @@ requires
|
|||
}
|
||||
});
|
||||
|
||||
Ox.print(self.options.id)
|
||||
that.$button = new Ox.Button($.extend(self.options, {
|
||||
id: self.buttonId,
|
||||
type: "text", // fixme: this shouldn't be necessary
|
||||
|
@ -2679,6 +2682,7 @@ requires
|
|||
if (!Ox.isUndefined(self.$items[pos])) {
|
||||
self.$items[pos].addClass("OxSelected");
|
||||
}
|
||||
Ox.print("addToSelection")
|
||||
that.triggerEvent("select", {
|
||||
ids: $.map(self.selected, function(v, i) {
|
||||
return self.ids[v];
|
||||
|
@ -3249,8 +3253,6 @@ requires
|
|||
|
||||
// Body
|
||||
|
||||
Ox.print("s.vC", self.visibleColumns);
|
||||
|
||||
that.$body = new Ox.List({
|
||||
construct: constructItem,
|
||||
id: self.options.id,
|
||||
|
@ -3702,6 +3704,15 @@ requires
|
|||
$item; // fixme: used?
|
||||
// fixme: attach all private vars to self?
|
||||
|
||||
self.keyboardEvents = {
|
||||
key_up: selectPreviousItem,
|
||||
key_down: selectNextItem,
|
||||
key_left: selectSupermenu,
|
||||
key_right: selectSubmenu,
|
||||
key_escape: hideMenu,
|
||||
key_enter: clickSelectedItem
|
||||
};
|
||||
|
||||
// construct
|
||||
that.items = [];
|
||||
that.submenus = {};
|
||||
|
@ -3747,6 +3758,7 @@ requires
|
|||
var item = that.items[position];
|
||||
if (!item.options("items").length) {
|
||||
if (that.options("parent")) {
|
||||
Ox.print("t.o.p", that.options("parent"))
|
||||
that.options("parent").hideMenu().triggerEvent("click");
|
||||
}
|
||||
if (item.options("checked") !== null && (!item.options("group") || !item.options("checked"))) {
|
||||
|
@ -3882,6 +3894,11 @@ requires
|
|||
return $("#" + Ox.toCamelCase(options.id + "/" + id));
|
||||
}
|
||||
|
||||
function hideMenu() {
|
||||
// called on key_escape
|
||||
that.hideMenu();
|
||||
}
|
||||
|
||||
function isFirstEnabledItem() {
|
||||
var ret = true;
|
||||
$.each(that.items, function(i, item) {
|
||||
|
@ -3987,6 +4004,7 @@ requires
|
|||
function selectNextItem() {
|
||||
var offset,
|
||||
selected = self.options.selected;
|
||||
Ox.print("sNI", selected)
|
||||
if (!isLastEnabledItem()) {
|
||||
if (selected == -1) {
|
||||
scrollMenuUp();
|
||||
|
@ -4020,6 +4038,7 @@ requires
|
|||
function selectPreviousItem() {
|
||||
var offset,
|
||||
selected = self.options.selected;
|
||||
Ox.print("sPI", selected)
|
||||
if (selected > - 1) {
|
||||
if (!isFirstEnabledItem()) {
|
||||
that.items[selected].removeClass("OxSelected");
|
||||
|
@ -4046,6 +4065,7 @@ requires
|
|||
}
|
||||
|
||||
function selectSubmenu() {
|
||||
Ox.print("selectSubmenu", self.options.selected)
|
||||
if (self.options.selected > -1) {
|
||||
var submenu = that.submenus[that.items[self.options.selected].options("id")];
|
||||
if (submenu && submenu.hasEnabledItems()) {
|
||||
|
@ -4060,6 +4080,7 @@ requires
|
|||
}
|
||||
|
||||
function selectSupermenu() {
|
||||
Ox.print("selectSupermenu", self.options.selected)
|
||||
if (self.options.parent) {
|
||||
that.items[self.options.selected].trigger("mouseleave");
|
||||
self.options.parent.gainFocus();
|
||||
|
@ -4129,14 +4150,7 @@ requires
|
|||
}
|
||||
that.hide()
|
||||
.loseFocus()
|
||||
.unbindEvent({
|
||||
key_up: selectPreviousItem,
|
||||
key_down: selectNextItem,
|
||||
key_left: selectSupermenu,
|
||||
key_right: selectSubmenu,
|
||||
key_escape: that.hideMenu,
|
||||
key_enter: clickItem
|
||||
})
|
||||
.unbindEvent(self.keyboardEvents)
|
||||
.triggerEvent("hide");
|
||||
that.$layer.hide();
|
||||
$document.unbind("click", click);
|
||||
|
@ -4188,14 +4202,7 @@ requires
|
|||
that.$container.height(menuHeight);
|
||||
}
|
||||
!self.options.parent && that.gainFocus();
|
||||
that.bindEvent({
|
||||
key_up: selectPreviousItem,
|
||||
key_down: selectNextItem,
|
||||
key_left: selectSupermenu,
|
||||
key_right: selectSubmenu,
|
||||
key_escape: that.hideMenu,
|
||||
key_enter: clickSelectedItem
|
||||
});
|
||||
that.bindEvent(self.keyboardEvents);
|
||||
setTimeout(function() {
|
||||
$document.bind("click", click);
|
||||
}, 100);
|
||||
|
|
Loading…
Reference in New Issue
Block a user