芝麻web文件管理V1.00
编辑当前文件:/home/pulsehostuk9/www/ebpt.pulsehost.co.uk/wp-content/plugins/lte-ext/inc/demo/assets/demo.js
/** * Check current status */ jQuery(function ($) { var inst = { localized: _lte_ext_backups_demo, getEventName: function(name) { return 'lte:backups-demo:status:'+ name; }, timeoutId: 0, timeoutTime: 3000, isBusy: 0, doAjax: function() { if (this.isBusy) { this.isBusy = 2; return false; } clearTimeout(this.timeoutId); lteEvents.trigger(this.getEventName('updating')); $.ajax({ url: ajaxurl, type: 'POST', dataType: 'json', data: { action: this.localized.ajax_action.status } }) .done(_.bind(function(r){ if (r.success) { lteEvents.trigger(this.getEventName('update'), r.data); } else { lteEvents.trigger(this.getEventName('update-fail')); } }, this)) .fail(_.bind(function(jqXHR, textStatus, errorThrown){ console.error('Ajax error', jqXHR, textStatus, errorThrown); lteEvents.trigger(this.getEventName('update-fail')); }, this)) .always(_.bind(function(data_jqXHR, textStatus, jqXHR_errorThrown){ lteEvents.trigger(this.getEventName('updated')); if (this.isBusy === 2) { this.isBusy = 0; this.doAjax(); } else { this.isBusy = 0; } this.timeoutId = setTimeout(_.bind(this.doAjax, this), this.timeoutTime); }, this)); return true; }, onUpdate: function(data) { this.timeoutTime = data.is_busy ? 3000 : 10000; }, init: function(){ this.init = function(){}; lteEvents.on(this.getEventName('do-update'), _.bind(function(){ this.doAjax(); }, this)); lteEvents.on(this.getEventName('update'), _.bind(function(data){ this.onUpdate(data); }, this)); this.doAjax(); } }; // let other scripts to listen events setTimeout(function(){ inst.init(); }, 100); }); /** * Current status */ jQuery(function($){ var inst = { failCount: 0, fwSoleModalId: 'fw-ext-backups-demo-status', onUpdating: function(){}, onUpdate: function(data) { if (data.is_busy) { lte.soleModal.show( this.fwSoleModalId, data.html, { allowClose: false, updateIfCurrent: true } ); } else { lte.soleModal.hide(this.fwSoleModalId); } this.failCount = 0; }, onUpdateFail: function() { if (this.failCount > 3) { lte.soleModal.show( this.fwSoleModalId, '
', { allowClose: false, updateIfCurrent: true } ); } ++this.failCount; }, onUpdated: function() {}, init: function(){ lteEvents.on({ 'lte:backups-demo:status:updating': _.bind(this.onUpdating, this), 'lte:backups-demo:status:update': _.bind(this.onUpdate, this), 'lte:backups-demo:status:update-fail': _.bind(this.onUpdateFail, this), 'lte:backups-demo:status:updated': _.bind(this.onUpdated, this) }); } }; inst.init(); }); /** * Install button */ jQuery(function($) { var inst = { localized: _lte_ext_backups_demo, isBusy: false, fwLoadingId: 'lte-demo-list', init: function(){ lteEvents.on('lte:backups-demo:status:update', function(data){ { $('#fw-ext-backups-demo-list .lte-ext-backups-demo-item').removeClass('active'); if (data.active_demo.id) { $('#demo-'+ data.active_demo.id).addClass('active'); } } if (data.active_demo.result) { if (data.active_demo.result === true) { lte.soleModal.hide(inst.fwLoadingId); setTimeout(function(){ $(document.body).fadeOut(); }, 500); // after modal hide animation end setTimeout(function(){ window.location.assign(data.home_url); }, 1000); // after all animations end } else { lte.soleModal.show( inst.fwLoadingId, '
'+ data.active_demo.result +'
' ); } } }); $('#lte-demo-list').on('click', '[data-install]', function(){ if (inst.isBusy) { console.log('Install is busy'); return; } var $this = $(this), demoId = $this.attr('data-install'), confirm_message = $this.attr('data-confirm'); if (confirm_message) { if (!confirm(confirm_message)) { return; } } inst.isBusy = true; lte.loading.show(inst.fwLoadingId); $.ajax({ url: ajaxurl, data: { action: inst.localized.ajax_action.install, id: demoId }, type: 'POST', dataType: 'json' }) .done(function(r){ if (r.success) { lteEvents.trigger('lte:backups-demo:status:do-update'); } else { lte.soleModal.show( 'fw-ext-backups-demo-install-error', ((r.data && r.data.length) ? r.data[0].message : '') ); } }) .fail(function(jqXHR, textStatus, errorThrown){ lte.soleModal.show( 'fw-ext-backups-demo-install-error', '
Ajax error
'+ '
'+ String(errorThrown) +'
' ); }) .always(function(data_jqXHR, textStatus, jqXHR_errorThrown){ inst.isBusy = false; lte.loading.hide(inst.fwLoadingId); }); }); } }; inst.init(); }); /** * "Cancel" functionality */ jQuery(function($){ var inst = { localized: _lte_ext_backups_demo, isBusy: false, fwLoadingId: 'fw-ext-backups-demo-install-cancel', doCancel: function(){ if (this.isBusy) { return; } else { if (!confirm(this.localized.l10n.abort_confirm)) { return; } this.isBusy = true; } inst.isBusy = true; lte.loading.show(inst.fwLoadingId); $.ajax({ url: ajaxurl, data: { action: inst.localized.ajax_action.cancel }, type: 'POST', dataType: 'json' }) .done(function(r){ if (r.success) { lteEvents.trigger('lte:backups-demo:status:do-update'); } else { console.warn('Cancel failed'); } }) .fail(function(jqXHR, textStatus, errorThrown){ lte.soleModal.show( 'fw-ext-backups-demo-install-error', '
Ajax error
'+ '
'+ String(errorThrown) +'
' ); }) .always(function(data_jqXHR, textStatus, jqXHR_errorThrown){ inst.isBusy = false; lte.loading.hide(inst.fwLoadingId); }); }, init: function(){ var that = this; lteEvents.on('lte:backups-demo:cancel', function(){ that.doCancel(); }); } }; inst.init(); }); /** * If loopback request failed, execute steps via ajax * @since 2.0.5 */ jQuery(function($){ if (typeof lte_ext_backups_loopback_failed == 'undefined') { return; } var inst = { running: false, isBusy: false, onUpdate: function(data) { this.running = data.is_busy; this.executeNextStep(data.ajax_steps.token, data.ajax_steps.active_tasks_hash); }, executeNextStep: function(token, activeTasksHash){ if (!this.running || this.isBusy) { return false; } this.isBusy = true; $.ajax({ url: ajaxurl, data: { action: 'lte:backups:continue-pending-task', token: token, active_tasks_hash: activeTasksHash }, type: 'POST', dataType: 'json' }) .done(function(r){ console.log(r); if (r.success) { lteEvents.trigger('lte:backups-demo:status:do-update'); } else { console.error('Ajax execution failed'); // execution will try to continue on next (auto) update } }) .fail(_.bind(function(jqXHR, textStatus, errorThrown){ console.error('Ajax error: '+ String(errorThrown)); }, this)) .always(_.bind(function(data_jqXHR, textStatus, jqXHR_errorThrown){ this.isBusy = false; }, this)); }, init: function(){ lteEvents.on('lte:backups-demo:status:update', _.bind(this.onUpdate, this)); } }; inst.init(); });