Template:Team:HokkaidoU Japan/JS
From 2014.igem.org
(Difference between revisions)
Line 18: | Line 18: | ||
//define the defaults for the plugin and how to call it | //define the defaults for the plugin and how to call it | ||
- | $.fn. | + | $.fn.dcMegaMenu = function(options){ |
//set default options | //set default options | ||
var defaults = { | var defaults = { | ||
Line 26: | Line 26: | ||
classSubLink: 'mega-hdr', | classSubLink: 'mega-hdr', | ||
classWidget: 'dc-extra', | classWidget: 'dc-extra', | ||
- | rowItems: | + | rowItems: 3, |
speed: 'fast', | speed: 'fast', | ||
- | effect: ' | + | effect: 'fade', |
event: 'hover', | event: 'hover', | ||
fullWidth: false, | fullWidth: false, | ||
Line 36: | Line 36: | ||
}; | }; | ||
- | //call in the default | + | //call in the default otions |
var options = $.extend(defaults, options); | var options = $.extend(defaults, options); | ||
- | var $ | + | var $dcMegaMenuObj = this; |
//act upon the element that is passed into the design | //act upon the element that is passed into the design | ||
- | return $ | + | return $dcMegaMenuObj.each(function(options){ |
var clSubParent = defaults.classSubParent; | var clSubParent = defaults.classSubParent; | ||
Line 55: | Line 55: | ||
$(this).addClass('mega-hover'); | $(this).addClass('mega-hover'); | ||
if(defaults.effect == 'fade'){ | if(defaults.effect == 'fade'){ | ||
- | + | $(subNav).fadeIn(defaults.speed); | |
} | } | ||
if(defaults.effect == 'slide'){ | if(defaults.effect == 'slide'){ | ||
- | + | $(subNav).show(defaults.speed); | |
} | } | ||
// beforeOpen callback; | // beforeOpen callback; | ||
Line 67: | Line 67: | ||
$(obj).addClass('mega-hover'); | $(obj).addClass('mega-hover'); | ||
if(defaults.effect == 'fade'){ | if(defaults.effect == 'fade'){ | ||
- | + | $(subNav).fadeIn(defaults.speed); | |
} | } | ||
if(defaults.effect == 'slide'){ | if(defaults.effect == 'slide'){ | ||
- | + | $(subNav).show(defaults.speed); | |
} | } | ||
// beforeOpen callback; | // beforeOpen callback; | ||
Line 76: | Line 76: | ||
} | } | ||
function megaOut(){ | function megaOut(){ | ||
- | + | var subNav = $('.sub',this); | |
- | + | $(this).removeClass('mega-hover'); | |
- | + | $(subNav).hide(); | |
- | + | // beforeClose callback; | |
- | + | defaults.beforeClose.call(this); | |
} | } | ||
function megaActionClose(obj){ | function megaActionClose(obj){ | ||
- | + | var subNav = $('.sub',obj); | |
- | + | $(obj).removeClass('mega-hover'); | |
- | + | $(subNav).hide(); | |
- | + | // beforeClose callback; | |
- | + | defaults.beforeClose.call(this); | |
} | } | ||
function megaReset(){ | function megaReset(){ | ||
- | + | $('li',$dcMegaMenuObj).removeClass('mega-hover'); | |
- | + | $('.sub',$dcMegaMenuObj).hide(); | |
} | } | ||
function megaSetup(){ | function megaSetup(){ | ||
- | + | $arrow = '<span class="dc-mega-icon"></span>'; | |
- | + | var clParentLi = clParent+'-li'; | |
- | + | var menuWidth = $dcMegaMenuObj.outerWidth(); | |
- | + | $('> li',$dcMegaMenuObj).each(function(){ | |
- | + | //Set Width of sub | |
- | + | var $mainSub = $('> ul',this); | |
- | + | var $primaryLink = $('> a',this); | |
- | + | if($mainSub.length){ | |
- | + | $primaryLink.addClass(clParent).append($arrow); | |
- | + | $mainSub.addClass('sub').wrap('<div class="'+clContainer+'" />'); | |
- | + | var pos = $(this).position(); | |
- | + | pl = pos.left; | |
- | + | if($('ul',$mainSub).length){ | |
- | + | $(this).addClass(clParentLi); | |
- | + | $('.'+clContainer,this).addClass('mega'); | |
- | + | $('> li',$mainSub).each(function(){ | |
- | + | if(!$(this).hasClass(clWidget)){ | |
- | + | $(this).addClass('mega-unit'); | |
- | + | if($('> ul',this).length){ | |
- | + | $(this).addClass(clSubParent); | |
- | + | $('> a',this).addClass(clSubParent+'-a'); | |
- | + | } else { | |
- | + | $(this).addClass(clSubLink); | |
- | + | $('> a',this).addClass(clSubLink+'-a'); | |
- | + | ||
} | } | ||
- | }); | + | } |
+ | }); | ||
// Create Rows | // Create Rows | ||
Line 150: | Line 150: | ||
var fw = menuWidth - cpad; | var fw = menuWidth - cpad; | ||
$mainSub.parent('.'+clContainer).css({width: fw+'px'}); | $mainSub.parent('.'+clContainer).css({width: fw+'px'}); | ||
- | $ | + | $dcMegaMenuObj.addClass('full-width'); |
} | } | ||
var iw = $('.mega-unit',$mainSub).outerWidth(true); | var iw = $('.mega-unit',$mainSub).outerWidth(true); | ||
Line 205: | Line 205: | ||
}); | }); | ||
// Set position of mega dropdown to bottom of main menu | // Set position of mega dropdown to bottom of main menu | ||
- | var menuHeight = $('> li > a',$ | + | var menuHeight = $('> li > a',$dcMegaMenuObj).outerHeight(true); |
- | $('.'+clContainer,$ | + | $('.'+clContainer,$dcMegaMenuObj).css({top: menuHeight+'px'}).css('z-index','1000'); |
if(defaults.event == 'hover'){ | if(defaults.event == 'hover'){ | ||
Line 217: | Line 217: | ||
out: megaOut | out: megaOut | ||
}; | }; | ||
- | $('li',$ | + | $('li',$dcMegaMenuObj).hoverIntent(config); |
} | } | ||
Line 228: | Line 228: | ||
}); | }); | ||
- | $('> li > a.'+clParent,$ | + | $('> li > a.'+clParent,$dcMegaMenuObj).click(function(e){ |
var $parentLi = $(this).parent(); | var $parentLi = $(this).parent(); | ||
if($parentLi.hasClass('mega-hover')){ | if($parentLi.hasClass('mega-hover')){ | ||
Line 245: | Line 245: | ||
}; | }; | ||
})(jQuery); | })(jQuery); | ||
+ | |||
/** | /** |
Revision as of 07:27, 28 August 2014