-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.hoverablePopover.js
56 lines (49 loc) · 1.87 KB
/
jquery.hoverablePopover.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
/*
* @author Andreas Arledal (andreas.arledal@me.com)
* @copyright Copyright (c) 2012 Andreas Arledal
* @license This HoverablePopover jQuery plug-in is dual licensed under the MIT and GPL licenses.
* version Version 1.0
*/
;(function ($) {
"use strict";
$.fn.hoverablePopover = function(options, threshold) {
options.trigger = 'manual';
return this.each(function() {
threshold = threshold || 200;
var popoverEntered = false,
self = $(this),
optionHideDelay = options.delay.hide || 0,
calculatedHideDelay = optionHideDelay - threshold,
hideTimeout;
if (calculatedHideDelay < 0) {
calculatedHideDelay = 0;
}
$(this).popover(options).hover(
function() {
popoverEntered = false;
$(this).popover('show');
},
function() {
setTimeout(function() {
if (popoverEntered !== true) {
setTimeout(function() {
self.popover('hide');
}, calculatedHideDelay);
}
}, threshold);
$('.popover')
.mouseenter(function () { clearTimeout(hideTimeout); popoverEntered = true; })
.mouseleave(
function () {
hideTimeout = setTimeout(function() {
popoverEntered = false;
self.popover('hide');
}, optionHideDelay);
}
)
;
}
);
});
};
})( jQuery );