[ Index ]
 

Code source de e107 0.7.8

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/e107_files/ -> nav_menu_alt.js (source)

   1  //<![CDATA[
   2  
   3  //*****************************************************************************
   4  // Do not remove this notice.
   5  //
   6  // Copyright 2000-2004 by Mike Hall.
   7  // See http://www.brainjar.com for terms of use.
   8  //*****************************************************************************
   9  
  10  //----------------------------------------------------------------------------
  11  // Code to determine the browser and version.
  12  //----------------------------------------------------------------------------
  13  
  14  function Browser() {
  15  
  16    var ua, s, i;
  17  
  18    this.isIE    = false;  // Internet Explorer
  19    this.isOP    = false;  // Opera
  20    this.isNS    = false;  // Netscape
  21    this.version = null;
  22  
  23    ua = navigator.userAgent;
  24  
  25    s = "Opera";
  26    if ((i = ua.indexOf(s)) >= 0) {
  27      this.isOP = true;
  28      this.version = parseFloat(ua.substr(i + s.length));
  29      return;
  30    }
  31  
  32    s = "Netscape6/";
  33    if ((i = ua.indexOf(s)) >= 0) {
  34      this.isNS = true;
  35      this.version = parseFloat(ua.substr(i + s.length));
  36      return;
  37    }
  38  
  39    // Treat any other "Gecko" browser as Netscape 6.1.
  40  
  41    s = "Gecko";
  42    if ((i = ua.indexOf(s)) >= 0) {
  43      this.isNS = true;
  44      this.version = 6.1;
  45      return;
  46    }
  47  
  48    s = "MSIE";
  49    if ((i = ua.indexOf(s))) {
  50      this.isIE = true;
  51      this.version = parseFloat(ua.substr(i + s.length));
  52      return;
  53    }
  54  }
  55  
  56  var browser = new Browser();
  57  
  58  //----------------------------------------------------------------------------
  59  // Code for handling the menu bar and active button.
  60  //----------------------------------------------------------------------------
  61  
  62  var activeButton = null;
  63  
  64  /* [MODIFIED] This code commented out, not needed for activate/deactivate
  65     on mouseover.
  66  
  67  // Capture mouse clicks on the page so any active button can be
  68  // deactivated.
  69  
  70  if (browser.isIE)
  71    document.onmousedown = pageMousedown;
  72  else
  73    document.addEventListener("mousedown", pageMousedown, true);
  74  
  75  function pageMousedown(event) {
  76  
  77    var el;
  78  
  79    // If there is no active button, exit.
  80  
  81    if (activeButton == null)
  82      return;
  83  
  84    // Find the element that was clicked on.
  85  
  86    if (browser.isIE)
  87      el = window.event.srcElement;
  88    else
  89      el = (event.target.tagName ? event.target : event.target.parentNode);
  90  
  91    // If the active button was clicked on, exit.
  92  
  93    if (el == activeButton)
  94      return;
  95  
  96    // If the element is not part of a menu, reset and clear the active
  97    // button.
  98  
  99    if (getContainerWith(el, "DIV", "menu") == null) {
 100      resetButton(activeButton);
 101      activeButton = null;
 102    }
 103  }
 104  
 105  [END MODIFIED] */
 106  
 107  function buttonClick(event, menuId) {
 108  
 109    var button;
 110  
 111    // Get the target button element.
 112  
 113    if (browser.isIE)
 114      button = window.event.srcElement;
 115    else
 116      button = event.currentTarget;
 117  
 118    // Blur focus from the link to remove that annoying outline.
 119  
 120    button.blur();
 121  
 122    // Associate the named menu to this button if not already done.
 123    // Additionally, initialize menu display.
 124  
 125    if (button.menu == null) {
 126      button.menu = document.getElementById(menuId);
 127      if (button.menu.isInitialized == null)
 128        menuInit(button.menu);
 129    }
 130  
 131    // [MODIFIED] Added for activate/deactivate on mouseover.
 132  
 133    // Set mouseout event handler for the button, if not already done.
 134  
 135    if (button.onmouseout == null)
 136      button.onmouseout = buttonOrMenuMouseout;
 137  
 138    // Exit if this button is the currently active one.
 139  
 140    if (button == activeButton)
 141      return false;
 142  
 143    // [END MODIFIED]
 144  
 145    // Reset the currently active button, if any.
 146  
 147    if (activeButton != null)
 148      resetButton(activeButton);
 149  
 150    // Activate this button, unless it was the currently active one.
 151  
 152    if (button != activeButton) {
 153      depressButton(button);
 154      activeButton = button;
 155    }
 156    else
 157      activeButton = null;
 158  
 159    return false;
 160  }
 161  
 162  function buttonMouseover(event, menuId) {
 163  
 164    var button;
 165  
 166    // [MODIFIED] Added for activate/deactivate on mouseover.
 167  
 168    // Activates this button's menu if no other is currently active.
 169  
 170    if (activeButton == null) {
 171      buttonClick(event, menuId);
 172      return;
 173    }
 174  
 175    // [END MODIFIED]
 176  
 177    // Find the target button element.
 178  
 179    if (browser.isIE)
 180      button = window.event.srcElement;
 181    else
 182      button = event.currentTarget;
 183  
 184    // If any other button menu is active, make this one active instead.
 185  
 186    if (activeButton != null && activeButton != button)
 187      buttonClick(event, menuId);
 188  }
 189  
 190  function depressButton(button) {
 191  
 192    var x, y;
 193  
 194    // Update the button's style class to make it look like it's
 195    // depressed.
 196  
 197    button.className += " menuButtonActive";
 198  
 199    // [MODIFIED] Added for activate/deactivate on mouseover.
 200  
 201    // Set mouseout event handler for the button, if not already done.
 202  
 203    if (button.onmouseout == null)
 204      button.onmouseout = buttonOrMenuMouseout;
 205    if (button.menu.onmouseout == null)
 206      button.menu.onmouseout = buttonOrMenuMouseout;
 207  
 208    // [END MODIFIED]
 209  
 210    // Position the associated drop down menu under the button and
 211    // show it.
 212  
 213    x = getPageOffsetLeft(button);
 214    y = getPageOffsetTop(button) + button.offsetHeight;
 215  
 216    // For IE, adjust position.
 217  
 218    if (browser.isIE) {
 219      x += button.offsetParent.clientLeft;
 220      y += button.offsetParent.clientTop - 1;
 221    }
 222  
 223    button.menu.style.left = x + "px";
 224    button.menu.style.top  = y + "px";
 225    button.menu.style.visibility = "visible";
 226  
 227    // For IE; size, position and show the menu's IFRAME as well.
 228  
 229    if (button.menu.iframeEl != null)
 230    {
 231      button.menu.iframeEl.style.left = button.menu.style.left;
 232      button.menu.iframeEl.style.top  = button.menu.style.top;
 233      button.menu.iframeEl.style.width  = button.menu.offsetWidth + "px";
 234      button.menu.iframeEl.style.height = button.menu.offsetHeight + "px";
 235      button.menu.iframeEl.style.display = "";
 236    }
 237  }
 238  
 239  function resetButton(button) {
 240  
 241    // Restore the button's style class.
 242  
 243    removeClassName(button, "menuButtonActive");
 244  
 245    // Hide the button's menu, first closing any sub menus.
 246  
 247    if (button.menu != null) {
 248      closeSubMenu(button.menu);
 249      button.menu.style.visibility = "hidden";
 250  
 251      // For IE, hide menu's IFRAME as well.
 252  
 253      if (button.menu.iframeEl != null)
 254        button.menu.iframeEl.style.display = "none";
 255    }
 256  }
 257  
 258  //----------------------------------------------------------------------------
 259  // Code to handle the menus and sub menus.
 260  //----------------------------------------------------------------------------
 261  
 262  function menuMouseover(event) {
 263  
 264    var menu;
 265  
 266    // Find the target menu element.
 267  
 268    if (browser.isIE)
 269      menu = getContainerWith(window.event.srcElement, "DIV", "menu");
 270    else
 271      menu = event.currentTarget;
 272  
 273    // Close any active sub menu.
 274  
 275    if (menu.activeItem != null)
 276      closeSubMenu(menu);
 277  }
 278  
 279  function menuItemMouseover(event, menuId) {
 280  
 281    var item, menu, x, y;
 282  
 283    // Find the target item element and its parent menu element.
 284  
 285    if (browser.isIE)
 286      item = getContainerWith(window.event.srcElement, "A", "menuItem");
 287    else
 288      item = event.currentTarget;
 289    menu = getContainerWith(item, "DIV", "menu");
 290  
 291    // Close any active sub menu and mark this one as active.
 292  
 293    if (menu.activeItem != null)
 294      closeSubMenu(menu);
 295    menu.activeItem = item;
 296  
 297    // Highlight the item element.
 298  
 299    item.className += " menuItemHighlight";
 300  
 301    // Initialize the sub menu, if not already done.
 302  
 303    if (item.subMenu == null) {
 304      item.subMenu = document.getElementById(menuId);
 305      if (item.subMenu.isInitialized == null)
 306        menuInit(item.subMenu);
 307    }
 308  
 309    // [MODIFIED] Added for activate/deactivate on mouseover.
 310  
 311    // Set mouseout event handler for the sub menu, if not already done.
 312  
 313    if (item.subMenu.onmouseout == null)
 314      item.subMenu.onmouseout = buttonOrMenuMouseout;
 315  
 316    // [END MODIFIED]
 317  
 318    // Get position for submenu based on the menu item.
 319  
 320    x = getPageOffsetLeft(item) + item.offsetWidth;
 321    y = getPageOffsetTop(item);
 322  
 323    // Adjust position to fit in view.
 324  
 325    var maxX, maxY;
 326  
 327    if (browser.isIE) {
 328      maxX = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft) +
 329        (document.documentElement.clientWidth != 0 ? document.documentElement.clientWidth : document.body.clientWidth);
 330      maxY = Math.max(document.documentElement.scrollTop, document.body.scrollTop) +
 331        (document.documentElement.clientHeight != 0 ? document.documentElement.clientHeight : document.body.clientHeight);
 332    }
 333    if (browser.isOP) {
 334      maxX = document.documentElement.scrollLeft + window.innerWidth;
 335      maxY = document.documentElement.scrollTop  + window.innerHeight;
 336    }
 337    if (browser.isNS) {
 338      maxX = window.scrollX + window.innerWidth;
 339      maxY = window.scrollY + window.innerHeight;
 340    }
 341    maxX -= item.subMenu.offsetWidth;
 342    maxY -= item.subMenu.offsetHeight;
 343  
 344    if (x > maxX)
 345      x = Math.max(0, x - item.offsetWidth - item.subMenu.offsetWidth
 346        + (menu.offsetWidth - item.offsetWidth));
 347    y = Math.max(0, Math.min(y, maxY));
 348  
 349    // Position and show the sub menu.
 350  
 351    item.subMenu.style.left       = x + "px";
 352    item.subMenu.style.top        = y + "px";
 353    item.subMenu.style.visibility = "visible";
 354  
 355    // For IE; size, position and display the menu's IFRAME as well.
 356  
 357    if (item.subMenu.iframeEl != null)
 358    {
 359      item.subMenu.iframeEl.style.left    = item.subMenu.style.left;
 360      item.subMenu.iframeEl.style.top     = item.subMenu.style.top;
 361      item.subMenu.iframeEl.style.width   = item.subMenu.offsetWidth + "px";
 362      item.subMenu.iframeEl.style.height  = item.subMenu.offsetHeight + "px";
 363      item.subMenu.iframeEl.style.display = "";
 364    }
 365  
 366    // Stop the event from bubbling.
 367  
 368    if (browser.isIE)
 369      window.event.cancelBubble = true;
 370    else
 371      event.stopPropagation();
 372  }
 373  
 374  function closeSubMenu(menu) {
 375  
 376    if (menu == null || menu.activeItem == null)
 377      return;
 378  
 379    // Recursively close any sub menus.
 380  
 381    if (menu.activeItem.subMenu != null) {
 382      closeSubMenu(menu.activeItem.subMenu);
 383      menu.activeItem.subMenu.style.visibility = "hidden";
 384  
 385      // For IE, hide the sub menu's IFRAME as well.
 386  
 387      if (menu.activeItem.subMenu.iframeEl != null)
 388        menu.activeItem.subMenu.iframeEl.style.display = "none";
 389  
 390      menu.activeItem.subMenu = null;
 391    }
 392  
 393    // Deactivate the active menu item.
 394  
 395    removeClassName(menu.activeItem, "menuItemHighlight");
 396    menu.activeItem = null;
 397  }
 398  
 399  // [MODIFIED] Added for activate/deactivate on mouseover. Handler for mouseout
 400  // event on buttons and menus.
 401  
 402  function buttonOrMenuMouseout(event) {
 403  
 404    var el;
 405  
 406    // If there is no active button, exit.
 407  
 408    if (activeButton == null)
 409      return;
 410  
 411    // Find the element the mouse is moving to.
 412  
 413    if (browser.isIE)
 414      el = window.event.toElement;
 415    else if (event.relatedTarget != null)
 416        el = (event.relatedTarget.tagName ? event.relatedTarget : event.relatedTarget.parentNode);
 417  
 418    // If the element is not part of a menu, reset the active button.
 419  
 420    if (getContainerWith(el, "DIV", "menu") == null) {
 421      resetButton(activeButton);
 422      activeButton = null;
 423    }
 424  }
 425  
 426  // [END MODIFIED]
 427  
 428  //----------------------------------------------------------------------------
 429  // Code to initialize menus.
 430  //----------------------------------------------------------------------------
 431  
 432  function menuInit(menu) {
 433  
 434    var itemList, spanList;
 435    var textEl, arrowEl;
 436    var itemWidth;
 437    var w, dw;
 438    var i, j;
 439  
 440    // For IE, replace arrow characters.
 441  
 442    if (browser.isIE) {
 443      menu.style.lineHeight = "2.5ex";
 444      spanList = menu.getElementsByTagName("SPAN");
 445      for (i = 0; i < spanList.length; i++)
 446        if (hasClassName(spanList[i], "menuItemArrow")) {
 447          spanList[i].style.fontFamily = "Webdings";
 448          spanList[i].firstChild.nodeValue = "4";
 449        }
 450    }
 451  
 452    // Find the width of a menu item.
 453  
 454    itemList = menu.getElementsByTagName("A");
 455    if (itemList.length > 0)
 456      itemWidth = itemList[0].offsetWidth;
 457    else
 458      return;
 459  
 460    // For items with arrows, add padding to item text to make the
 461    // arrows flush right.
 462  
 463    for (i = 0; i < itemList.length; i++) {
 464      spanList = itemList[i].getElementsByTagName("SPAN");
 465      textEl  = null;
 466      arrowEl = null;
 467      for (j = 0; j < spanList.length; j++) {
 468        if (hasClassName(spanList[j], "menuItemText"))
 469          textEl = spanList[j];
 470        if (hasClassName(spanList[j], "menuItemArrow"))
 471          arrowEl = spanList[j];
 472      }
 473      if (textEl != null && arrowEl != null) {
 474        textEl.style.paddingRight = (itemWidth 
 475          - (textEl.offsetWidth + arrowEl.offsetWidth)) + "px";
 476        // For Opera, remove the negative right margin to fix a display bug.
 477        if (browser.isOP)
 478          arrowEl.style.marginRight = "0px";
 479      }
 480    }
 481  
 482    // Fix IE hover problem by setting an explicit width on first item of
 483    // the menu.
 484  
 485    if (browser.isIE) {
 486      w = itemList[0].offsetWidth;
 487      itemList[0].style.width = w + "px";
 488      dw = itemList[0].offsetWidth - w;
 489      w -= dw;
 490      itemList[0].style.width = w + "px";
 491    }
 492  
 493    // Fix the IE display problem (SELECT elements and other windowed controls
 494    // overlaying the menu) by adding an IFRAME under the menu.
 495  
 496    if (browser.isIE) {
 497      var iframeEl = document.createElement("iframe");
 498      iframeEl.frameBorder = 0;
 499      iframeEl.src = "#";
 500      iframeEl.style.display = "none";
 501      iframeEl.style.position = "absolute";
 502      iframeEl.style.filter = "progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)";
 503      menu.iframeEl = menu.parentNode.insertBefore(iframeEl, menu);
 504    }
 505  
 506    // Mark menu as initialized.
 507  
 508    menu.isInitialized = true;
 509  }
 510  
 511  //----------------------------------------------------------------------------
 512  // General utility functions.
 513  //----------------------------------------------------------------------------
 514  
 515  function getContainerWith(node, tagName, className) {
 516  
 517    // Starting with the given node, find the nearest containing element
 518    // with the specified tag name and style class.
 519  
 520    while (node != null) {
 521      if (node.tagName != null && node.tagName == tagName &&
 522          hasClassName(node, className))
 523        return node;
 524      node = node.parentNode;
 525    }
 526  
 527    return node;
 528  }
 529  
 530  function hasClassName(el, name) {
 531  
 532    var i, list;
 533  
 534    // Return true if the given element currently has the given class
 535    // name.
 536  
 537    list = el.className.split(" ");
 538    for (i = 0; i < list.length; i++)
 539      if (list[i] == name)
 540        return true;
 541  
 542    return false;
 543  }
 544  
 545  function removeClassName(el, name) {
 546  
 547    var i, curList, newList;
 548  
 549    if (el.className == null)
 550      return;
 551  
 552    // Remove the given class name from the element's className property.
 553  
 554    newList = new Array();
 555    curList = el.className.split(" ");
 556    for (i = 0; i < curList.length; i++)
 557      if (curList[i] != name)
 558        newList.push(curList[i]);
 559    el.className = newList.join(" ");
 560  }
 561  
 562  function getPageOffsetLeft(el) {
 563  
 564    var x;
 565  
 566    // Return the x coordinate of an element relative to the page.
 567  
 568    x = el.offsetLeft;
 569    if (el.offsetParent != null)
 570      x += getPageOffsetLeft(el.offsetParent);
 571  
 572    return x;
 573  }
 574  
 575  function getPageOffsetTop(el) {
 576  
 577    var y;
 578  
 579    // Return the x coordinate of an element relative to the page.
 580  
 581    y = el.offsetTop;
 582    if (el.offsetParent != null)
 583      y += getPageOffsetTop(el.offsetParent);
 584  
 585    return y;
 586  }
 587  
 588  //]]>


Généré le : Sun Apr 1 01:23:32 2007 par Balluche grâce à PHPXref 0.7