WordPress/wp-admin/js/updates.min.js
Boone Gorges 69504de9d8 jshint fixes for shiny updates JS.
As introduced in [31333].

Props iseulde.
See #29820.
Built from https://develop.svn.wordpress.org/trunk@31341


git-svn-id: http://core.svn.wordpress.org/trunk@31322 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-02-05 19:52:22 +00:00

1 line
5.3 KiB
JavaScript

window.wp=window.wp||{},function(a,b,c,d){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(e,f){var g;if("plugins"===c||"plugins-network"===c?g=a("#"+f).next().find(".update-message"):"plugin-install"===c&&(g=a(".plugin-card-"+f).find(".update-now")),g.addClass("updating-message"),g.text(b.updates.l10n.updating),b.updates.updateLock)return void b.updates.updateQueue.push({type:"update-plugin",data:{plugin:e,slug:f}});b.updates.updateLock=!0;var h={action:"update-plugin",_ajax_nonce:b.updates.ajaxNonce,plugin:e,slug:f};a.ajax({type:"post",url:d,data:h,complete:b.updates.updateRequestComplete})},b.updates.updateRequestComplete=function(a){if(b.updates.updateLock=!1,a.responseJSON&&a.responseJSON.success)b.updates.updateSuccess(a.responseJSON);else{var c=b.updates.l10n.updateFailed;a.responseJSON&&a.responseJSON.data&&a.responseJSON.data.error&&(c+=": "+a.responseJSON.data.error),window.alert(c),a.responseJSON&&a.responseJSON.data&&a.responseJSON.data.slug&&b.updates.updateError(a.responseJSON)}b.updates.queueChecker()},b.updates.updateSuccess=function(d){var e;"plugins"===c||"plugins-network"===c?(e=a("#"+d.data.slug).next().find(".update-message"),a("#"+d.data.slug).addClass("updated").removeClass("update"),a("#"+d.data.slug+"-update").addClass("updated").removeClass("update")):"plugin-install"===c&&(e=a(".plugin-card-"+d.data.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.data.slug).next().find(".update-message"):"plugin-install"===c&&(e=a(".plugin-card-"+d.data.slug).find(".update-now")),e.removeClass("updating-message"),e.text(b.updates.l10n.updateFailed)},b.updates.installPlugin=function(c){var e=a(".plugin-card-"+c).find(".install-now");if(e.addClass("updating-message"),e.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 f={action:"install-plugin",_ajax_nonce:b.updates.ajaxNonce,slug:c};a.ajax({type:"post",url:d,data:f,complete:b.updates.installRequestComplete})},b.updates.installRequestComplete=function(a){if(b.updates.updateLock=!1,a.responseJSON&&a.responseJSON.success)b.updates.installSuccess(a.responseJSON);else{var c=b.updates.l10n.installFailed;a.responseJSON&&a.responseJSON.data&&a.responseJSON.data.error&&(c+=": "+a.responseJSON.data.error),window.alert(c),a.responseJSON&&a.responseJSON.data&&a.responseJSON.data.slug&&b.updates.installError(a.responseJSON)}b.updates.queueChecker()},b.updates.installSuccess=function(c){var d=a(".plugin-card-"+c.data.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.data.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.target);b.updates.updatePlugin(d.data("plugin"),d.data("slug"))}),a(".plugin-card .install-now").on("click",function(c){c.preventDefault();var d=a(c.target);d.hasClass("button-disabled")||b.updates.installPlugin(d.data("slug"))})}),a(window).on("message",function(c){var d,e=c.originalEvent,f=document.location,g=f.protocol+"//"+f.hostname;e.origin===g&&(d=a.parseJSON(e.data),"undefined"!=typeof d.action&&"decrementUpdateCount"===d.action&&b.updates.decrementCount(d.upgradeType))})}(jQuery,window.wp,window.pagenow,window.ajaxurl);