-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmenu.js
More file actions
180 lines (165 loc) · 6.04 KB
/
menu.js
File metadata and controls
180 lines (165 loc) · 6.04 KB
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
// Menu Script by Matt Hillman
$(document).ready(function() {
var anyMenuOpen = 0;
var dw = $(document).width();
$(window).resize(function() {
dw = $(document).width();
});
function addMenu() {anyMenuOpen++;}
function closeMenu() { (anyMenuOpen <= 0) ? anyMenuOpen = 0 : anyMenuOpen--; }
$('ul.subnav').each(function(i, el) {
$(el).parent('li').append('<span class="arrow">></span>');
});
$('ul.navmenu li').each(function(i, el) {
var left_calc = false;
$(window).resize(function() {
left_calc = false;
});
$(el).bind('mouseover.triggerEvent', function() {
if (!left_calc) {
var p = $(this);
var c = $($('ul', this).get(0));
var sub_left = p.outerWidth() - 2;
if ((p.offset().left + p.outerWidth() + c.outerWidth()) > dw) {
sub_left = 0-c.outerWidth();
}
c.css('left', sub_left + 'px');
left_calc = true;
}
});
if (window.overrideSubWithJS) {
$(el).hover(function() {
$('> a', this).addClass('over');
}, function() {
$('> a', this).removeClass('over');
});
}
});
$(".navitem > a").each(function(i, el) {
var trigger = el;
var mouseOverSub = false;
var popupId = trigger.id.replace('-top', '-menu');
var popup = $('#'+popupId).css('opacity', 0);
var shown = false;
var beingShown = false;
var subSetupComplete = false;
if (popup.size() > 0) {
popup.hover(function() {
mouseOverSub = true;
}, function() { // hide on mouseout of menu
mouseOverSub = false;
popup.animate({
opacity: 0
}, 200, 'linear', function() {
popup.css('display', 'none');
$(trigger).removeClass('sub-clicked');
shown = false;
closeMenu(); // code above should only allow one menu to show at a time...
});
});
$(trigger).bind('click.triggerEvent', function(e) { //When trigger is clicked...
e.preventDefault();
$(this).blur();
//hide any other menus that are currently shown
$('.navmenu').each(function() {
if (this.id !== popupId && $(this).css('display') !== 'none') {
$(this).trigger('mouseout');
}
});
if (shown && $('#'+popupId).css('display')==='none') {
shown = false;
}
if (beingShown) { // currently animating, do nothing
return;
} else if (shown) { // currently showing menu, hide
popup.animate({
opacity: 0
}, 200, 'linear', function() {
popup.css('display', 'none');
$(trigger).removeClass('sub-clicked');
shown = false;
closeMenu(); // code above should only allow one menu to show at a time...
});
} else { // if all else fails, show the menu
beingShown = true;
var left_point = $(trigger).offset().left;
if (left_point + popup.width() > $(document).width()) {
left_point = ($(trigger).offset().left + $(trigger).width())-popup.width();
}
$(trigger).addClass('sub-clicked');
popup.css({
top: $(trigger).offset().top + $(trigger).parent().height() - 2,
left: left_point,
display: 'block'
}).animate({
opacity: 1
}, 10, 'linear', function() {
beingShown = false;
shown = true;
addMenu();
if (window.overrideSubWithJS) {
if (!subSetupComplete) {
//handle sub-menus
setupSub(popup);
subSetupComplete = true;
}
}
});
}
}).hover(function() {
if (anyMenuOpen > 0 && $('#' + trigger.id.replace('-top', '-menu')).size() > 0 && $('#' + trigger.id.replace('-top', '-menu')).css('display')!=='block') {
$(trigger).trigger('click');
}
}, function() { //On Hover Out
shown = false;
beingShown = false;
mouseOverSub = false;
});
}
});
});
function setupSub(popup) {
$('li', popup).each(function(i, el) {
var subMenuHideTimer = null;
var thisSub = el;
var subShown = false;
if ($('> ul', thisSub).size() > 0) {
$(thisSub).append('<span class="arrow">></span>');
$(thisSub).unbind('mouseover.triggerEvent').bind('mouseover.triggerEvent', function() {
if (subMenuHideTimer) clearTimeout(subMenuHideTimer);
if (!subShown) {
var sub_left = $(thisSub).width() -2;
if (($(thisSub).offset().left + $(thisSub).width() + $($('> ul', thisSub)[0]).width()) > $(document).width()) {
sub_left = 0-$($('> ul', thisSub)[0]).width();
}
$('> ul', thisSub).css('left', sub_left + 'px');
$('> ul', thisSub).css({
opacity: 0,
top: 2,//$(thisSub).position().top + 2,
left: sub_left,
display: 'block'
}).animate({
opacity: 1
}, 10, 'linear', function() {
subShown = true;
});
}
}).unbind('mouseout.triggerEvent').bind('mouseout.triggerEvent', function() {
subMenuHideTimer = setTimeout(function() {
$('> ul', thisSub).animate({
opacity: 0
}, 200, 'linear', function() {}).css({
display: 'none'
});
subShown = false;
}, 200);
});
$('> ul', thisSub).each(function() { setupSub(this); });
}
}).hover(function() {
$(this).addClass('sub-hover');
}, function() {
$(this).removeClass('sub-hover');
subShown = false;
});
}