/** * Copyright (c) Loft.Ocean * http://www.loftocean.com */ ( function( $ ) { "use strict"; var llp_file_ext = [ 'jpg', 'jpeg', 'png', 'gif', 'mov', 'avi', 'mpg', '3gp', '3g2', 'midi', 'mid', 'pdf', 'doc', 'ppt', 'odt', 'pptx', 'docx', 'pps', 'ppsx', 'xls', 'xlsx', 'key', 'mp3', 'ogg', 'wma', 'm4a', 'wav', 'mp4', 'm4v', 'webm', 'ogv', 'wmv', 'flv', 'svg', 'svgz' ]; var $DOMBody = $( 'body' ), leavingShowAll = loftloaderPro['insiteTransitionShowAll'] === 'undefined' ? false : loftloaderPro['insiteTransitionShowAll'], leavingProgressMax = ( typeof loftloaderPro['leavingProgressMax'] === 'undefined' ) ? 60 : loftloaderPro['leavingProgressMax'], $globalExcluded = $(), minTimer = '', maxTimer = '', rapidPercentage = parseInt( ( leavingProgressMax * 0.9 ), 10 ), LoftLoaderProSessionStorage = { getItem: function( name ) { try { return sessionStorage.getItem( name ); } catch( msg ) { return false; } }, setItem: function( name, value ) { try { sessionStorage.setItem( name, value ); } catch ( msg ) { } } }; function llp_check_a( $a ) { if ( $a && $a.length ) { var target = $a.attr( 'target' ), href = $a.attr( 'href' ); return ( ( typeof target == 'undefined' ) || ( target.toLowerCase() !== '_blank' ) ) && llp_exclude_a( $a ) && ( href && llp_check_url( href ) ); } return false; } function llp_check_random_message() { var $message = $( '#loftloader-wrapper .loader-message' ), message = llp_get_random_message(); if ( $message.length && message ) { $message.html( message ); LoftLoaderProSessionStorage.setItem( 'loftloader-pro-next-random-message', message ); } } function register_smooth_transition_link( $item ) { var href = $item.attr( 'href' ); if ( ! $item.data( 'loftloader-pro-checked' ) ) { if ( href && llp_check_a( $item ) ) { $item.off( 'click' ).on( 'click', function( e ) { e.preventDefault(); var $loader = $( '#loftloader-wrapper' ), $closeBtn = $loader.find( '.loader-close-button' ); llp_check_random_message(); $( document ).trigger( 'loftloaderpro.spt.start' ); $( 'html' ).removeClass( 'loftloader-pro-spt-hide' ); $loader.length && ! loftloaderPro.insiteTransitionDisplayOption ? $loader.css( 'transition-delay', '' ) : ''; $DOMBody.addClass( 'leaves' ); if ( leavingShowAll ) { var leavingTimer = typeof loftloaderPro[ 'leavingTimer' ] === 'undefined' ? 900 : loftloaderPro[ 'leavingTimer' ]; leavingTimer = isNaN( leavingTimer ) ? 900 : Math.max( 0, parseInt( leavingTimer, 10 ) ); $DOMBody.addClass( 'spt-show-all' ); $( document ).trigger( 'loftloaderpro.image.check' ); Progress.initValue = 0; Progress.reset(); Progress.render( rapidPercentage, leavingTimer * 0.7 ); setTimeout( function() { Progress.render( ( loftloaderPro.insiteTransitionDisplayOnCurrent ? 100 : leavingProgressMax ), leavingTimer * 0.3 ); }, leavingTimer * 0.7 ); LoftLoaderProSessionStorage.setItem( 'loftloader-pro-smooth-transition', 'on' ); setTimeout( function() { window.location.href = href; if ( $closeBtn.length && loftloaderPro.insiteTransitionShowCloseButton ) { $closeBtn.css( { 'display': '', 'opacity': 1 } ); } }, leavingTimer ); } else { window.location.href = href; } } ); } $item.data( 'loftloader-pro-checked', true ); } } function observe_DOM_changes() { var targetNode = $DOMBody.get( 0 ), // Select the node that will be observed for mutations config = { attributes: false, childList: true, subtree: true }, // Options for the observer (which mutations to observe) callback = function( mutationsList, observer ) { // Callback function to execute when mutations are observed //for ( let mutation of mutationsList ) { mutationsList.forEach( function( mutation ) { if ( mutation.type === 'childList' ) { var $links = ( 'A' === mutation.target.tagName ) ? $( mutation.target ) : $( mutation.target ).find( 'a' ); if ( $links.length ) { $links.each( function() { register_smooth_transition_link( $( this ) ); } ); } } } ); }, observer = new MutationObserver( callback ); // Start observing the target node for configured mutations observer.observe( targetNode, config ); } function llp_update_percentage_progress( current ) { llp_loader_update_style( 'loftloader-pro-progress-percentage-style', '#loftloader-wrapper span.percentage:after, #loftloader-wrapper .load-count:after { content: "' + Math.ceil( current ) + '%"; };' ); } function llp_exclude_a( $a ) { var $loader = $( '#loftloader-wrapper' ), classes = $a.attr( 'class' ), ajax_enabled = classes && ( classes.indexOf( 'ajax' ) !== -1 ), cart = $a.parent( '.site-header-cart').length, excluded = loftloaderPro.insiteTransitionCustomExcluded ? loftloaderPro.insiteTransitionCustomExcluded : false; excluded = ( excluded && $( excluded ).length ) ? $( excluded ) : false; return ! $a.parent('.product-remove').length && ( ( ! $globalExcluded.length ) || $a.not( $globalExcluded ).length ) && ( ( excluded && $a.not( excluded ).length ) || ! excluded ) && ( typeof $a.attr( 'onclick' ) == 'undefined' ) && ! ajax_enabled && ! cart; } // Check if url is to current site function llp_check_url( url ) { if ( url ) { var file_ext = false, site_root = document.createElement( 'a' ), current = document.createElement( 'a' ), target = document.createElement( 'a' ); target.href = url; current.href = window.location.href; site_root.href = loftloaderPro.siteRootURL; file_ext = target.pathname.split( '.' ).pop(); return ( target.href.replace( /https?:\/\//i, '' ).indexOf( site_root.href.replace( /https?:\/\//i, '' ) ) === 0 ) && ( url.substr( 0, 1 ) !== '#' ) && ! ( ( current.pathname == target.pathname ) && ( target.hash || ( url.indexOf( '#' ) !== -1 ) ) ) && ( llp_file_ext.indexOf( file_ext ) === -1 ); } return false; } // Check if the smooth insite page transition enabled function llp_check_insite_transition() { return loftloaderPro && loftloaderPro.insiteTransition && ( 'on' == loftloaderPro.insiteTransition ) && loftloaderPro.siteRootURL; } /* * @description Update the number when choose progress type bar+number * @param int current percentage number 0 - 100 */ function llp_update_progress_count( current, $load ) { if ( $load && $load.length ) { var $count = $load.next( '.load-count' ), container_width = $load.width() * current / 100, offset_x = ( container_width > $count.width() ) ? ( container_width - $count.width() ) : 0, offset_y = $load.parent().hasClass( 'bottom' ) ? '-100%' : '100%'; $count.css( 'transform', 'translate(' + offset_x + 'px, ' + offset_y + ')' ); } } $( window ).bind( 'pageshow', function( event ) { if ( event.originalEvent.persisted ) { var $body = $('body'), $loader = $( '#loftloader-wrapper' ); $loader.length ? $loader.css( 'transition-delay', '0s' ) : ''; if ( $body.length && $body.hasClass( 'leaves' ) ) { $body.removeClass( 'leaves' ); } if ( $body.length && ! $body.hasClass( 'loftloader-loaded' ) ) { $body.addClass( 'loaded loftloader-loaded' ); } } } ); // Helper extention to test current element has any of the classes listed. $.fn.llpHasAnyClass = function( classes ) { var self = $( $( this )[0] ), ret = false; $.each( classes, function( i, cls ) { if ( self.hasClass( cls ) ) { ret = true; return false; } } ); return ret; } // Helper function, updating style element in with given id function llp_loader_update_style( id, style ) { var $style = $( 'head' ).find( '#' + id ); if ( ! $style.length ) { $style = $( '