commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-new / civicrm / packages / jquery / plugins / jquery.menu.js
1 /*
2 * jQuery Menu plugin
3 * Version: 0.0.9
4 *
5 * Copyright (c) 2007 Roman Weich
6 * http://p.sohei.org
7 *
8 * Dual licensed under the MIT and GPL licenses
9 * (This means that you can choose the license that best suits your project, and use it accordingly):
10 * http://www.opensource.org/licenses/mit-license.php
11 * http://www.gnu.org/licenses/gpl.html
12 *
13 * Changelog:
14 * v 0.0.9 - 2008-01-19
15 */
16
17 (function($)
18 {
19 var menus = [], //list of all menus
20 visibleMenus = [], //list of all visible menus
21 activeMenu = activeItem = null,
22 menuDIVElement = $('<div class="menu-div outerbox" style="position:absolute;top:0;left:0;display:none;"><div class="shadowbox1"></div><div class="shadowbox2"></div><div class="shadowbox3"></div></div>')[0],
23 menuULElement = $('<ul class="menu-ul innerbox"></ul>')[0],
24 menuItemElement = $('<li style="position:relative;"><div class="menu-item"></div></li>')[0],
25 arrowElement = $('<img class="menu-item-arrow" />')[0],
26 $rootDiv = $('<div id="root-menu-div" style="position:absolute;top:0;left:0;"></div>'), //create main menu div
27 defaults = {
28 // $.Menu options
29 showDelay : 200,
30 hideDelay : 200,
31 hoverOpenDelay: 0,
32 offsetTop : 0,
33 offsetLeft : 0,
34 minWidth: 0,
35 onOpen: null,
36 onClose: null,
37
38 // $.MenuItem options
39 onClick: null,
40 arrowSrc: null,
41 addExpando: false,
42
43 // $.fn.menuFromElement options
44 copyClassAttr: false
45 };
46
47 $(function(){
48 $rootDiv.appendTo('body');
49 });
50
51 $.extend({
52 MenuCollection : function(items) {
53
54 this.menus = [];
55
56 this.init(items);
57 }
58 });
59 $.extend($.MenuCollection, {
60 prototype : {
61 init : function(items)
62 {
63 if ( items && items.length )
64 {
65 for ( var i = 0; i < items.length; i++ )
66 {
67 this.addMenu(items[i]);
68 items[i].menuCollection = this;
69 }
70 }
71 },
72 addMenu : function(menu)
73 {
74 if ( menu instanceof $.Menu )
75 this.menus.push(menu);
76
77 menu.menuCollection = this;
78
79 var self = this;
80 $(menu.target).hover(function(){
81 if ( menu.visible )
82 return;
83
84 //when there is an open menu in this collection, hide it and show the new one
85 for ( var i = 0; i < self.menus.length; i++ )
86 {
87 if ( self.menus[i].visible )
88 {
89 self.menus[i].hide();
90 menu.show();
91 return;
92 }
93 }
94 }, function(){});
95 }
96 }
97 });
98
99
100 $.extend({
101 Menu : function(target, items, options) {
102 this.menuItems = []; //all direct child $.MenuItem objects
103 this.subMenus = []; //all subMenus from this.menuItems
104 this.visible = false;
105 this.active = false; //this menu has hover or one of its submenus is open
106 this.parentMenuItem = null;
107 this.settings = $.extend({}, defaults, options);
108 this.target = target;
109 this.$eDIV = null;
110 this.$eUL = null;
111 this.timer = null;
112 this.menuCollection = null;
113 this.openTimer = null;
114
115 this.init();
116 if ( items && items.constructor == Array )
117 this.addItems(items);
118 }
119 });
120
121 $.extend($.Menu, {
122 checkMouse : function(e)
123 {
124 var t = e.target;
125
126 //the user clicked on the target of the currenty open menu
127 if ( visibleMenus.length && t == visibleMenus[0].target )
128 return;
129
130 //get the last node before the #root-menu-div
131 while ( t.parentNode && t.parentNode != $rootDiv[0] )
132 t = t.parentNode;
133
134 //is the found node one of the visible menu elements?
135 if ( !$(visibleMenus).filter(function(){ return this.$eDIV[0] == t }).length )
136 {
137 $.Menu.closeAll();
138 }
139 },
140 checkKey : function(e)
141 {
142 switch ( e.keyCode )
143 {
144 case 13: //return
145 if ( activeItem )
146 activeItem.click(e, activeItem.$eLI[0]);
147 break;
148 case 27: //ESC
149 $.Menu.closeAll();
150 break;
151 case 37: //left
152 if ( !activeMenu )
153 activeMenu = visibleMenus[0];
154 var a = activeMenu;
155 if ( a && a.parentMenuItem ) //select the parent menu and close the submenu
156 {
157 //unbind the events temporary, as we dont want the hoverout event to fire
158 var pmi = a.parentMenuItem;
159 pmi.$eLI.unbind('mouseout').unbind('mouseover');
160 a.hide();
161 pmi.hoverIn(true);
162 setTimeout(function(){ //bind again..but delay it
163 pmi.bindHover();
164 });
165 }
166 else if ( a && a.menuCollection ) //select the previous menu in the collection
167 {
168 var pos,
169 mcm = a.menuCollection.menus;
170 if ( (pos = $.inArray(a, mcm)) > -1 )
171 {
172 if ( --pos < 0 )
173 pos = mcm.length - 1;
174 $.Menu.closeAll();
175 mcm[pos].show();
176 mcm[pos].setActive();
177 if ( mcm[pos].menuItems.length ) //select the first item
178 mcm[pos].menuItems[0].hoverIn(true);
179 }
180 }
181 break;
182 case 38: //up
183 if ( activeMenu )
184 activeMenu.selectNextItem(-1);
185 break;
186 case 39: //right
187 if ( !activeMenu )
188 activeMenu = visibleMenus[0];
189 var m,
190 a = activeMenu,
191 asm = activeItem ? activeItem.subMenu : null;
192 if ( a )
193 {
194 if ( asm && asm.menuItems.length ) //select the submenu
195 {
196 asm.show();
197 asm.menuItems[0].hoverIn();
198 }
199 else if ( (a = a.inMenuCollection()) ) //select the next menu in the collection
200 {
201 var pos,
202 mcm = a.menuCollection.menus;
203 if ( (pos = $.inArray(a, mcm)) > -1 )
204 {
205 if ( ++pos >= mcm.length )
206 pos = 0;
207 $.Menu.closeAll();
208 mcm[pos].show();
209 mcm[pos].setActive();
210 if ( mcm[pos].menuItems.length ) //select the first item
211 mcm[pos].menuItems[0].hoverIn(true);
212 }
213 }
214 }
215 break;
216 case 40: //down
217 if ( !activeMenu )
218 {
219 if ( visibleMenus.length && visibleMenus[0].menuItems.length )
220 visibleMenus[0].menuItems[0].hoverIn();
221 }
222 else
223 activeMenu.selectNextItem();
224 break;
225 }
226 if ( e.keyCode > 36 && e.keyCode < 41 )
227 return false; //this will prevent scrolling
228 },
229 closeAll : function()
230 {
231 while ( visibleMenus.length )
232 visibleMenus[0].hide();
233 },
234 setDefaults : function(d)
235 {
236 $.extend(defaults, d);
237 },
238 prototype : {
239 /**
240 * create / initialize new menu
241 */
242 init : function()
243 {
244 var self = this;
245 if ( !this.target )
246 return;
247 else if ( this.target instanceof $.MenuItem )
248 {
249 this.parentMenuItem = this.target;
250 this.target.addSubMenu(this);
251 this.target = this.target.$eLI;
252 }
253
254 menus.push(this);
255
256 //use the dom methods instead the ones from jquery (faster)
257 this.$eDIV = $(menuDIVElement.cloneNode(1));
258 this.$eUL = $(menuULElement.cloneNode(1));
259 this.$eDIV[0].appendChild(this.$eUL[0]);
260 $rootDiv[0].appendChild(this.$eDIV[0]);
261
262 //bind events
263 if ( !this.parentMenuItem )
264 {
265 $(this.target).click(function(e){
266 self.onClick(e);
267 }).hover(function(e){
268 self.setActive();
269
270 if ( self.settings.hoverOpenDelay )
271 {
272 self.openTimer = setTimeout(function(){
273 if ( !self.visible )
274 self.onClick(e);
275 }, self.settings.hoverOpenDelay);
276 }
277 }, function(){
278 if ( !self.visible )
279 $(this).removeClass('activetarget');
280
281 if ( self.openTimer )
282 clearTimeout(self.openTimer);
283 });
284 }
285 else
286 {
287 this.$eDIV.hover(function(){
288 self.setActive();
289 }, function(){});
290 }
291 },
292 setActive : function()
293 {
294 if ( !this.parentMenuItem )
295 $(this.target).addClass('activetarget');
296 else
297 this.active = true;
298 },
299 addItem : function(item)
300 {
301 if ( item instanceof $.MenuItem )
302 {
303 if ( $.inArray(item, this.menuItems) == -1 )
304 {
305 this.$eUL.append(item.$eLI);
306 this.menuItems.push(item);
307 item.parentMenu = this;
308 if ( item.subMenu )
309 this.subMenus.push(item.subMenu);
310 }
311 }
312 else
313 {
314 this.addItem(new $.MenuItem(item, this.settings));
315 }
316 },
317 addItems : function(items)
318 {
319 for ( var i = 0; i < items.length; i++ )
320 {
321 this.addItem(items[i]);
322 }
323 },
324 removeItem : function(item)
325 {
326 var pos = $.inArray(item, this.menuItems);
327 if ( pos > -1 )
328 this.menuItems.splice(pos, 1);
329 item.parentMenu = null;
330 },
331 hide : function()
332 {
333 if ( !this.visible )
334 return;
335
336 var i,
337 pos = $.inArray(this, visibleMenus);
338
339 this.$eDIV.hide();
340
341 if ( pos >= 0 )
342 visibleMenus.splice(pos, 1);
343 this.visible = this.active = false;
344
345 $(this.target).removeClass('activetarget');
346
347 //hide all submenus
348 for ( i = 0; i < this.subMenus.length; i++ )
349 {
350 this.subMenus[i].hide();
351 }
352
353 //set all items inactive (e.g. remove hover class..)
354 for ( i = 0; i < this.menuItems.length; i++ )
355 {
356 if ( this.menuItems[i].active )
357 this.menuItems[i].setInactive();
358 }
359
360 if ( !visibleMenus.length ) //unbind events when the last menu was closed
361 $(document).unbind('mousedown', $.Menu.checkMouse).unbind('keydown', $.Menu.checkKey);
362
363 if ( activeMenu == this )
364 activeMenu = null;
365
366 if ( this.settings.onClose )
367 this.settings.onClose.call(this);
368 },
369 show : function(e)
370 {
371 if ( this.visible )
372 return;
373
374 var zi,
375 pmi = this.parentMenuItem;
376
377 if ( this.menuItems.length ) //show only when it has items
378 {
379 if ( pmi ) //set z-index
380 {
381 zi = parseInt(pmi.parentMenu.$eDIV.css('z-index'));
382 this.$eDIV.css('z-index', (isNaN(zi) ? 1 : zi + 1));
383 }
384 this.$eDIV.css({visibility: 'hidden', display:'block'});
385
386 //set min-width
387 if ( this.settings.minWidth )
388 {
389 if ( this.$eDIV.width() < this.settings.minWidth )
390 this.$eDIV.css('width', this.settings.minWidth);
391 }
392
393 this.setPosition();
394 this.$eDIV.css({display:'none', visibility: ''}).show();
395
396 if ( this.settings.onOpen )
397 this.settings.onOpen.call(this);
398 }
399 if ( visibleMenus.length == 0 )
400 $(document).bind('mousedown', $.Menu.checkMouse).bind('keydown', $.Menu.checkKey);
401
402 this.visible = true;
403 visibleMenus.push(this);
404 },
405 setPosition : function()
406 {
407 var $t, o, posX, posY,
408 pmo, //parent menu offset
409 wst, //window scroll top
410 wsl, //window scroll left
411 ww = $(window).width(),
412 wh = $(window).height(),
413 pmi = this.parentMenuItem,
414 height = this.$eDIV[0].clientHeight,
415 width = this.$eDIV[0].clientWidth,
416 pheight; //parent height
417
418 if ( pmi )
419 {
420 //position on the right side of the parent menu item
421 o = pmi.$eLI.offset();
422 posX = o.left + pmi.$eLI.width();
423 posY = o.top;
424 }
425 else
426 {
427 //position right below the target
428 $t = $(this.target);
429 o = $t.offset();
430 posX = o.left + this.settings.offsetLeft;
431 posY = o.top + $t.height() + this.settings.offsetTop;
432 }
433
434 //y-pos
435 if ( $.fn.scrollTop )
436 {
437 wst = $(window).scrollTop();
438 if ( wh < height ) //menu is bigger than the window
439 {
440 //position the menu at the top of the visible area
441 posY = wst;
442 }
443 else if ( wh + wst < posY + height ) //outside on the bottom?
444 {
445 if ( pmi )
446 {
447 pmo = pmi.parentMenu.$eDIV.offset();
448 pheight = pmi.parentMenu.$eDIV[0].clientHeight;
449 if ( height <= pheight )
450 {
451 //bottom position = parentmenu-bottom position
452 posY = pmo.top + pheight - height;
453 }
454 else
455 {
456 //top position = parentmenu-top position
457 posY = pmo.top;
458 }
459 //still outside on the bottom?
460 if ( wh + wst < posY + height )
461 {
462 //shift the menu upwards till the bottom is visible
463 posY -= posY + height - (wh + wst);
464 }
465 }
466 else
467 {
468 //shift the menu upwards till the bottom is visible
469 posY -= posY + height - (wh + wst);
470 }
471 }
472 }
473 //x-pos
474 if ( $.fn.scrollLeft )
475 {
476 wsl = $(window).scrollLeft();
477 if ( ww + wsl < posX + width )
478 {
479 if ( pmi )
480 {
481 //display the menu not on the right side but on the left side
482 posX -= pmi.$eLI.width() + width;
483 //outside on the left now?
484 if ( posX < wsl )
485 posX = wsl;
486 }
487 else
488 {
489 //shift the menu to the left until it fits
490 posX -= posX + width - (ww + wsl);
491 }
492 }
493 }
494
495 //set position
496 this.$eDIV.css({left: posX, top: posY});
497 },
498 onClick : function(e)
499 {
500 if ( this.visible )
501 {
502 this.hide();
503 this.setActive(); //the class is removed in the hide() method..add it again
504 }
505 else
506 {
507 //close all open menus
508 $.Menu.closeAll();
509 this.show(e);
510 }
511 },
512 addTimer : function(callback, delay)
513 {
514 var self = this;
515 this.timer = setTimeout(function(){
516 callback.call(self);
517 self.timer = null;
518 }, delay);
519 },
520 removeTimer : function()
521 {
522 if ( this.timer )
523 {
524 clearTimeout(this.timer);
525 this.timer = null;
526 }
527 },
528 selectNextItem : function(offset)
529 {
530 var i, pos = 0,
531 mil = this.menuItems.length,
532 o = offset || 1;
533
534 //get current pos
535 for ( i = 0; i < mil; i++ )
536 {
537 if ( this.menuItems[i].active )
538 {
539 pos = i;
540 break;
541 }
542 }
543 this.menuItems[pos].hoverOut();
544
545 do //jump over the separators
546 {
547 pos += o;
548 if ( pos >= mil )
549 pos = 0;
550 else if ( pos < 0 )
551 pos = mil - 1;
552 } while ( this.menuItems[pos].separator );
553 this.menuItems[pos].hoverIn(true);
554 },
555 inMenuCollection : function()
556 {
557 var m = this;
558 while ( m.parentMenuItem )
559 m = m.parentMenuItem.parentMenu;
560 return m.menuCollection ? m : null;
561 },
562 destroy : function() //delete menu
563 {
564 var pos, item;
565
566 this.hide();
567
568 //unbind events
569 if ( !this.parentMenuItem )
570 $(this.target).unbind('click').unbind('mouseover').unbind('mouseout');
571 else
572 this.$eDIV.unbind('mouseover').unbind('mouseout');
573
574 //destroy all items
575 while ( this.menuItems.length )
576 {
577 item = this.menuItems[0];
578 item.destroy();
579 delete item;
580 }
581
582 if ( (pos = $.inArray(this, menus)) > -1 )
583 menus.splice(pos, 1);
584
585 if ( this.menuCollection )
586 {
587 if ( (pos = $.inArray(this, this.menuCollection.menus)) > -1 )
588 this.menuCollection.menus.splice(pos, 1);
589 }
590
591 this.$eDIV.remove();
592 }
593 }
594 });
595
596 $.extend({
597 MenuItem : function(obj, options)
598 {
599 if ( typeof obj == 'string' )
600 obj = {src: obj};
601
602 this.src = obj.src || '';
603 this.url = obj.url || null;
604 this.urlTarget = obj.target || null;
605 this.addClass = obj.addClass || null;
606 this.data = obj.data || null;
607
608 this.$eLI = null;
609 this.parentMenu = null;
610 this.subMenu = null;
611 this.settings = $.extend({}, defaults, options);
612 this.active = false;
613 this.enabled = true;
614 this.separator = false;
615
616 this.init();
617
618 if ( obj.subMenu )
619 new $.Menu(this, obj.subMenu, options);
620 }
621 });
622
623 $.extend($.MenuItem, {
624 prototype : {
625 init : function()
626 {
627 var i, isStr,
628 src = this.src,
629 self = this;
630
631 this.$eLI = $(menuItemElement.cloneNode(1));
632
633 if ( this.addClass )
634 this.$eLI[0].setAttribute('class', this.addClass);
635
636 if ( this.settings.addExpando && this.data )
637 this.$eLI[0].menuData = this.data;
638
639 if ( src == '' )
640 {
641 this.$eLI.addClass('menu-separator');
642 this.separator = true;
643 }
644 else
645 {
646 isStr = typeof src == 'string';
647 if ( isStr && this.url ) //create a link node, when we have an url
648 src = $('<a href="' + this.url + '"' + (this.urlTarget ? 'target="' + this.urlTarget + '"' : '') + '>' + src + '</a>');
649 else if ( isStr || !src.length )
650 src = [src];
651 //go through the passed DOM-Elements (or jquery objects or text nodes.) and append them to the menus list item
652 //this.$eLI.append(this.src) is really slow when having a lot(!!!) of items
653 for ( i = 0; i < src.length; i++ )
654 {
655 if ( typeof src[i] == 'string' )
656 {
657 //we cant use createTextNode, as html entities won't be displayed correctly (eg. &copy;)
658 elem = document.createElement('span');
659 elem.innerHTML = src[i];
660 this.$eLI[0].firstChild.appendChild(elem);
661 }
662 else
663 this.$eLI[0].firstChild.appendChild(src[i].cloneNode(1));
664 }
665 }
666
667 this.$eLI.click(function(e){
668 self.click(e, this);
669 });
670 this.bindHover();
671 },
672 click : function(e, scope)
673 {
674 if ( this.enabled && this.settings.onClick )
675 this.settings.onClick.call(scope, e, this);
676 },
677 bindHover : function()
678 {
679 var self = this;
680 this.$eLI.hover(function(){
681 self.hoverIn();
682 }, function(){
683 self.hoverOut();
684 });
685 },
686 hoverIn : function(noSubMenu)
687 {
688 this.removeTimer();
689
690 var i,
691 pms = this.parentMenu.subMenus,
692 pmi = this.parentMenu.menuItems,
693 self = this;
694
695 //remove the timer from the parent item, when there is one (e.g. to close the menu)
696 if ( this.parentMenu.timer )
697 this.parentMenu.removeTimer();
698
699 if ( !this.enabled )
700 return;
701
702 //deactivate all menuItems on the same level
703 for ( i = 0; i < pmi.length; i++ )
704 {
705 if ( pmi[i].active )
706 pmi[i].setInactive();
707 }
708
709 this.setActive();
710 activeMenu = this.parentMenu;
711
712 //are there open submenus on the same level? close them!
713 for ( i = 0; i < pms.length; i++ )
714 {
715 if ( pms[i].visible && pms[i] != this.subMenu && !pms[i].timer ) //close if there is no closetimer running already
716 pms[i].addTimer(function(){
717 this.hide();
718 }, pms[i].settings.hideDelay);
719 }
720
721 if ( this.subMenu && !noSubMenu )
722 {
723 //set timeout to show menu
724 this.subMenu.addTimer(function(){
725 this.show();
726 }, this.subMenu.settings.showDelay);
727 }
728 },
729 hoverOut : function()
730 {
731 this.removeTimer();
732
733 if ( !this.enabled )
734 return;
735
736 if ( !this.subMenu || !this.subMenu.visible )
737 this.setInactive();
738 },
739 removeTimer : function()
740 {
741 if ( this.subMenu )
742 {
743 this.subMenu.removeTimer();
744 }
745 },
746 setActive : function()
747 {
748 this.active = true;
749 this.$eLI.addClass('active');
750
751 //set the parent menu item active too if necessary
752 var pmi = this.parentMenu.parentMenuItem;
753 if ( pmi && !pmi.active )
754 pmi.setActive();
755
756 activeItem = this;
757 },
758 setInactive : function()
759 {
760 this.active = false;
761 this.$eLI.removeClass('active');
762 if ( this == activeItem )
763 activeItem = null;
764 },
765 enable : function()
766 {
767 this.$eLI.removeClass('disabled');
768 this.enabled = true;
769 },
770 disable : function()
771 {
772 this.$eLI.addClass('disabled');
773 this.enabled = false;
774 },
775 destroy : function()
776 {
777 this.removeTimer();
778
779 this.$eLI.remove();
780
781 //unbind events
782 this.$eLI.unbind('mouseover').unbind('mouseout').unbind('click');
783 //delete submenu
784 if ( this.subMenu )
785 {
786 this.subMenu.destroy();
787 delete this.subMenu;
788 }
789 this.parentMenu.removeItem(this);
790 },
791 addSubMenu : function(menu)
792 {
793 if ( this.subMenu )
794 return;
795 this.subMenu = menu;
796 if ( this.parentMenu && $.inArray(menu, this.parentMenu.subMenus) == -1 )
797 this.parentMenu.subMenus.push(menu);
798 if ( this.settings.arrowSrc )
799 {
800 var a = arrowElement.cloneNode(0);
801 a.setAttribute('src', this.settings.arrowSrc);
802 this.$eLI[0].firstChild.appendChild(a);
803 }
804 }
805 }
806 });
807
808
809 $.extend($.fn, {
810 menuFromElement : function(options, list, bar)
811 {
812 var createItems = function(ul)
813 {
814 var menuItems = [],
815 subItems,
816 menuItem,
817 lis, $li, i, subUL, submenu, target,
818 classNames = null;
819
820 lis = getAllChilds(ul, 'LI');
821 for ( i = 0; i < lis.length; i++ )
822 {
823 subItems = [];
824
825 if ( !lis[i].childNodes.length ) //empty item? add separator
826 {
827 menuItems.push(new $.MenuItem('', options));
828 continue;
829 }
830
831 if ( (subUL = getOneChild(lis[i], 'UL')) )
832 {
833 subItems = createItems(subUL);
834 //remove subUL from DOM
835 $(subUL).remove();
836 }
837
838 //select the target...get the elements inside the li
839 $li = $(lis[i]);
840 if ( $li[0].childNodes.length == 1 && $li[0].childNodes[0].nodeType == 3 )
841 target = $li[0].childNodes[0].nodeValue;
842 else
843 target = $li[0].childNodes;
844
845 if ( options && options.copyClassAttr )
846 classNames = $li.attr('class');
847
848 //create item
849 menuItem = new $.MenuItem({src: target, addClass: classNames}, options);
850 menuItems.push(menuItem);
851 //add submenu
852 if ( subItems.length )
853 new $.Menu(menuItem, subItems, options);
854
855 }
856 return menuItems;
857 };
858 return this.each(function()
859 {
860 var ul, m;
861 //get the list element
862 if ( list || (ul = getOneChild(this, 'UL')) )
863 {
864 //if a specific list element is used, clone it, as we probably need it more than once
865 ul = list ? $(list).clone(true)[0] : ul;
866 menuItems = createItems(ul);
867 if ( menuItems.length )
868 {
869 m = new $.Menu(this, menuItems, options);
870 if ( bar )
871 bar.addMenu(m);
872 }
873 $(ul).hide();
874 }
875 });
876 },
877 menuBarFromUL : function(options)
878 {
879 return this.each(function()
880 {
881 var i,
882 lis = getAllChilds(this, 'LI');
883
884 if ( lis.length )
885 {
886 bar = new $.MenuCollection();
887 for ( i = 0; i < lis.length; i++ )
888 $(lis[i]).menuFromElement(options, null, bar);
889 }
890 });
891 },
892 menuBar : function(options, items)
893 {
894 return this.each(function()
895 {
896 if ( items && items.constructor == Array )
897 new $.Menu(this, items, options);
898 else
899 {
900 if ( this.nodeName.toUpperCase() == 'UL' )
901 $(this).menuBarFromUL(options);
902 else
903 $(this).menuFromElement(options, items);
904 }
905 });
906 }
907 });
908
909 //faster than using jquery
910 var getOneChild = function(elem, name)
911 {
912 if ( !elem )
913 return null;
914
915 var n = elem.firstChild;
916 for ( ; n; n = n.nextSibling )
917 {
918 if ( n.nodeType == 1 && n.nodeName.toUpperCase() == name )
919 return n;
920 }
921 return null;
922 };
923 //faster than using jquery
924 var getAllChilds = function(elem, name)
925 {
926 if ( !elem )
927 return [];
928
929 var r = [],
930 n = elem.firstChild;
931 for ( ; n; n = n.nextSibling )
932 {
933 if ( n.nodeType == 1 && n.nodeName.toUpperCase() == name )
934 r[r.length] = n;
935 }
936 return r;
937 };
938
939 })(jQuery);