Initial commit
This commit is contained in:
913
wp-content/plugins/gp-premium/sites/assets/js/admin.js
Normal file
913
wp-content/plugins/gp-premium/sites/assets/js/admin.js
Normal file
@ -0,0 +1,913 @@
|
||||
jQuery( document ).ready( function($) {
|
||||
|
||||
var bLazy = new Blazy({
|
||||
selector: '.lazyload',
|
||||
success: function(ele){
|
||||
$( ele ).parent().addClass( 'image-loaded' );
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Demo sites
|
||||
*/
|
||||
$( '.site-box .preview-site' ).on( 'click', function( e ) {
|
||||
e.preventDefault();
|
||||
var _this = $( this );
|
||||
var site_box = _this.closest( '.site-box' );
|
||||
|
||||
if ( ! site_box.find( 'iframe' ).attr( 'src' ) ) {
|
||||
site_box.find( 'iframe' ).attr( 'src', site_box.data( 'site-data' ).preview_url );
|
||||
}
|
||||
|
||||
site_box.find( 'iframe' ).on( 'load', function () {
|
||||
site_box.find( '.demo-loading' ).fadeOut().remove();
|
||||
});
|
||||
|
||||
site_box.find( '.site-demo' ).show().addClass( 'open' );
|
||||
} );
|
||||
|
||||
$( '.site-demo .close-demo' ).on( 'click', function( e ) {
|
||||
$( '.site-demo' ).hide().removeClass( 'open' );
|
||||
bLazy.revalidate();
|
||||
} );
|
||||
|
||||
$( '.demo-panel .show-desktop' ).on( 'click', function( e ) {
|
||||
$( this ).addClass( 'active' ).siblings().removeClass( 'active' );
|
||||
$( '.site-demo' ).removeClass( 'mobile' ).removeClass( 'tablet' );
|
||||
} );
|
||||
|
||||
$( '.demo-panel .show-tablet' ).on( 'click', function( e ) {
|
||||
$( this ).addClass( 'active' ).siblings().removeClass( 'active' );
|
||||
$( '.site-demo' ).removeClass( 'mobile' ).addClass( 'tablet' );
|
||||
} );
|
||||
|
||||
$( '.demo-panel .show-mobile' ).on( 'click', function( e ) {
|
||||
$( this ).addClass( 'active' ).siblings().removeClass( 'active' );
|
||||
$( '.site-demo' ).addClass( 'mobile' ).removeClass( 'tablet' );
|
||||
} );
|
||||
|
||||
$( '.site-demo .get-started' ).on( 'click', function( e ) {
|
||||
$( '.site-demo' ).hide().removeClass( 'open' );
|
||||
|
||||
if ( ! $( '.generatepress-sites' ).hasClass( 'site-open' ) ) {
|
||||
var this_site = $( this ).closest( '.site-box' );
|
||||
|
||||
$( '.generatepress-sites' ).addClass( 'site-open' );
|
||||
$( '.library-filters' ).hide();
|
||||
var screenshot = this_site.find( '.site-card-screenshot img' ).attr( 'src' );
|
||||
|
||||
this_site.find( '.site-overview-screenshot img' ).attr( 'src', screenshot );
|
||||
this_site.siblings().hide();
|
||||
this_site.find( '.step-one' ).hide().next().show();
|
||||
}
|
||||
} );
|
||||
|
||||
/**
|
||||
* Site card controls
|
||||
*/
|
||||
$( '.site-box .close' ).on( 'click', function( e ) {
|
||||
e.preventDefault();
|
||||
var siteBox = $( '.site-box' ),
|
||||
page_builder = $( '.generatepress-sites' ).attr( 'data-page-builder' );
|
||||
|
||||
siteBox.find( '.steps' ).hide();
|
||||
siteBox.find( '.step-one' ).fadeIn().css( 'display', '' );
|
||||
|
||||
$( '.generatepress-sites' ).removeClass( 'site-open' );
|
||||
$( '.library-filters' ).show();
|
||||
siteBox.siblings( page_builder ).fadeIn( 'fast' );
|
||||
|
||||
bLazy.revalidate();
|
||||
|
||||
if ( $( 'body' ).hasClass( 'site-import-data-exists' ) ) {
|
||||
$( '.remove-site' ).show();
|
||||
$( '.remove-site .do-remove-site' ).show();
|
||||
$( '.remove-site .skip-remove-site' ).show();
|
||||
$( '.generatepress-sites' ).addClass( 'remove-site-needed' );
|
||||
window.scrollTo( { top: 0 } );
|
||||
}
|
||||
} );
|
||||
|
||||
$( '.site-box .next' ).on( 'click', function( e ) {
|
||||
var page_builder = $( '.generatepress-sites' ).attr( 'data-page-builder' );
|
||||
var this_site = $( this ).closest( '.site-box' );
|
||||
var next_site = this_site.nextAll( page_builder ).not( '.disabled-site' ).first();
|
||||
|
||||
if ( ! next_site.length ) {
|
||||
next_site = $( '.generatepress-sites' ).find( '.site-box' + page_builder ).first();
|
||||
}
|
||||
|
||||
var screenshot = next_site.find( '.site-card-screenshot img' ).attr( 'data-src' );
|
||||
|
||||
if ( ! screenshot ) {
|
||||
screenshot = next_site.find( '.site-card-screenshot img' ).attr( 'src' );
|
||||
}
|
||||
|
||||
if ( this_site.parent().hasClass( 'site-open' ) ) {
|
||||
this_site.hide();
|
||||
next_site.show().find( '.step-one' ).hide().next().show();
|
||||
next_site.find( '.site-overview-screenshot img' ).attr( 'src', screenshot );
|
||||
}
|
||||
|
||||
if ( this_site.find( '.site-demo' ).hasClass( 'open' ) ) {
|
||||
this_site.find( '.site-demo' ).hide().removeClass( 'open' );
|
||||
|
||||
if ( ! next_site.find( 'iframe' ).attr( 'src' ) ) {
|
||||
next_site.find( 'iframe' ).attr( 'src', next_site.data( 'site-data' ).preview_url );
|
||||
}
|
||||
|
||||
next_site.find( 'iframe' ).on( 'load', function () {
|
||||
next_site.find( '.demo-loading' ).fadeOut().remove();
|
||||
});
|
||||
|
||||
next_site.find( '.site-demo' ).show().addClass( 'open' );
|
||||
}
|
||||
|
||||
if ( $( 'body' ).hasClass( 'site-import-data-exists' ) ) {
|
||||
$( '.remove-site' ).show();
|
||||
$( '.remove-site .do-remove-site' ).show();
|
||||
$( '.remove-site .skip-remove-site' ).show();
|
||||
$( '.generatepress-sites' ).addClass( 'remove-site-needed' );
|
||||
}
|
||||
} );
|
||||
|
||||
$( '.site-box .prev' ).on( 'click', function( e ) {
|
||||
var page_builder = $( '.generatepress-sites' ).attr( 'data-page-builder' );
|
||||
var this_site = $( this ).closest( '.site-box' );
|
||||
var prev_site = this_site.prevAll( page_builder ).not( '.disabled-site' ).first();
|
||||
|
||||
if ( ! prev_site.length ) {
|
||||
prev_site = $( '.generatepress-sites' ).find( '.site-box' + page_builder ).last();
|
||||
}
|
||||
|
||||
var screenshot = prev_site.find( '.site-card-screenshot img' ).attr( 'data-src' );
|
||||
|
||||
if ( ! screenshot ) {
|
||||
screenshot = prev_site.find( '.site-card-screenshot img' ).attr( 'src' );
|
||||
}
|
||||
|
||||
if ( this_site.parent().hasClass( 'site-open' ) ) {
|
||||
this_site.hide();
|
||||
prev_site.show().find( '.step-one' ).hide().next().show();
|
||||
prev_site.find( '.site-overview-screenshot img' ).attr( 'src', screenshot );
|
||||
}
|
||||
|
||||
if ( this_site.find( '.site-demo' ).hasClass( 'open' ) ) {
|
||||
this_site.find( '.site-demo' ).hide().removeClass( 'open' );
|
||||
|
||||
if ( ! prev_site.find( 'iframe' ).attr( 'src' ) ) {
|
||||
prev_site.find( 'iframe' ).attr( 'src', prev_site.data( 'site-data' ).preview_url );
|
||||
}
|
||||
|
||||
prev_site.find( 'iframe' ).on( 'load', function () {
|
||||
prev_site.find( '.demo-loading' ).fadeOut().remove();
|
||||
});
|
||||
|
||||
prev_site.find( '.site-demo' ).show().addClass( 'open' );
|
||||
}
|
||||
|
||||
if ( $( 'body' ).hasClass( 'site-import-data-exists' ) ) {
|
||||
$( '.remove-site' ).show();
|
||||
$( '.remove-site .do-remove-site' ).show();
|
||||
$( '.remove-site .skip-remove-site' ).show();
|
||||
$( '.generatepress-sites' ).addClass( 'remove-site-needed' );
|
||||
}
|
||||
} );
|
||||
|
||||
$( '.site-box .site-details' ).on( 'click', function( e ) {
|
||||
var _this = $( this ),
|
||||
siteBox = _this.closest( '.site-box' ),
|
||||
step = _this.closest( '.steps' ),
|
||||
screenshot = step.find( '.site-card-screenshot img' ).attr( 'data-src' );
|
||||
|
||||
if ( ! screenshot ) {
|
||||
screenshot = step.find( '.site-card-screenshot img' ).attr( 'src' );
|
||||
}
|
||||
|
||||
$( '.generatepress-sites' ).addClass( 'site-open' );
|
||||
$( '.library-filters' ).hide();
|
||||
|
||||
_this.closest( '.site-box' ).siblings().hide();
|
||||
step.hide();
|
||||
step.next().fadeIn( 'fast' );
|
||||
siteBox.find( '.site-overview-screenshot img' ).attr( 'src', screenshot );
|
||||
} );
|
||||
|
||||
$( '.confirm-content-import' ).on( 'change', function() {
|
||||
var siteBox = $( this ).closest( '.site-box' );
|
||||
|
||||
if ( $( this ).is( ':checked' ) ) {
|
||||
siteBox.find( 'input.import-content' ).attr( 'disabled', false );
|
||||
} else {
|
||||
siteBox.find( 'input.import-content' ).attr( 'disabled', 'disabled' );
|
||||
}
|
||||
} );
|
||||
|
||||
$( '.confirm-options-import' ).on( 'change', function() {
|
||||
var siteBox = $( this ).closest( '.site-box' );
|
||||
|
||||
if ( $( this ).is( ':checked' ) ) {
|
||||
siteBox.find( 'input.backup-options' ).attr( 'disabled', false );
|
||||
siteBox.find( 'input.import-options' ).attr( 'disabled', false );
|
||||
} else {
|
||||
siteBox.find( 'input.backup-options' ).attr( 'disabled', 'disabled' );
|
||||
siteBox.find( 'input.import-options' ).attr( 'disabled', 'disabled' );
|
||||
}
|
||||
} );
|
||||
|
||||
$( '.page-builder-group' ).on( 'change', function( e ) {
|
||||
e.preventDefault();
|
||||
|
||||
var _this = $( this ),
|
||||
filter = _this.val();
|
||||
|
||||
// _this.siblings().removeClass( 'active' );
|
||||
// _this.addClass( 'active' );
|
||||
|
||||
if ( '' == filter ) {
|
||||
$( '.site-box' ).show();
|
||||
$( '.generatepress-sites' ).attr( 'data-page-builder', '' );
|
||||
} else {
|
||||
$( '.site-box:not(.' + filter + ')' ).hide();
|
||||
$( '.site-box.' + filter ).show();
|
||||
$( '.generatepress-sites' ).attr( 'data-page-builder', '.' + filter );
|
||||
}
|
||||
|
||||
bLazy.revalidate();
|
||||
} );
|
||||
|
||||
var setup_demo_content = function( _this ) {
|
||||
var site_box = _this.closest( '.site-box' );
|
||||
var site_data = site_box.data( 'site-data' );
|
||||
|
||||
if ( ! site_box.hasClass( 'data-content-loaded' ) ) {
|
||||
// Prevent duplicate setup.
|
||||
site_box.addClass( 'data-content-loaded' );
|
||||
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: generate_sites_params.ajaxurl,
|
||||
data: {
|
||||
action: 'generate_setup_demo_content_' + site_data.slug,
|
||||
nonce: generate_sites_params.nonce,
|
||||
},
|
||||
success: function( data ) {
|
||||
console.log(data);
|
||||
|
||||
if ( data.content ) {
|
||||
if ( data.widgets ) {
|
||||
site_box.find( '.site-action.import-content' ).attr( 'data-widgets', true );
|
||||
} else {
|
||||
site_box.find( '.site-action.import-content' ).attr( 'data-widgets', false );
|
||||
}
|
||||
|
||||
if ( data.plugins ) {
|
||||
$.ajax( {
|
||||
type: 'POST',
|
||||
url: generate_sites_params.ajaxurl,
|
||||
data: {
|
||||
action: 'generate_check_plugins_' + site_data.slug,
|
||||
nonce: generate_sites_params.nonce,
|
||||
data: site_box.data( 'site-data' ),
|
||||
},
|
||||
success: function( data ) {
|
||||
console.log( data );
|
||||
site_box.find( '.site-plugins' ).hide();
|
||||
site_box.find( '.plugin-area' ).show();
|
||||
site_box.find( '.site-action.import-content' ).attr( 'data-plugins', JSON.stringify( data.plugin_data ) );
|
||||
|
||||
$.each( data.plugin_data, function( index, value ) {
|
||||
var slug = value.slug.substring( 0, value.slug.indexOf( '/' ) );
|
||||
|
||||
if ( value.repo && ! value.installed ) {
|
||||
site_box.find( '.automatic-plugins' ).fadeIn();
|
||||
site_box.find( '.automatic-plugins ul' ).append( '<li data-slug="' + slug + '">' + value.name + '</li>' );
|
||||
} else if ( value.installed || value.active ) {
|
||||
site_box.find( '.installed-plugins' ).fadeIn();
|
||||
site_box.find( '.installed-plugins ul' ).append( '<li class="plugin-installed" data-slug="' + slug + '">' + value.name + '</li>' );
|
||||
} else {
|
||||
site_box.find( '.manual-plugins' ).fadeIn();
|
||||
site_box.find( '.manual-plugins ul' ).append( '<li>' + value.name + '</li>' );
|
||||
}
|
||||
} );
|
||||
|
||||
if ( $.isEmptyObject( data.plugin_data ) ) {
|
||||
site_box.find( '.no-plugins' ).fadeIn();
|
||||
}
|
||||
|
||||
site_box.find( '.loading' ).hide();
|
||||
site_box.find( '.site-action.import-content' ).show();
|
||||
site_box.find( '.confirm-content-import-message' ).show();
|
||||
site_box.find( '.skip-content-import' ).show();
|
||||
},
|
||||
error: function( data ) {
|
||||
console.log( data );
|
||||
site_box.find( '.site-message' ).hide();
|
||||
site_box.find( '.error-message' ).html( data.status + ' ' + data.statusText + ' <a href="https://docs.generatepress.com/article/error-codes-importing/" target="_blank" rel="noopener">[?]</a>' ).show();
|
||||
siteBox.find( '.theme-options .big-loader' ).css( 'opacity', '0' );
|
||||
siteBox.find( '.theme-options .number' ).css( 'opacity', '1' );
|
||||
}
|
||||
} );
|
||||
} else {
|
||||
site_box.find( '.loading' ).hide();
|
||||
site_box.find( '.site-action.import-content' ).show();
|
||||
site_box.find( '.confirm-content-import-message' ).show();
|
||||
site_box.find( '.skip-content-import' ).show();
|
||||
}
|
||||
} else {
|
||||
site_box.find( '.loading' ).hide();
|
||||
site_box.find( '.demo-content .big-loader' ).css( 'opacity', '0' );
|
||||
site_box.find( '.demo-content .number' ).css( 'opacity', '1' ).addClass( 'step-complete' );
|
||||
_this.next( 'input' ).show();
|
||||
|
||||
setTimeout( function() {
|
||||
site_box.find( '.import-complete .number' ).css( 'opacity', '1' ).addClass( 'step-complete' );
|
||||
}, 500 );
|
||||
}
|
||||
|
||||
|
||||
},
|
||||
error: function( data ) {
|
||||
console.log( data );
|
||||
site_box.removeClass( 'data-loaded' );
|
||||
site_box.find( '.loading' ).hide();
|
||||
site_box.find( '.error-message' ).html( data.status + ' ' + data.statusText + ' <a href="https://docs.generatepress.com/article/error-codes-importing/" target="_blank" rel="noopener">[?]</a>' ).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Backup options.
|
||||
*/
|
||||
$( '.site-box .backup-options' ).on( 'click', function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
var _this = $( this ),
|
||||
siteBox = _this.closest( '.site-box' );
|
||||
|
||||
_this.hide();
|
||||
siteBox.find( '.confirm-backup-options' ).hide();
|
||||
backup_options( _this );
|
||||
} );
|
||||
|
||||
/**
|
||||
* Backup and import theme options.
|
||||
*/
|
||||
$( '.site-box .import-options' ).on( 'click', function( e ) {
|
||||
e.preventDefault();
|
||||
|
||||
var _this = $( this );
|
||||
|
||||
_this.hide();
|
||||
_this.closest( '.site-box' ).find( '.confirm-backup-options' ).hide();
|
||||
import_options( _this );
|
||||
} );
|
||||
|
||||
function backup_options( _this ) {
|
||||
var siteBox = _this.closest( '.site-box' )
|
||||
data = siteBox.data( 'site-data' );
|
||||
|
||||
siteBox.find( '.site-message' ).text( generate_sites_params.backing_up_options );
|
||||
siteBox.find( '.loading' ).show();
|
||||
|
||||
$.ajax( {
|
||||
type: 'POST',
|
||||
url: generate_sites_params.ajaxurl,
|
||||
data: {
|
||||
action: 'generate_backup_options_' + data.slug,
|
||||
nonce: generate_sites_params.nonce,
|
||||
},
|
||||
success: function( data ) {
|
||||
download( data, 'generatepress-options-backup.json', 'application/json' );
|
||||
|
||||
siteBox.find( '.loading' ).hide();
|
||||
_this.next( 'input' ).show();
|
||||
},
|
||||
error: function( data ) {
|
||||
console.log( data );
|
||||
siteBox.find( '.error-message' ).html( data.status + ' ' + data.statusText + ' <a href="https://docs.generatepress.com/article/error-codes-importing/" target="_blank" rel="noopener">[?]</a>' ).show();
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
function import_options( _this ) {
|
||||
var siteBox = _this.closest( '.site-box' ),
|
||||
data = siteBox.data( 'site-data' );
|
||||
|
||||
siteBox.find( '.site-message' ).text( generate_sites_params.importing_options );
|
||||
siteBox.find( '.loading' ).show();
|
||||
siteBox.find( '.theme-options .big-loader' ).css( 'opacity', '1' );;
|
||||
siteBox.find( '.theme-options .number' ).css( 'opacity', '0' );
|
||||
|
||||
$.ajax( {
|
||||
type: 'POST',
|
||||
url: generate_sites_params.ajaxurl,
|
||||
data: {
|
||||
action: 'generate_import_options_' + data.slug,
|
||||
nonce: generate_sites_params.nonce,
|
||||
},
|
||||
success: function( data ) {
|
||||
if ( 'undefined' !== typeof data.success && ! data.success ) {
|
||||
siteBox.find( '.loading' ).hide();
|
||||
siteBox.find( '.error-message' ).html( data.data ).show();
|
||||
siteBox.find( '.theme-options .big-loader' ).css( 'opacity', '0' );
|
||||
siteBox.find( '.theme-options .number' ).css( 'opacity', '1' );
|
||||
return;
|
||||
}
|
||||
|
||||
console.log( 'Options imported.' );
|
||||
|
||||
_this.hide();
|
||||
siteBox.find( '.loading' ).hide();
|
||||
siteBox.find( '.theme-options .big-loader' ).css( 'opacity', '0' );
|
||||
siteBox.find( '.theme-options .number' ).css( 'opacity', '1' ).addClass( 'step-complete' );
|
||||
$( 'body' ).addClass( 'site-import-data-exists' );
|
||||
|
||||
siteBox.find( '.site-message' ).text( generate_sites_params.checking_demo_content );
|
||||
siteBox.find( '.loading' ).show();
|
||||
setup_demo_content( _this );
|
||||
},
|
||||
error: function( data ) {
|
||||
console.log( data );
|
||||
siteBox.find( '.loading' ).hide();
|
||||
siteBox.find( '.error-message' ).html( data.status + ' ' + data.statusText + ' <a href="https://docs.generatepress.com/article/error-codes-importing/" target="_blank" rel="noopener">[?]</a>' ).show();
|
||||
siteBox.find( '.theme-options .big-loader' ).css( 'opacity', '0' );
|
||||
siteBox.find( '.theme-options .number' ).css( 'opacity', '1' );
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
$( '.site-box' ).on( 'click', '.skip-content-import a', function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
var _this = $( this ),
|
||||
siteBox = _this.closest( '.site-box' );
|
||||
|
||||
siteBox.find( '.skip-content-import' ).hide();
|
||||
siteBox.find( '.demo-content' ).css( 'opacity', '0.5' );
|
||||
siteBox.find( '.confirm-content-import-message' ).hide();
|
||||
siteBox.find( '.action-buttons input' ).hide();
|
||||
siteBox.find( '.action-buttons input.view-site' ).show();
|
||||
siteBox.find( '.import-complete .number' ).css( 'opacity', '1' ).addClass( 'step-complete' );
|
||||
} );
|
||||
|
||||
/**
|
||||
* Install and activate plugins.
|
||||
* Before content, as content may be depedent on plugins.
|
||||
*/
|
||||
$( '.site-box' ).on( 'click', '.import-content', function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
var _this = $( this )
|
||||
siteBox = _this.closest( '.site-box' ),
|
||||
plugins = _this.data( 'plugins' ),
|
||||
plugin_text = siteBox.find( '.automatic-plugins li' );
|
||||
|
||||
_this.hide();
|
||||
siteBox.find( '.skip-content-import' ).hide();
|
||||
siteBox.find( '.loading' ).show();
|
||||
siteBox.find( '.confirm-content-import-message' ).hide();
|
||||
siteBox.find( '.demo-content .big-loader' ).css( 'opacity', '1' );
|
||||
siteBox.find( '.demo-content .number' ).css( 'opacity', '0' );
|
||||
$( 'body' ).addClass( 'site-import-content-exists' );
|
||||
|
||||
siteBox.attr( 'data-plugins', JSON.stringify( plugins ) );
|
||||
|
||||
if ( ! $.isEmptyObject( plugins ) ) {
|
||||
siteBox.find( '.site-message' ).text( generate_sites_params.installing_plugins );
|
||||
|
||||
$.each( plugins, function( index, value ) {
|
||||
var plugin_slug = value.slug.split('/')[0];
|
||||
|
||||
var plugin_row = plugin_text.filter( function () {
|
||||
return $( this ).attr( 'data-slug' ) == plugin_slug;
|
||||
} );
|
||||
|
||||
if ( 'elementor' === plugin_slug ) {
|
||||
siteBox.find( '.replace-elementor-urls' ).show();
|
||||
}
|
||||
|
||||
if ( ! value.installed ) {
|
||||
plugin_row.find( '.loading' ).show();
|
||||
plugin_row.addClass( 'installing-plugins' );
|
||||
|
||||
// Install BB Lite if Pro doesn't exist.
|
||||
if ( 'bb-plugin' == plugin_slug ) {
|
||||
plugin_slug = 'beaver-builder-lite-version';
|
||||
}
|
||||
|
||||
wp.updates.installPlugin( {
|
||||
slug: plugin_slug,
|
||||
success: function( data ) {
|
||||
console.log( data );
|
||||
|
||||
plugin_row.removeClass( 'installing-plugins' ).addClass( 'plugin-installed' );
|
||||
plugin_row.removeClass( 'show-loading' ).next().addClass( 'show-loading' );
|
||||
|
||||
// Remove current plugin from queue
|
||||
delete plugins[index];
|
||||
|
||||
if ( $.isEmptyObject( plugins ) ) {
|
||||
// Onto the next step
|
||||
activate_plugins( _this );
|
||||
}
|
||||
},
|
||||
error: function( data ) {
|
||||
console.log(data);
|
||||
|
||||
plugin_row.append( '<span class="plugin-error">' + data.errorMessage + '</span>' );
|
||||
plugin_row.removeClass( 'installing-plugins' ).addClass( 'plugin-install-failed' );
|
||||
plugin_row.removeClass( 'show-loading' ).next().addClass( 'show-loading' );
|
||||
|
||||
// Remove current plugin from queue
|
||||
delete plugins[index];
|
||||
|
||||
if ( $.isEmptyObject( plugins ) ) {
|
||||
// Onto the next step
|
||||
activate_plugins( _this );
|
||||
}
|
||||
}
|
||||
} );
|
||||
} else {
|
||||
// Remove current plugin from queue
|
||||
delete plugins[index];
|
||||
|
||||
if ( $.isEmptyObject( plugins ) ) {
|
||||
// Onto the next step
|
||||
activate_plugins( _this );
|
||||
}
|
||||
}
|
||||
|
||||
} );
|
||||
} else {
|
||||
download_content( _this );
|
||||
}
|
||||
} );
|
||||
|
||||
function activate_plugins( _this ) {
|
||||
var siteBox = _this.closest( '.site-box' ),
|
||||
data = siteBox.data( 'site-data' );
|
||||
|
||||
siteBox.find( '.site-message' ).text( generate_sites_params.activating_plugins );
|
||||
|
||||
setTimeout( function() {
|
||||
$.ajax( {
|
||||
type: 'POST',
|
||||
url: generate_sites_params.ajaxurl,
|
||||
data: {
|
||||
action: 'generate_activate_plugins_' + data.slug,
|
||||
nonce: generate_sites_params.nonce,
|
||||
},
|
||||
success: function( data ) {
|
||||
console.log( data );
|
||||
download_content( _this );
|
||||
},
|
||||
error: function( data ) {
|
||||
console.log( data );
|
||||
siteBox.find( '.loading' ).hide();
|
||||
siteBox.find( '.error-message' ).html( data.status + ' ' + data.statusText + ' <a href="https://docs.generatepress.com/article/error-codes-importing/" target="_blank" rel="noopener">[?]</a>' ).show();
|
||||
siteBox.find( '.theme-options .big-loader' ).css( 'opacity', '0' );
|
||||
siteBox.find( '.theme-options .number' ).css( 'opacity', '1' );
|
||||
}
|
||||
} );
|
||||
}, 250 );
|
||||
}
|
||||
|
||||
function download_content( _this ) {
|
||||
var siteBox = _this.closest( '.site-box' ),
|
||||
data = siteBox.data( 'site-data' );
|
||||
|
||||
siteBox.find( '.site-message' ).text( generate_sites_params.downloading_content );
|
||||
|
||||
$.ajax( {
|
||||
type: 'POST',
|
||||
url: generate_sites_params.ajaxurl,
|
||||
data: {
|
||||
action: 'generate_download_content_' + data.slug,
|
||||
nonce: generate_sites_params.nonce,
|
||||
},
|
||||
success: function( data ) {
|
||||
console.log( data );
|
||||
|
||||
import_content( _this );
|
||||
},
|
||||
error: function( data ) {
|
||||
console.log( data );
|
||||
|
||||
siteBox.find( '.loading' ).hide();
|
||||
siteBox.find( '.error-message' ).html( data.status + ' ' + data.statusText + ' <a href="https://docs.generatepress.com/article/error-codes-importing/" target="_blank" rel="noopener">[?]</a>' ).show();
|
||||
siteBox.find( '.theme-options .big-loader' ).css( 'opacity', '0' );
|
||||
siteBox.find( '.theme-options .number' ).css( 'opacity', '1' );
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
function import_content( _this ) {
|
||||
var siteBox = _this.closest( '.site-box' ),
|
||||
data = siteBox.data( 'site-data' );
|
||||
|
||||
siteBox.find( '.site-message' ).text( generate_sites_params.importing_content );
|
||||
|
||||
$.ajax( {
|
||||
type: 'POST',
|
||||
url: generate_sites_params.ajaxurl,
|
||||
data: {
|
||||
action: 'generate_import_content_' + data.slug,
|
||||
nonce: generate_sites_params.nonce,
|
||||
},
|
||||
success: function( data ) {
|
||||
console.log( data );
|
||||
|
||||
import_site_options( _this );
|
||||
},
|
||||
error: function( data ) {
|
||||
console.log( data );
|
||||
|
||||
siteBox.find( '.loading' ).hide();
|
||||
siteBox.find( '.error-message' ).html( data.status + ' ' + data.statusText + ' <a href="https://docs.generatepress.com/article/error-codes-importing/" target="_blank" rel="noopener">[?]</a>' ).show();
|
||||
siteBox.find( '.theme-options .big-loader' ).css( 'opacity', '0' );
|
||||
siteBox.find( '.theme-options .number' ).css( 'opacity', '1' );
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
/**
|
||||
* Import site options.
|
||||
* Comes last, as options may be dependent on plugins.
|
||||
*/
|
||||
function import_site_options( _this ) {
|
||||
var siteBox = _this.closest( '.site-box' ),
|
||||
data = siteBox.data( 'site-data' );
|
||||
|
||||
siteBox.find( '.site-message' ).text( generate_sites_params.importing_site_options );
|
||||
|
||||
setTimeout( function() {
|
||||
$.ajax( {
|
||||
type: 'POST',
|
||||
url: generate_sites_params.ajaxurl,
|
||||
data: {
|
||||
action: 'generate_import_site_options_' + data.slug,
|
||||
nonce: generate_sites_params.nonce,
|
||||
},
|
||||
success: function( data ) {
|
||||
console.log( data );
|
||||
|
||||
if ( '1' == _this.data( 'widgets' ) ) {
|
||||
|
||||
import_widgets( _this );
|
||||
|
||||
} else {
|
||||
|
||||
siteBox.find( '.loading' ).hide();
|
||||
siteBox.find( '.site-message' ).hide();
|
||||
siteBox.find( '.demo-content .big-loader' ).css( 'opacity', '0' );
|
||||
siteBox.find( '.demo-content .number' ).css( 'opacity', '1' ).addClass( 'step-complete' );
|
||||
_this.next( 'input' ).show();
|
||||
siteBox.find( '.import-complete .number' ).css( 'opacity', '1' ).addClass( 'step-complete' );
|
||||
|
||||
}
|
||||
},
|
||||
error: function( data ) {
|
||||
console.log( data );
|
||||
|
||||
siteBox.find( '.loading' ).hide();
|
||||
siteBox.find( '.error-message' ).html( data.status + ' ' + data.statusText + ' <a href="https://docs.generatepress.com/article/error-codes-importing/" target="_blank" rel="noopener">[?]</a>' ).show();
|
||||
siteBox.find( '.theme-options .big-loader' ).css( 'opacity', '0' );
|
||||
siteBox.find( '.theme-options .number' ).css( 'opacity', '1' );
|
||||
}
|
||||
} );
|
||||
}, 250 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Import widgets.
|
||||
*/
|
||||
function import_widgets( _this ) {
|
||||
var siteBox = _this.closest( '.site-box' ),
|
||||
data = siteBox.data( 'site-data' );
|
||||
|
||||
siteBox.find( '.site-message' ).text( generate_sites_params.importing_widgets );
|
||||
|
||||
setTimeout( function() {
|
||||
$.ajax( {
|
||||
type: 'POST',
|
||||
url: generate_sites_params.ajaxurl,
|
||||
data: {
|
||||
action: 'generate_import_widgets_' + data.slug,
|
||||
nonce: generate_sites_params.nonce,
|
||||
},
|
||||
success: function( data ) {
|
||||
console.log( data );
|
||||
|
||||
siteBox.find( '.loading' ).hide();
|
||||
siteBox.find( '.site-message' ).hide();
|
||||
siteBox.find( '.demo-content .big-loader' ).css( 'opacity', '0' );
|
||||
siteBox.find( '.demo-content .number' ).css( 'opacity', '1' ).addClass( 'step-complete' );
|
||||
_this.next( 'input' ).show();
|
||||
siteBox.find( '.import-complete .number' ).css( 'opacity', '1' ).addClass( 'step-complete' );
|
||||
},
|
||||
error: function( data ) {
|
||||
console.log( data );
|
||||
|
||||
siteBox.find( '.loading' ).hide();
|
||||
siteBox.find( '.error-message' ).html( data.status + ' ' + data.statusText + ' <a href="https://docs.generatepress.com/article/error-codes-importing/" target="_blank" rel="noopener">[?]</a>' ).show();
|
||||
siteBox.find( '.theme-options .big-loader' ).css( 'opacity', '0' );
|
||||
siteBox.find( '.theme-options .number' ).css( 'opacity', '1' );
|
||||
}
|
||||
} );
|
||||
}, 250 );
|
||||
}
|
||||
|
||||
/**
|
||||
* View our completed site.
|
||||
*/
|
||||
$( '.site-box .view-site, .remove-site .view-site' ).on( 'click', function( e ) {
|
||||
e.preventDefault();
|
||||
|
||||
window.location.href = generate_sites_params.home_url;
|
||||
} );
|
||||
|
||||
function restoreThemeOptions() {
|
||||
var restoreBox = $( '.remove-site' );
|
||||
|
||||
restoreBox.find( '.do-remove-site' ).hide()
|
||||
restoreBox.find( '.skip-remove-site' ).hide();
|
||||
restoreBox.find( '.loading' ).show();
|
||||
restoreBox.find( '.remove-site-message' ).text( generate_sites_params.restoreThemeOptions );
|
||||
|
||||
$.ajax( {
|
||||
type: 'POST',
|
||||
url: generate_sites_params.ajaxurl,
|
||||
data: {
|
||||
action: 'generate_restore_theme_options',
|
||||
nonce: generate_sites_params.nonce,
|
||||
},
|
||||
success: function( data ) {
|
||||
if ( generate_sites_params.hasContentBackup || $( 'body' ).hasClass( 'site-import-content-exists' ) ) {
|
||||
restoreSiteOptions();
|
||||
} else {
|
||||
restoreCSS();
|
||||
}
|
||||
console.log( data );
|
||||
},
|
||||
error: function( data ) {
|
||||
console.log( data );
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
function restoreSiteOptions() {
|
||||
var restoreBox = $( '.remove-site' );
|
||||
|
||||
restoreBox.find( '.remove-site-message' ).text( generate_sites_params.restoreSiteOptions );
|
||||
|
||||
$.ajax( {
|
||||
type: 'POST',
|
||||
url: generate_sites_params.ajaxurl,
|
||||
data: {
|
||||
action: 'generate_restore_site_options',
|
||||
nonce: generate_sites_params.nonce,
|
||||
},
|
||||
success: function( data ) {
|
||||
restoreContent();
|
||||
console.log( data );
|
||||
},
|
||||
error: function( data ) {
|
||||
console.log( data );
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
function restoreContent() {
|
||||
var restoreBox = $( '.remove-site' );
|
||||
|
||||
restoreBox.find( '.remove-site-message' ).text( generate_sites_params.restoreContent );
|
||||
|
||||
$.ajax( {
|
||||
type: 'POST',
|
||||
url: generate_sites_params.ajaxurl,
|
||||
data: {
|
||||
action: 'generate_restore_content',
|
||||
nonce: generate_sites_params.nonce,
|
||||
},
|
||||
success: function( data ) {
|
||||
restorePlugins();
|
||||
console.log( data );
|
||||
},
|
||||
error: function( data ) {
|
||||
console.log( data );
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
function restorePlugins() {
|
||||
var restoreBox = $( '.remove-site' );
|
||||
|
||||
restoreBox.find( '.remove-site-message' ).text( generate_sites_params.restorePlugins );
|
||||
|
||||
$.ajax( {
|
||||
type: 'POST',
|
||||
url: generate_sites_params.ajaxurl,
|
||||
data: {
|
||||
action: 'generate_restore_plugins',
|
||||
nonce: generate_sites_params.nonce,
|
||||
},
|
||||
success: function( data ) {
|
||||
restoreWidgets();
|
||||
console.log( data );
|
||||
},
|
||||
error: function( data ) {
|
||||
console.log( data );
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
function restoreWidgets() {
|
||||
var restoreBox = $( '.remove-site' );
|
||||
|
||||
restoreBox.find( '.remove-site-message' ).text( generate_sites_params.restoreWidgets );
|
||||
|
||||
$.ajax( {
|
||||
type: 'POST',
|
||||
url: generate_sites_params.ajaxurl,
|
||||
data: {
|
||||
action: 'generate_restore_widgets',
|
||||
nonce: generate_sites_params.nonce,
|
||||
},
|
||||
success: function( data ) {
|
||||
restoreCSS();
|
||||
console.log( data );
|
||||
},
|
||||
error: function( data ) {
|
||||
console.log( data );
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
function restoreCSS() {
|
||||
var restoreBox = $( '.remove-site' );
|
||||
|
||||
restoreBox.find( '.remove-site-message' ).text( generate_sites_params.restoreCSS );
|
||||
|
||||
$.ajax( {
|
||||
type: 'POST',
|
||||
url: generate_sites_params.ajaxurl,
|
||||
data: {
|
||||
action: 'generate_restore_css',
|
||||
nonce: generate_sites_params.nonce,
|
||||
},
|
||||
success: function( data ) {
|
||||
cleanUp();
|
||||
console.log( data );
|
||||
},
|
||||
error: function( data ) {
|
||||
console.log( data );
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
function cleanUp() {
|
||||
var restoreBox = $( '.remove-site' );
|
||||
|
||||
restoreBox.find( '.remove-site-message' ).text( generate_sites_params.cleanUp );
|
||||
|
||||
$.ajax( {
|
||||
type: 'POST',
|
||||
url: generate_sites_params.ajaxurl,
|
||||
data: {
|
||||
action: 'generate_restore_site_clean_up',
|
||||
nonce: generate_sites_params.nonce,
|
||||
},
|
||||
success: function( data ) {
|
||||
restoreBox.find( '.loading' ).hide();
|
||||
restoreBox.hide();
|
||||
|
||||
$( '.generatepress-sites' ).removeClass( 'remove-site-needed' );
|
||||
$( 'body' ).removeClass( 'site-import-content-exists' );
|
||||
$( 'body' ).removeClass( 'site-import-data-exists' );
|
||||
console.log( data );
|
||||
},
|
||||
error: function( data ) {
|
||||
console.log( data );
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
$( '.do-remove-site' ).on( 'click', function( e ) {
|
||||
e.preventDefault();
|
||||
|
||||
if ( confirm( generate_sites_params.confirmRemoval ) ) {
|
||||
restoreThemeOptions();
|
||||
}
|
||||
} );
|
||||
|
||||
$( '.skip-remove-site' ).on( 'click', function( e ) {
|
||||
e.preventDefault();
|
||||
|
||||
$( '.remove-site' ).hide();
|
||||
$( '.generatepress-sites' ).removeClass( 'remove-site-needed' );
|
||||
$( 'body' ).removeClass( 'site-import-content-exists' );
|
||||
$( 'body' ).removeClass( 'site-import-data-exists' );
|
||||
} );
|
||||
} );
|
6
wp-content/plugins/gp-premium/sites/assets/js/blazy.min.js
vendored
Normal file
6
wp-content/plugins/gp-premium/sites/assets/js/blazy.min.js
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
/*!
|
||||
hey, [be]Lazy.js - v1.8.2 - 2016.10.25
|
||||
A fast, small and dependency free lazy load script (https://github.com/dinbror/blazy)
|
||||
(c) Bjoern Klinggaard - @bklinggaard - http://dinbror.dk/blazy
|
||||
*/
|
||||
(function(q,m){"function"===typeof define&&define.amd?define(m):"object"===typeof exports?module.exports=m():q.Blazy=m()})(this,function(){function q(b){var c=b._util;c.elements=E(b.options);c.count=c.elements.length;c.destroyed&&(c.destroyed=!1,b.options.container&&l(b.options.container,function(a){n(a,"scroll",c.validateT)}),n(window,"resize",c.saveViewportOffsetT),n(window,"resize",c.validateT),n(window,"scroll",c.validateT));m(b)}function m(b){for(var c=b._util,a=0;a<c.count;a++){var d=c.elements[a],e;a:{var g=d;e=b.options;var p=g.getBoundingClientRect();if(e.container&&y&&(g=g.closest(e.containerClass))){g=g.getBoundingClientRect();e=r(g,f)?r(p,{top:g.top-e.offset,right:g.right+e.offset,bottom:g.bottom+e.offset,left:g.left-e.offset}):!1;break a}e=r(p,f)}if(e||t(d,b.options.successClass))b.load(d),c.elements.splice(a,1),c.count--,a--}0===c.count&&b.destroy()}function r(b,c){return b.right>=c.left&&b.bottom>=c.top&&b.left<=c.right&&b.top<=c.bottom}function z(b,c,a){if(!t(b,a.successClass)&&(c||a.loadInvisible||0<b.offsetWidth&&0<b.offsetHeight))if(c=b.getAttribute(u)||b.getAttribute(a.src)){c=c.split(a.separator);var d=c[A&&1<c.length?1:0],e=b.getAttribute(a.srcset),g="img"===b.nodeName.toLowerCase(),p=(c=b.parentNode)&&"picture"===c.nodeName.toLowerCase();if(g||void 0===b.src){var h=new Image,w=function(){a.error&&a.error(b,"invalid");v(b,a.errorClass);k(h,"error",w);k(h,"load",f)},f=function(){g?p||B(b,d,e):b.style.backgroundImage='url("'+d+'")';x(b,a);k(h,"load",f);k(h,"error",w)};p&&(h=b,l(c.getElementsByTagName("source"),function(b){var c=a.srcset,e=b.getAttribute(c);e&&(b.setAttribute("srcset",e),b.removeAttribute(c))}));n(h,"error",w);n(h,"load",f);B(h,d,e)}else b.src=d,x(b,a)}else"video"===b.nodeName.toLowerCase()?(l(b.getElementsByTagName("source"),function(b){var c=a.src,e=b.getAttribute(c);e&&(b.setAttribute("src",e),b.removeAttribute(c))}),b.load(),x(b,a)):(a.error&&a.error(b,"missing"),v(b,a.errorClass))}function x(b,c){v(b,c.successClass);c.success&&c.success(b);b.removeAttribute(c.src);b.removeAttribute(c.srcset);l(c.breakpoints,function(a){b.removeAttribute(a.src)})}function B(b,c,a){a&&b.setAttribute("srcset",a);b.src=c}function t(b,c){return-1!==(" "+b.className+" ").indexOf(" "+c+" ")}function v(b,c){t(b,c)||(b.className+=" "+c)}function E(b){var c=[];b=b.root.querySelectorAll(b.selector);for(var a=b.length;a--;c.unshift(b[a]));return c}function C(b){f.bottom=(window.innerHeight||document.documentElement.clientHeight)+b;f.right=(window.innerWidth||document.documentElement.clientWidth)+b}function n(b,c,a){b.attachEvent?b.attachEvent&&b.attachEvent("on"+c,a):b.addEventListener(c,a,{capture:!1,passive:!0})}function k(b,c,a){b.detachEvent?b.detachEvent&&b.detachEvent("on"+c,a):b.removeEventListener(c,a,{capture:!1,passive:!0})}function l(b,c){if(b&&c)for(var a=b.length,d=0;d<a&&!1!==c(b[d],d);d++);}function D(b,c,a){var d=0;return function(){var e=+new Date;e-d<c||(d=e,b.apply(a,arguments))}}var u,f,A,y;return function(b){if(!document.querySelectorAll){var c=document.createStyleSheet();document.querySelectorAll=function(a,b,d,h,f){f=document.all;b=[];a=a.replace(/\[for\b/gi,"[htmlFor").split(",");for(d=a.length;d--;){c.addRule(a[d],"k:v");for(h=f.length;h--;)f[h].currentStyle.k&&b.push(f[h]);c.removeRule(0)}return b}}var a=this,d=a._util={};d.elements=[];d.destroyed=!0;a.options=b||{};a.options.error=a.options.error||!1;a.options.offset=a.options.offset||100;a.options.root=a.options.root||document;a.options.success=a.options.success||!1;a.options.selector=a.options.selector||".b-lazy";a.options.separator=a.options.separator||"|";a.options.containerClass=a.options.container;a.options.container=a.options.containerClass?document.querySelectorAll(a.options.containerClass):!1;a.options.errorClass=a.options.errorClass||"b-error";a.options.breakpoints=a.options.breakpoints||!1;a.options.loadInvisible=a.options.loadInvisible||!1;a.options.successClass=a.options.successClass||"b-loaded";a.options.validateDelay=a.options.validateDelay||25;a.options.saveViewportOffsetDelay=a.options.saveViewportOffsetDelay||50;a.options.srcset=a.options.srcset||"data-srcset";a.options.src=u=a.options.src||"data-src";y=Element.prototype.closest;A=1<window.devicePixelRatio;f={};f.top=0-a.options.offset;f.left=0-a.options.offset;a.revalidate=function(){q(a)};a.load=function(a,b){var c=this.options;void 0===a.length?z(a,b,c):l(a,function(a){z(a,b,c)})};a.destroy=function(){var a=this._util;this.options.container&&l(this.options.container,function(b){k(b,"scroll",a.validateT)});k(window,"scroll",a.validateT);k(window,"resize",a.validateT);k(window,"resize",a.saveViewportOffsetT);a.count=0;a.elements.length=0;a.destroyed=!0};d.validateT=D(function(){m(a)},a.options.validateDelay,a);d.saveViewportOffsetT=D(function(){C(a.options.offset)},a.options.saveViewportOffsetDelay,a);C(a.options.offset);l(a.options.breakpoints,function(a){if(a.width>=window.screen.width)return u=a.src,!1});setTimeout(function(){q(a)})}});
|
167
wp-content/plugins/gp-premium/sites/assets/js/download.js
Normal file
167
wp-content/plugins/gp-premium/sites/assets/js/download.js
Normal file
@ -0,0 +1,167 @@
|
||||
//download.js v4.2, by dandavis; 2008-2016. [MIT] see http://danml.com/download.html for tests/usage
|
||||
// v1 landed a FF+Chrome compat way of downloading strings to local un-named files, upgraded to use a hidden frame and optional mime
|
||||
// v2 added named files via a[download], msSaveBlob, IE (10+) support, and window.URL support for larger+faster saves than dataURLs
|
||||
// v3 added dataURL and Blob Input, bind-toggle arity, and legacy dataURL fallback was improved with force-download mime and base64 support. 3.1 improved safari handling.
|
||||
// v4 adds AMD/UMD, commonJS, and plain browser support
|
||||
// v4.1 adds url download capability via solo URL argument (same domain/CORS only)
|
||||
// v4.2 adds semantic variable names, long (over 2MB) dataURL support, and hidden by default temp anchors
|
||||
// https://github.com/rndme/download
|
||||
|
||||
(function (root, factory) {
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
// AMD. Register as an anonymous module.
|
||||
define([], factory);
|
||||
} else if (typeof exports === 'object') {
|
||||
// Node. Does not work with strict CommonJS, but
|
||||
// only CommonJS-like environments that support module.exports,
|
||||
// like Node.
|
||||
module.exports = factory();
|
||||
} else {
|
||||
// Browser globals (root is window)
|
||||
root.download = factory();
|
||||
}
|
||||
}(this, function () {
|
||||
|
||||
return function download(data, strFileName, strMimeType) {
|
||||
|
||||
var self = window, // this script is only for browsers anyway...
|
||||
defaultMime = "application/octet-stream", // this default mime also triggers iframe downloads
|
||||
mimeType = strMimeType || defaultMime,
|
||||
payload = data,
|
||||
url = !strFileName && !strMimeType && payload,
|
||||
anchor = document.createElement("a"),
|
||||
toString = function(a){return String(a);},
|
||||
myBlob = (self.Blob || self.MozBlob || self.WebKitBlob || toString),
|
||||
fileName = strFileName || "download",
|
||||
blob,
|
||||
reader;
|
||||
myBlob= myBlob.call ? myBlob.bind(self) : Blob ;
|
||||
|
||||
if(String(this)==="true"){ //reverse arguments, allowing download.bind(true, "text/xml", "export.xml") to act as a callback
|
||||
payload=[payload, mimeType];
|
||||
mimeType=payload[0];
|
||||
payload=payload[1];
|
||||
}
|
||||
|
||||
|
||||
if(url && url.length< 2048){ // if no filename and no mime, assume a url was passed as the only argument
|
||||
fileName = url.split("/").pop().split("?")[0];
|
||||
anchor.href = url; // assign href prop to temp anchor
|
||||
if(anchor.href.indexOf(url) !== -1){ // if the browser determines that it's a potentially valid url path:
|
||||
var ajax=new XMLHttpRequest();
|
||||
ajax.open( "GET", url, true);
|
||||
ajax.responseType = 'blob';
|
||||
ajax.onload= function(e){
|
||||
download(e.target.response, fileName, defaultMime);
|
||||
};
|
||||
setTimeout(function(){ ajax.send();}, 0); // allows setting custom ajax headers using the return:
|
||||
return ajax;
|
||||
} // end if valid url?
|
||||
} // end if url?
|
||||
|
||||
|
||||
//go ahead and download dataURLs right away
|
||||
if(/^data:([\w+-]+\/[\w+.-]+)?[,;]/.test(payload)){
|
||||
|
||||
if(payload.length > (1024*1024*1.999) && myBlob !== toString ){
|
||||
payload=dataUrlToBlob(payload);
|
||||
mimeType=payload.type || defaultMime;
|
||||
}else{
|
||||
return navigator.msSaveBlob ? // IE10 can't do a[download], only Blobs:
|
||||
navigator.msSaveBlob(dataUrlToBlob(payload), fileName) :
|
||||
saver(payload) ; // everyone else can save dataURLs un-processed
|
||||
}
|
||||
|
||||
}else{//not data url, is it a string with special needs?
|
||||
if(/([\x80-\xff])/.test(payload)){
|
||||
var i=0, tempUiArr= new Uint8Array(payload.length), mx=tempUiArr.length;
|
||||
for(i;i<mx;++i) tempUiArr[i]= payload.charCodeAt(i);
|
||||
payload=new myBlob([tempUiArr], {type: mimeType});
|
||||
}
|
||||
}
|
||||
blob = payload instanceof myBlob ?
|
||||
payload :
|
||||
new myBlob([payload], {type: mimeType}) ;
|
||||
|
||||
|
||||
function dataUrlToBlob(strUrl) {
|
||||
var parts= strUrl.split(/[:;,]/),
|
||||
type= parts[1],
|
||||
decoder= parts[2] == "base64" ? atob : decodeURIComponent,
|
||||
binData= decoder( parts.pop() ),
|
||||
mx= binData.length,
|
||||
i= 0,
|
||||
uiArr= new Uint8Array(mx);
|
||||
|
||||
for(i;i<mx;++i) uiArr[i]= binData.charCodeAt(i);
|
||||
|
||||
return new myBlob([uiArr], {type: type});
|
||||
}
|
||||
|
||||
function saver(url, winMode){
|
||||
|
||||
if ('download' in anchor) { //html5 A[download]
|
||||
anchor.href = url;
|
||||
anchor.setAttribute("download", fileName);
|
||||
anchor.className = "download-js-link";
|
||||
anchor.innerHTML = "downloading...";
|
||||
anchor.style.display = "none";
|
||||
document.body.appendChild(anchor);
|
||||
setTimeout(function() {
|
||||
anchor.click();
|
||||
document.body.removeChild(anchor);
|
||||
if(winMode===true){setTimeout(function(){ self.URL.revokeObjectURL(anchor.href);}, 250 );}
|
||||
}, 66);
|
||||
return true;
|
||||
}
|
||||
|
||||
// handle non-a[download] safari as best we can:
|
||||
if(/(Version)\/(\d+)\.(\d+)(?:\.(\d+))?.*Safari\//.test(navigator.userAgent)) {
|
||||
if(/^data:/.test(url)) url="data:"+url.replace(/^data:([\w\/\-\+]+)/, defaultMime);
|
||||
if(!window.open(url)){ // popup blocked, offer direct download:
|
||||
if(confirm("Displaying New Document\n\nUse Save As... to download, then click back to return to this page.")){ location.href=url; }
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
//do iframe dataURL download (old ch+FF):
|
||||
var f = document.createElement("iframe");
|
||||
document.body.appendChild(f);
|
||||
|
||||
if(!winMode && /^data:/.test(url)){ // force a mime that will download:
|
||||
url="data:"+url.replace(/^data:([\w\/\-\+]+)/, defaultMime);
|
||||
}
|
||||
f.src=url;
|
||||
setTimeout(function(){ document.body.removeChild(f); }, 333);
|
||||
|
||||
}//end saver
|
||||
|
||||
|
||||
|
||||
|
||||
if (navigator.msSaveBlob) { // IE10+ : (has Blob, but not a[download] or URL)
|
||||
return navigator.msSaveBlob(blob, fileName);
|
||||
}
|
||||
|
||||
if(self.URL){ // simple fast and modern way using Blob and URL:
|
||||
saver(self.URL.createObjectURL(blob), true);
|
||||
}else{
|
||||
// handle non-Blob()+non-URL browsers:
|
||||
if(typeof blob === "string" || blob.constructor===toString ){
|
||||
try{
|
||||
return saver( "data:" + mimeType + ";base64," + self.btoa(blob) );
|
||||
}catch(y){
|
||||
return saver( "data:" + mimeType + "," + encodeURIComponent(blob) );
|
||||
}
|
||||
}
|
||||
|
||||
// Blob but not URL support:
|
||||
reader=new FileReader();
|
||||
reader.onload=function(e){
|
||||
saver(this.result);
|
||||
};
|
||||
reader.readAsDataURL(blob);
|
||||
}
|
||||
return true;
|
||||
}; /* end download() */
|
||||
}));
|
Reference in New Issue
Block a user