From 10713605886afbf2af3b4a9557c56d4d1e865095 Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Mon, 4 Mar 2019 12:18:01 +0300 Subject: [PATCH] [SSE] Add tooltip with function description --- apps/common/main/lib/component/MenuItem.js | 9 +++++++ apps/common/main/lib/extend/Bootstrap.js | 14 +++++++++- .../main/app/controller/DocumentHolder.js | 27 ++++++++++++++++--- 3 files changed, 45 insertions(+), 5 deletions(-) diff --git a/apps/common/main/lib/component/MenuItem.js b/apps/common/main/lib/component/MenuItem.js index c0f7c99fd..6b81c41f4 100644 --- a/apps/common/main/lib/component/MenuItem.js +++ b/apps/common/main/lib/component/MenuItem.js @@ -135,6 +135,7 @@ define([ this.toggleGroup = me.options.toggleGroup; this.template = me.options.template || this.template; this.iconCls = me.options.iconCls; + this.hint = me.options.hint; this.rendered = false; if (this.menu !== null && !(this.menu instanceof Common.UI.Menu)) { @@ -189,6 +190,14 @@ define([ } } + if (me.options.hint) { + el.attr('data-toggle', 'tooltip'); + el.tooltip({ + title : me.options.hint, + placement : me.options.hintAnchor||'cursor' + }); + } + if (this.disabled) $(this.el).toggleClass('disabled', this.disabled); diff --git a/apps/common/main/lib/extend/Bootstrap.js b/apps/common/main/lib/extend/Bootstrap.js index c83f5f5da..a69a8e174 100755 --- a/apps/common/main/lib/extend/Bootstrap.js +++ b/apps/common/main/lib/extend/Bootstrap.js @@ -165,13 +165,25 @@ function patchDropDownKeyDownAdditional(e) { // only for formula menu when typin if (!$items.length) return; - var index = $items.index($items.filter('.focus')); + var index = $items.index($items.filter('.focus')), + previndex = index; if (e.keyCode == 38) { index > 0 ? index-- : ($this.hasClass('no-cyclic') ? (index = 0) : (index = $items.length - 1));} else // up if (e.keyCode == 40) { index < $items.length - 1 ? index++ : ($this.hasClass('no-cyclic') ? (index = $items.length - 1) : (index = 0));} // down if (!~index) index=0; $items.removeClass('focus'); $items.eq(index).addClass('focus'); + + if (previndex !== index) { + var tip = $items.eq(previndex).parent().data('bs.tooltip'); + if (tip) { + tip.hide(); + } + tip = $items.eq(index).parent().data('bs.tooltip'); + if (tip) { + tip.show(); + } + } } function getParent($this) { diff --git a/apps/spreadsheeteditor/main/app/controller/DocumentHolder.js b/apps/spreadsheeteditor/main/app/controller/DocumentHolder.js index b544f991b..f42b5c824 100644 --- a/apps/spreadsheeteditor/main/app/controller/DocumentHolder.js +++ b/apps/spreadsheeteditor/main/app/controller/DocumentHolder.js @@ -1894,9 +1894,13 @@ define([ var me = this, documentHolderView = me.documentHolder, menu = documentHolderView.funcMenu, - menuContainer = documentHolderView.cmpEl.find('#menu-formula-selection'); + menuContainer = documentHolderView.cmpEl.find('#menu-formula-selection'), + funcdesc = SSE.Views.FormulaLang.getDescription(Common.Utils.InternalSettings.get("sse-settings-func-locale")); for (var i = 0; i < menu.items.length; i++) { + var tip = menu.items[i].cmpEl.data('bs.tooltip'); + if (tip) + tip.hide(); menu.removeItem(menu.items[i]); i--; } @@ -1909,9 +1913,13 @@ define([ }); _.each(funcarr, function(menuItem, index) { var type = menuItem.asc_getType(), + name = menuItem.asc_getName(), + origname = me.api.asc_getFormulaNameByLocale(name), mnu = new Common.UI.MenuItem({ - iconCls: (type==Asc.c_oAscPopUpSelectorType.Func) ? 'mnu-popup-func': ((type==Asc.c_oAscPopUpSelectorType.Table) ? 'mnu-popup-table' : 'mnu-popup-range') , - caption: menuItem.asc_getName() + iconCls: (type==Asc.c_oAscPopUpSelectorType.Func) ? 'mnu-popup-func': ((type==Asc.c_oAscPopUpSelectorType.Table) ? 'mnu-popup-table' : 'mnu-popup-range') , + caption: name, + hint : (funcdesc && funcdesc[origname]) ? funcdesc[origname].d : '', + hintAnchor: 'right' }).on('click', function(item, e) { setTimeout(function(){ me.api.asc_insertFormula(item.caption, type, false ); }, 10); }); @@ -1958,6 +1966,13 @@ define([ Common.UI.Menu.Manager.hideAll(); } }; + menu.on('hide:after', function(){ + for (var i = 0; i < menu.items.length; i++) { + var tip = menu.items[i].cmpEl.data('bs.tooltip'); + if (tip) + tip.hide(); + } + }); menu.render(menuContainer); menu.cmpEl.attr({tabindex: "-1"}); @@ -1982,7 +1997,11 @@ define([ me.cellEditor.focus(); menu.cmpEl.toggleClass('from-cell-edit', infocus); _.delay(function() { - menu.cmpEl.find('li:first a').addClass('focus'); + var a = menu.cmpEl.find('li:first a'); + a.addClass('focus'); + var tip = a.parent().data('bs.tooltip'); + if (tip) + tip.show(); }, 10); if (!infocus) _.delay(function() {