Team:Team:NCTU Formosa/js/jquery.dlmenu
From 2013.igem.org
(Created page with "/** * jquery.dlmenu.js v1.0.1 * http://www.codrops.com * * Licensed under the MIT license. * http://www.opensource.org/licenses/mit-license.php * * Copyright 2013, Codrop...") |
|||
Line 8: | Line 8: | ||
* Copyright 2013, Codrops | * Copyright 2013, Codrops | ||
* http://www.codrops.com | * http://www.codrops.com | ||
+ | * | ||
+ | * Modified by Calvin Hue | ||
*/ | */ | ||
;( function( $, window, undefined ) { | ;( function( $, window, undefined ) { | ||
Line 21: | Line 23: | ||
}; | }; | ||
+ | var elem1 = document.getElementById("navb"); | ||
// the options | // the options | ||
$.DLMenu.defaults = { | $.DLMenu.defaults = { | ||
Line 78: | Line 81: | ||
this.$trigger.on( 'click.dlmenu', function() { | this.$trigger.on( 'click.dlmenu', function() { | ||
- | |||
if( self.open ) { | if( self.open ) { | ||
self._closeMenu(); | self._closeMenu(); | ||
Line 86: | Line 88: | ||
} | } | ||
return false; | return false; | ||
- | + | ||
} ); | } ); | ||
this.$menuitems.on( 'click.dlmenu', function( event ) { | this.$menuitems.on( 'click.dlmenu', function( event ) { | ||
+ | if(window.getComputedStyle(elem1, null).getPropertyValue("display")!="none"){ | ||
event.stopPropagation(); | event.stopPropagation(); | ||
Line 124: | Line 127: | ||
self.options.onLinkClick( $item, event ); | self.options.onLinkClick( $item, event ); | ||
} | } | ||
- | + | } | |
} ); | } ); | ||
this.$back.on( 'click.dlmenu', function( event ) { | this.$back.on( 'click.dlmenu', function( event ) { | ||
+ | if(window.getComputedStyle(elem1, null).getPropertyValue("display")!="none"){ | ||
var $this = $( this ), | var $this = $( this ), | ||
$submenu = $this.parents( 'ul.navsub:first' ), | $submenu = $this.parents( 'ul.navsub:first' ), | ||
Line 160: | Line 164: | ||
return false; | return false; | ||
- | + | } | |
} ); | } ); | ||
}, | }, | ||
closeMenu : function() { | closeMenu : function() { | ||
+ | |||
if( this.open ) { | if( this.open ) { | ||
this._closeMenu(); | this._closeMenu(); | ||
} | } | ||
- | + | } | |
+ | , | ||
_closeMenu : function() { | _closeMenu : function() { | ||
+ | |||
var self = this, | var self = this, | ||
onTransitionEndFn = function() { | onTransitionEndFn = function() { | ||
Line 188: | Line 195: | ||
this.open = false; | this.open = false; | ||
- | + | } | |
+ | , | ||
openMenu : function() { | openMenu : function() { | ||
+ | |||
if( !this.open ) { | if( !this.open ) { | ||
this._openMenu(); | this._openMenu(); | ||
} | } | ||
- | + | } | |
+ | , | ||
_openMenu : function() { | _openMenu : function() { | ||
+ | |||
var self = this; | var self = this; | ||
// clicking somewhere else makes the menu close | // clicking somewhere else makes the menu close | ||
Line 205: | Line 216: | ||
this.$trigger.addClass( 'dl-active' ); | this.$trigger.addClass( 'dl-active' ); | ||
this.open = true; | this.open = true; | ||
- | + | } | |
+ | , | ||
// resets the menu to its original state (first level of options) | // resets the menu to its original state (first level of options) | ||
_resetMenu : function() { | _resetMenu : function() { | ||
+ | |||
this.$menu.removeClass( 'dl-subview' ); | this.$menu.removeClass( 'dl-subview' ); | ||
this.$menuitems.removeClass( 'dl-subview dl-subviewopen' ); | this.$menuitems.removeClass( 'dl-subview dl-subviewopen' ); | ||
+ | |||
} | } | ||
}; | }; | ||
Line 220: | Line 234: | ||
$.fn.dlmenu = function( options ) { | $.fn.dlmenu = function( options ) { | ||
+ | |||
+ | if(window.getComputedStyle(elem1, null).getPropertyValue("display")!="none"){ | ||
if ( typeof options === 'string' ) { | if ( typeof options === 'string' ) { | ||
var args = Array.prototype.slice.call( arguments, 1 ); | var args = Array.prototype.slice.call( arguments, 1 ); | ||
Line 249: | Line 265: | ||
return this; | return this; | ||
}; | }; | ||
- | + | } | |
} )( jQuery, window ); | } )( jQuery, window ); |
Revision as of 09:19, 29 August 2013
/**
* jquery.dlmenu.js v1.0.1 * http://www.codrops.com * * Licensed under the MIT license. * http://www.opensource.org/licenses/mit-license.php * * Copyright 2013, Codrops * http://www.codrops.com * * Modified by Calvin Hue */
- ( function( $, window, undefined ) {
'use strict';
// global var Modernizr = window.Modernizr, $body = $( 'body' );
$.DLMenu = function( options, element ) { this.$el = $( element ); this._init( options ); };
var elem1 = document.getElementById("navb"); // the options $.DLMenu.defaults = { // classes for the animation effects animationClasses : { classin : 'dl-animate-in-1', classout : 'dl-animate-out-1' }, // callback: click a link that has a sub menu // el is the link element (li); name is the level name onLevelClick : function( el, name ) { return false; }, // callback: click a link that does not have a sub menu // el is the link element (li); ev is the event obj onLinkClick : function( el, ev ) { return false; } };
$.DLMenu.prototype = { _init : function( options ) {
// options this.options = $.extend( true, {}, $.DLMenu.defaults, options ); // cache some elements and initialize some variables this._config();
var animEndEventNames = { 'WebkitAnimation' : 'webkitAnimationEnd', 'OAnimation' : 'oAnimationEnd', 'msAnimation' : 'MSAnimationEnd', 'animation' : 'animationend' }, transEndEventNames = { 'WebkitTransition' : 'webkitTransitionEnd', 'MozTransition' : 'transitionend', 'OTransition' : 'oTransitionEnd', 'msTransition' : 'MSTransitionEnd', 'transition' : 'transitionend' }; // animation end event name this.animEndEventName = animEndEventNames[ Modernizr.prefixed( 'animation' ) ] + '.dlmenu'; // transition end event name this.transEndEventName = transEndEventNames[ Modernizr.prefixed( 'transition' ) ] + '.dlmenu', // support for css animations and css transitions this.supportAnimations = Modernizr.cssanimations, this.supportTransitions = Modernizr.csstransitions;
this._initEvents();
}, _config : function() { this.open = false; this.$trigger = this.$el.children( '.dl-trigger' ); this.$menu = this.$el.children( 'ul.nav' ); this.$menuitems = this.$menu.find( 'li:not(.dl-back)' );
this.$el.find( 'ul.navsub' ).prepend( '