diff --git a/apps/common/main/lib/component/Menu.js b/apps/common/main/lib/component/Menu.js index bb04c6b57..321f2813a 100644 --- a/apps/common/main/lib/component/Menu.js +++ b/apps/common/main/lib/component/Menu.js @@ -409,6 +409,10 @@ define([ }, onAfterKeydownMenu: function(e) { + this.trigger('keydown:before', this, e); + if (e.isDefaultPrevented()) + return; + if (e.keyCode == Common.UI.Keys.RETURN) { var li = $(e.target).closest('li'); if (li.length<=0) li = $(e.target).parent().find('li .dataview'); diff --git a/apps/common/main/resources/less/dropdown-menu.less b/apps/common/main/resources/less/dropdown-menu.less index 4391584d3..5aa203037 100644 --- a/apps/common/main/resources/less/dropdown-menu.less +++ b/apps/common/main/resources/less/dropdown-menu.less @@ -16,6 +16,15 @@ } } + &.internal-menu { + border: none; + border-radius: 0; + .box-shadow(none); + margin: 0; + padding: 0; + overflow: hidden; + } + li { & > a { padding: 5px 20px; diff --git a/apps/spreadsheeteditor/main/app/view/FormulaTab.js b/apps/spreadsheeteditor/main/app/view/FormulaTab.js index 80a8720b7..098ba5deb 100644 --- a/apps/spreadsheeteditor/main/app/view/FormulaTab.js +++ b/apps/spreadsheeteditor/main/app/view/FormulaTab.js @@ -262,27 +262,59 @@ define([ }); } if (arr.length) { - arr.push(new Common.UI.MenuItem({ - caption: '--' - })); - arr.push(new Common.UI.MenuItem({ - caption: me.txtAdditional, - value: 'more' - })); - if (btn.menu && btn.menu.rendered) { - btn.menu.removeAll(); - arr.forEach(function(item){ - btn.menu.addItem(item); - }); + var menu = btn.menu.items[0]._internalMenu; + if (menu) { + menu.removeAll(); + arr.forEach(function(item){ + menu.addItem(item); + }); + } } else { btn.setMenu(new Common.UI.Menu({ - restoreHeight: 415, - items: arr + items: [ + {template: _.template('
')}, + { caption: '--' }, + { + caption: me.txtAdditional, + value: 'more' + } + ] })); - btn.menu.on('item:click', function (menu, item, e) { + btn.menu.items[2].on('click', function (item, e) { me.fireEvent('function:apply', [{name: item.caption, origin: item.value}, false, name]); }); + btn.menu.on('show:after', function (menu, e) { + var internalMenu = menu.items[0]._internalMenu; + internalMenu.scroller.update({alwaysVisibleY: true}); + _.delay(function() { + menu.items[0]._internalMenu && menu.items[0]._internalMenu.cmpEl.focus(); + }, 10); + }).on('keydown:before', function(menu, e) { + if (e.keyCode == Common.UI.Keys.RETURN) { + e.preventDefault(); + e.stopPropagation(); + } + } ); + + var menuContainer = btn.menu.items[0].cmpEl.children(':first'); + var menu = new Common.UI.Menu({ + maxHeight: 300, + cls: 'internal-menu', + items: arr + }); + menu.render(menuContainer); + menu.cmpEl.css({ + display : 'block', + position : 'relative', + left : 0, + top : 0 + }); + menu.cmpEl.attr({tabindex: "-1"}); + menu.on('item:click', function (menu, item, e) { + me.fireEvent('function:apply', [{name: item.caption, origin: item.value}, false, name]); + }); + btn.menu.items[0]._internalMenu = menu; } } btn.setDisabled(arr.length<1);