-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathui.menu.js
289 lines (249 loc) · 7.16 KB
/
ui.menu.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
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
(function($) {
$.widget("ui.menu", {
active: false,
last_activated: null,
last_menu_level: null,
last_level: null,
timer_id: null,
_init: function() {
this._menufy();
},
deactivate: function () {
this.$sub_menus.addClass('ui-helper-hidden');
this.$lis.removeClass('ui-state-active');
this.active = false;
this.last_activated = null;
},
activate: function(li, force) {
if (force) {
this.active = true;
}
if (!this.active) {
return;
}
var submenu = li.submenu;
if (!submenu) {
return;
}
if (this.last_activated == li) {this.last_level = null; return;}
this.last_activated = li;
this.last_level = submenu.level;
this.last_menu_level = submenu.level;
var menu_entry = $(li);
if (submenu.level == 0)
{
this.deactivate();
this.active = true;
menu_entry.addClass('ui-state-active');
submenu.css('left', (menu_entry.offset().left-1)+"px");
submenu.css('top', (menu_entry.offset().top+menu_entry.outerHeight()+1)+"px");
}
else
{
this.$sub_menus.each(function (i, sub_menu) {
if (sub_menu.level >= submenu.level)
$(sub_menu).addClass('ui-helper-hidden');
});
var parent_menu = $(li.parentNode);
submenu.css('left', (parent_menu.offset().left+parent_menu.outerWidth()-1)+"px");
submenu.css('top', (menu_entry.offset().top-1)+"px");
}
// IE6 hack for first level submenu widths being way off
if (submenu.outerWidth() > 500 || submenu.outerWidth() < 10)
{
submenu.css('width', "0px");
}
submenu.css('width', submenu.innerWidth() + "px");
submenu.removeClass('ui-helper-hidden');
},
_menufy: function() {
this.top_level = this.element.children('ul:first, ol:first').eq(0);
this.$lis = $('li', this.top_level);
this.$sub_menus = $([]);
var self = this, o = this.options;
function getSubmenus($lis, level)
{
if ($lis.length == 0) return;
var menu = $($lis[0].parentNode);
// Main menu entries are buttons
var addState = function(state, el) {
if (el.is(':not(.ui-state-disabled)')) {
el.addClass('ui-state-' + state);
}
};
var removeState = function(state, el) {
el.removeClass('ui-state-' + state);
};
if (level == 0)
{
$lis.addClass('ui-state-default');
$lis.eq($lis.length-1).addClass('ui-corner-right');
$lis.bind('mouseover', function() {
addState('hover', $(this));
});
$lis.bind('mouseout', function() {
removeState('hover', $(this));
});
}
else
{
$lis.bind('mouseover.menu', function() {
addState('hover', $(this));
});
$lis.bind('mouseout.menu', function() {
removeState('hover', $(this));
});
}
var has_images = false;
// Make empty li elements to be separators
$lis.each(function (i, li) {
if (li.innerHTML == '')
{
$(li).addClass('ui-menu-separator ui-widget-content');
$(li).unbind('.menu');
}
var $imgs = $('img', li);
if ($imgs.length)
{
$imgs.addClass('ui-helper-reset');
has_images = true;
}
$(li).attr('depth', level - 1);
});
if (has_images && level > 0)
menu.addClass('ui-menu-submenu-images');
var $ids = $lis.map(function() { return $('a', this)[0]; });
var has_children = false;
$ids.each(function(i, a) {
var href = $(a).attr('href');
var target = $(a).attr('target');
var fragmentId = /^#.+/; // Safari 2 reports '#' for an empty hash
// For dynamically created HTML that contains a hash as href IE < 8 expands
// such href to the full page url with hash and then misinterprets tab as ajax.
// Same consideration applies for an added tab with a fragment identifier
// since a[href=#fragment-identifier] does unexpectedly not match.
// Thus normalize href attribute...
if (href.split('#')[0] == location.toString().split('#')[0]) {
href = a.hash;
}
//added to make full bar clickable! -Kyle M.
if(href.indexOf('#') !== 0 && target != '_blank')
{
var li = a.parentNode;
li.onclick = function(){window.location=href;};
li.style.cursor = 'pointer';
}
// submenu
if (fragmentId.test(href)) {
var li = a.parentNode;
// Nuke the anchor tag
li.innerHTML = a.innerHTML;
li.href = href;
li.target = target;
var selector = self._sanitizeSelector(href);
self.$sub_menus = self.$sub_menus.add(selector);
var submenu = $(selector);
li.submenu = submenu;
submenu[0].level = level;
submenu.level = level;
submenu.addClass('ui-helper-hidden');
// Add arrow if there is a submenu.
var row = $(li);
var arrow = $('<div class="ui-icon ui-icon-triangle-1-e"></div>');
row.prepend(arrow);
if (level > 0)
{
has_children = true;
}
else
{
var item = $(li);
$(li).css('padding-right', '30px');
var arrow = $('div', item);
arrow.css('left', (item.innerWidth()-52) + "px");
}
getSubmenus($('li', submenu), level + 1);
}
});
if (has_children && level > 0)
menu.addClass('ui-menu-submenu-children');
if (level == 0)
{/*
$lis.bind('click.tabs', function(e) {
e.stopPropagation();
if (self.active)
self.deactivate();
else
self.activate(this, true);
});*/
$lis.bind('mouseover.tabs', function() {
if(self.timer_id != null)
{
clearTimeout(self.timer_id);
self.timer_id = null;
}
self.activate(this, true);
});
self.$lis.bind('mouseout.tabs', function(e) {
if(self.timer_id != null)
{
clearTimeout(self.timer_id);
self.timer_id = null;
}
self.timer_id = setTimeout(function () { self.deactivate(); }, 500);
});
}
else
{
$lis.bind('mouseover.tabs', function(e) {
if(self.timer_id != null)
{
clearTimeout(self.timer_id);
self.timer_id = null;
}
var depth = $(this).attr('depth');
self.activate(this, true);
if(this.submenu)
{
this.submenu.removeClass('ui-helper-hidden');
}
else
{
self.$sub_menus.each(function (i, sub_menu) {
if (sub_menu.level > depth)
{
$(sub_menu).addClass('ui-helper-hidden');
}
});
}
}
);
self.$sub_menus.bind('mouseout.tabs', function(e) {
if(self.timer_id != null)
{
clearTimeout(self.timer_id);
self.timer_id = null;
}
self.timer_id = setTimeout(function () { self.deactivate(); }, 500);
});
}
}
// attach necessary classes for styling
this.element.addClass('ui-menu ui-widget');
this.top_level.addClass('ui-menu-toplevel ui-widget-header ui-helper-reset ui-helper-clearfix');
// Start the recursive processing
getSubmenus(this.$lis, 0);
this.$sub_menus.addClass('ui-helper-reset ui-menu-submenu ui-widget ui-widget-content');
// deactivate the menu when the page is clicked anywhere
$(document).bind('click', function (e) {
// Only catch left clicks
if (e.button > 0) return;
e.stopPropagation();
self.deactivate();
});
},
_sanitizeSelector: function(hash) {
return hash.replace(/:/g, '\\:'); // we need this because an id may contain a ":"
}
});
})(jQuery);