/* global avadaAdminL10nStrings, ajaxurl, allTags, awbPrebuilts, awbSetupWizard */ /* jshint -W117 */ /* eslint no-unused-vars: off */ this.imagePreview = function() { jQuery( '.theme' ).hover( function() { jQuery( this ).find( '.screenshot-hover' ).css( 'visibility', 'visible' ); }, function() { jQuery( this ).find( '.screenshot-hover' ).css( 'visibility', 'visible' ); } ); }; // Starting the script on page load. jQuery( document ).ready( function() { var copyDebugReport; jQuery( '.help_tip' ).tipTip( { attribute: 'data-tip' } ); jQuery( 'a.help_tip' ).on( 'click', function() { return false; } ); jQuery( '.debug-report-button' ).on( 'click', function() { var report = ''; jQuery( '.avada-db-status h2:not(.avada-status-no-export), .avada-db-status table:not(.avada-status-no-export) tbody' ).each( function() { var label, theName, theValueElement, theValue, valueArray, tempLine; if ( jQuery( this ).is( 'h2' ) ) { label = jQuery( this ).data( 'export-label' ) || jQuery( this ).text(); report = report + '\n### ' + jQuery.trim( label ) + ' ###\n\n'; } else { jQuery( 'tr', jQuery( this ) ).each( function() { label = jQuery( this ).find( 'td:eq(0)' ).data( 'export-label' ) || jQuery( this ).find( 'td:eq(0)' ).text(); theName = jQuery.trim( label ).replace( /(<([^>]+)>)/ig, '' ); // Remove HTML. theValueElement = jQuery( this ).find( 'td:eq(2)' ); if ( 1 <= jQuery( theValueElement ).find( 'img' ).length ) { theValue = jQuery.trim( jQuery( theValueElement ).find( 'img' ).attr( 'alt' ) ); } else { theValue = jQuery.trim( jQuery( this ).find( 'td:eq(2)' ).text() ); } valueArray = theValue.split( ', ' ); if ( 1 < valueArray.length ) { // If value have a list of plugins ',' // Split to add new line. tempLine = ''; jQuery.each( valueArray, function( key, line ) { tempLine = tempLine + line + '\n'; } ); theValue = tempLine; } report = report + '' + theName + ': ' + theValue + '\n'; } ); } } ); try { jQuery( '.debug-report' ).slideDown(); jQuery( '.debug-report textarea' ).val( report ).focus().select(); return false; } catch ( e ) {} // eslint-disable-line no-empty return false; } ); jQuery( '#copy-for-support' ).tipTip( { attribute: 'data-tip', activation: 'click', fadeIn: 50, fadeOut: 50, delay: 100, enter: function() { copyDebugReport(); } } ); copyDebugReport = function() { jQuery( '.debug-report textarea' ).select(); document.execCommand( 'copy' ); }; } ); jQuery( document ).ready( function() { var importedLabel, tags, importedFilter, importStagesLength, removeStagesLength, demoType, disablePreview = jQuery( '.preview-all' ), importerDialog = jQuery( '#dialog-demo-confirm' ), importNotifications, prepareDemoImport, importDemo, prepareDemoRemove, removeDemo, importReport; if ( jQuery( 'body' ).hasClass( 'avada_page_avada-prebuilt-websites' ) ) { // If clicked on import data button. jQuery( '.button-install-demo' ).on( 'click', function( e ) { if ( avadaAdminL10nStrings.hasOwnProperty( demoType ) ) { importerDialog.html( avadaAdminL10nStrings[ demoType ] ); } else { importerDialog.html( avadaAdminL10nStrings[ 'default' ] ); } jQuery( '#' + importerDialog.attr( 'id' ) ).dialog( { dialogClass: 'avada-demo-dialog', resizable: false, draggable: false, height: 'auto', width: 400, modal: true, buttons: { Cancel: function() { importerDialog.html( '' ); jQuery( this ).dialog( 'close' ); }, OK: function() { prepareDemoImport(); importerDialog.html( '' ); jQuery( this ).dialog( 'close' ); } } } ); e.preventDefault(); } ); importReport = function( message, progress ) { jQuery( '#demo-modal-' + demoType + ' .awb-admin-modal-status-bar-label span' ).html( message ); jQuery( '#demo-modal-' + demoType + ' .awb-admin-modal-status-bar-progress-bar' ).css( 'width', ( 100 * progress ) + '%' ); }; importDemo = function( data ) { if ( data.importStages.length === importStagesLength ) { importReport( avadaAdminL10nStrings.currently_processing.replace( '%s', avadaAdminL10nStrings.download ), ( importStagesLength - data.importStages.length ) / importStagesLength ); } jQuery.post( ajaxurl, data, function( response ) { var importLabel; if ( 'content' === data.importStages[ 0 ] ) { jQuery.each( jQuery( '#import-' + data.demoType + ' input:checkbox[data-type=content]:checked' ), function( ) { jQuery( this ).prop( 'disabled', true ); jQuery( '#remove-' + data.demoType + ' input:checkbox[value=' + jQuery( this ).val() + ']' ).prop( 'checked', true ); } ); } else { jQuery( '#import-' + data.demoType + ' input:checkbox[value=' + data.importStages[ 0 ] + ']' ).prop( 'disabled', true ); jQuery( '#remove-' + data.demoType + ' input:checkbox[value=' + data.importStages[ 0 ] + ']' ).prop( 'checked', true ); } data.importStages.shift(); if ( ( 0 < response.indexOf( 'partially completed' ) || 0 <= response.indexOf( '{"status"' ) ) && 0 < data.importStages.length ) { if ( 'content' === data.importStages[ 0 ] ) { if ( 1 === data.contentTypes.length ) { importLabel = jQuery( 'label[for=import-' + data.contentTypes[ 0 ] + '-' + demoType + ']' ).html(); } else { importLabel = avadaAdminL10nStrings.content; } } else if ( 'general_data' === data.importStages[ 0 ] ) { importLabel = avadaAdminL10nStrings.general_data; } else if ( -1 !== data.importStages[ 0 ].indexOf( 'convertplug_' ) ) { importLabel = jQuery( 'label[for=import-convertplug-' + demoType + ']' ).html(); } else { importLabel = jQuery( 'label[for=import-' + data.importStages[ 0 ] + '-' + demoType + ']' ).html(); } importReport( avadaAdminL10nStrings.currently_processing.replace( '%s', importLabel ), ( importStagesLength - data.importStages.length ) / importStagesLength ); importDemo( data ); } else if ( -1 === response && response.indexOf( 'imported' ) ) { // eslint-disable-line no-empty } else if ( 1 < response.indexOf( avadaAdminL10nStrings.file_does_not_exist ) ) { // eslint-disable-line no-empty } else { setTimeout( function() { jQuery( '#demo-modal-' + demoType + ' input[type="checkbox"][value="uninstall"]' ).prop( 'disabled', false ); jQuery( '#demo-modal-' + demoType + ' input[type="checkbox"][value="all"]' ).prop( 'disabled', true ); jQuery( '#demo-modal-' + demoType ).removeClass( 'demo-import-in-progress' ); importReport( '', 1 ); jQuery( '#demo-modal-' + demoType + ' .button-done-demo' ).css( 'display', 'flex' ); if ( true === data.allImport ) { importedLabel.html( avadaAdminL10nStrings.full_import ); } else { importedLabel.html( avadaAdminL10nStrings.partial_import ); } importedLabel.show(); jQuery( '#theme-demo-' + demoType + ' .button-install-open-modal' ).html( avadaAdminL10nStrings.modify ); if ( -1 === tags.indexOf( 'imported' ) ) { jQuery( '#theme-demo-' + demoType ).parent().data( 'tags', tags + ',imported' ); importedFilter.data( 'count', importedFilter.data( 'count' ) + 1 ); importedFilter.children( '.count' ).html( '(' + importedFilter.data( 'count' ) + ')' ); } }, 4000 ); } } ).fail( function( xhr, textStatus, errorThrown ) { var message, dialogArgs = { dialogClass: 'avada-demo-dialog', resizable: false, draggable: false, height: 'auto', title: 'Import Failed', width: 400, modal: true, buttons: { OK: function() { importerDialog.html( '' ); jQuery( this ).dialog( 'close' ); location.reload(); } } }; if ( 'object' === typeof xhr.responseJSON && 'string' === typeof xhr.responseJSON.data ) { message = xhr.responseJSON.data; } else if ( 'Request Timeout' === errorThrown ) { message = avadaAdminL10nStrings.error_timeout; } else if ( ( 'Internal Server Error' === errorThrown || 500 === xhr.status ) && 'string' === typeof xhr.responseText ) { message = xhr.responseText; // Open default WP message link in new tab (happens when PHP max_execution time is reached). if ( -1 !== xhr.responseText.indexOf( ' totalImages ? totalImages : totalProcessed + batchSize; if ( startNum <= totalImages && endNum <= totalImages ) { $statusText.text ( $statusText.data( 'text' ) + ' ' + startNum + ' - ' + endNum + ' ' + $statusText.data( 'text-of' ) + ' ' + totalImages ); $progressBar.css( 'width', progressPercent + '%' ); } if ( ! response.data.finished ) { processBatch(); } else { $progressBar.css( 'width', '100%' ); $statusText.text( $statusText.data( 'text-total' ) + ' ' + totalProcessed ); } } else { $statusText.text( 'Error: ' + response.data ); } } ).fail( function() { $statusText.text( 'AJAX request failed.' ); } ); } processBatch(); } ); // Registration scroll to. function scrollToRegistration() { var target = jQuery( '#avada-db-registration' ), adminbarHeight = jQuery( '#wpadminbar' ).length ? jQuery( '#wpadminbar' ).height() : 0, scrollSticky = jQuery( '.avada-db-menu-sticky' ).length ? jQuery( '.avada-db-menu-sticky' ).height() : 0, newScrollPosition = target.offset().top - adminbarHeight - scrollSticky - 20; jQuery( 'html, body' ).animate( { scrollTop: newScrollPosition }, 450 ); } if ( -1 !== window.location.href.indexOf( '#_avada-db-registration' ) ) { scrollToRegistration(); } jQuery( 'a[href="#avada-db-registration"]' ).on( 'click', function( event ) { event.preventDefault(); scrollToRegistration(); } ); } );