-
Notifications
You must be signed in to change notification settings - Fork 2
/
make_dropdown.js
executable file
·67 lines (52 loc) · 1.51 KB
/
make_dropdown.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
(function($){
var timeout = 500;
var closetimer = 0;
var ddmenuitem = null;
// From https://github.com/Modernizr/Modernizr/blob/master/modernizr.js
var isTouch = ('ontouchstart' in window) ||
window.DocumentTouch && document instanceof DocumentTouch;
// jsddm funcs from http://javascript-array.com/scripts/jquery_simple_drop_down_menu/
function jsddm_open($this){
jsddm_canceltimer();
jsddm_close();
ddmenuitem = $this.find('ul').css('visibility', 'visible');
}
function jsddm_close() {
if(ddmenuitem){
ddmenuitem.css('visibility', 'hidden');
ddmenuitem = null;
}
}
function jsddm_timer() {
closetimer = window.setTimeout(jsddm_close, timeout);
}
function jsddm_canceltimer() {
if(closetimer)
{ window.clearTimeout(closetimer);
closetimer = null;
}
}
function jsddm_toggle($this) {
if (ddmenuitem && $this.has(ddmenuitem[0]).length){
jsddm_close();
}
else {
jsddm_open($this);
}
}
$.fn.make_dropdown = function(options){
return this.each(function(){
if (options && options['timeout']){
timeout = options['timeout'];
}
$(this).click(function(event){
jsddm_toggle($(this));
event.stopPropagation();
});
if (!isTouch){
$(this).mouseover(function(){ jsddm_open($(this)) }).mouseout(jsddm_timer);
}
});
}
$(document).click(jsddm_close);
})(jQuery);