WordPress/wp-admin/js/updates.min.js

1 line
4.5 KiB
JavaScript
Raw Normal View History

window.wp=window.wp||{},function(a,b,c){b.updates={},b.updates.ajaxNonce=window._wpUpdatesSettings.ajax_nonce,b.updates.l10n=window._wpUpdatesSettings.l10n,b.updates.updateLock=!1,b.updates.updateQueue=[],b.updates.decrementCount=function(b){var c,d,e=a("#wp-admin-bar-updates .ab-label"),f=a('a[href="update-core.php"] .update-plugins'),g=a("#menu-plugins");if(c=e.text(),c=parseInt(c,10)-1,!(0>c||isNaN(c))&&(a("#wp-admin-bar-updates .ab-item").removeAttr("title"),e.text(c),f.each(function(a,b){b.className=b.className.replace(/count-\d+/,"count-"+c)}),f.removeAttr("title"),f.find(".update-count").text(c),"plugin"===b)){if(d=g.find(".plugin-count").eq(0).text(),d=parseInt(d,10)-1,0>d||isNaN(d))return;g.find(".plugin-count").text(d),g.find(".update-plugins").each(function(a,b){b.className=b.className.replace(/count-\d+/,"count-"+d)}),d>0?a(".subsubsub .upgrade .count").text("("+d+")"):a(".subsubsub .upgrade").remove()}},b.updates.updatePlugin=function(d,e){var f;if("plugins"===c||"plugins-network"===c?f=a("#"+e).next().find(".update-message"):"plugin-install"===c&&(f=a(".plugin-card-"+e).find(".update-now")),f.addClass("updating-message"),f.text(b.updates.l10n.updating),b.updates.updateLock)return void b.updates.updateQueue.push({type:"update-plugin",data:{plugin:d,slug:e}});b.updates.updateLock=!0;var g={_ajax_nonce:b.updates.ajaxNonce,plugin:d,slug:e};b.ajax.post("update-plugin",g).done(b.updates.updateSuccess).fail(b.updates.updateError).always(b.updates.updateAlways)},b.updates.updateSuccess=function(d){var e;"plugins"===c||"plugins-network"===c?(e=a("#"+d.slug).next().find(".update-message"),a("#"+d.slug).addClass("updated").removeClass("update"),a("#"+d.slug+"-update").addClass("updated").removeClass("update")):"plugin-install"===c&&(e=a(".plugin-card-"+d.slug).find(".update-now"),e.addClass("button-disabled")),e.removeClass("updating-message").addClass("updated-message"),e.text(b.updates.l10n.updated),b.updates.decrementCount("plugin")},b.updates.updateError=function(d){var e;"plugins"===c||"plugins-network"===c?e=a("#"+d.slug).next().find(".update-message"):"plugin-install"===c&&(e=a(".plugin-card-"+d.slug).find(".update-now")),e.removeClass("updating-message"),e.text(b.updates.l10n.updateFailed)},b.updates.updateAlways=function(){b.updates.updateLock=!1,b.updates.queueChecker()},b.updates.installPlugin=function(c){var d=a(".plugin-card-"+c).find(".install-now");if(d.addClass("updating-message"),d.text(b.updates.l10n.installing),b.updates.updateLock)return void b.updates.updateQueue.push({type:"install-plugin",data:{slug:c}});b.updates.updateLock=!0;var e={_ajax_nonce:b.updates.ajaxNonce,slug:c};b.ajax.post("install-plugin",e).done(b.updates.installSuccess).fail(b.updates.installError).always(b.updates.updateAlways)},b.updates.installSuccess=function(c){var d=a(".plugin-card-"+c.slug).find(".install-now");d.removeClass("updating-message").addClass("updated-message button-disabled"),d.text(b.updates.l10n.installed)},b.updates.installError=function(c){var d=a(".plugin-card-"+c.slug).find(".install-now");d.removeClass("updating-message"),d.text(b.updates.l10n.installNow)},b.updates.queueChecker=function(){if(!(b.updates.updateLock||b.updates.updateQueue.length<=0)){var a=b.updates.updateQueue.shift();switch(a.type){case"update-plugin":b.updates.updatePlugin(a.data.plugin,a.data.slug);break;case"install-plugin":b.updates.installPlugin(a.data.slug);break;default:window.console.log("Failed to exect queued update job."),window.console.log(a)}}},a(document).ready(function(){a(".plugin-update-tr .update-link").on("click",function(c){c.preventDefault();var d=a(c.target).parents(".plugin-update-tr");b.updates.updatePlugin(d.data("plugin"),d.data("slug"))}),a("#bulk-action-form").on("submit",function(c){var d,e,f;"update-selected"==a("#bulk-action-selector-top").val()&&(c.preventDefault(),a('input[name="checked[]"]:checked').each(function(c,g){d=a(g),e=d.val(),f=d.parents("tr").prop("id"),b.updates.updatePlugin(e,f),d.attr("checked",!1)}))}),a(".plugin-card .update-now").on("click",function(c){c.preventDefault();var d=a(c.targe