home *** CD-ROM | disk | FTP | other *** search
/ 41-134-104-147.dsl.mweb.co.za / 41-134-104-147.dsl.mweb.co.za.tar / 41-134-104-147.dsl.mweb.co.za / js / droppy.js < prev    next >
Text File  |  2010-08-20  |  2KB  |  62 lines

  1. /*
  2.  * Droppy 0.1.2
  3.  * (c) 2008 Jason Frame (jason@onehackoranother.com)
  4.  */
  5. $.fn.droppy = function(options) {
  6.     
  7.   options = $.extend({speed: 250}, options || {});
  8.   
  9.   this.each(function() {
  10.     
  11.     var root = this, zIndex = 1000;
  12.     
  13.     function getSubnav(ele) {
  14.       if (ele.nodeName.toLowerCase() == 'li') {
  15.         var subnav = $('> ul', ele);
  16.         return subnav.length ? subnav[0] : null;
  17.       } else {
  18.         return ele;
  19.       }
  20.     }
  21.     
  22.     function getActuator(ele) {
  23.       if (ele.nodeName.toLowerCase() == 'ul') {
  24.         return $(ele).parents('li')[0];
  25.       } else {
  26.         return ele;
  27.       }
  28.     }
  29.     
  30.     function hide() {
  31.       var subnav = getSubnav(this);
  32.       if (!subnav) return;
  33.       $.data(subnav, 'cancelHide', false);
  34.       setTimeout(function() {
  35.         if (!$.data(subnav, 'cancelHide')) {
  36.           $(subnav).slideUp(options.speed);
  37.         }
  38.       }, 500);
  39.     }
  40.   
  41.     function show() {
  42.       var subnav = getSubnav(this);
  43.       if (!subnav) return;
  44.       $.data(subnav, 'cancelHide', true);
  45.       $(subnav).css({zIndex: zIndex++}).slideDown(options.speed);
  46.       if (this.nodeName.toLowerCase() == 'ul') {
  47.         var li = getActuator(this);
  48.         $(li).addClass('hover');
  49.         $('> a', li).addClass('hover');
  50.       }
  51.     }
  52.     
  53.     $('ul, li', this).hover(show, hide);
  54.     $('li', this).hover(
  55.       function() { $(this).addClass('hover'); $('> a', this).addClass('hover'); },
  56.       function() { $(this).removeClass('hover'); $('> a', this).removeClass('hover'); }
  57.     );
  58.     
  59.   });
  60.   
  61. };
  62.