wp/wp-content/themes/IN-MOTION-package-u1/in-motion/js/jquery.iconmenu.js
changeset 0 d970ebf37754
equal deleted inserted replaced
-1:000000000000 0:d970ebf37754
       
     1 (function($) {
       
     2 	
       
     3 	var methods = {
       
     4 			init 	: function( options ) {
       
     5 				
       
     6 				if( this.length ) {
       
     7 					
       
     8 					var settings = {
       
     9 						// configuration for the mouseenter event
       
    10 						animMouseenter		: {
       
    11 							'mText' : {speed : 350, easing : 'easeOutExpo', delay : 140, dir : 1},
       
    12 							'sText' : {speed : 350, easing : 'easeOutExpo', delay : 0, dir : 1},
       
    13 							'icon'  : {speed : 350, easing : 'easeOutExpo', delay : 280, dir : 1}
       
    14 						},
       
    15 						// configuration for the mouseleave event
       
    16 						animMouseleave		: {
       
    17 							'mText' : {speed : 300, easing : 'easeInExpo', delay : 140, dir : 1},
       
    18 							'sText' : {speed : 300, easing : 'easeInExpo', delay : 280, dir : 1},
       
    19 							'icon'  : {speed : 300, easing : 'easeInExpo', delay : 0, dir : 1}
       
    20 						},
       
    21 						// speed for the item bg color animation
       
    22 						boxAnimSpeed		: 300,
       
    23 						// default text color (same defined in the css)
       
    24 						defaultTextColor	: '#3a3939',
       
    25 						defaultCircleHoverColor	: '#383938',
       
    26 						// default bg color (same defined in the css)
       
    27 						defaultBgColor		: '#fff'
       
    28 					};
       
    29 					
       
    30 					return this.each(function() {
       
    31 						
       
    32 						// if options exist, lets merge them with our default settings
       
    33 						if ( options ) {
       
    34 							$.extend( settings, options );
       
    35 						}
       
    36 						
       
    37 						var $el 			= $(this),
       
    38 							// the menu items
       
    39 							$menuItems		= $el.children('li'),
       
    40 							// save max delay time for mouseleave anim parameters
       
    41 						maxdelay	= Math.max( settings.animMouseleave['mText'].speed + settings.animMouseleave['mText'].delay ,
       
    42 												settings.animMouseleave['sText'].speed + settings.animMouseleave['sText'].delay ,
       
    43 												settings.animMouseleave['icon'].speed + settings.animMouseleave['icon'].delay
       
    44 											  ),
       
    45 							// timeout for the mouseenter event
       
    46 							// lets us move the mouse quickly over the items,
       
    47 							// without triggering the mouseenter event
       
    48 							t_mouseenter;
       
    49 						
       
    50 						// save default top values for the moving elements:
       
    51 						// the elements that animate inside each menu item
       
    52 						$menuItems.find('.sti-item').each(function() {
       
    53 							var $el	= $(this);
       
    54 							$el.data('deftop', $el.position().top);
       
    55 						});
       
    56 						
       
    57 						// ************** Events *************
       
    58 						// mouseenter event for each menu item
       
    59 						$menuItems.bind('mouseenter', function(e) {
       
    60 							
       
    61 							clearTimeout(t_mouseenter);
       
    62 							
       
    63 							var $item		= $(this),
       
    64 								$wrapper	= $item.children('a'),
       
    65 								wrapper_h	= $wrapper.height(),
       
    66 								// the elements that animate inside this menu item
       
    67 								$movingItems= $wrapper.find('.sti-item'),
       
    68 								// the color that the texts will have on hover
       
    69 								hovercolor	= $item.data('hovercolor');
       
    70 							
       
    71 							t_mouseenter	= setTimeout(function() {
       
    72 								// indicates the item is on hover state
       
    73 								$item.addClass('sti-current');
       
    74 								
       
    75 								$movingItems.each(function(i) {
       
    76 									var $item			= $(this),
       
    77 										item_sti_type	= $item.data('type'),
       
    78 										speed			= settings.animMouseenter[item_sti_type].speed,
       
    79 										easing			= settings.animMouseenter[item_sti_type].easing,
       
    80 										delay			= settings.animMouseenter[item_sti_type].delay,
       
    81 										dir				= settings.animMouseenter[item_sti_type].dir,
       
    82 										// if dir is 1 the item moves downwards
       
    83 										// if -1 then upwards
       
    84 										style			= {'top' : -dir * wrapper_h + 'px'};
       
    85 									
       
    86 									if( item_sti_type === 'icon' ) {
       
    87 										// this sets another bg image for the icon
       
    88 										style.backgroundPosition	= 'bottom left';
       
    89 									} else {
       
    90 										style.color					= hovercolor;
       
    91 									}
       
    92 									// we hide the icon, move it up or down, and then show it
       
    93 									$item.hide().css(style).show();
       
    94 									clearTimeout($item.data('time_anim'));
       
    95 									$item.data('time_anim',
       
    96 										setTimeout(function() {
       
    97 											// now animate each item to its default tops
       
    98 											// each item will animate with a delay specified in the options
       
    99 											$item.stop(true)
       
   100 												 .animate({top : $item.data('deftop') + 'px'}, speed, easing);
       
   101 										}, delay)
       
   102 									);
       
   103 								});
       
   104 								// animate the bg color of the item
       
   105 								$wrapper.stop(true).animate({
       
   106 									backgroundColor: settings.defaultCircleHoverColor
       
   107 								}, settings.boxAnimSpeed );
       
   108 							
       
   109 							}, 100);	
       
   110 
       
   111 						})
       
   112 						// mouseleave event for each menu item
       
   113 						.bind('mouseleave', function(e) {
       
   114 							
       
   115 							clearTimeout(t_mouseenter);
       
   116 							
       
   117 							var $item		= $(this),
       
   118 								$wrapper	= $item.children('a'),
       
   119 								wrapper_h	= $wrapper.height(),
       
   120 								$movingItems= $wrapper.find('.sti-item');
       
   121 							
       
   122 							if(!$item.hasClass('sti-current')) 
       
   123 								return false;		
       
   124 							
       
   125 							$item.removeClass('sti-current');
       
   126 							
       
   127 							$movingItems.each(function(i) {
       
   128 								var $item			= $(this),
       
   129 									item_sti_type	= $item.data('type'),
       
   130 									speed			= settings.animMouseleave[item_sti_type].speed,
       
   131 									easing			= settings.animMouseleave[item_sti_type].easing,
       
   132 									delay			= settings.animMouseleave[item_sti_type].delay,
       
   133 									dir				= settings.animMouseleave[item_sti_type].dir;
       
   134 								
       
   135 								clearTimeout($item.data('time_anim'));
       
   136 								
       
   137 								setTimeout(function() {
       
   138 									
       
   139 									$item.stop(true).animate({'top' : -dir * wrapper_h + 'px'}, speed, easing, function() {
       
   140 										
       
   141 										if( delay + speed === maxdelay ) {
       
   142 											
       
   143 											$wrapper.stop(true).animate({
       
   144 												backgroundColor: settings.defaultBgColor
       
   145 											}, settings.boxAnimSpeed );
       
   146 											
       
   147 											$movingItems.each(function(i) {
       
   148 												var $el				= $(this),
       
   149 													style			= {'top' : $el.data('deftop') + 'px'};
       
   150 												
       
   151 												if( $el.data('type') === 'icon' ) {
       
   152 													style.backgroundPosition	= 'top left';
       
   153 												} else {
       
   154 													style.color					= settings.defaultTextColor;
       
   155 												}
       
   156 												
       
   157 												$el.hide().css(style).show();
       
   158 											});
       
   159 											
       
   160 										}
       
   161 									});
       
   162 								}, delay);
       
   163 							});
       
   164 						});
       
   165 						
       
   166 					});
       
   167 				}
       
   168 			}
       
   169 		};
       
   170 	
       
   171 	$.fn.iconmenu = function(method) {
       
   172 		if ( methods[method] ) {
       
   173 			return methods[method].apply( this, Array.prototype.slice.call( arguments, 1 ));
       
   174 		} else if ( typeof method === 'object' || ! method ) {
       
   175 			return methods.init.apply( this, arguments );
       
   176 		} else {
       
   177 			$.error( 'Method ' +  method + ' does not exist on jQuery.iconmenu' );
       
   178 		}
       
   179 	};
       
   180 	
       
   181 })(jQuery);