WordPress/wp-admin/js/updates.min.js
Aaron Jorbin 4c05e8c71c More clean up from removal of Shiny Plugin Installs
See #31773, #29820
Unprops Jorbin, Pento


Built from https://develop.svn.wordpress.org/trunk@31900


git-svn-id: http://core.svn.wordpress.org/trunk@31879 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2015-03-26 16:30:27 +00:00

1 line
5.7 KiB
JavaScript

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.shouldRequestFilesystemCredentials=null,b.updates.filesystemCredentials={ftp:{host:null,username:null,password:null,connectionType:null},ssh:{publicKey:null,privateKey:null}},b.updates.updateLock=!1,b.updates.updateDoneSuccessfully=!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('[data-slug="'+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.a11y.speak(b.updates.l10n.updatingMsg),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,username:b.updates.filesystemCredentials.ftp.username,password:b.updates.filesystemCredentials.ftp.password,hostname:b.updates.filesystemCredentials.ftp.hostname,connection_type:b.updates.filesystemCredentials.ftp.connectionType,public_key:b.updates.filesystemCredentials.ssh.publicKey,private_key:b.updates.filesystemCredentials.ssh.privateKey};b.ajax.post("update-plugin",g).done(b.updates.updateSuccess).fail(b.updates.updateError)},b.updates.updateSuccess=function(d){var e;if("plugins"===c||"plugins-network"===c){var f=a('[data-slug="'+d.slug+'"]').first();e=f.next().find(".update-message"),f.addClass("updated").removeClass("update");var g=f.find(".plugin-version-author-uri").html().replace(d.oldVersion,d.newVersion);f.find(".plugin-version-author-uri").html(g)}else"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.a11y.speak(b.updates.l10n.updatedMsg),b.updates.decrementCount("plugin"),b.updates.updateDoneSuccessfully=!0,b.updates.updateLock=!1,b.updates.queueChecker()},b.updates.updateError=function(d){var e;return b.updates.updateDoneSuccessfully=!1,d.errorCode&&"unable_to_connect_to_filesystem"==d.errorCode?void b.updates.credentialError(d,"update-plugin"):("plugins"===c||"plugins-network"===c?e=a('[data-slug="'+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),void b.a11y.speak(b.updates.l10n.updateFailed))},b.updates.showErrorInCredentialsForm=function(b){var c=a(".notification-dialog");c.find(".error").remove(),c.find("h3").after('<div class="error">'+b+"</div>")},b.updates.credentialError=function(a,c){b.updates.updateQueue.push({type:c,data:{plugin:a.plugin,slug:a.slug}}),b.updates.showErrorInCredentialsForm(a.error),b.updates.requestFilesystemCredentials()},b.updates.queueChecker=function(){if(!(b.updates.updateLock||b.updates.updateQueue.length<=0)){var a=b.updates.updateQueue.shift();b.updates.updatePlugin(a.data.plugin,a.data.slug)}},b.updates.requestFilesystemCredentials=function(){b.updates.updateDoneSuccessfully===!1&&(b.updates.updateLock=!0,a("body").addClass("modal-open"),a("#request-filesystem-credentials-dialog").show())},a(document).ready(function(){b.updates.shouldRequestFilesystemCredentials=a("#request-filesystem-credentials-dialog").length<=0?!1:!0,a("#request-filesystem-credentials-dialog form").on("submit",function(){return b.updates.filesystemCredentials.ftp.hostname=a("#hostname").val(),b.updates.filesystemCredentials.ftp.username=a("#username").val(),b.updates.filesystemCredentials.ftp.password=a("#password").val(),b.updates.filesystemCredentials.ftp.connectionType=a('input[name="connection_type"]:checked').val(),b.updates.filesystemCredentials.ssh.publicKey=a("#public_key").val(),b.updates.filesystemCredentials.ssh.privateKey=a("#private_key").val(),a("#request-filesystem-credentials-dialog").hide(),a("body").removeClass("modal-open"),b.updates.updateLock=!1,b.updates.queueChecker(),!1}),a(".plugin-update-tr .update-link").on("click",function(c){c.preventDefault(),b.updates.shouldRequestFilesystemCredentials&&!b.updates.updateLock&&b.updates.requestFilesystemCredentials();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(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);