-
Notifications
You must be signed in to change notification settings - Fork 1
/
NRTooltip.js
64 lines (64 loc) · 1.98 KB
/
NRTooltip.js
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
(function() {
var $, NRTooltip;
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
$ = jQuery;
$.fn.extend({
NRTooltip: function(options) {
var settings;
settings = {
correction: {
top: 0,
left: 0
},
elements: false
};
settings = $.extend(settings, options);
return this.each(function() {
return new NRTooltip(this, settings);
});
}
});
NRTooltip = (function() {
function NRTooltip(element, settings) {
var hideTip, showTip;
this.element = element;
this.settings = settings;
if ($('.NRTooltip').length === 0) {
$('body').append('<div class="NRTooltip"><span></span><div class="NRTooltip_tip"></div></div>');
}
if (this.settings.elements) {
this.elements = this.settings.elements;
$(this.element).delegate(this.elements, "mouseover", function(e) {
return showTip(e);
});
$(this.element).delegate(this.elements, "mouseout", function(e) {
return hideTip(e);
});
} else {
$(this.element).mouseover(function(e) {
return showTip(e);
});
$(this.element).mouseout(function(e) {
return hideTip(e);
});
}
showTip = __bind(function(e) {
var data, elem, position;
elem = $(e.target);
position = elem.offset();
data = $(elem).data('tooltip');
if (data) {
$('.NRTooltip span').html(data);
$('.NRTooltip').addClass('visible');
position.top -= $('.NRTooltip').outerHeight() + 6 - this.settings.correction.top;
position.left += elem.outerWidth() / 2 - $('.NRTooltip').outerWidth() / 2 + this.settings.correction.left;
return $('.NRTooltip').offset(position);
}
}, this);
hideTip = function(e) {
return $('.NRTooltip').removeClass('visible');
};
}
return NRTooltip;
})();
}).call(this);