-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.tooltip.js
114 lines (73 loc) · 3.04 KB
/
jquery.tooltip.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
107
108
109
110
111
112
113
114
/*
tooltip 1.2 - jQuery plugin
written by O! Interactive, Acuna
http://ointeractive.ru
Copyright (c) 2014-2015 O! Interactive, Acuna (http://ointeractive.ru)
Dual licensed under the MIT (MIT-LICENSE.txt)
and GPL (GPL-LICENSE.txt) licenses.
Built for jQuery library
http://jquery.com
Dependencies: none
1.0 22.05.2014
Первый приватный релиз
1.1 18.06.2015
+ Реализована возможность скрытия по клику
+ Добавлена возможность вывода собственного контента
*/
(function ($) {
$.fn.tooltip = function (options) {
options = $.extend ({
'xOffset': 15,
'yOffset': 25,
'id': 'tooltip',
'clickRemove': false,
'content': null,
'useElement': '',
'style': null,
'elementStyle': {},
}, options);
$(this).each (function () {
var self = $(this), title = self.attr ('title');
self.hover (
function (e) {
var content;
if (options['content'])
content = options['content'] (self, options);
else if (options['useElement'])
content = ('#' + options['useElement']).html ();
else
content = title;
if (content != '' && $.type (content) != 'undefined') {
self.attr ('title', '');
$('body').append ('<div id="' + options['id'] + '" class="tooltip-content">' + content + '</div>');
var elem = $('#' + options['id']);
if (!options['style'])
options['style'] = function (e) {
return { 'position':'absolute', 'top':(elem.visible () - options['yOffset']) + 'px', 'left':(e.pageX + options['xOffset']) + 'px', 'display':'none' };
};
elem.css (options['style'] (elem, self, options))
.fadeIn ('fast');
$.each (options['elementStyle'], function (key, value) {
elem.find (key).each (function () {
$(this).css (value (elem, $(this), self, options));
});
});
}
},
function () {
$('#' + options['id']).remove ();
self.attr ('title', title);
}
);
self.mousemove (function (e) {
$('#' + options['id'])
.css ({ 'top':(e.pageY - options['yOffset']) + 'px', 'left':(e.pageX + options['xOffset']) + 'px' });
});
if (options['clickRemove'])
self.mousedown (function (e) {
$('#' + options['id']).remove ();
self.attr ('title', title);
});
});
};
})($);