").append( $.parseHTML( responseText, document, true ) );
var $main = html.find( '#main' );
var newtitles = {
'title' : html.find( 'title' ),
'navtitle' : html.find( '.site-title-wrap h1' )
};
var newclasses = $main.attr( 'class' ).replace( 'site-main', '' );
var content = $main.children().unwrap();
var appp_header_right = html.find( '#top-menu3' );
var appp_pull_left = html.find( '.pull-left' );
var appp_modal = html.find( '.io-modal' );
var appp_activity_modal = html.find( '#activity-post-form' );
// Get scripts on new page and filter out any that have been loaded on the page already
var scripts = app.scriptLoader( html.find( 'script[src]' ) );
var styles = app.styleLoader( html.find( 'link[type="text/css"]' ) );
// @TODO figure out how to re-load localized data
// app.loadL10n( html );
// Replace existing page body classes with new
app.$.body.attr( 'class', newclasses );
app.$.main.attr( 'class', newclasses );
// Replace existing page
with new
titles.title.text( newtitles.title.text() );
// Replace existing page nav title with new
titles.navtitle.html( newtitles.navtitle.html() );
// Replace existing page content with new
$( '#top-menu3' ).replaceWith( appp_header_right );
$( '.pull-left' ).replaceWith( appp_pull_left );
$( '#activity-post-form' ).replaceWith( appp_activity_modal );
$selector.html( content );
// Change url to reflect new page
app.change_url( href );
// }, 60);
app.timeout = setTimeout(function (){
// Loop through our new scripts
$.each( scripts, function( filename, url ) {
app.log( '$.each(scripts)', filename, url );
var response = app.loadScript( url, true, function() {
// Increase our scripts loaded count
app.scriptsLoadedCount++;
app.log( 'script retrieved', url );
app.log( 'scripts retrieved', app.scriptsLoadedCount );
});
if ( response ) {
response
.done(function( script, textStatus, jqXHR ) {
// jqXHR.requestURL = url;
// app.log( 'rescript: Status', url );
})
.fail(function( jqXHR, settings, exception ) {
app.log( 'loadScript: Triggered ajaxError handler for: '+ url, exception );
});
// Add this script loading ajax request to our pending xhr requests
app.xhr.push( response );
}
});
$.each( styles, function( filename, url ) {
app.log( '$.each(styles)', filename, url );
app.loadCSS( url );
app.stylesLoadedCount++;
app.log( 'style retrieved', url );
app.log( 'styles retrieved', app.stylesLoadedCount );
});
}, 30);
// A hook for other JS functions to run
// Passes in jQuery, our $selector and the href
$(document).trigger( 'load_ajax_content_done', $, $selector, href );
app.$.body.trigger( 'post-load', $, $selector, href );
if(parent) {
// Message our frame so we know when to run scripts
parent.postMessage( 'load_ajax_content_done', '*');
}
}).complete( function( jqXHR, status ) {
var href;
// jqXHR.requestURL = href;
// app.log( 'selector load was performed.' );
// Hide spinner
app.$.spinner.fadeOut('fast');
if ( status !== 'success' )
return;
// app.log( 'selector load was successful.' );
app.$.main.animate({scrollTop:0}, 'fast');
// add current_page_item class the clicked tab or drawer item
if ( $(that).parents().hasClass('footer-menu') ) {
href = $( that ).attr('href');
$( '.footer-menu li' ).removeClass('current_page_item');
$( that ).parent().addClass('current_page_item');
$( '#site-navigation ul.menu li' ).removeClass('current_page_item');
$('#site-navigation ul.menu a[href="' + href + '"]').parent().addClass('current_page_item');
}
if ( $(that).parents().hasClass('menu') ) {
href = $( that ).attr('href');
$( '#site-navigation ul.menu li' ).removeClass('current_page_item');
$( that ).parent().addClass('current_page_item');
$( '.footer-menu li' ).removeClass('current_page_item');
$('.footer-menu a[href="' + href + '"]').parent().addClass('current_page_item');
}
});
// Add this ajax request to our pending xhr requests
app.xhr.push( status );
app.doingAjax = false;
};
app.canAjax = function( $element ) {
return false;
};
app.canModal = function( $element ) {
return ( apppresser.appp.can_ajax && ! $element.is('a.no-modal, .no-modal a') );
};
app.change_url = function( newurl ) {
newurl = newurl || apppresser.backhref;
// Change url to reflect new page
window.history.pushState({},'', newurl);
var prevUrl = JSON.parse(sessionStorage.urlHistory);
if( !app.backLoad ) {
// place newurl on top of url history array if moving forward in navigation,
// but only if it's not already the first element already there
if( prevUrl.length === 0 || ( prevUrl.length && prevUrl[0].url != window.location.href ) ) {
// adds new url to the beginning of the array
prevUrl.unshift({
url: newurl
});
}
}
//save adjusted url history array to local storage incase browser gets refreshed
sessionStorage.urlHistory = JSON.stringify( prevUrl ) ;
app.backLoad = false;
};
app.loadL10n = function( html ) {
var inlineScripts = html.find( "script[type='text/javascript']" ).text();
var pattern = /\/\* \*\//;
// var test = inlineScripts.search(pattern);
var matches = inlineScripts.match(pattern);
var script = matches[1];
eval( script );
};
app.loadScript = function(url, arg1, arg2) {
var cache = false, callback = null;
// arg1 and arg2 can be interchangable as either the callback function or the cache bool
if ($.isFunction(arg1)){
callback = arg1;
cache = arg2 || cache;
} else {
cache = arg1 || cache;
callback = arg2 || callback;
}
// equivalent to a $.getScript but with control over cacheing
return $.ajax({
url: url,
type: 'GET',
dataType: 'script',
cache: cache,
success: callback
});
};
app.loadCSS = function( href ) {
var cssLink = $('');
$("head").append(cssLink); // IE hack: append before setting href
cssLink.attr({
rel: "stylesheet",
type: "text/css",
href: href
});
};
app.untrailingslashit = function(str) {
if ( str.substr(-1) == '/' ) {
return str.substr(0, str.length - 1);
}
return str;
};
/**
* Safely log things if query var is set
* @since 1.0.0
*/
app.log = function() {
if ( this.appp.debug && console && typeof console.log === 'function' ) {
console.log.apply(console, arguments);
}
};
/**
* Group logged items
* @since 1.0.0
*/
app.logGroup = function( groupName, expanded ) {
if ( this.appp.debug && console && typeof console.group === 'function' ) {
if ( groupName === true ) {
console.groupEnd();
} else if ( typeof groupName === 'undefined' ) {
if ( expanded )
console.group();
else
console.groupCollapsed();
} else {
if ( expanded )
console.group( groupName );
else
console.groupCollapsed( groupName );
}
}
};
/* AppTheme Free only -- START */
app.isMSIE = function() {
var ua = window.navigator.userAgent;
var msie = ua.indexOf("MSIE ");
console.log(ua);
if (msie > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./)) // If Internet Explorer, return version number
return true;
return false;
};
app.isFirefox = function() {
return (navigator.userAgent.toLowerCase().indexOf('firefox') > -1);
};
/* AppTheme Free only -- END */
/*
* Handles ajax modal new password request
*/
app.newPassword = function() {
var codeMsg = $('.reset-code-rsp');
console.log('newPassword');
if( $('#lost_email').val() === '' ) {
codeMsg.html('Email required.');
return false;
}
codeMsg.html('1>');
var data = {
// app_lost_password functions found in apppresser core plugin, inc/AppPresser_Ajax_Extras.php
action: 'app-lost-password',
email: $('#lost_email').val(),
nonce: $('#app_new_password').val()
};
console.dir(data);
var reset = $.ajax({
type: 'post',
url : apppCore.ajaxurl,
dataType: 'json',
data : data,
success: function( response ) {
console.dir(response);
codeMsg.html(response.data.message);
$('input[type=text]').val('');
$('input[type=password]').val('');
},
error: function(e) {
console.log('Password reset error ' + e);
}
});
return reset;
};
/*
* Handles ajax modal change password request
*/
app.changePassword = function() {
var pwVal = $('#app-pw').val();
var pwrVal = $('#app-pwr').val();
var rCode = $('#reset-code').val();
var pwMsg = $('.psw-msg');
console.log('changePassword');
if ( pwVal != pwrVal || pwVal === '' ) {
pwMsg.html('Passwords do not match.');
return false;
}
if ( rCode === '' ) {
pwMsg.html('Please enter your reset code.');
return false;
}
pwMsg.html('');
var data = {
action: 'app-validate-password',
code: rCode,
password: pwVal,
nonce: $('#app_new_password').val()
};
var validation = $.ajax({
type: 'post',
url : apppCore.ajaxurl,
dataType: 'json',
data : data,
success: function( response ) {
pwMsg.html(response.data.message);
$('#app-pw').val('');
$('#app-pwr').val('');
if( response.data.success ) {
pwMsg.append(' Logging you in...');
setTimeout( function() {
window.location.reload();
}, 1000);
}
}
});
return validation;
};
/*
* Ajax password reset events
*/
$( 'body' )
.on('click', '#app-new-password', app.newPassword )
.on('click', '#app-change-password', app.changePassword );
/*
* Add comment to page after submitted with ajax
*/
app.appendComment = function( author, comment ) {
var el;
if( $('.comment-list') ) {
el = $('.comment-list');
} else {
el = $('#comments');
}
console.log('Append ', el);
el.append( '' );
};
// do not submit comment if no value
$( 'body' ).on( 'click', '#respond #submit', function() {
// comment check
var $comment = $( this ).closest( '#respond' ).find( '#comment' ),
comment = $.trim( $comment.val() );
if ( comment === '' ) {
alert( appp.i18n_required_comment_text );
return false;
}
// rating check
var $rating = $( this ).closest( '#respond' ).find( '#rating' ),
rating = $rating.val();
if ( $rating.size() > 0 && ! rating && wc_single_product_params.review_rating_required === 'yes' && comment !== '' ) {
alert( wc_single_product_params.i18n_required_rating_text );
return false;
}
});
/*
* Ajax comment modal
*/
if( $('body').hasClass('logged-in') ) {
$('.ajax-comment-form-author, .ajax-comment-form-email, .ajax-comment-form-url').hide();
}
$('body')
.on('click' , '.comment-reply-link', function() {
// get the comment id from href
var re = /replytocom=([0-9]*)/;
var comment_id = re.exec(this.href);
// send comment id to form and open comment modal
$('#ajax-comment-parent').val(comment_id[1]);
$( '.appp-comment-btn' ).trigger('click');
} )
.on( 'click', '#ajax-comment-form-submit #submit', function() {
var commentform=$('#commentform');
// Defining the Status message element
var statusdiv = $('#comment-status');
var comment_author = $('.ajax-comment-form-author #author').val();
var comment_email = $('.ajax-comment-form-email #email').val();
var comment = $('.ajax-comment-form-comment #comment').val();
var comment_parent = $('#ajax-comment-parent').val();
var logged_in = $('body').hasClass('logged-in');
var commentData;
if(logged_in) {
$('.ajax-comment-form-author, .ajax-comment-form-email, .ajax-comment-form-url').hide();
commentData = {
comment_post_ID: $('#commentform #comment_post_ID').val(),
comment: comment,
comment_parent: comment_parent,
};
} else {
// if name, email, or comment empty, show error
if( !comment_author || !comment_email || !comment ) {
statusdiv.html('Please fill out required fields.
');
return false;
}
commentData = {
author: comment_author,
email: comment_email,
url: $('.ajax-comment-form-url #url').val(),
comment_post_ID: $('#commentform #comment_post_ID').val(),
comment: comment,
comment_parent: comment_parent,
};
}
//Add a status message
statusdiv.html('Processing...
');
//Extract action URL from commentform
var formurl=commentform.attr('action');
//Post Form with data
$.ajax({
type: 'post',
url: formurl,
data: commentData,
error: function(XMLHttpRequest, textStatus, errorThrown){
statusdiv.html('You might have left one of the fields blank, or be posting too quickly
');
},
success: function(data, textStatus){
// console.log( data );
if(textStatus=="success") {
statusdiv.html('Thanks for your comment. We appreciate your response.
');
app.appendComment( comment_author, comment );
setTimeout( function() {
$( ".io-modal-close" ).trigger( "click" );
}, 1500 );
} else {
statusdiv.html('Please wait a while before posting your next comment
');
commentform.find('textarea[name=comment]').val('');
}
}
});
return false;
});
app.init();
window.apppresser = app;
})(window, document, jQuery);
' + comment + '