tooltip.js
2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
var WPMLCore = WPMLCore || {};
WPMLCore.Tooltip = function (element) {
this.trigger = element;
this.content = this.trigger.html(this.trigger.html()).text();
this.edge = 'bottom';
this.align = 'left';
this.margin_left = '-54px';
if (!this.content) {
this.content = this.decodeEntities(this.trigger.data('content'));
}
if (this.trigger.data('edge')) {
this.edge = this.trigger.data('edge');
}
if (this.trigger.data('align')) {
this.align = this.trigger.data('align');
}
if (this.trigger.data('margin_left')) {
this.margin_left = this.trigger.data('margin_left');
}
this.trigger.empty();
this.trigger.click(jQuery.proxy(this.onTriggerClick, this));
};
WPMLCore.Tooltip.prototype = {
open: function () {
if (this.trigger.length && this.content) {
this.trigger.addClass('js-wpml-active-tooltip');
this.trigger.pointer({
pointerClass: 'js-wpml-tooltip',
content: this.content,
position: {
edge: this.edge,
align: this.align
},
show: jQuery.proxy(this.onShow, this),
close: this.onClose,
buttons: this.buttons
}).pointer('open');
}
},
onShow: function (event, t) {
t.pointer.css('marginLeft', this.margin_left);
},
onClose: function (event, t) {
t.pointer.css('marginLeft', '0');
},
onTriggerClick: function (e) {
e.preventDefault();
this.open();
},
buttons: function (event, t) {
var button = jQuery('<a class="close" href="#"> </a>');
return button.on('click.pointer', function (e) {
e.preventDefault();
t.element.pointer('close');
});
},
decodeEntities: function (encodedString) {
var textArea = document.createElement('textarea');
textArea.innerHTML = encodedString;
return textArea.value;
}
};
WPMLCore.initializeTooltips = function() {
"use strict";
var tooltips = jQuery('.js-wpml-tooltip-open'), tooltip = {};
tooltips.each(function (index, element) {
tooltip = new WPMLCore.Tooltip(jQuery(element));
});
};
(function () {
'use strict';
jQuery(function () {
WPMLCore.initializeTooltips();
});
}());