resources/js/easyajax.js
//Construct Page based on URL and SETTINGS
Construct Page based on URL and SETTINGS
Construct Page based on URL and SETTINGS
function constructPage( url, settings, element ) {
        $.ajax({
            async: true,
            url: url,
            dataType: 'HTML',
            method: settings.navigation.options.method,
            data: settings.navigation.options.method,
            beforeSend: function() {
                $( 'body' ).addClass( 'loading' );
                settings.navigation.beforeCall.call('');
            },
            success: function( data ) {
                $( 'body' ).removeClass( 'loading' );
                let body = data.substring( data.indexOf("<body>"), data.indexOf("</body>") + 7 ),
                    title = $( data ).filter('title').text(),
                    scripts = getScripts( data, url );
                let deferred = new $.Deferred(),
                    promise = deferred.promise();
                for ( let i in scripts ) {
                    (function () {
                        promise = promise.then( function() {
                            return loadScript( scripts[i] );
                        });
                    }());
                }
                deferred.resolve();
                $( settings.navigation.options.appendTo ).html( body );
                if( settings.navigation.options.urlUpdate ) history.pushState( body, title, url );
                if( settings.navigation.options.titleUpdate ) $( document ).attr( 'title', title );
                settings.navigation.onPageLoad.call('', element, url);
            },
            error: function( jqXHR, textStatus, errorThrown ) {
                settings.navigation.onError( jqXHR, textStatus, errorThrown );
            }
        });
    }
function constructPage ( url , settings , element ) { $ . ajax ( { async : true , url : url , dataType : 'HTML' , method : settings . navigation . options . method , data : settings . navigation . options . method , beforeSend : function ( ) { $ ( 'body' ) . addClass ( 'loading' ) ; settings . navigation . beforeCall . call ( '' ) ; } , success : function ( data ) { $ ( 'body' ) . removeClass ( 'loading' ) ; let body = data . substring ( data . indexOf ( "<body>" ) , data . indexOf ( "</body>" ) + 7 ) , title = $ ( data ) . filter ( 'title' ) . text ( ) , scripts = getScripts ( data , url ) ; let deferred = new $ . Deferred ( ) , promise = deferred . promise ( ) ; for ( let i in scripts ) { ( function ( ) { promise = promise . then ( function ( ) { return loadScript ( scripts [ i ] ) ; } ) ; } ( ) ) ; } deferred . resolve ( ) ; $ ( settings . navigation . options . appendTo ) . html ( body ) ; if ( settings . navigation . options . urlUpdate ) history . pushState ( body , title , url ) ; if ( settings . navigation . options . titleUpdate ) $ ( document ) . attr ( 'title' , title ) ; settings . navigation . onPageLoad . call ( '' , element , url ) ; } , error : function ( jqXHR , textStatus , errorThrown ) { settings . navigation . onError ( jqXHR , textStatus , errorThrown ) ; } } ) ; }
Construct Page based on URL and SETTINGS
Construct Page based on URL and SETTINGS
//Call outside function //Load asynchronous scripts in page //Construct page //Update URL //Update Title //Call outsite function //Call outside function