Current File : /home/kelaby89/muzza.fit/wp-content/themes/deadlift/assets/js/t/deadlift.js
/*!
 * Additional Theme Methods
 *
 * Deadlift 1.8.2
 */
/* jshint -W062 */

/* global DeadliftParams, DeadliftUi, WVC, Cookies, Event, WVCParams, CountUp */
var Deadlift = function( $ ) {

	'use strict';

	return {
		initFlag : false,
		isEdge : ( navigator.userAgent.match( /(Edge)/i ) ) ? true : false,
		isWVC : 'undefined' !== typeof WVC,
		isMobile : ( navigator.userAgent.match( /(iPad)|(iPhone)|(iPod)|(Android)|(PlayBook)|(BB10)|(BlackBerry)|(Opera Mini)|(IEMobile)|(webOS)|(MeeGo)/i ) ) ? true : false,
		loaded : false,

		/**
		 * Init all functions
		 */
		init : function () {

			if ( this.initFlag ) {
				return;
			}

			var _this = this;

			this.setNavDesktopDataAttr();
			this.menuHover();
			this.wcLiveSearch();
			this.quickView();
			this.loginPopup();
			this.stickyProductDetails();
			this.transitionCosmetic();
			this.startPercent();

			this.isMobile = DeadliftParams.isMobile;

			if ( this.isWVC ) {

			}

			$( window ).on( 'wwcq_product_quickview_loaded', function( event ) {

			} );

			$( window ).scroll( function() {
				var scrollTop = $( window ).scrollTop();
				_this.backToTopSkin( scrollTop );
			} );

			this.initFlag = true;
		},

		/**
		 * Get mouse direction
		 */
		getMouseDirection : function() {
			var mX = 0;

			$( 'body' ).mousemove( function( e ) {

				if ( e.pageX < mX) {

					//console.log('From Right');
					return 'right';

				} else {

					//console.log('From Left');
					return 'left';
				}

				// set new mX after doing test above
				mX = e.pageX;
			} );
		},

		/**
		 * Navigation hover effect
		 */
		setNavDesktopDataAttr : function () {

			if ( this.isMobile ) {
				return;
			}

			var selector = '.nav-menu-desktop > li:not(.menu-button-primary):not(.menu-button-secondary) > a:first-child .menu-item-text-container';

			$( selector ).each( function() {
				$( this ).wrapInner( '<span />' );
				$( this ).attr( 'data-text', $( this ).text() );
			} );

			$( '.nav-menu-desktop > li:not(.menu-button-primary):not(.menu-button-secondary)' ).each( function() {
				if ( $( this ).hasClass( 'menu-item' ) ) {
					$( this ).append(  '<span class="menu-item-fill" />' );
				}
			} );
		},

		/**
		 * Menu hover
		 */
		menuHover : function() {

			if ( this.isMobile ) {
				return;
			}

			var _this = this,
				selector = '.nav-menu-desktop > li:not(.menu-button-primary):not(.menu-button-secondary)',
				el_pos,
				edge;

			$( document ).on( 'mouseenter', selector, function( e ) {

				el_pos = $( this ).offset(),
			        	edge = _this.closestEdge( e.pageX - el_pos.left, e.pageY - el_pos.top, $(this).width(), $(this).height() );


			      $( this ).removeClass( 'out out-from-left out-from-right' );

				if ( 'right' === edge ) {

					//  console.log( 'enter right ');

					$( this ).addClass( 'over over-from-right' );

				} else {

					 // console.log( 'enter left' );

					$( this ).addClass( 'over over-from-left' );
				}

			} ).on( 'mouseleave', selector, function( e ) {

				el_pos = $( this ).offset(),
			        	edge = _this.closestEdge( e.pageX - el_pos.left, e.pageY - el_pos.top, $(this).width(), $(this).height() );

			        $( this ).removeClass( 'over over-from-left over-from-right' );

				if ( 'right' === edge ) {

					//console.log( 'leave right ');

					$( this ).addClass( 'out out-from-right' );
				} else {

					//console.log( 'leave left ');

					$( this ).addClass( 'out out-from-left' );
				}


			} );
		},

		closestEdge : function ( x,y,w,h ) {
			var topEdgeDist = this.distMetric( x,y,w/2,0 );
			var bottomEdgeDist = this.distMetric( x,y,w/2,h );
			var leftEdgeDist = this.distMetric( x,y,0,h/2 );
			var rightEdgeDist = this.distMetric( x,y,w,h/2 );

			var min = Math.min( topEdgeDist, bottomEdgeDist, leftEdgeDist, rightEdgeDist );
			switch ( min ) {
				case leftEdgeDist:
					return 'left';
				case rightEdgeDist:
					return 'right';
				case topEdgeDist:
					return 'top';
				case bottomEdgeDist:
					return 'bottom';
			}
		},

		distMetric : function ( x,y,x2,y2 ) {
			var xDiff = x - x2,
				yDiff = y - y2;
			return ( xDiff * xDiff ) + ( yDiff * yDiff );
		},

		/**
		 * WC live search
		 */
		wcLiveSearch : function () {
			$( '.wvc-wc-search-form' ).addClass( 'live-search-form' ).append( '<span style="display:none" class="fa search-form-loader fa-circle-o-notch fa-spin hide"></span>' );

			DeadliftUi.liveSearch();
		},

		/**
		 * Product quickview
		 */
		quickView : function () {

			$( document ).on( 'added_to_cart', function( event, fragments, cart_hash, $button ) {
				if ( $button.hasClass( 'product-add-to-cart' ) ) {
					//console.log( 'good?' );
					$button.attr( 'href', DeadliftParams.WooCommerceCartUrl );
					$button.find( 'span' ).attr( 'title', DeadliftParams.l10n.viewCart );
					$button.removeClass( 'ajax_add_to_cart' );
				}
			} );
		},

		/**
		 * Sticky product layout
		 */
		stickyProductDetails : function() {
			if ( $.isFunction( $.fn.stick_in_parent ) ) {
				if ( $( 'body' ).hasClass( 'sticky-product-details' ) ) {
					$( '.entry-single-product .summary' ).stick_in_parent( {
						offset_top : parseInt( DeadliftParams.portfolioSidebarOffsetTop, 10 ) + 40
					} );
				}
			}
		},

		/**
		 * Check back to top color
		 */
		backToTopSkin : function( scrollTop ) {

			if ( scrollTop < 550 ) {
				return;
			}

			$( '.wvc-row' ).each( function() {

				if ( $( this ).hasClass( 'wvc-font-light' ) && ! $( this ).hasClass( 'wvc-row-bg-transparent' ) ) {

						var $button = $( '#back-to-top' ),
						buttonOffset = $button.position().top + $button.width() / 2 ,
						sectionTop = $( this ).offset().top - scrollTop,
						sectionBottom = sectionTop + $( this ).outerHeight();

					if ( sectionTop < buttonOffset && sectionBottom > buttonOffset ) {
						$button.addClass( 'back-to-top-light' );
					} else {
						$button.removeClass( 'back-to-top-light' );
					}
				}
			} );
		},

		/**
		 * WC login popup
		 */
		loginPopup: function () {
			var $body = $("body"),
				clicked = false;

			$(document).on(
				"click",
				".account-item-icon-user-not-logged-in, .close-loginform-button",
				function (event) {
					event.preventDefault();

					if ($body.hasClass("loginform-popup-toggle")) {

						$body.removeClass("loginform-popup-toggle");

					} else {

						$body.removeClass("overlay-menu-toggle");

						if ( $(".wvc-login-form").length || $(".wolf-core-login-form").length ) {

							$body.addClass("loginform-popup-toggle");

						} else if ( ! clicked ) {
							/* AJAX call */
							$.post(
								DeadliftParams.ajaxUrl,
								{ action: "deadlift_ajax_get_wc_login_form" },
								function (response) {
									//console.log(response);

									if (response) {
										$("#loginform-overlay-content").append(
											response
										);

										$body.addClass(
											"loginform-popup-toggle"
										);
									}
								}
							);
						}
					}
				}
			);

			if (!this.isMobile) {
				$(document).mouseup(function (event) {
					if (1 !== event.which) {
						return;
					}

					var $container = $("#loginform-overlay-content");

					if (
						!$container.is(event.target) &&
						$container.has(event.target).length === 0
					) {
						$body.removeClass("loginform-popup-toggle");
					}
				});
			}
		},

		/**
		 * Overlay transition
		 */
		transitionCosmetic : function() {

			$( document ).on( 'click', '.internal-link:not(.disabled)', function( event ) {

				if ( ! event.ctrlKey ) {

					event.preventDefault();

					var $link = $( this );

					$( 'body' ).removeClass( 'mobile-menu-toggle overlay-menu-toggle offcanvas-menu-toggle loginform-popup-toggle' );
					$( 'body' ).addClass( 'loading transitioning' );

					Cookies.set( DeadliftParams.themeSlug + '_session_loaded', true, { expires: null } );

					if ( $( '.deadlift-loader-overlay' ).length ) {
						$( '.deadlift-loader-overlay' ).one( DeadliftUi.transitionEventEnd(), function() {
							Cookies.remove( DeadliftParams.themeSlug + '_session_loaded' );
							window.location = $link.attr( 'href' );
						} );
					} else {
						window.location = $link.attr( 'href' );
					}
				}
			} );
		},

		/**
		 * Star counter loader
		 */
		startPercent : function() {

			if ( $( '#deadlift-percent' ).length ) {

				var _this = this,
					overlay = $( '#deadlift-loader' ),
					progressNumber = 'deadlift-percent',
					$progressNumber = $( '#' + progressNumber ),
					duration = 3,
					numAnimText,
					options = {
						useEasing: true,
						useGrouping: true,
						separator: ',',
						decimal: '.',
						suffix: '%'
					};

				overlay.fadeIn( '', function() {
					$progressNumber.addClass( 'deadlift-percent-show' ).one( DeadliftUi.transitionEventEnd(), function() {

						numAnimText = new CountUp( progressNumber, 0, 100, 0, duration, options );

						numAnimText.start( function() {
							$progressNumber
								.removeClass( 'deadlift-percent-show' )
								.addClass( 'deadlift-percent-hide' )
								.one( DeadliftUi.transitionEventEnd(), function() {
									_this.reveal();
								} );
						} );
					} );
				} );
			}
		},

		reveal : function() {

			var _this = this;

			$( 'body' ).addClass( 'loaded reveal' );
			_this.fireContent();
		},

		/**
		* Page Load
		*/
		loadingAnimation : function () {

			var _this = this,
				delay = 50;

	    	if ( $( '#deadlift-percent' ).length ) {
	    		return;
	    	}

			setTimeout( function() {

				$( 'body' ).addClass( 'loaded' );

				if ( $( '.deadlift-loader-overlay' ).length ) {

					$( 'body' ).addClass( 'reveal' );

					$( '.deadlift-loader-overlay' ).one( DeadliftUi.transitionEventEnd(), function() {

						_this.fireContent();

						setTimeout( function() {

							$( 'body' ).addClass( 'one-sec-loaded' );

						}, 100 );
					} );

				} else {

					$( 'body' ).addClass( 'reveal' );

					_this.fireContent();

					setTimeout( function() {

						$( 'body' ).addClass( 'one-sec-loaded' );

					}, 100 );
				}
			}, delay );
 		},

		fireContent : function () {

			var _this = this;

			// Animate
			$( window ).trigger( 'page_loaded' );
			DeadliftUi.wowAnimate();
			window.dispatchEvent( new Event( 'resize' ) );
			window.dispatchEvent( new Event( 'scroll' ) ); // Force WOW effect
			$( window ).trigger( 'just_loaded' );
			$( 'body' ).addClass( 'one-sec-loaded' );
		}
	};

}( jQuery );

( function( $ ) {

	'use strict';

	$( document ).ready( function() {
		Deadlift.init();
	} );

	$( window ).load( function() {
		Deadlift.loadingAnimation();
	} );

} )( jQuery );
Page not found – Hello World !