fix ticket #239 (Ox.Menu / Ox.MainMenu: setKeyboard / setItemKeyboard options are missing)

This commit is contained in:
rolux 2014-05-13 01:47:09 +02:00
parent 56468a9208
commit 2fbc59e713
3 changed files with 30 additions and 7 deletions

View file

@ -255,6 +255,12 @@ Ox.MainMenu = function(options, self) {
return that; return that;
}; };
that.setItemKeyboard = function(id, keyboard) {
var item = that.getItem(id);
item && item.options({keyboard: keyboard});
return that;
};
/*@ /*@
setItemTitle <f> setItemTitle setItemTitle <f> setItemTitle
(id, title) -> <o> set item title (id, title) -> <o> set item title

View file

@ -770,6 +770,12 @@ Ox.Menu = function(options, self) {
return that; return that;
}; };
that.setItemKeyboard = function(id, keyboard) {
var item = that.getItem(id);
item && item.options({keyboard: keyboard});
return that;
};
/*@ /*@
setItemTitle <f> setItemTitle setItemTitle <f> setItemTitle
(id, title) -> <o> set item title (id, title) -> <o> set item title

View file

@ -53,6 +53,11 @@ Ox.MenuItem = function(options, self) {
disabled: self.options.disabled disabled: self.options.disabled
}); });
}, },
keyboard: function() {
self.options.keyboard = parseKeyboard(self.options.keyboard);
that.$modifiers.html(formatModifiers());
that.$key.html(formatKey());
},
title: function() { title: function() {
self.options.title = Ox.makeArray(self.options.title); self.options.title = Ox.makeArray(self.options.title);
that.$title.html(self.options.title[0]); that.$title.html(self.options.title[0]);
@ -116,11 +121,7 @@ Ox.MenuItem = function(options, self) {
.append( .append(
that.$modifiers = Ox.$('<td>') that.$modifiers = Ox.$('<td>')
.addClass('OxCell OxModifiers') .addClass('OxCell OxModifiers')
.html( .html(formatModifiers())
self.options.keyboard.modifiers.map(function(modifier) {
return Ox.UI.symbols[modifier];
}).join('')
)
) )
.append( .append(
that.$key = Ox.$('<td>') that.$key = Ox.$('<td>')
@ -130,11 +131,21 @@ Ox.MenuItem = function(options, self) {
.html( .html(
self.options.items.length self.options.items.length
? Ox.UI.symbols.triangle_right ? Ox.UI.symbols.triangle_right
: Ox.UI.symbols[self.options.keyboard.key] : formatKey()
|| self.options.keyboard.key.toUpperCase()
) )
); );
function formatKey() {
return Ox.UI.symbols[self.options.keyboard.key]
|| self.options.keyboard.key.toUpperCase();
}
function formatModifiers() {
return self.options.keyboard.modifiers.map(function(modifier) {
return Ox.UI.symbols[modifier];
}).join('');
}
function parseKeyboard(str) { function parseKeyboard(str) {
var modifiers = str.split(' '), var modifiers = str.split(' '),
key = modifiers.pop(); key = modifiers.pop();