-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhoverableHover.js
84 lines (75 loc) · 1.71 KB
/
hoverableHover.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
/*
* hoverableHover
*
* Copyright (c) 2011 Rodney Carvalho
*
* Licensed under the MIT license:
* http://www.opensource.org/licenses/mit-license.php
*
* Version: 0.9
*
* Project home:
* https://github.com/rcarvalho/hoverable-hover
*
* See README.txt for instructions
*
*/
hoverableHover = {
hoverElem: null,
popup: null,
timeoutToken: null,
opts: {},
init: function(selector, opts){
if(opts == undefined){
opts = {};
}
hoverableHover.opts = opts;
var popup = opts.popup;
var timeout = opts.timeout;
if(timeout == undefined){
timeout = 700;
}
hoverableHover.popup = popup;
$(selector).live('mouseover', function(){
if($(popup).is(':visible')){
hoverableHover.hidePopup();
}
hoverableHover.hoverElem = this;
if(opts.beforeShow){
opts.beforeShow(this);
}
$(popup).show();
if(opts.afterShow){
opts.afterShow(this);
}
});
$(selector).live('mouseout',function(){
hoverableHover.startTimeout(timeout);
});
$(popup).live('mouseover', function(){
hoverableHover.cancelTimeout();
});
$(popup).live('mouseout', function(){
hoverableHover.startTimeout(timeout);
});
},
cancelTimeout: function(){
if(hoverableHover.timeoutToken){
clearTimeout(hoverableHover.timeoutToken);
hoverableHover.timeoutToken = null;
}
},
startTimeout: function(timeout){
hoverableHover.timeoutToken = setTimeout("hoverableHover.hidePopup()",timeout);
},
hidePopup: function(){
hoverableHover.cancelTimeout();
if(hoverableHover.opts.beforeHide){
hoverableHover.opts.beforeHide(hoverableHover.hoverElem);
}
$(hoverableHover.popup).hide();
if(hoverableHover.opts.afterHide){
hoverableHover.opts.afterHide(hoverableHover.hoverElem);
}
}
};