'use strict';

var fadeMenuDirective = angular.module('ngFadeMenu', [ ] );

fadeMenuDirective.directive( 'ngFadeMenu', function( $timeout, screenSize ) 
{
	return {
		restrict: 'A',
		link: function( scope, element, attr )
		{
			scope.mobile = screenSize.on( 'xs, sm', function( match ){
				scope.mobile = match;
			});

			scope.$watch( 'mobile' );

			if ( !scope.mobile )
			{	
				var timeoutPromise;
				// resetFadeTimeout();
				element.parent(  ).parent(  ).parent(  ).parent(  ).parent(  ).bind( 'mousemove', function( e )
				{
					resetFadeTimeout(  );
				} );

				scope.$watch( 'stateName', function( newValue, oldValue )
				{
					resetFadeTimeout(  );
				} );

				scope.$watch( 'stateParams.section', function( newValue, oldValue )
				{
					resetFadeTimeout(  );
				} );

				function resetFadeTimeout(  )
				{
					element.removeClass( 'hidden' );
					$timeout.cancel( timeoutPromise );
					if ( scope.stateName === "root" || ( scope.stateName === "root.section-state" && scope.stateParams.section !== "news" && scope.stateParams.section !== "search" ) )
					{
						timeoutPromise = $timeout( function ( e )
						{
							element.addClass( 'hidden' );
						}, 3000 );
					}
				}
			}

			
		}
	}
});
@@ -320,69 +320,8 @@
 );%0A%0A
-%09%09%09scope.$watch( 'mobile' );%0A%0A%09%09%09if ( !scope.mobile )%0A%09%09%09%7B%09%0A%09
 %09%09%09v
@@ -339,17 +339,16 @@
 romise;%0A
-%09
 %09%09%09// re
@@ -365,17 +365,16 @@
 eout();%0A
-%09
 %09%09%09eleme
@@ -463,28 +463,26 @@
 ion( e )%0A%09%09%09
-%09
 %7B%0A
-%09
 %09%09%09%09resetFad
@@ -494,32 +494,30 @@
 out(  );%0A%09%09%09
-%09
 %7D );%0A%0A
-%09
 %09%09%09scope.$wa
@@ -560,36 +560,34 @@
 , oldValue )%0A%09%09%09
-%09
 %7B%0A
-%09
 %09%09%09%09resetFadeTim
@@ -599,24 +599,22 @@
   );%0A%09%09%09
-%09
 %7D );%0A%0A
-%09
 %09%09%09scope
@@ -676,17 +676,16 @@
 Value )%0A
-%09
 %09%09%09%7B%0A%09%09%09
@@ -685,17 +685,16 @@
 %09%09%7B%0A%09%09%09%09
-%09
 resetFad
@@ -710,24 +710,22 @@
   );%0A%09%09%09
-%09
 %7D );%0A%0A
-%09
 %09%09%09funct
@@ -749,16 +749,45 @@
 out(  )%0A
+%09%09%09%7B%0A%09%09%09%09if( !scope.mobile )%0A
 %09%09%09%09%7B%0A%09%09
@@ -1165,19 +1165,16 @@
 %09%09%7D%0A%09%09%09%7D
-%0A%0A%09
 %09%09%0A%09%09%7D%0A%09

Fix menu fade mobile detection iOS bug