Skip to content

Commit

Permalink
Delayed rendering for button hints
Browse files Browse the repository at this point in the history
  • Loading branch information
JuliaRadzhabova committed Mar 5, 2024
1 parent fea4f30 commit ea6fe16
Showing 1 changed file with 55 additions and 20 deletions.
75 changes: 55 additions & 20 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 @@ -802,7 +804,50 @@ define([
this.btnMenuEl = $(btnEl[1]);
} else {
this.btnEl = cmpEl;
this.btnEl.attr('data-toggle', '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) {
Expand All @@ -811,38 +856,28 @@ define([
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',
zIndex : tipZIndex
});
this.btnMenuEl && this.btnMenuEl.tooltip({
html: !!isHtml,
title : hint[1],
placement : this.options.hintAnchor||'cursor',
zIndex : tipZIndex
});
},

updateHint: function(hint, isHtml) {
this.options.hint = hint;
if (!this.rendered) return;

if (this.btnEl && this.btnEl.data('bs.tooltip'))
this.btnEl.removeData('bs.tooltip');
if (this.btnMenuEl && this.btnMenuEl.data('bs.tooltip'))
this.btnMenuEl.removeData('bs.tooltip');

this.createHint(hint, isHtml);

if (this.disabled || !Common.Utils.isGecko) {
Expand Down

0 comments on commit ea6fe16

Please sign in to comment.