-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.dropdead.js
90 lines (78 loc) · 3.26 KB
/
jquery.dropdead.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
(function( $ ) {
$.fn.dropDead = function(options) {
var settings = $.extend({
menuElement: 'ul',
submenuClass: 'submenu',
itemHoverClass: 'submenu-item-hover',
locationAttr: 'title',
callback: function (element, attrValue) {
location.href = element.attr(attrValue);
}
}, options);
return this.each(function () {
var $this = $(this),
list = ($this.children(settings.menuElement).length > 0) ?
$this.children(settings.menuElement) :
$this.next(settings.menuElement);
var items = list.children(),
lastItem = list.children(':last-child');
list.hide();
list.addClass(settings.submenuClass);
var menuLeft = $this.position().left, menuTop = $this.position().top,
menuPadding = $this.css('padding'),
menuPaddingBottom = _getIntegerValue($this.css('padding-bottom')),
menuBorderLeftWidth = _getIntegerValue($this.css('border-left-width')),
menuBorderTopWidth = _getIntegerValue($this.css('border-top-width')),
listBorderWidth = _getIntegerValue(list.css('border-left-width'));
list.css({
'padding': '0',
'margin': '0',
'list-style': 'none',
'left': menuLeft+'px',
'position': 'absolute',
'top': (menuTop + $this.height() + 2*menuBorderTopWidth + 2*menuPaddingBottom) + 'px'
});
items.css({
'border-bottom': '1px solid '+list.css('border-bottom-color'),
'cursor': 'pointer',
'padding': menuPadding,
'text-align': 'center',
'min-width': ($this.width() + 2*(menuBorderLeftWidth - listBorderWidth)) +'px'
});
lastItem.css({
'border-bottom': '0'
});
if (items.css('display') == 'inline')
items.css('display', 'block');
$this.mouseover(function (event) {
list.show();
}).mouseout(function (event) {
list.hide();
});
list.mouseover(function (event) {
list.show();
}).mouseout(function (event) {
list.hide();
});
items.mouseover(function () {
$(this).addClass(settings.itemHoverClass);
}).mouseout(function () {
$(this).removeClass(settings.itemHoverClass);
}).focusin(function () {
$(this).addClass(settings.itemHoverClass);
}).focusout(function () {
$(this).removeClass(settings.itemHoverClass);
}).click(function () {
settings.callback($(this), settings.locationAttr);
list.hide();
});
});
};
function _getIntegerValue(value) {
if (value == undefined)
return 0;
else if (value.match(/^[0-9]+/) == null)
return 0;
return new Number(value.match(/^[0-9]+/)[0]);
}
})(jQuery);