Redesigned "setTooltip" method

This commit is contained in:
Maxim Voloshin 2016-09-28 17:22:03 +03:00
parent 939b87ffed
commit 87ed7b7989
1 changed files with 20 additions and 28 deletions

View File

@ -2,6 +2,17 @@
import KeyboardShortcut from '../../keyboardshortcut/keyboardshortcut'; import KeyboardShortcut from '../../keyboardshortcut/keyboardshortcut';
const TOOLTIP_POSITIONS = {
'top': 's',
'left': 'e',
'right': 'w',
'bottom': 'n',
'top-left': 'se',
'top-right': 'sw',
'bottom-left': 'ne',
'bottom-right': 'nw'
};
/** /**
* Created by hristo on 12/22/14. * Created by hristo on 12/22/14.
*/ */
@ -90,17 +101,13 @@ import KeyboardShortcut from '../../keyboardshortcut/keyboardshortcut';
* appropriate class (ex. "tooltip-n") and "content" attribute. * appropriate class (ex. "tooltip-n") and "content" attribute.
*/ */
activateTooltips: function () { activateTooltips: function () {
function getTitle () {
return this.getAttribute('content');
}
function getGravity () {
return this.getAttribute('data-tooltip');
}
AJS.$('[data-tooltip]').tooltip({ AJS.$('[data-tooltip]').tooltip({
gravity: getGravity, gravity() {
title: getTitle, return this.getAttribute('data-tooltip');
},
title() {
return this.getAttribute('content')
},
html: true, // handle multiline tooltips html: true, // handle multiline tooltips
// two options to prevent tooltips from being stuck: // two options to prevent tooltips from being stuck:
live: true, // attach listener to document element live: true, // attach listener to document element
@ -116,25 +123,10 @@ import KeyboardShortcut from '../../keyboardshortcut/keyboardshortcut';
* @param position the position of the tooltip in relation to the element * @param position the position of the tooltip in relation to the element
*/ */
setTooltip: function (element, key, position) { setTooltip: function (element, key, position) {
let positions = { element.setAttribute('data-tooltip', TOOLTIP_POSITIONS[position]);
'top': 's', element.setAttribute('data-i18n', '[content]' + key);
'top-left': 'se',
'left': 'e',
'bottom-left': 'ne',
'bottom': 'n',
'bottom-right': 'nw',
'right': 'w',
'top-right': 'sw'
};
$(element).each(function () { APP.translation.translateElement($(element));
var el = $(this);
el.attr("data-i18n", "[content]" + key)
.attr('data-tooltip', positions[position]);
APP.translation.translateElement(el);
});
}, },
/** /**