Changeset 31409
- Timestamp:
- 02/11/2015 05:05:13 AM (10 years ago)
- Location:
- trunk/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/js/updates.js
r31341 r31409 1 1 window.wp = window.wp || {}; 2 2 3 (function( $, wp, pagenow , ajaxurl) {3 (function( $, wp, pagenow ) { 4 4 wp.updates = {}; 5 5 … … 123 123 124 124 var data = { 125 'action': 'update-plugin',126 125 '_ajax_nonce': wp.updates.ajaxNonce, 127 126 'plugin': plugin, … … 129 128 }; 130 129 131 $.ajax( { 132 type: 'post', 133 url: ajaxurl, 134 data: data, 135 complete: wp.updates.updateRequestComplete 136 } ); 137 }; 138 139 /** 140 * After an update attempt has completed, deal with the response. 141 * 142 * @since 4.2.0 143 * 144 * @param {jqXHR} jqxhr The jQuery XMLHttpRequest for the request. 145 */ 146 wp.updates.updateRequestComplete = function( jqxhr ) { 147 wp.updates.updateLock = false; 148 if ( jqxhr.responseJSON && jqxhr.responseJSON.success ) { 149 wp.updates.updateSuccess( jqxhr.responseJSON ); 150 } else { 151 var alertText = wp.updates.l10n.updateFailed; 152 if ( jqxhr.responseJSON && jqxhr.responseJSON.data && jqxhr.responseJSON.data.error ) { 153 alertText += ': ' + jqxhr.responseJSON.data.error; 154 } 155 window.alert( alertText ); 156 if ( jqxhr.responseJSON && jqxhr.responseJSON.data && jqxhr.responseJSON.data.slug ) { 157 wp.updates.updateError( jqxhr.responseJSON ); 158 } 159 } 160 /** 161 * Check the queue. 162 */ 163 wp.updates.queueChecker(); 130 wp.ajax.post( 'update-plugin', data ) 131 .done( wp.updates.updateSuccess ) 132 .fail( wp.updates.updateError ) 133 .always( wp.updates.updateAlways ); 164 134 }; 165 135 … … 174 144 var $message; 175 145 if ( 'plugins' === pagenow || 'plugins-network' === pagenow ) { 176 $message = $( '#' + response. data.slug ).next().find( '.update-message' );177 $( '#' + response. data.slug ).addClass( 'updated' ).removeClass( 'update' );178 $( '#' + response. data.slug + '-update' ).addClass( 'updated' ).removeClass( 'update' );146 $message = $( '#' + response.slug ).next().find( '.update-message' ); 147 $( '#' + response.slug ).addClass( 'updated' ).removeClass( 'update' ); 148 $( '#' + response.slug + '-update' ).addClass( 'updated' ).removeClass( 'update' ); 179 149 } else if ( 'plugin-install' === pagenow ) { 180 $message = $( '.plugin-card-' + response. data.slug ).find( '.update-now' );150 $message = $( '.plugin-card-' + response.slug ).find( '.update-now' ); 181 151 $message.addClass( 'button-disabled' ); 182 152 } … … 198 168 var $message; 199 169 if ( 'plugins' === pagenow || 'plugins-network' === pagenow ) { 200 $message = $( '#' + response. data.slug ).next().find( '.update-message' );170 $message = $( '#' + response.slug ).next().find( '.update-message' ); 201 171 } else if ( 'plugin-install' === pagenow ) { 202 $message = $( '.plugin-card-' + response. data.slug ).find( '.update-now' );172 $message = $( '.plugin-card-' + response.slug ).find( '.update-now' ); 203 173 } 204 174 $message.removeClass( 'updating-message' ); 205 175 $message.text( wp.updates.l10n.updateFailed ); 206 176 }; 177 178 /** 179 * After an update attempt has completed, check the queue. 180 * 181 * @since 4.2.0 182 */ 183 wp.updates.updateAlways = function() { 184 wp.updates.updateLock = false; 185 wp.updates.queueChecker(); 186 }; 187 207 188 208 189 /** … … 232 213 233 214 var data = { 234 'action': 'install-plugin',235 215 '_ajax_nonce': wp.updates.ajaxNonce, 236 216 'slug': slug 237 217 }; 238 218 239 $.ajax( { 240 type: 'post', 241 url: ajaxurl, 242 data: data, 243 complete: wp.updates.installRequestComplete 244 } ); 245 }; 246 247 248 /** 249 * After an installation attempt has completed, deal with the response. 250 * 251 * @since 4.2.0 252 * 253 * @param {jqXHR} jqxhr The jQuery XMLHttpRequest for the request. 254 */ 255 wp.updates.installRequestComplete = function( jqxhr ) { 256 wp.updates.updateLock = false; 257 if ( jqxhr.responseJSON && jqxhr.responseJSON.success ) { 258 wp.updates.installSuccess( jqxhr.responseJSON ); 259 } else { 260 var alertText = wp.updates.l10n.installFailed; 261 if ( jqxhr.responseJSON && jqxhr.responseJSON.data && jqxhr.responseJSON.data.error ) { 262 alertText += ': ' + jqxhr.responseJSON.data.error; 263 } 264 window.alert( alertText ); 265 if ( jqxhr.responseJSON && jqxhr.responseJSON.data && jqxhr.responseJSON.data.slug ) { 266 wp.updates.installError( jqxhr.responseJSON ); 267 } 268 } 269 /** 270 * Check the queue. 271 */ 272 wp.updates.queueChecker(); 219 wp.ajax.post( 'install-plugin', data ) 220 .done( wp.updates.installSuccess ) 221 .fail( wp.updates.installError ) 222 .always( wp.updates.updateAlways ); 273 223 }; 274 224 … … 281 231 */ 282 232 wp.updates.installSuccess = function( response ) { 283 var $message = $( '.plugin-card-' + response. data.slug ).find( '.install-now' );233 var $message = $( '.plugin-card-' + response.slug ).find( '.install-now' ); 284 234 285 235 $message.removeClass( 'updating-message' ).addClass( 'updated-message button-disabled' ); … … 295 245 */ 296 246 wp.updates.installError = function( response ) { 297 var $message = $( '.plugin-card-' + response. data.slug ).find( '.install-now' );247 var $message = $( '.plugin-card-' + response.slug ).find( '.install-now' ); 298 248 299 249 $message.removeClass( 'updating-message' ); -
trunk/src/wp-includes/script-loader.php
r31373 r31409 501 501 ) ); 502 502 503 $scripts->add( 'updates', "/wp-admin/js/updates$suffix.js", array( 'jquery' ) );503 $scripts->add( 'updates', "/wp-admin/js/updates$suffix.js", array( 'jquery', 'wp-util' ) ); 504 504 did_action( 'init' ) && $scripts->localize( 'updates', '_wpUpdatesSettings', array( 505 505 'ajax_nonce' => wp_create_nonce( 'updates' ),
Note: See TracChangeset
for help on using the changeset viewer.