-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.quicktip.js
106 lines (82 loc) · 3.67 KB
/
jquery.quicktip.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
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
;(function($, window, document, undefined) {
var pluginName = 'tooltip', debug = false;
var internal = {
reposition: function(event) {
var mousex = event.pageX, mousey = event.pageY;
$(this).data(pluginName)['tooltip'].css({top: mousey + 'px', left: mousex + 'px'});
},
show: function(event) {
if (debug) console.log(pluginName + '.show()');
var $this = $(this), data = $this.data(pluginName);
data['tooltip'].stop(true, true).fadeIn(600);
$this.on('mousemove.' + pluginName, internal.reposition);
},
hide: function(event) {
if (debug) console.log(pluginName + '.hide()');
var $this = $(this), data = $this.data(pluginName);
$this.off('mousemove.' + pluginName, internal.reposition);
data['tooltip'].stop(true, true).fadeOut(400);
}
};
var external = {
init: function(options) {
if (debug) console.log(pluginName + '.init()');
options = $.extend(
true,
{},
$.fn[pluginName].defaults,
typeof options == 'object' && options
);
return this.each(function() {
var $this = $(this), data = $this.data(pluginName);
if (data) return;
var title = $this.attr('title');
if (!title) return;
var $tooltip = $('<div />', {
class: options.class,
text: title
}).appendTo('body').hide();
var data = {
tooltip: $tooltip,
options: options,
title: title
};
$this
.data(pluginName, data)
.attr('title', '')
.on('mouseenter.' + pluginName, internal.show)
.on('mouseleave.' + pluginName, internal.hide);
});
},
update: function(content) {
if (debug) console.log(pluginName + '.update(content)', content);
return this.each(function() {
var $this = $(this), // One link
data = $this.data(pluginName);
if (!data) return; // Nothing here
data['tooltip'].html(content);
});
},
destroy: function() {
if (debug) console.log(pluginName + '.destroy()');
return this.each(function() {
var $this = $(this),
data = $this.data(pluginName);
if (!data) return;
$this
.attr('title', data['title'])
.off('.' + pluginName)
.removeData(pluginName);
data['tooltip'].remove();
});
}
};
$.fn[pluginName] = function(method) {
if (external[method]) return external[method].apply(this, Array.prototype.slice.call(arguments, 1));
else if ($.type(method) === 'object' || !method) return external.init.apply(this, arguments);
else $.error('Method ' + method + ' does not exist on jQuery.' + pluginName + '.js');
};
$.fn[pluginName].defaults = {
class: pluginName + 'Element'
};
})(window.jQuery);