Edit File by line
/home/barbar84/www/wp-conte.../themes/Divi/core/admin/js
File: portability.js
( function( $ ) {
[0] Fix | Delete
[1] Fix | Delete
"use strict";
[2] Fix | Delete
[3] Fix | Delete
// Extend etCorePortability since it is declared by localization.
[4] Fix | Delete
window.etCore.portability = $.extend( etCorePortability, {
[5] Fix | Delete
[6] Fix | Delete
cancelled: false,
[7] Fix | Delete
[8] Fix | Delete
boot: function( $instance ) {
[9] Fix | Delete
var $this = this;
[10] Fix | Delete
var $customizeHeader = $( '#customize-header-actions' );
[11] Fix | Delete
var $customizePortability = $( '.et-core-customize-controls-close' );
[12] Fix | Delete
[13] Fix | Delete
// Moved portability button into customizer header
[14] Fix | Delete
if ( $customizeHeader.length && $customizePortability.length ) {
[15] Fix | Delete
$customizeHeader.append( $customizePortability );
[16] Fix | Delete
}
[17] Fix | Delete
[18] Fix | Delete
$( '[data-et-core-portability]' ).each( function() {
[19] Fix | Delete
$this.listen( $( this ) );
[20] Fix | Delete
} );
[21] Fix | Delete
[22] Fix | Delete
// Release unecessary cache.
[23] Fix | Delete
etCorePortability = null;
[24] Fix | Delete
},
[25] Fix | Delete
[26] Fix | Delete
listen: function( $el ) {
[27] Fix | Delete
var $this = this;
[28] Fix | Delete
[29] Fix | Delete
$el.find( '[data-et-core-portability-export]' ).click( function( e ) {
[30] Fix | Delete
e.preventDefault();
[31] Fix | Delete
[32] Fix | Delete
if ( ! $this.actionsDisabled() ) {
[33] Fix | Delete
$this.disableActions();
[34] Fix | Delete
$this.export();
[35] Fix | Delete
}
[36] Fix | Delete
} );
[37] Fix | Delete
[38] Fix | Delete
[39] Fix | Delete
$el.find( '.et-core-portability-export-form input[type="text"]' ).on( 'keydown', function( e ) {
[40] Fix | Delete
if ( 13 === e.keyCode ) {
[41] Fix | Delete
e.preventDefault();
[42] Fix | Delete
$el.find( '[data-et-core-portability-export]' ).click();
[43] Fix | Delete
}
[44] Fix | Delete
} );
[45] Fix | Delete
[46] Fix | Delete
// Portability populate import.
[47] Fix | Delete
$el.find( '.et-core-portability-import-form input[type="file"]' ).on( 'change', function( e ) {
[48] Fix | Delete
$this.populateImport( $( this ).get( 0 ).files[0] );
[49] Fix | Delete
} );
[50] Fix | Delete
[51] Fix | Delete
$el.find( '.et-core-portability-import' ).click( function( e ) {
[52] Fix | Delete
e.preventDefault();
[53] Fix | Delete
[54] Fix | Delete
if ( ! $this.actionsDisabled() ) {
[55] Fix | Delete
$this.disableActions();
[56] Fix | Delete
$this.import();
[57] Fix | Delete
}
[58] Fix | Delete
} );
[59] Fix | Delete
[60] Fix | Delete
// Trigger file window.
[61] Fix | Delete
$el.find( '.et-core-portability-import-form button' ).click( function( e ) {
[62] Fix | Delete
e.preventDefault();
[63] Fix | Delete
$this.instance( 'input[type="file"]' ).trigger( 'click' );
[64] Fix | Delete
} );
[65] Fix | Delete
[66] Fix | Delete
// Cancel request.
[67] Fix | Delete
$el.find( '[data-et-core-portability-cancel]' ).click( function( e ) {
[68] Fix | Delete
e.preventDefault();
[69] Fix | Delete
$this.cancel();
[70] Fix | Delete
} );
[71] Fix | Delete
},
[72] Fix | Delete
[73] Fix | Delete
validateImportFile: function( file, noOutput ) {
[74] Fix | Delete
if ( undefined !== file && 'undefined' != typeof file.name && 'undefined' != typeof file.type && 'json' == file.name.split( '.' ).slice( -1 )[0] ) {
[75] Fix | Delete
[76] Fix | Delete
return true;
[77] Fix | Delete
}
[78] Fix | Delete
[79] Fix | Delete
if ( ! noOutput ) {
[80] Fix | Delete
etCore.modalContent( '<p>' + this.text.invalideFile + '</p>', false, 3000, '#et-core-portability-import' );
[81] Fix | Delete
}
[82] Fix | Delete
[83] Fix | Delete
this.enableActions();
[84] Fix | Delete
[85] Fix | Delete
return false;
[86] Fix | Delete
},
[87] Fix | Delete
[88] Fix | Delete
populateImport: function( file ) {
[89] Fix | Delete
if ( ! this.validateImportFile( file ) ) {
[90] Fix | Delete
return;
[91] Fix | Delete
}
[92] Fix | Delete
[93] Fix | Delete
$( '.et-core-portability-import-placeholder' ).text( file.name );
[94] Fix | Delete
},
[95] Fix | Delete
[96] Fix | Delete
import: function(noBackup) {
[97] Fix | Delete
var $this = this;
[98] Fix | Delete
var file = $this.instance('input[type="file"]').get(0).files[0];
[99] Fix | Delete
[100] Fix | Delete
if (undefined === window.FormData) {
[101] Fix | Delete
etCore.modalContent('<p>' + this.text.browserSupport + '</p>', false, 3000, '#et-core-portability-import');
[102] Fix | Delete
[103] Fix | Delete
$this.enableActions();
[104] Fix | Delete
[105] Fix | Delete
return;
[106] Fix | Delete
}
[107] Fix | Delete
[108] Fix | Delete
if (!$this.validateImportFile(file)) {
[109] Fix | Delete
return;
[110] Fix | Delete
}
[111] Fix | Delete
[112] Fix | Delete
$this.addProgressBar( $this.text.importing );
[113] Fix | Delete
[114] Fix | Delete
// Export Backup if set.
[115] Fix | Delete
if ( $this.instance( '[name="et-core-portability-import-backup"]' ).is( ':checked' ) && ! noBackup ) {
[116] Fix | Delete
$this.export( true );
[117] Fix | Delete
[118] Fix | Delete
$( $this ).on( 'exported', function() {
[119] Fix | Delete
$this.import( true );
[120] Fix | Delete
} );
[121] Fix | Delete
[122] Fix | Delete
return;
[123] Fix | Delete
}
[124] Fix | Delete
[125] Fix | Delete
var includeGlobalPresets = $this.instance('[name="et-core-portability-import-include-global-presets"]').is(':checked');
[126] Fix | Delete
[127] Fix | Delete
$this.ajaxAction( {
[128] Fix | Delete
action: 'et_core_portability_import',
[129] Fix | Delete
file: file,
[130] Fix | Delete
include_global_presets: includeGlobalPresets,
[131] Fix | Delete
nonce: $this.nonces.import
[132] Fix | Delete
}, function( response ) {
[133] Fix | Delete
etCore.modalContent( '<div class="et-core-loader et-core-loader-success"></div>', false, 3000, '#et-core-portability-import' );
[134] Fix | Delete
$this.toggleCancel();
[135] Fix | Delete
[136] Fix | Delete
$( document ).delay( 3000 ).queue( function() {
[137] Fix | Delete
etCore.modalContent( '<div class="et-core-loader"></div>', false, false, '#et-core-portability-import' );
[138] Fix | Delete
[139] Fix | Delete
$( this ).dequeue().delay( 2000 ).queue( function() {
[140] Fix | Delete
// Save post content for individual content.
[141] Fix | Delete
if ( 'undefined' !== typeof response.data.postContent ) {
[142] Fix | Delete
var save = $( '#save-action #save-post' );
[143] Fix | Delete
[144] Fix | Delete
if ( save.length === 0 ) {
[145] Fix | Delete
save = $( '#publishing-action input[type="submit"]' );
[146] Fix | Delete
}
[147] Fix | Delete
[148] Fix | Delete
if ( 'undefined' !== typeof window.tinyMCE && window.tinyMCE.get( 'content' ) && ! window.tinyMCE.get( 'content' ).isHidden() ) {
[149] Fix | Delete
var editor = window.tinyMCE.get( 'content' );
[150] Fix | Delete
[151] Fix | Delete
editor.setContent( $.trim( response.data.postContent ), { format: 'html' } );
[152] Fix | Delete
} else {
[153] Fix | Delete
$( '#content' ).val( $.trim( response.data.postContent ) );
[154] Fix | Delete
}
[155] Fix | Delete
[156] Fix | Delete
save.trigger( 'click' );
[157] Fix | Delete
[158] Fix | Delete
window.onbeforeunload = function() {
[159] Fix | Delete
$( 'body' ).fadeOut( 500 );
[160] Fix | Delete
}
[161] Fix | Delete
} else {
[162] Fix | Delete
$( 'body' ).fadeOut( 500, function() {
[163] Fix | Delete
// Remove confirmation popup before relocation.
[164] Fix | Delete
$( window ).unbind( 'beforeunload' );
[165] Fix | Delete
[166] Fix | Delete
window.location = window.location.href.replace(/reset\=true\&|\&reset\=true/,'');
[167] Fix | Delete
} )
[168] Fix | Delete
}
[169] Fix | Delete
} );
[170] Fix | Delete
} );
[171] Fix | Delete
}, true );
[172] Fix | Delete
},
[173] Fix | Delete
[174] Fix | Delete
export: function( backup ) {
[175] Fix | Delete
var $this = this,
[176] Fix | Delete
progressBarMessages = backup ? $this.text.backuping : $this.text.exporting;
[177] Fix | Delete
[178] Fix | Delete
$this.save( function() {
[179] Fix | Delete
var posts = {},
[180] Fix | Delete
content = false;
[181] Fix | Delete
[182] Fix | Delete
// Include selected posts.
[183] Fix | Delete
if ( $this.instance( '[name="et-core-portability-posts"]' ).is( ':checked' ) ) {
[184] Fix | Delete
$( '#posts-filter [name="post[]"]:checked:enabled' ).each( function() {
[185] Fix | Delete
posts[this.id] = this.value;
[186] Fix | Delete
} );
[187] Fix | Delete
[188] Fix | Delete
// do not proceed and display error message if no Items selected
[189] Fix | Delete
if ( $.isEmptyObject( posts ) ) {
[190] Fix | Delete
etCore.modalContent( '<div class="et-core-loader et-core-loader-fail"></div><h3>' + $this.text.noItemsSelected + '</h3>', false, true, '#' + $this.instance( '.ui-tabs-panel:visible' ).attr( 'id' ) );
[191] Fix | Delete
[192] Fix | Delete
$this.enableActions();
[193] Fix | Delete
[194] Fix | Delete
return;
[195] Fix | Delete
}
[196] Fix | Delete
}
[197] Fix | Delete
[198] Fix | Delete
$this.addProgressBar( progressBarMessages );
[199] Fix | Delete
[200] Fix | Delete
// Get post layout.
[201] Fix | Delete
if ( 'undefined' !== typeof window.tinyMCE && window.tinyMCE.get( 'content' ) && ! window.tinyMCE.get( 'content' ).isHidden() ) {
[202] Fix | Delete
content = window.tinyMCE.get( 'content' ).getContent();
[203] Fix | Delete
} else if ( $( 'textarea#content' ).length > 0 ) {
[204] Fix | Delete
content = $( 'textarea#content' ).val();
[205] Fix | Delete
}
[206] Fix | Delete
[207] Fix | Delete
if ( false !== content ) {
[208] Fix | Delete
content = content.replace( /^([^\[]*){1}/, '' );
[209] Fix | Delete
content = content.replace( /([^\]]*)$/, '' );
[210] Fix | Delete
}
[211] Fix | Delete
[212] Fix | Delete
var applyGlobalPresets = $this.instance( '[name="et-core-portability-apply-presets"]' ).is( ':checked' );
[213] Fix | Delete
[214] Fix | Delete
$this.ajaxAction( {
[215] Fix | Delete
action: 'et_core_portability_export',
[216] Fix | Delete
content: content,
[217] Fix | Delete
selection: $.isEmptyObject( posts ) ? false : JSON.stringify( posts ),
[218] Fix | Delete
apply_global_presets: applyGlobalPresets,
[219] Fix | Delete
nonce: $this.nonces.export
[220] Fix | Delete
}, function( response ) {
[221] Fix | Delete
var time = ' ' + new Date().toJSON().replace( 'T', ' ' ).replace( ':', 'h' ).substring( 0, 16 ),
[222] Fix | Delete
downloadURL = $this.instance( '[data-et-core-portability-export]' ).data( 'et-core-portability-export' ),
[223] Fix | Delete
query = {
[224] Fix | Delete
'timestamp': response.data.timestamp,
[225] Fix | Delete
'name': encodeURIComponent( $this.instance( '.et-core-portability-export-form input' ).val() + ( backup ? time : '' ) ),
[226] Fix | Delete
};
[227] Fix | Delete
[228] Fix | Delete
$.each( query, function( key, value ) {
[229] Fix | Delete
if ( value ) {
[230] Fix | Delete
downloadURL = downloadURL + '&' + key + '=' + value;
[231] Fix | Delete
}
[232] Fix | Delete
} );
[233] Fix | Delete
[234] Fix | Delete
// Remove confirmation popup before relocation.
[235] Fix | Delete
$( window ).unbind( 'beforeunload' );
[236] Fix | Delete
[237] Fix | Delete
window.location.assign( encodeURI( downloadURL ) );
[238] Fix | Delete
[239] Fix | Delete
if ( ! backup ) {
[240] Fix | Delete
etCore.modalContent( '<div class="et-core-loader et-core-loader-success"></div>', false, 3000, '#et-core-portability-export' );
[241] Fix | Delete
$this.toggleCancel();
[242] Fix | Delete
}
[243] Fix | Delete
[244] Fix | Delete
$( $this ).trigger( 'exported' );
[245] Fix | Delete
} );
[246] Fix | Delete
} );
[247] Fix | Delete
},
[248] Fix | Delete
[249] Fix | Delete
exportFB: function( exportUrl, postId, content, fileName, importFile, page, timestamp, progress = 0, estimation = 1 ) {
[250] Fix | Delete
var $this = this;
[251] Fix | Delete
[252] Fix | Delete
// Trigger event which updates VB-UI's progress bar
[253] Fix | Delete
window.et_fb_export_progress = progress;
[254] Fix | Delete
window.et_fb_export_estimation = estimation;
[255] Fix | Delete
[256] Fix | Delete
var exportEvent = document.createEvent('Event');
[257] Fix | Delete
exportEvent.initEvent('et_fb_layout_export_in_progress', true, true);
[258] Fix | Delete
window.dispatchEvent(exportEvent);
[259] Fix | Delete
[260] Fix | Delete
page = typeof page === 'undefined' ? 1 : page;
[261] Fix | Delete
[262] Fix | Delete
$.ajax( {
[263] Fix | Delete
type: 'POST',
[264] Fix | Delete
url: etCore.ajaxurl,
[265] Fix | Delete
dataType: 'json',
[266] Fix | Delete
data: {
[267] Fix | Delete
action: 'et_core_portability_export',
[268] Fix | Delete
content: content.shortcode,
[269] Fix | Delete
global_presets: content.global_presets,
[270] Fix | Delete
timestamp: timestamp !== undefined ? timestamp : 0,
[271] Fix | Delete
nonce: $this.nonces.export,
[272] Fix | Delete
post: postId,
[273] Fix | Delete
context: 'et_builder',
[274] Fix | Delete
page: page,
[275] Fix | Delete
},
[276] Fix | Delete
success: function( response ) {
[277] Fix | Delete
var errorEvent = document.createEvent( 'Event' );
[278] Fix | Delete
[279] Fix | Delete
errorEvent.initEvent( 'et_fb_layout_export_error', true, true );
[280] Fix | Delete
[281] Fix | Delete
// The error is unknown but most of the time it would be cased by the server max size being exceeded.
[282] Fix | Delete
if ( 'string' === typeof response && '0' === response ) {
[283] Fix | Delete
window.et_fb_export_layout_message = $this.text.maxSizeExceeded;
[284] Fix | Delete
window.dispatchEvent( errorEvent );
[285] Fix | Delete
[286] Fix | Delete
return;
[287] Fix | Delete
}
[288] Fix | Delete
// Memory size set on server is exhausted.
[289] Fix | Delete
else if ( 'string' === typeof response && response.toLowerCase().indexOf( 'memory size' ) >= 0 ) {
[290] Fix | Delete
window.et_fb_export_layout_message = $this.text.memoryExhausted;
[291] Fix | Delete
window.dispatchEvent( errorEvent );
[292] Fix | Delete
return;
[293] Fix | Delete
}
[294] Fix | Delete
// Paginate.
[295] Fix | Delete
else if ( 'undefined' !== typeof response.page ) {
[296] Fix | Delete
if ( $this.cancelled ) {
[297] Fix | Delete
return;
[298] Fix | Delete
}
[299] Fix | Delete
[300] Fix | Delete
// Update progress bar
[301] Fix | Delete
var updatedProgress = Math.ceil((response.page * 100) / response.total_pages);
[302] Fix | Delete
var updatedEstimation = Math.ceil(((response.total_pages - response.page) * 6) / 60);
[303] Fix | Delete
[304] Fix | Delete
// If progress param isn't empty, updated progress should continue from it
[305] Fix | Delete
// because before exportFB(), shortcode should've been prepared via another
[306] Fix | Delete
// ajax request first
[307] Fix | Delete
if (0 < progress) {
[308] Fix | Delete
const remainingProgress = (100 - progress) / 100;
[309] Fix | Delete
updatedProgress = (updatedProgress * remainingProgress) + progress;
[310] Fix | Delete
}
[311] Fix | Delete
[312] Fix | Delete
// Update global variables
[313] Fix | Delete
window.et_fb_export_progress = updatedProgress;
[314] Fix | Delete
window.et_fb_export_estimation = updatedEstimation;
[315] Fix | Delete
[316] Fix | Delete
// Dispatch event to trigger UI update
[317] Fix | Delete
window.dispatchEvent(exportEvent);
[318] Fix | Delete
[319] Fix | Delete
return $this.exportFB(
[320] Fix | Delete
exportUrl,
[321] Fix | Delete
postId,
[322] Fix | Delete
content,
[323] Fix | Delete
fileName,
[324] Fix | Delete
importFile,
[325] Fix | Delete
(page + 1),
[326] Fix | Delete
response.timestamp,
[327] Fix | Delete
updatedProgress,
[328] Fix | Delete
updatedEstimation
[329] Fix | Delete
);
[330] Fix | Delete
} else if ( 'undefined' !== typeof response.data && 'undefined' !== typeof response.data.message ) {
[331] Fix | Delete
window.et_fb_export_layout_message = $this.text[response.data.message];
[332] Fix | Delete
window.dispatchEvent( errorEvent );
[333] Fix | Delete
return;
[334] Fix | Delete
}
[335] Fix | Delete
[336] Fix | Delete
var time = ' ' + new Date().toJSON().replace( 'T', ' ' ).replace( ':', 'h' ).substring( 0, 16 ),
[337] Fix | Delete
downloadURL = exportUrl,
[338] Fix | Delete
query = {
[339] Fix | Delete
'timestamp': response.data.timestamp,
[340] Fix | Delete
'name': '' !== fileName ? fileName : encodeURIComponent( time ),
[341] Fix | Delete
};
[342] Fix | Delete
[343] Fix | Delete
$.each( query, function( key, value ) {
[344] Fix | Delete
if ( value ) {
[345] Fix | Delete
downloadURL = downloadURL + '&' + key + '=' + value;
[346] Fix | Delete
}
[347] Fix | Delete
} );
[348] Fix | Delete
[349] Fix | Delete
// Remove confirmation popup before relocation.
[350] Fix | Delete
$( window ).unbind( 'beforeunload' );
[351] Fix | Delete
[352] Fix | Delete
// Update progress bar's global variables
[353] Fix | Delete
window.et_fb_export_progress = 100;
[354] Fix | Delete
window.et_fb_export_estimation = 0;
[355] Fix | Delete
[356] Fix | Delete
// Dispatch event to trigger UI update
[357] Fix | Delete
window.dispatchEvent(exportEvent);
[358] Fix | Delete
window.location.assign( encodeURI( downloadURL ) );
[359] Fix | Delete
[360] Fix | Delete
// perform import if needed
[361] Fix | Delete
if ( typeof importFile !== 'undefined' ) {
[362] Fix | Delete
$this.importFB( importFile, postId );
[363] Fix | Delete
} else {
[364] Fix | Delete
var event = document.createEvent( 'Event' );
[365] Fix | Delete
[366] Fix | Delete
event.initEvent( 'et_fb_layout_export_finished', true, true );
[367] Fix | Delete
[368] Fix | Delete
// trigger event to communicate with FB
[369] Fix | Delete
window.dispatchEvent( event );
[370] Fix | Delete
}
[371] Fix | Delete
}
[372] Fix | Delete
} );
[373] Fix | Delete
},
[374] Fix | Delete
[375] Fix | Delete
importFB: function(file, postId, options) {
[376] Fix | Delete
var $this = this;
[377] Fix | Delete
var errorEvent = document.createEvent( 'Event' );
[378] Fix | Delete
[379] Fix | Delete
window.et_fb_import_progress = 0;
[380] Fix | Delete
window.et_fb_import_estimation = 1;
[381] Fix | Delete
[382] Fix | Delete
errorEvent.initEvent( 'et_fb_layout_import_error', true, true );
[383] Fix | Delete
[384] Fix | Delete
if ( undefined === window.FormData ) {
[385] Fix | Delete
window.et_fb_import_layout_message = this.text.browserSupport;
[386] Fix | Delete
window.dispatchEvent( errorEvent );
[387] Fix | Delete
return;
[388] Fix | Delete
}
[389] Fix | Delete
[390] Fix | Delete
if ( ! $this.validateImportFile( file, true ) ) {
[391] Fix | Delete
window.et_fb_import_layout_message = this.text.invalideFile;
[392] Fix | Delete
window.dispatchEvent( errorEvent );
[393] Fix | Delete
return;
[394] Fix | Delete
}
[395] Fix | Delete
[396] Fix | Delete
if ('undefined' === typeof options) {
[397] Fix | Delete
options = {};
[398] Fix | Delete
}
[399] Fix | Delete
[400] Fix | Delete
options = $.extend({
[401] Fix | Delete
replace: false
[402] Fix | Delete
}, options);
[403] Fix | Delete
[404] Fix | Delete
var fileSize = Math.ceil( ( file.size / ( 1024 * 1024 ) ).toFixed( 2 ) ),
[405] Fix | Delete
formData = new FormData(),
[406] Fix | Delete
requestData = {
[407] Fix | Delete
action: 'et_core_portability_import',
[408] Fix | Delete
include_global_presets: options.includeGlobalPresets,
[409] Fix | Delete
file: file,
[410] Fix | Delete
content: false,
[411] Fix | Delete
timestamp: 0,
[412] Fix | Delete
nonce: $this.nonces.import,
[413] Fix | Delete
post: postId,
[414] Fix | Delete
replace: options.replace ? '1' : '0',
[415] Fix | Delete
context: 'et_builder'
[416] Fix | Delete
};
[417] Fix | Delete
[418] Fix | Delete
/**
[419] Fix | Delete
* Max size set on server is exceeded.
[420] Fix | Delete
*
[421] Fix | Delete
* 0 indicating "unlimited" according to php specs
[422] Fix | Delete
* https://www.php.net/manual/en/ini.core.php#ini.post-max-size
[423] Fix | Delete
**/
[424] Fix | Delete
if (
[425] Fix | Delete
( 0 > $this.postMaxSize && fileSize >= $this.postMaxSize )
[426] Fix | Delete
|| ( 0 > $this.uploadMaxSize && fileSize >= $this.uploadMaxSize )
[427] Fix | Delete
) {
[428] Fix | Delete
window.et_fb_import_layout_message = this.text.maxSizeExceeded;
[429] Fix | Delete
window.dispatchEvent( errorEvent );
[430] Fix | Delete
return;
[431] Fix | Delete
}
[432] Fix | Delete
[433] Fix | Delete
$.each(requestData, function(name, value) {
[434] Fix | Delete
if ('file' === name) {
[435] Fix | Delete
// Explicitly set the file name.
[436] Fix | Delete
// Otherwise it'll be set to 'Blob' in case of Blob type, but we need actual filename here.
[437] Fix | Delete
formData.append('file', value, value.name);
[438] Fix | Delete
} else {
[439] Fix | Delete
formData.append(name, value);
[440] Fix | Delete
}
[441] Fix | Delete
});
[442] Fix | Delete
[443] Fix | Delete
var importFBAjax = function( importData ) {
[444] Fix | Delete
$.ajax( {
[445] Fix | Delete
type: 'POST',
[446] Fix | Delete
url: etCore.ajaxurl,
[447] Fix | Delete
processData: false,
[448] Fix | Delete
contentType: false,
[449] Fix | Delete
data: formData,
[450] Fix | Delete
success: function( response ) {
[451] Fix | Delete
var event = document.createEvent( 'Event' );
[452] Fix | Delete
[453] Fix | Delete
event.initEvent( 'et_fb_layout_import_in_progress', true, true );
[454] Fix | Delete
[455] Fix | Delete
// Handle known error
[456] Fix | Delete
if ( ! response.success && 'undefined' !== typeof response.data && 'undefined' !== typeof response.data.message && 'undefined' !== typeof $this.text[ response.data.message ] ) {
[457] Fix | Delete
window.et_fb_import_layout_message = $this.text[ response.data.message ];
[458] Fix | Delete
window.dispatchEvent( errorEvent );
[459] Fix | Delete
}
[460] Fix | Delete
// The error is unknown but most of the time it would be cased by the server max size being exceeded.
[461] Fix | Delete
else if ( 'string' === typeof response && ('0' === response || '' === response) ) {
[462] Fix | Delete
window.et_fb_import_layout_message = $this.text.maxSizeExceeded;
[463] Fix | Delete
window.dispatchEvent( errorEvent );
[464] Fix | Delete
[465] Fix | Delete
return;
[466] Fix | Delete
}
[467] Fix | Delete
// Memory size set on server is exhausted.
[468] Fix | Delete
else if ( 'string' === typeof response && response.toLowerCase().indexOf( 'memory size' ) >= 0 ) {
[469] Fix | Delete
window.et_fb_import_layout_message = $this.text.memoryExhausted;
[470] Fix | Delete
window.dispatchEvent( errorEvent );
[471] Fix | Delete
[472] Fix | Delete
return;
[473] Fix | Delete
}
[474] Fix | Delete
// Pagination
[475] Fix | Delete
else if ( 'undefined' !== typeof response.page && 'undefined' !== typeof response.total_pages ) {
[476] Fix | Delete
// Update progress bar
[477] Fix | Delete
var progress = Math.ceil( ( response.page * 100 ) / response.total_pages );
[478] Fix | Delete
var estimation = Math.ceil( ( ( response.total_pages - response.page ) * 6 ) / 60 );
[479] Fix | Delete
[480] Fix | Delete
window.et_fb_import_progress = progress;
[481] Fix | Delete
window.et_fb_import_estimation = estimation;
[482] Fix | Delete
[483] Fix | Delete
// Import data
[484] Fix | Delete
var nextImportData = importData;
[485] Fix | Delete
nextImportData.append( 'page', ( parseInt(response.page) + 1 ) );
[486] Fix | Delete
nextImportData.append( 'timestamp', response.timestamp );
[487] Fix | Delete
nextImportData.append( 'file', null );
[488] Fix | Delete
[489] Fix | Delete
importFBAjax( nextImportData );
[490] Fix | Delete
[491] Fix | Delete
// trigger event to communicate with FB
[492] Fix | Delete
window.dispatchEvent( event );
[493] Fix | Delete
} else {
[494] Fix | Delete
// Update progress bar
[495] Fix | Delete
window.et_fb_import_progress = 100;
[496] Fix | Delete
window.et_fb_import_estimation = 0;
[497] Fix | Delete
[498] Fix | Delete
// trigger event to communicate with FB
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function