| 1 |
jQuery(document).ready(function () { |
| 2 |
const 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('click', '.yay-recommended-plugins-layout .plugin-action-buttons .activate-now', function() { |
| 21 |
const file = jQuery(this).attr("data-plugin-file"); |
| 22 |
activatePlugin(jQuery(this), file); |
| 23 |
}); |
| 24 |
jQuery('body').on('click', '.yay-recommended-plugins-layout .plugin-action-buttons .install-now', function() { |
| 25 |
if(!jQuery(this).hasClass("updating-message") ) { |
| 26 |
const plugin = jQuery(this).attr("data-install-url"); |
| 27 |
installPlugin(jQuery(this), plugin); |
| 28 |
} |
| 29 |
}); |
| 30 |
jQuery('body').on('click', '.yay-recommended-plugins-layout .plugin-action-buttons .update-now', function() { |
| 31 |
if(!jQuery(this).hasClass("updating-message") ) { |
| 32 |
const plugin = jQuery(this).attr("data-plugin"); |
| 33 |
updatePlugin(jQuery(this), plugin); |
| 34 |
} |
| 35 |
}); |
| 36 |
}) |
| 37 |
function getData(tab) { |
| 38 |
const loadingHtml = '<div class="loading-content"><span class="spinner is-active"></span></div>'; |
| 39 |
jQuery(".yay-recommended-plugins-layout #the-list").html(loadingHtml); |
| 40 |
jQuery(".yay-recommended-plugins-layout .plugin-install-tab").addClass("loading-process"); |
| 41 |
jQuery.ajax({ |
| 42 |
url: yayRecommended.admin_ajax, |
| 43 |
type: "POST", |
| 44 |
data: { |
| 45 |
action: "yay_recommended_get_plugin_data", |
| 46 |
tab: tab, |
| 47 |
nonce: yayRecommended.nonce |
| 48 |
}, |
| 49 |
success: function(response) { |
| 50 |
if(response.success === true) { |
| 51 |
const html = response.data.html; |
| 52 |
jQuery( ".yay-recommended-plugins-layout #the-list" ).html(html); |
| 53 |
jQuery(".yay-recommended-plugins-layout .plugin-install-tab").removeClass("loading-process"); |
| 54 |
} |
| 55 |
} |
| 56 |
}) |
| 57 |
} |
| 58 |
|
| 59 |
function activatePlugin(element,file) { |
| 60 |
element.addClass("button-disabled"); |
| 61 |
element.attr("disabled", "disabled"); |
| 62 |
element.text("Processing..."); |
| 63 |
jQuery.ajax({ |
| 64 |
url: yayRecommended.admin_ajax, |
| 65 |
type: "POST", |
| 66 |
data: { |
| 67 |
action: "yay_recommended_activate_plugin", |
| 68 |
file: file, |
| 69 |
nonce: yayRecommended.nonce |
| 70 |
}, |
| 71 |
success: function(response) { |
| 72 |
if(response.success === true) { |
| 73 |
const pluginStatus = jQuery(".yay-recommended-plugins-layout .plugin-status-inactive[data-plugin-file='" + file +"']") |
| 74 |
pluginStatus.text("Active"); |
| 75 |
pluginStatus.addClass("plugin-status-active"); |
| 76 |
pluginStatus.removeClass("plugin-status-inactive"); |
| 77 |
element.removeClass("active-now"); |
| 78 |
element.text("Activated"); |
| 79 |
} else { |
| 80 |
element.removeClass("button-disabled"); |
| 81 |
element.prop("disabled", false); |
| 82 |
element.text("Activated"); |
| 83 |
} |
| 84 |
}, |
| 85 |
}) |
| 86 |
} |
| 87 |
|
| 88 |
function installPlugin(element,plugin) { |
| 89 |
element.removeClass("button-primary"); |
| 90 |
element.addClass("updating-message"); |
| 91 |
element.text("Installing..."); |
| 92 |
jQuery.ajax({ |
| 93 |
url: yayRecommended.admin_ajax, |
| 94 |
type: "POST", |
| 95 |
data: { |
| 96 |
action: "yay_recommended_upgrade_plugin", |
| 97 |
type: 'install', |
| 98 |
plugin: plugin, |
| 99 |
nonce: yayRecommended.nonce |
| 100 |
}, |
| 101 |
success: function(response) { |
| 102 |
if(response.success === true) { |
| 103 |
element.removeClass("updating-message"); |
| 104 |
element.addClass("updated-message installed button-disabled"); |
| 105 |
element.attr("disabled", "disabled"); |
| 106 |
element.removeAttr("data-install-url"); |
| 107 |
element.text("Installed!"); |
| 108 |
setTimeout(() => { |
| 109 |
const pluginStatus = jQuery(".yay-recommended-plugins-layout .plugin-status-not-install[data-plugin-url='" + plugin +"']") |
| 110 |
pluginStatus.text("Active"); |
| 111 |
pluginStatus.addClass("plugin-status-active"); |
| 112 |
pluginStatus.removeClass("plugin-status-not-install"); |
| 113 |
pluginStatus.removeAttr("data-install-url"); |
| 114 |
element.removeClass("install-now updated-message installed"); |
| 115 |
element.text("Activated"); |
| 116 |
element.removeAttr("aria-label"); |
| 117 |
}, 500); |
| 118 |
|
| 119 |
} else { |
| 120 |
element.removeClass("updating-message"); |
| 121 |
element.addClass("button-primary"); |
| 122 |
element.text("Install Now"); |
| 123 |
} |
| 124 |
}, |
| 125 |
}) |
| 126 |
} |
| 127 |
|
| 128 |
function updatePlugin(element,plugin) { |
| 129 |
element.addClass("updating-message"); |
| 130 |
element.text("Updating..."); |
| 131 |
jQuery.ajax({ |
| 132 |
url: yayRecommended.admin_ajax, |
| 133 |
type: "POST", |
| 134 |
data: { |
| 135 |
action: "yay_recommended_upgrade_plugin", |
| 136 |
type: "update", |
| 137 |
plugin: plugin, |
| 138 |
nonce: yayRecommended.nonce |
| 139 |
}, |
| 140 |
success: function(response) { |
| 141 |
if(response.success === true) { |
| 142 |
element.removeClass("updating-message"); |
| 143 |
element.addClass("updated-message button-disabled"); |
| 144 |
element.attr("disabled", "disabled"); |
| 145 |
element.text("Updated!"); |
| 146 |
if(response.data.active === false) { |
| 147 |
const pluginStatus = jQuery(".yay-recommended-plugins-layout .plugin-status-inactive[data-plugin-file='" + plugin +"']"); |
| 148 |
pluginStatus.text("Active"); |
| 149 |
pluginStatus.addClass("plugin-status-active"); |
| 150 |
pluginStatus.removeClass("plugin-status-inactive"); |
| 151 |
pluginStatus.removeAttr("data-plugin-file"); |
| 152 |
} |
| 153 |
} else { |
| 154 |
element.removeClass("updating-message"); |
| 155 |
element.text("Update Now"); |
| 156 |
} |
| 157 |
}, |
| 158 |
}) |
| 159 |
} |
| 160 |
|