| 1 |
jQuery(document).ready(function () { |
| 2 |
var wooActive = window.yayRecommended.woo_active; |
| 3 |
if (wooActive === '') { |
| 4 |
getData('featured'); |
| 5 |
} else { |
| 6 |
getData('woocommerce'); |
| 7 |
} |
| 8 |
|
| 9 |
jQuery('.yay-recommended-plugins-layout .plugin-install-tab').on('click', function () { |
| 10 |
if (jQuery(this).children().hasClass('current') === false) { |
| 11 |
getData(jQuery(this).attr('data-tab')); |
| 12 |
jQuery('.yay-recommended-plugins-layout .plugin-install-tab a').each(function () { |
| 13 |
if (jQuery(this).hasClass('current') === true) { |
| 14 |
jQuery(this).removeClass('current'); |
| 15 |
} |
| 16 |
}); |
| 17 |
jQuery(this).children().addClass('current'); |
| 18 |
} |
| 19 |
}); |
| 20 |
jQuery('body').on( |
| 21 |
'click', |
| 22 |
'.yay-recommended-plugins-layout .plugin-action-buttons .activate-now', |
| 23 |
function () { |
| 24 |
var file = jQuery(this).attr('data-plugin-file'); |
| 25 |
activatePlugin(jQuery(this), file); |
| 26 |
} |
| 27 |
); |
| 28 |
jQuery('body').on( |
| 29 |
'click', |
| 30 |
'.yay-recommended-plugins-layout .plugin-action-buttons .install-now', |
| 31 |
function () { |
| 32 |
if (!jQuery(this).hasClass('updating-message')) { |
| 33 |
var plugin = jQuery(this).attr('data-install-url'); |
| 34 |
installPlugin(jQuery(this), plugin); |
| 35 |
} |
| 36 |
} |
| 37 |
); |
| 38 |
jQuery('body').on( |
| 39 |
'click', |
| 40 |
'.yay-recommended-plugins-layout .plugin-action-buttons .update-now', |
| 41 |
function () { |
| 42 |
if (!jQuery(this).hasClass('updating-message')) { |
| 43 |
var plugin = jQuery(this).attr('data-plugin'); |
| 44 |
updatePlugin(jQuery(this), plugin); |
| 45 |
} |
| 46 |
} |
| 47 |
); |
| 48 |
}); |
| 49 |
|
| 50 |
function getData(tab) { |
| 51 |
var loadingHtml = '<div class="loading-content"><span class="spinner is-active"></span></div>'; |
| 52 |
jQuery('.yay-recommended-plugins-layout #the-list').html(loadingHtml); |
| 53 |
jQuery('.yay-recommended-plugins-layout .plugin-install-tab').addClass('loading-process'); |
| 54 |
jQuery.ajax({ |
| 55 |
url: yayRecommended.admin_ajax, |
| 56 |
type: 'POST', |
| 57 |
data: { action: 'yay_recommended_get_plugin_data', tab: tab, nonce: yayRecommended.nonce }, |
| 58 |
success: function (response) { |
| 59 |
if (response.success === true) { |
| 60 |
jQuery('.yay-recommended-plugins-layout #the-list').html(response.data.html); |
| 61 |
jQuery('.yay-recommended-plugins-layout .plugin-install-tab').removeClass('loading-process'); |
| 62 |
} |
| 63 |
}, |
| 64 |
}); |
| 65 |
} |
| 66 |
|
| 67 |
function activatePlugin(element, file) { |
| 68 |
element.addClass('button-disabled').attr('disabled', 'disabled').text('Processing...'); |
| 69 |
jQuery.ajax({ |
| 70 |
url: yayRecommended.admin_ajax, |
| 71 |
type: 'POST', |
| 72 |
data: { action: 'yay_recommended_activate_plugin', file: file, nonce: yayRecommended.nonce }, |
| 73 |
success: function (response) { |
| 74 |
if (response.success === true) { |
| 75 |
var pluginStatus = jQuery(".yay-recommended-plugins-layout .plugin-status-inactive[data-plugin-file='" + file + "']"); |
| 76 |
pluginStatus.text('Active').addClass('plugin-status-active').removeClass('plugin-status-inactive'); |
| 77 |
element.removeClass('active-now').text('Activated'); |
| 78 |
} else { |
| 79 |
element.removeClass('button-disabled').prop('disabled', false).text('Activated'); |
| 80 |
} |
| 81 |
}, |
| 82 |
}); |
| 83 |
} |
| 84 |
|
| 85 |
function installPlugin(element, plugin) { |
| 86 |
var otherButtons = jQuery('.yay-recommended-plugins-layout .plugin-action-buttons .install-now').not(element); |
| 87 |
otherButtons.prop('disabled', true).addClass('button-disabled'); |
| 88 |
element.removeClass('button-primary').addClass('updating-message').text('Installing...'); |
| 89 |
jQuery.ajax({ |
| 90 |
url: yayRecommended.admin_ajax, |
| 91 |
type: 'POST', |
| 92 |
data: { action: 'yay_recommended_upgrade_plugin', type: 'install', plugin: plugin, nonce: yayRecommended.nonce }, |
| 93 |
success: function (response) { |
| 94 |
if (response.success === true) { |
| 95 |
element.removeClass('updating-message').addClass('updated-message installed button-disabled').attr('disabled', 'disabled').removeAttr('data-install-url').text('Installed!'); |
| 96 |
setTimeout(function () { |
| 97 |
var pluginStatus = jQuery(".yay-recommended-plugins-layout .plugin-status-not-install[data-plugin-url='" + plugin + "']"); |
| 98 |
pluginStatus.text('Active').addClass('plugin-status-active').removeClass('plugin-status-not-install').removeAttr('data-install-url'); |
| 99 |
element.removeClass('install-now updated-message installed').text('Activated').removeAttr('aria-label'); |
| 100 |
}, 500); |
| 101 |
} else { |
| 102 |
element.removeClass('updating-message').addClass('button-primary').text('Install Now'); |
| 103 |
} |
| 104 |
otherButtons.prop('disabled', false).removeClass('button-disabled'); |
| 105 |
}, |
| 106 |
error: function () { |
| 107 |
element.removeClass('updating-message').addClass('button-primary').text('Install Now'); |
| 108 |
otherButtons.prop('disabled', false).removeClass('button-disabled'); |
| 109 |
}, |
| 110 |
}); |
| 111 |
} |
| 112 |
|
| 113 |
function updatePlugin(element, plugin) { |
| 114 |
element.addClass('updating-message').text('Updating...'); |
| 115 |
jQuery.ajax({ |
| 116 |
url: yayRecommended.admin_ajax, |
| 117 |
type: 'POST', |
| 118 |
data: { action: 'yay_recommended_upgrade_plugin', type: 'update', plugin: plugin, nonce: yayRecommended.nonce }, |
| 119 |
success: function (response) { |
| 120 |
if (response.success === true) { |
| 121 |
element.removeClass('updating-message').addClass('updated-message button-disabled').attr('disabled', 'disabled').text('Updated!'); |
| 122 |
if (response.data.active === false) { |
| 123 |
var pluginStatus = jQuery(".yay-recommended-plugins-layout .plugin-status-inactive[data-plugin-file='" + plugin + "']"); |
| 124 |
pluginStatus.text('Active').addClass('plugin-status-active').removeClass('plugin-status-inactive').removeAttr('data-plugin-file'); |
| 125 |
} |
| 126 |
} else { |
| 127 |
element.removeClass('updating-message').text('Update Now'); |
| 128 |
} |
| 129 |
}, |
| 130 |
}); |
| 131 |
} |
| 132 |
|