Skip to content

Commit

Permalink
Merge pull request #2883 from ONLYOFFICE/fix/button-hint
Browse files Browse the repository at this point in the history
Fix/button hint
  • Loading branch information
JuliaRadzhabova authored Mar 11, 2024
2 parents 9e3b3ad + ea6fe16 commit a23b58a
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 84 deletions.
141 changes: 79 additions & 62 deletions apps/common/main/lib/component/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ define([
options : {
id : null,
hint : false,
delayRenderHint : true,
enableToggle : false,
allowDepress : true,
toggleGroup : null,
Expand Down Expand Up @@ -352,6 +353,7 @@ define([
me.style = me.options.style;
me.rendered = false;
me.stopPropagation = me.options.stopPropagation;
me.delayRenderHint = me.options.delayRenderHint;

// if ( /(?<!-)svg-icon(?!-)/.test(me.options.iconCls) )
// me.options.scaling = false;
Expand Down Expand Up @@ -475,44 +477,6 @@ define([
isGroup = el.hasClass('btn-group'),
isSplit = el.hasClass('split');

if (me.options.hint) {
var modalParents = me.cmpEl.closest('.asc-window');

if (typeof me.options.hint == 'object' && me.options.hint.length>1 && $('button', el).length>0) {
var btnEl = $('button', el);
me.btnEl = $(btnEl[0]);
me.btnMenuEl = $(btnEl[1]);
} else {
me.btnEl = me.cmpEl;
me.btnEl.attr('data-toggle', 'tooltip');
}
me.btnEl.tooltip({
title : (typeof me.options.hint == 'string') ? me.options.hint : me.options.hint[0],
placement : me.options.hintAnchor||'cursor'
});
me.btnMenuEl && me.btnMenuEl.tooltip({
title : me.options.hint[1],
placement : me.options.hintAnchor||'cursor'
});

if (modalParents.length > 0) {
me.btnEl.data('bs.tooltip').tip().css('z-index', parseInt(modalParents.css('z-index')) + 10);
me.btnMenuEl && me.btnMenuEl.data('bs.tooltip').tip().css('z-index', parseInt(modalParents.css('z-index')) + 10);
var onModalClose = function(dlg) {
if (modalParents[0] !== dlg.$window[0]) return;
var tip = me.btnEl.data('bs.tooltip');
if (tip) {
if (tip.dontShow===undefined)
tip.dontShow = true;

tip.hide();
}
Common.NotificationCenter.off({'modal:close': onModalClose});
};
Common.NotificationCenter.on({'modal:close': onModalClose});
}
}

if (_.isString(me.toggleGroup)) {
me.enableToggle = true;
}
Expand Down Expand Up @@ -662,6 +626,8 @@ define([

me.rendered = true;

me.options.hint && me.createHint(me.options.hint);

if (me.pressed) {
me.toggle(me.pressed, true);
}
Expand Down Expand Up @@ -822,14 +788,14 @@ define([
return (this.cmpEl) ? this.cmpEl.is(":visible") : $(this.el).is(":visible");
},

updateHint: function(hint, isHtml) {
createHint: function(hint, isHtml) {
this.options.hint = hint;

if (!this.rendered) return;

var cmpEl = this.cmpEl,
modalParents = cmpEl.closest('.asc-window');

var me = this,
cmpEl = this.cmpEl,
modalParents = cmpEl.closest('.asc-window'),
tipZIndex = modalParents.length > 0 ? parseInt(modalParents.css('z-index')) + 10 : undefined;

if (!this.btnEl) {
if (typeof this.options.hint == 'object' && this.options.hint.length>1 && $('button', cmpEl).length>0) {
Expand All @@ -838,30 +804,81 @@ define([
this.btnMenuEl = $(btnEl[1]);
} else {
this.btnEl = cmpEl;
this.btnEl.attr('data-toggle', 'tooltip');
}
}

if (this.btnEl.data('bs.tooltip'))
this.btnEl.removeData('bs.tooltip');
if (this.btnMenuEl && this.btnMenuEl.data('bs.tooltip'))
this.btnMenuEl.removeData('bs.tooltip');
var tip = this.btnEl.data('bs.tooltip');
tip && tip.updateTitle(typeof hint === 'string' ? hint : hint[0]);
if (this.btnMenuEl) {
tip = this.btnMenuEl.data('bs.tooltip');
tip && tip.updateTitle(hint[1]);
}
if (!this._isTooltipInited) {
if (this.delayRenderHint) {
this.btnEl.one('mouseenter', function(){ // hide tooltip when mouse is over menu
me.btnEl.tooltip({
html: !!isHtml,
title : (typeof me.options.hint == 'string') ? me.options.hint : me.options.hint[0],
placement : me.options.hintAnchor||'cursor',
zIndex : tipZIndex
});
!Common.Utils.isGecko && (me.btnEl.data('bs.tooltip').enabled = !me.disabled);
me.btnEl.mouseenter();
});
this.btnMenuEl && this.btnMenuEl.one('mouseenter', function(){ // hide tooltip when mouse is over menu
me.btnMenuEl.tooltip({
html: !!isHtml,
title : me.options.hint[1],
placement : me.options.hintAnchor||'cursor',
zIndex : tipZIndex
});
!Common.Utils.isGecko && (me.btnMenuEl.data('bs.tooltip').enabled = !me.disabled);
me.btnMenuEl.mouseenter();
});
} else {
this.btnEl.tooltip({
html: !!isHtml,
title : (typeof this.options.hint == 'string') ? this.options.hint : this.options.hint[0],
placement : this.options.hintAnchor||'cursor',
zIndex : tipZIndex
});
this.btnMenuEl && this.btnMenuEl.tooltip({
html: !!isHtml,
title : this.options.hint[1],
placement : this.options.hintAnchor||'cursor',
zIndex : tipZIndex
});
}
if (modalParents.length > 0) {
var onModalClose = function(dlg) {
if (modalParents[0] !== dlg.$window[0]) return;
var tip = me.btnEl.data('bs.tooltip');
if (tip) {
if (tip.dontShow===undefined)
tip.dontShow = true;
tip.hide();
}
if (me.btnMenuEl) {
tip = me.btnMenuEl.data('bs.tooltip');
if (tip) {
if (tip.dontShow===undefined)
tip.dontShow = true;
tip.hide();
}
}
Common.NotificationCenter.off({'modal:close': onModalClose});
};
Common.NotificationCenter.on({'modal:close': onModalClose});
}
this._isTooltipInited = true;
}
},

this.btnEl.tooltip({
html: !!isHtml,
title : (typeof hint == 'string') ? hint : hint[0],
placement : this.options.hintAnchor||'cursor'
});
this.btnMenuEl && this.btnMenuEl.tooltip({
html: !!isHtml,
title : hint[1],
placement : this.options.hintAnchor||'cursor'
});
updateHint: function(hint, isHtml) {
this.options.hint = hint;
if (!this.rendered) return;

if (modalParents.length > 0) {
this.btnEl.data('bs.tooltip').tip().css('z-index', parseInt(modalParents.css('z-index')) + 10);
this.btnMenuEl && this.btnMenuEl.data('bs.tooltip').tip().css('z-index', parseInt(modalParents.css('z-index')) + 10);
}
this.createHint(hint, isHtml);

if (this.disabled || !Common.Utils.isGecko) {
var tip = this.btnEl.data('bs.tooltip');
Expand Down
29 changes: 8 additions & 21 deletions apps/common/main/lib/component/TreeView.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ define([
selected: false,
allowSelected: true,
disabled: false,
getTipFromName: true,
level: 0,
index: 0
}
Expand Down Expand Up @@ -368,29 +369,16 @@ define([
name = record.get('name'),
me = this;

if (name.length > 37 - record.get('level')*2)
record.set('tip', name);
else
record.set('tip', '');

var el = item.$el || $(item.el);
var tip = el.data('bs.tooltip');
if (tip) {
if (tip.dontShow===undefined)
tip.dontShow = true;
el.removeData('bs.tooltip');
(tip.tip()).remove();
}
if (record.get('tip')) {
record.get('getTipFromName') && record.set('tip', name.length > 37 - record.get('level')*2 ? name : '');

var el = item.$el || $(item.el),
tip = el.data('bs.tooltip');
if (tip)
tip.updateTitle(record.get('tip'));
else if (record.get('tip') && el.attr('data-toggle')!=='tooltip') { // init tooltip
el.attr('data-toggle', 'tooltip');
el.tooltip({
title : record.get('tip'),
placement : 'cursor',
zIndex : this.tipZIndex
});
if (this.delayRenderTips)
el.one('mouseenter', function(){
el.attr('data-toggle', 'tooltip');
el.tooltip({
title : record.get('tip'),
placement : 'cursor',
Expand All @@ -399,7 +387,6 @@ define([
el.mouseenter();
});
else {
el.attr('data-toggle', 'tooltip');
el.tooltip({
title : record.get('tip'),
placement : 'cursor',
Expand Down
2 changes: 1 addition & 1 deletion apps/common/main/lib/util/Tip.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@
clearTimeout(self.timeout);
self.hoverState = 'in';

if (this._updateTitle) {
if (this._updateTitle!==undefined) {
this.tip().find('.tooltip-inner')[this.options.html ? 'html' : 'text'](this.options.title);
this._updateTitle = undefined;
}
Expand Down
2 changes: 2 additions & 0 deletions apps/documenteditor/main/app/controller/Navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ define([
arr[0].set('isNotHeader', true);
arr[0].set('name', this.txtBeginning);
arr[0].set('tip', this.txtGotoBeginning);
arr[0].set('getTipFromName', false);
}

var me = this;
Expand Down Expand Up @@ -376,6 +377,7 @@ define([
arr[0].set('isNotHeader', true);
arr[0].set('name', this.txtBeginning);
arr[0].set('tip', this.txtGotoBeginning);
arr[0].set('getTipFromName', false);
}
this.getApplication().getCollection('Navigation').reset(arr);
if (this.panelNavigation && this.panelNavigation.viewNavigationList && this.panelNavigation.viewNavigationList.scroller)
Expand Down
1 change: 1 addition & 0 deletions apps/pdfeditor/main/app/controller/Navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ define([
arr[0].set('isNotHeader', true);
arr[0].set('name', this.txtBeginning);
arr[0].set('tip', this.txtGotoBeginning);
arr[0].set('getTipFromName', false);
}
this.getApplication().getCollection('Navigation').reset(arr);
if (this.panelNavigation && this.panelNavigation.viewNavigationList && this.panelNavigation.viewNavigationList.scroller)
Expand Down

0 comments on commit a23b58a

Please sign in to comment.