From 826eb5548d281a5d9e222c53568c0262b0fdf540 Mon Sep 17 00:00:00 2001 From: rlx <0x0073@0x2620.org> Date: Sat, 24 Mar 2012 11:04:27 +0000 Subject: [PATCH] allow menu item to trigger native file dialog when pressing enter --- source/Ox.UI/js/Form/Ox.FileButton.js | 8 ++++++++ source/Ox.UI/js/Menu/Ox.Menu.js | 19 +++++++++++++------ source/Ox.UI/js/Menu/Ox.MenuItem.js | 2 +- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/source/Ox.UI/js/Form/Ox.FileButton.js b/source/Ox.UI/js/Form/Ox.FileButton.js index 457224b3..c7becc96 100644 --- a/source/Ox.UI/js/Form/Ox.FileButton.js +++ b/source/Ox.UI/js/Form/Ox.FileButton.js @@ -100,6 +100,14 @@ Ox.FileButton = function(options, self) { } } + that.blurButton = function() { + self.$input.blur(); + } + + that.focusButton = function() { + self.$input.focus(); + }; + return that; } \ No newline at end of file diff --git a/source/Ox.UI/js/Menu/Ox.Menu.js b/source/Ox.UI/js/Menu/Ox.Menu.js index 96200d81..3f732ed6 100644 --- a/source/Ox.UI/js/Menu/Ox.Menu.js +++ b/source/Ox.UI/js/Menu/Ox.Menu.js @@ -439,9 +439,14 @@ Ox.Menu = function(options, self) { function selectItem(position) { var item; if (self.options.selected > -1) { - //Ox.Log('Menu', 's.o.s', self.options.selected, that.items) - item = that.items[self.options.selected] - item && item.removeClass('OxSelected'); + item = that.items[self.options.selected]; + if (item) { + item.removeClass('OxSelected'); + if (item.options('file')) { + item.$button.blurButton(); + that.bindEvent({key_enter: clickSelectedItem}) + } + } /* disabled that.triggerEvent('deselect', { id: item.options('id'), @@ -457,15 +462,17 @@ Ox.Menu = function(options, self) { return false; } }); - item.options('items').length && that.submenus[item.options('id')].showMenu(); // fixme: do we want to switch to this style? + item.options('items').length && that.submenus[item.options('id')].showMenu(); item.addClass('OxSelected'); - ///* disabled + if (item.options('file')) { + item.$button.focusButton(); + that.unbindEvent('key_enter'); + } that.triggerEvent('select', { id: item.options('id'), title: Ox.isString(item.options('title')[0]) ? Ox.stripTags(item.options('title')[0]) : '' }); - //*/ } self.options.selected = position; } diff --git a/source/Ox.UI/js/Menu/Ox.MenuItem.js b/source/Ox.UI/js/Menu/Ox.MenuItem.js index e261c36c..7c52e003 100644 --- a/source/Ox.UI/js/Menu/Ox.MenuItem.js +++ b/source/Ox.UI/js/Menu/Ox.MenuItem.js @@ -80,7 +80,7 @@ Ox.MenuItem = function(options, self) { .html( self.options.file ? - Ox.FileButton(Ox.extend(Ox.clone(self.options.file), { + that.$button = Ox.FileButton(Ox.extend(Ox.clone(self.options.file), { title: self.options.title[0], width: self.options.file.width })).bindEvent({