1// SpryMenuBar.js - version 0.13 - Spry Pre-Release 1.6.1 2 3// 4 5// Copyright (c) 2006. Adobe Systems Incorporated. 6 7// All rights reserved. 8 9// 10 11// Redistribution and use in source and binary forms, with or without 12 13// modification, are permitted provided that the following conditions are met: 14 15// 16 17// * Redistributions of source code must retain the above copyright notice, 18 19// this list of conditions and the following disclaimer. 20 21// * Redistributions in binary form must reproduce the above copyright notice, 22 23// this list of conditions and the following disclaimer in the documentation 24 25// and/or other materials provided with the distribution. 26 27// * Neither the name of Adobe Systems Incorporated nor the names of its 28 29// contributors may be used to endorse or promote products derived from this 30 31// software without specific prior written permission. 32 33// 34 35// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 36 37// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 38 39// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 40 41// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 42 43// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 44 45// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 46 47// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 48 49// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 50 51// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 52 53// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 54 55// POSSIBILITY OF SUCH DAMAGE. 56 57 58 59/******************************************************************************* 60 61 62 63 SpryMenuBar.js 64 65 This file handles the JavaScript for Spry Menu Bar. You should have no need 66 67 to edit this file. Some highlights of the MenuBar object is that timers are 68 69 used to keep submenus from showing up until the user has hovered over the parent 70 71 menu item for some time, as well as a timer for when they leave a submenu to keep 72 73 showing that submenu until the timer fires. 74 75 76 77 *******************************************************************************/ 78 79 80 81(function() { // BeginSpryComponent 82 83 84 85if (typeof Spry == "undefined") window.Spry = {}; if (!Spry.Widget) Spry.Widget = {}; 86 87 88 89Spry.BrowserSniff = function() 90 91{ 92 93 var b = navigator.appName.toString(); 94 95 var up = navigator.platform.toString(); 96 97 var ua = navigator.userAgent.toString(); 98 99 100 101 this.mozilla = this.ie = this.opera = this.safari = false; 102 103 var re_opera = /Opera.([0-9\.]*)/i; 104 105 var re_msie = /MSIE.([0-9\.]*)/i; 106 107 var re_gecko = /gecko/i; 108 109 var re_safari = /(applewebkit|safari)\/([\d\.]*)/i; 110 111 var r = false; 112 113 114 115 if ( (r = ua.match(re_opera))) { 116 117 this.opera = true; 118 119 this.version = parseFloat(r[1]); 120 121 } else if ( (r = ua.match(re_msie))) { 122 123 this.ie = true; 124 125 this.version = parseFloat(r[1]); 126 127 } else if ( (r = ua.match(re_safari))) { 128 129 this.safari = true; 130 131 this.version = parseFloat(r[2]); 132 133 } else if (ua.match(re_gecko)) { 134 135 var re_gecko_version = /rv:\s*([0-9\.]+)/i; 136 137 r = ua.match(re_gecko_version); 138 139 this.mozilla = true; 140 141 this.version = parseFloat(r[1]); 142 143 } 144 145 this.windows = this.mac = this.linux = false; 146 147 148 149 this.Platform = ua.match(/windows/i) ? "windows" : 150 151 (ua.match(/linux/i) ? "linux" : 152 153 (ua.match(/mac/i) ? "mac" : 154 155 ua.match(/unix/i)? "unix" : "unknown")); 156 157 this[this.Platform] = true; 158 159 this.v = this.version; 160 161 162 163 if (this.safari && this.mac && this.mozilla) { 164 165 this.mozilla = false; 166 167 } 168 169}; 170 171 172 173Spry.is = new Spry.BrowserSniff(); 174 175 176 177// Constructor for Menu Bar 178 179// element should be an ID of an unordered list (<ul> tag) 180 181// preloadImage1 and preloadImage2 are images for the rollover state of a menu 182 183Spry.Widget.MenuBar = function(element, opts) 184 185{ 186 187 this.init(element, opts); 188 189}; 190 191 192 193Spry.Widget.MenuBar.prototype.init = function(element, opts) 194 195{ 196 197 this.element = this.getElement(element); 198 199 200 201 // represents the current (sub)menu we are operating on 202 203 this.currMenu = null; 204 205 this.showDelay = 250; 206 207 this.hideDelay = 600; 208 209 if(typeof document.getElementById == 'undefined' || (navigator.vendor == 'Apple Computer, Inc.' && typeof window.XMLHttpRequest == 'undefined') || (Spry.is.ie && typeof document.uniqueID == 'undefined')) 210 211 { 212 213 // bail on older unsupported browsers 214 215 return; 216 217 } 218 219 220 221 // Fix IE6 CSS images flicker 222 223 if (Spry.is.ie && Spry.is.version < 7){ 224 225 try { 226
227 document.execCommand("BackgroundImageCache", false, true); 228 229 } catch(err) {} 230 231 } 232 233 234 235 this.upKeyCode = Spry.Widget.MenuBar.KEY_UP; 236 237 this.downKeyCode = Spry.Widget.MenuBar.KEY_DOWN; 238 239 this.leftKeyCode = Spry.Widget.MenuBar.KEY_LEFT; 240 241 this.rightKeyCode = Spry.Widget.MenuBar.KEY_RIGHT; 242 243 this.escKeyCode = Spry.Widget.MenuBar.KEY_ESC; 244 245 246 247 this.hoverClass = 'MenuBarItemHover'; 248 249 this.subHoverClass = 'MenuBarItemSubmenuHover'; 250 251 this.subVisibleClass ='MenuBarSubmenuVisible'; 252 253 this.hasSubClass = 'MenuBarItemSubmenu'; 254 255 this.activeClass = 'MenuBarActive'; 256 257 this.isieClass = 'MenuBarItemIE'; 258 259 this.verticalClass = 'MenuBarVertical'; 260 261 this.horizontalClass = 'MenuBarHorizontal'; 262 263 this.enableKeyboardNavigation = true; 264 265 266 267 this.hasFocus = false; 268 269 // load hover images now 270 271 if(opts) 272 273 { 274 275 for(var k in opts) 276 277 { 278 279 if (typeof this[k] == 'undefined') 280 281 { 282 283 var rollover = new Image; 284 285 rollover.src = opts[k]; 286 287 } 288 289 } 290 291 Spry.Widget.MenuBar.setOptions(this, opts); 292 293 } 294 295 296 297 // safari doesn't support tabindex 298 299 if (Spry.is.safari) 300 301 this.enableKeyboardNavigation = false; 302 303 304 305 if(this.element) 306 307 { 308 309 this.currMenu = this.element; 310 311 var items = this.element.getElementsByTagName('li'); 312 313 for(var i=0; i<items.length; i++) 314 315 { 316 317 if (i > 0 && this.enableKeyboardNavigation) 318 319 items[i].getElementsByTagName('a')[0].tabIndex='-1'; 320 321 322 323 this.initialize(items[i], element); 324 325 if(Spry.is.ie) 326 327 { 328 329 this.addClassName(items[i], this.isieClass); 330 331 items[i].style.position = "static"; 332 333 } 334 335 } 336 337 if (this.enableKeyboardNavigation) 338 339 { 340 341 var self = this; 342 343 this.addEventListener(document, 'keydown', function(e){self.keyDown(e); }, false); 344 345 } 346 347 348 349 if(Spry.is.ie) 350 351 { 352 353 if(this.hasClassName(this.element, this.verticalClass)) 354 355 { 356 357 this.element.style.position = "relative"; 358 359 } 360 361 var linkitems = this.element.getElementsByTagName('a'); 362 363 for(var i=0; i<linkitems.length; i++) 364 365 { 366 367 linkitems[i].style.position = "relative"; 368 369 } 370 371 } 372 373 } 374 375}; 376 377Spry.Widget.MenuBar.KEY_ESC = 27; 378 379Spry.Widget.MenuBar.KEY_UP = 38; 380 381Spry.Widget.MenuBar.KEY_DOWN = 40; 382 383Spry.Widget.MenuBar.KEY_LEFT = 37; 384 385Spry.Widget.MenuBar.KEY_RIGHT = 39; 386 387 388 389Spry.Widget.MenuBar.prototype.getElement = function(ele) 390 391{ 392 393 if (ele && typeof ele == "string") 394 395 return document.getElementById(ele); 396 397 return ele; 398 399}; 400 401 402 403Spry.Widget.MenuBar.prototype.hasClassName = function(ele, className) 404 405{ 406 407 if (!ele || !className || !ele.className || ele.className.search(new RegExp("\\b" + className + "\\b")) == -1) 408 409 { 410 411 return false; 412 413 } 414 415 return true; 416 417}; 418 419 420 421Spry.Widget.MenuBar.prototype.addClassName = function(ele, className) 422 423{ 424 425 if (!ele || !className || this.hasClassName(ele, className)) 426 427 return; 428 429 ele.className += (ele.className ? " " : "") + className; 430 431}; 432 433 434 435Spry.Widget.MenuBar.prototype.removeClassName = function(ele, className) 436 437{ 438 439 if (!ele || !className || !this.hasClassName(ele, className)) 440 441 return; 442 443 ele.className = ele.className.replace(new RegExp("\\s*\\b" + className + "\\b", "g"), ""); 444 445}; 446 447 448 449// addEventListener for Menu Bar 450 451// attach an event to a tag without creating obtrusive HTML code 452 453Spry.Widget.MenuBar.prototype.addEventListener = function(element, eventType, handler, capture) 454 455{ 456 457 try 458 459 { 460 461 if (element.addEventListener) 462 463 { 464 465 element.addEventListener(eventType, handler, capture); 466 467 } 468 469 else if (element.attachEvent) 470 471 { 472 473 element.attachEvent('on' + eventType, handler); 474 475 } 476 477 } 478 479 catch (e) {} 480 481}; 482 483 484 485// createIframeLayer for Menu Bar 486 487// creates an IFRAME underneath a menu so that it will show above form controls and ActiveX 488 489Spry.Widget.MenuBar.prototype.createIframeLayer = function(menu) 490 491{ 492 493 var layer = document.createElement('iframe'); 494 495 layer.tabIndex = '-1'; 496 497 layer.src = 'javascript:""'; 498 499 layer.frameBorder = '0'; 500 501 layer.scrolling = 'no'; 502 503 menu.parentNode.appendChild(layer); 504 505 506 507 layer.style.left = menu.offsetLeft + 'px'; 508 509 layer.style.top = menu.offsetTop + 'px'; 510 511 layer.style.width = menu.offsetWidth + 'px'; 512 513 layer.style.height = menu.offsetHeight + 'px'; 514 515}; 516 517 518 519// removeIframeLayer for Menu Bar 520 521// removes an IFRAME underneath a menu to reveal any form controls and ActiveX 522 523Spry.Widget.MenuBar.prototype.removeIframeLayer = function(menu) 524 525{ 526 527 var layers = ((menu == this.element) ? menu : menu.parentNode).getElementsByTagName('iframe'); 528 529 while(layers.length > 0) 530 531 { 532 533 layers[0].parentNode.removeChild(layers[0]); 534 535 } 536 537}; 538 539 540 541// clearMenus for Menu Bar 542 543// root is the top level unordered list (<ul> tag) 544 545Spry.Widget.MenuBar.prototype.clearMenus = function(root) 546 547{ 548 549 var menus = root.getElementsByTagName('ul'); 550 551 for(var i=0; i<menus.length; i++) 552 553 this.hideSubmenu(menus[i]); 554 555 556 557 this.removeClassName(this.element, this.activeClass); 558 559}; 560 561 562 563// bubbledTextEvent for Menu Bar 564 565// identify bubbled up text events in Safari so we can ignore them 566 567Spry.Widget.MenuBar.prototype.bubbledTextEvent = function() 568 569{ 570 571 return Spry.is.safari && (event.target == event.relatedTarget.parentNode || (event.eventPhase == 3 && event.target.parentNode == event.relatedTarget)); 572 573}; 574 575 576 577// showSubmenu for Menu Bar 578 579// set the proper CSS class on this menu to show it 580 581Spry.Widget.MenuBar.prototype.showSubmenu = function(menu) 582 583{ 584 585 if(this.currMenu) 586 587 { 588 589 this.clearMenus(this.currMenu); 590 591 this.currMenu = null; 592 593 } 594 595 596 597 if(menu) 598 599 { 600 601 this.addClassName(menu, this.subVisibleClass); 602 603 if(typeof document.all != 'undefined' && !Spry.is.opera && navigator.vendor != 'KDE') 604 605 { 606 607 if(!this.hasClassName(this.element, this.horizontalClass) || menu.parentNode.parentNode != this.element) 608 609 { 610 611 menu.style.top = menu.parentNode.offsetTop + 'px'; 612 613 } 614 615 } 616 617 if(Spry.is.ie && Spry.is.version < 7) 618 619 { 620 621 this.createIframeLayer(menu); 622 623 } 624 625 } 626 627 this.addClassName(this.element, this.activeClass); 628 629}; 630 631 632 633// hideSubmenu for Menu Bar 634 635// remove the proper CSS class on this menu to hide it 636 637Spry.Widget.MenuBar.prototype.hideSubmenu = function(menu) 638 639{ 640 641 if(menu) 642 643 { 644 645 this.removeClassName(menu, this.subVisibleClass); 646 647 if(typeof document.all != 'undefined' && !Spry.is.opera && navigator.vendor != 'KDE') 648 649 { 650 651 menu.style.top = ''; 652 653 menu.style.left = ''; 654 655 } 656 657 if(Spry.is.ie && Spry.is.version < 7) 658 659 this.removeIframeLayer(menu); 660 661 } 662 663}; 664 665 666 667// initialize for Menu Bar 668 669// create event listeners for the Menu Bar widget so we can properly 670 671// show and hide submenus 672 673Spry.Widget.MenuBar.prototype.initialize = function(listitem, element) 674 675{ 676 677 var opentime, closetime; 678 679 var link = listitem.getElementsByTagName('a')[0]; 680 681 var submenus = listitem.getElementsByTagName('ul'); 682 683 var menu = (submenus.length > 0 ? submenus[0] : null); 684 685 686 687 if(menu) 688 689 this.addClassName(link, this.hasSubClass); 690 691 692 693 if(!Spry.is.ie) 694 695 { 696 697 // define a simple function that comes standard in IE to determine 698 699 // if a node is within another node 700 701 listitem.contains = function(testNode) 702 703 { 704 705 // this refers to the list item 706 707 if(testNode == null) 708 709 return false;
710 711 712 713 if(testNode == this) 714 715 return true; 716 717 else 718 719 return this.contains(testNode.parentNode); 720 721 }; 722 723 } 724 725 726 727 // need to save this for scope further down 728 729 var self = this; 730 731 this.addEventListener(listitem, 'mouseover', function(e){self.mouseOver(listitem, e);}, false); 732 733 this.addEventListener(listitem, 'mouseout', function(e){if (self.enableKeyboardNavigation) self.clearSelection(); self.mouseOut(listitem, e);}, false); 734 735 736 737 if (this.enableKeyboardNavigation) 738 739 { 740 741 this.addEventListener(link, 'blur', function(e){self.onBlur(listitem);}, false); 742 743 this.addEventListener(link, 'focus', function(e){self.keyFocus(listitem, e);}, false); 744 745 } 746 747}; 748 749Spry.Widget.MenuBar.prototype.keyFocus = function (listitem, e) 750 751{ 752 753 this.lastOpen = listitem.getElementsByTagName('a')[0]; 754 755 this.addClassName(this.lastOpen, listitem.getElementsByTagName('ul').length > 0 ? this.subHoverClass : this.hoverClass); 756 757 this.hasFocus = true; 758 759}; 760 761Spry.Widget.MenuBar.prototype.onBlur = function (listitem) 762 763{ 764 765 this.clearSelection(listitem); 766 767}; 768 769Spry.Widget.MenuBar.prototype.clearSelection = function(el){ 770 771 //search any intersection with the current open element 772 773 if (!this.lastOpen) 774 775 return; 776 777 778 779 if (el) 780 781 { 782 783 el = el.getElementsByTagName('a')[0]; 784 785 786 787 // check children 788 789 var item = this.lastOpen; 790 791 while (item != this.element) 792 793 { 794 795 var tmp = el; 796 797 while (tmp != this.element) 798 799 { 800 801 if (tmp == item) 802 803 return; 804 805 try{ 806 807 tmp = tmp.parentNode; 808 809 }catch(err){break;} 810 811 } 812 813 item = item.parentNode; 814 815 } 816 817 } 818 819 var item = this.lastOpen; 820 821 while (item != this.element) 822 823 { 824 825 this.hideSubmenu(item.parentNode); 826 827 var link = item.getElementsByTagName('a')[0]; 828 829 this.removeClassName(link, this.hoverClass); 830 831 this.removeClassName(link, this.subHoverClass); 832 833 item = item.parentNode; 834 835 } 836 837 this.lastOpen = false; 838 839}; 840 841Spry.Widget.MenuBar.prototype.keyDown = function (e) 842 843{ 844 845 if (!this.hasFocus) 846 847 return; 848 849 850 851 if (!this.lastOpen) 852 853 { 854 855 this.hasFocus = false; 856 857 return; 858 859 } 860 861 862 863 var e = e|| event; 864 865 var listitem = this.lastOpen.parentNode; 866 867 var link = this.lastOpen; 868 869 var submenus = listitem.getElementsByTagName('ul'); 870 871 var menu = (submenus.length > 0 ? submenus[0] : null); 872 873 var hasSubMenu = (menu) ? true : false; 874 875 876 877 var opts = [listitem, menu, null, this.getSibling(listitem, 'previousSibling'), this.getSibling(listitem, 'nextSibling')]; 878 879 880 881 if (!opts[3]) 882 883 opts[2] = (listitem.parentNode.parentNode.nodeName.toLowerCase() == 'li')?listitem.parentNode.parentNode:null; 884 885 886 887 var found = 0; 888 889 switch (e.keyCode){ 890 891 case this.upKeyCode: 892 893 found = this.getElementForKey(opts, 'y', 1); 894 895 break; 896 897 case this.downKeyCode: 898 899 found = this.getElementForKey(opts, 'y', -1); 900 901 break; 902 903 case this.leftKeyCode: 904 905 found = this.getElementForKey(opts, 'x', 1); 906 907 break; 908 909 case this.rightKeyCode: 910 911 found = this.getElementForKey(opts, 'x', -1); 912 913 break; 914 915 case this.escKeyCode: 916 917 case 9: 918 919 this.clearSelection(); 920 921 this.hasFocus = false; 922 923 default: return; 924 925 } 926 927 switch (found) 928 929 { 930 931 case 0: return; 932 933 case 1: 934 935 //subopts 936 937 this.mouseOver(listitem, e); 938 939 break; 940 941 case 2: 942 943 //parent 944 945 this.mouseOut(opts[2], e); 946 947 break; 948 949 case 3: 950 951 case 4: 952 953 // left - right 954 955 this.removeClassName(link, hasSubMenu ? this.subHoverClass : this.hoverClass); 956 957 break; 958 959 } 960 961 var link = opts[found].getElementsByTagName('a')[0]; 962 963 if (opts[found].nodeName.toLowerCase() == 'ul') 964 965 opts[found] = opts[found].getElementsByTagName('li')[0]; 966 967 968 969 this.addClassName(link, opts[found].getElementsByTagName('ul').length > 0 ? this.subHoverClass : this.hoverClass); 970 971 this.lastOpen = link; 972 973 opts[found].getElementsByTagName('a')[0].focus(); 974 975 976 977 //stop further event handling by the browser 978 979 return Spry.Widget.MenuBar.stopPropagation(e); 980 981}; 982 983Spry.Widget.MenuBar.prototype.mouseOver = function (listitem, e) 984 985{ 986 987 var link = listitem.getElementsByTagName('a')[0]; 988 989 var submenus = listitem.getElementsByTagName('ul'); 990 991 var menu = (submenus.length > 0 ? submenus[0] : null); 992 993 var hasSubMenu = (menu) ? true : false; 994 995 if (this.enableKeyboardNavigation) 996 997 this.clearSelection(listitem); 998 999 1000 1001 if(this.bubbledTextEvent()) 1002 1003 { 1004 1005 // ignore bubbled text events 1006 1007 return; 1008 1009 } 1010 1011 1012 1013 if (listitem.closetime) 1014 1015 clearTimeout(listitem.closetime); 1016 1017 1018 1019 if(this.currMenu == listitem) 1020 1021 { 1022 1023 this.currMenu = null; 1024 1025 } 1026 1027 1028 1029 // move the focus too 1030 1031 if (this.hasFocus) 1032 1033 link.focus(); 1034 1035 1036 1037 // show menu highlighting 1038 1039 this.addClassName(link, hasSubMenu ? this.subHoverClass : this.hoverClass); 1040 1041 this.lastOpen = link; 1042 1043 if(menu && !this.hasClassName(menu, this.subHoverClass)) 1044 1045 { 1046 1047 var self = this; 1048 1049 listitem.opentime = window.setTimeout(function(){self.showSubmenu(menu);}, this.showDelay); 1050 1051 } 1052 1053}; 1054 1055Spry.Widget.MenuBar.prototype.mouseOut = function (listitem, e) 1056 1057{ 1058 1059 var link = listitem.getElementsByTagName('a')[0]; 1060 1061 var submenus = listitem.getElementsByTagName('ul'); 1062 1063 var menu = (submenus.length > 0 ? submenus[0] : null); 1064 1065 var hasSubMenu = (menu) ? true : false;
1066 1067 if(this.bubbledTextEvent()) 1068 1069 { 1070 1071 // ignore bubbled text events 1072 1073 return; 1074 1075 } 1076 1077 1078 1079 var related = (typeof e.relatedTarget != 'undefined' ? e.relatedTarget : e.toElement); 1080 1081 if(!listitem.contains(related)) 1082 1083 { 1084 1085 if (listitem.opentime) 1086 1087 clearTimeout(listitem.opentime); 1088 1089 this.currMenu = listitem; 1090 1091 1092 1093 // remove menu highlighting 1094 1095 this.removeClassName(link, hasSubMenu ? this.subHoverClass : this.hoverClass); 1096 1097 if(menu) 1098 1099 { 1100 1101 var self = this; 1102 1103 listitem.closetime = window.setTimeout(function(){self.hideSubmenu(menu);}, this.hideDelay); 1104 1105 } 1106 1107 if (this.hasFocus) 1108 1109 link.blur(); 1110 1111 } 1112 1113}; 1114 1115Spry.Widget.MenuBar.prototype.getSibling = function(element, sibling) 1116 1117{ 1118 1119 var child = element[sibling]; 1120 1121 while (child && child.nodeName.toLowerCase() !='li') 1122 1123 child = child[sibling]; 1124 1125 1126 1127 return child; 1128 1129}; 1130 1131Spry.Widget.MenuBar.prototype.getElementForKey = function(els, prop, dir) 1132 1133{ 1134 1135 var found = 0; 1136 1137 var rect = Spry.Widget.MenuBar.getPosition; 1138 1139 var ref = rect(els[found]); 1140 1141 1142 1143 var hideSubmenu = false; 1144 1145 //make the subelement visible to compute the position 1146 1147 if (els[1] && !this.hasClassName(els[1], this.MenuBarSubmenuVisible)) 1148 1149 { 1150 1151 els[1].style.visibility = 'hidden'; 1152 1153 this.showSubmenu(els[1]); 1154 1155 hideSubmenu = true; 1156 1157 } 1158 1159 1160 1161 var isVert = this.hasClassName(this.element, this.verticalClass); 1162 1163 var hasParent = els[0].parentNode.parentNode.nodeName.toLowerCase() == 'li' ? true : false; 1164 1165 1166 1167 for (var i = 1; i < els.length; i++){ 1168 1169 //when navigating on the y axis in vertical menus, ignore children and parents 1170 1171 if(prop=='y' && isVert && (i==1 || i==2)) 1172 1173 { 1174 1175 continue; 1176 1177 } 1178 1179 //when navigationg on the x axis in the FIRST LEVEL of horizontal menus, ignore children and parents 1180 1181 if(prop=='x' && !isVert && !hasParent && (i==1 || i==2)) 1182 1183 { 1184 1185 continue; 1186 1187 } 1188 1189 1190 1191 if (els[i]) 1192 1193 { 1194 1195 var tmp = rect(els[i]); 1196 1197 if ( (dir * tmp[prop]) < (dir * ref[prop])) 1198 1199 { 1200 1201 ref = tmp; 1202 1203 found = i; 1204 1205 } 1206 1207 } 1208 1209 } 1210 1211 1212 1213 // hide back the submenu 1214 1215 if (els[1] && hideSubmenu){ 1216 1217 this.hideSubmenu(els[1]); 1218 1219 els[1].style.visibility = ''; 1220 1221 } 1222 1223 1224 1225 return found; 1226 1227}; 1228 1229Spry.Widget.MenuBar.camelize = function(str) 1230 1231{ 1232 1233 if (str.indexOf('-') == -1){ 1234 1235 return str; 1236 1237 } 1238 1239 var oStringList = str.split('-'); 1240 1241 var isFirstEntry = true; 1242 1243 var camelizedString = ''; 1244 1245 1246 1247 for(var i=0; i < oStringList.length; i++) 1248 1249 { 1250 1251 if(oStringList[i].length>0) 1252 1253 { 1254 1255 if(isFirstEntry) 1256 1257 { 1258 1259 camelizedString = oStringList[i]; 1260 1261 isFirstEntry = false; 1262 1263 } 1264 1265 else 1266 1267 { 1268 1269 var s = oStringList[i]; 1270 1271 camelizedString += s.charAt(0).toUpperCase() + s.substring(1); 1272 1273 } 1274 1275 } 1276 1277 } 1278 1279 1280 1281 return camelizedString; 1282 1283}; 1284 1285 1286 1287Spry.Widget.MenuBar.getStyleProp = function(element, prop) 1288 1289{ 1290 1291 var value; 1292 1293 try 1294 1295 { 1296 1297 if (element.style) 1298 1299 value = element.style[Spry.Widget.MenuBar.camelize(prop)]; 1300 1301 1302 1303 if (!value) 1304 1305 if (document.defaultView && document.defaultView.getComputedStyle) 1306 1307 { 1308 1309 var css = document.defaultView.getComputedStyle(element, null); 1310 1311 value = css ? css.getPropertyValue(prop) : null; 1312 1313 } 1314 1315 else if (element.currentStyle) 1316 1317 { 1318 1319 value = element.currentStyle[Spry.Widget.MenuBar.camelize(prop)]; 1320 1321 } 1322 1323 } 1324 1325 catch (e) {} 1326 1327 1328 1329 return value == 'auto' ? null : value; 1330 1331}; 1332 1333Spry.Widget.MenuBar.getIntProp = function(element, prop) 1334 1335{ 1336 1337 var a = parseInt(Spry.Widget.MenuBar.getStyleProp(element, prop),10); 1338 1339 if (isNaN(a)) 1340 1341 return 0; 1342 1343 return a; 1344 1345}; 1346 1347 1348 1349Spry.Widget.MenuBar.getPosition = function(el, doc) 1350 1351{ 1352 1353 doc = doc || document; 1354 1355 if (typeof(el) == 'string') { 1356 1357 el = doc.getElementById(el); 1358 1359 } 1360 1361 1362 1363 if (!el) { 1364 1365 return false; 1366 1367 } 1368 1369 1370 1371 if (el.parentNode === null || Spry.Widget.MenuBar.getStyleProp(el, 'display') == 'none') { 1372 1373 //element must be visible to have a box 1374 1375 return false; 1376 1377 } 1378 1379 1380 1381 var ret = {x:0, y:0}; 1382 1383 var parent = null; 1384 1385 var box; 1386 1387 1388 1389 if (el.getBoundingClientRect) { // IE 1390 1391 box = el.getBoundingClientRect(); 1392 1393 var scrollTop = doc.documentElement.scrollTop || doc.body.scrollTop; 1394 1395 var scrollLeft = doc.documentElement.scrollLeft || doc.body.scrollLeft; 1396 1397 ret.x = box.left + scrollLeft; 1398 1399 ret.y = box.top + scrollTop; 1400 1401 } else if (doc.getBoxObjectFor) { // gecko 1402 1403 box = doc.getBoxObjectFor(el); 1404 1405 ret.x = box.x; 1406 1407 ret.y = box.y; 1408 1409 } else { // safari/opera 1410 1411 ret.x = el.offsetLeft; 1412 1413 ret.y = el.offsetTop; 1414 1415 parent = el.offsetParent; 1416 1417 if (parent != el) { 1418 1419 while (parent) { 1420 1421 ret.x += parent.offsetLeft; 1422 1423 ret.y += parent.offsetTop; 1424 1425 parent = parent.offsetParent; 1426 1427 } 1428 1429 } 1430 1431 // opera & (safari absolute) incorrectly account for body offsetTop 1432 1433 if (Spry.is.opera || Spry.is.safari && Spry.Widget.MenuBar.getStyleProp(el, 'position') == 'absolute') 1434 1435 ret.y -= doc.body.offsetTop; 1436 1437 } 1438 1439 if (el.parentNode) 1440 1441 parent = el.parentNode; 1442 1443 else 1444 1445 parent = null; 1446 1447 if (parent.nodeName){ 1448 1449 var cas = parent.nodeName.toUpperCase(); 1450 1451 while (parent && cas != 'BODY' && cas != 'HTML') { 1452 1453 cas = parent.nodeName.toUpperCase(); 1454 1455 ret.x -= parent.scrollLeft; 1456 1457 ret.y -= parent.scrollTop; 1458 1459 if (parent.parentNode) 1460 1461 parent = parent.parentNode; 1462 1463 else 1464 1465 parent = null; 1466 1467 } 1468 1469 } 1470 1471 return ret; 1472 1473}; 1474 1475 1476 1477Spry.Widget.MenuBar.stopPropagation = function(ev) 1478 1479{ 1480 1481 if (ev.stopPropagation) 1482 1483 ev.stopPropagation(); 1484 1485 else 1486 1487 ev.cancelBubble = true; 1488 1489 if (ev.preventDefault) 1490 1491 ev.preventDefault(); 1492 1493 else 1494 1495 ev.returnValue = false;
1496 1497}; 1498 1499 1500 1501Spry.Widget.MenuBar.setOptions = function(obj, optionsObj, ignoreUndefinedProps) 1502 1503{ 1504 1505 if (!optionsObj) 1506 1507 return; 1508 1509 for (var optionName in optionsObj) 1510 1511 { 1512 1513 if (ignoreUndefinedProps && optionsObj[optionName] == undefined) 1514 1515 continue; 1516 1517 obj[optionName] = optionsObj[optionName]; 1518 1519 } 1520 1521}; 1522 1523 1524 1525})(); // EndSpryComponent 1526
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.