| @@ -110,9 +110,9 @@ | ||
| 110 | 110 | var $obj = $( this ), |
| 111 | 111 | $container = $obj.parents( '.imagify-data-actions-container' ), |
| 112 | 112 | id = w.imagify.modal.sanitizeId( $container.data( 'id' ) ), |
| 113 | 113 | context = w.imagify.modal.sanitizeContext( $container.data( 'context' ) ), |
| 114 | - href, processingTemplate; | |
| 114 | + href, processingTemplate, previousHtml; | |
| 115 | 115 | |
| 116 | 116 | e.preventDefault(); |
| 117 | 117 | |
| 118 | 118 | if ( w.imagify.modal.isItemLocked( context, id ) ) { |
| @@ -122,14 +122,18 @@ | ||
| 122 | 122 | w.imagify.modal.lockItem( context, id ); |
| 123 | 123 | |
| 124 | 124 | href = $obj.attr( 'href' ); |
| 125 | 125 | processingTemplate = w.imagify.template( 'imagify-button-processing' ); |
| 126 | + previousHtml = $container.html(); | |
| 126 | 127 | |
| 127 | 128 | $container.html( processingTemplate( { |
| 128 | 129 | label: $obj.data( 'processing-label' ) |
| 129 | 130 | } ) ); |
| 130 | 131 | |
| 131 | - $.get( href.replace( 'admin-post.php', 'admin-ajax.php' ) ) | |
| 132 | + $.get( { | |
| 133 | + url: href.replace( 'admin-post.php', 'admin-ajax.php' ), | |
| 134 | + timeout: 60000 // Throw an error if not completed after 60 sec. | |
| 135 | + } ) | |
| 132 | 136 | .done( function( response ) { |
| 133 | 137 | if ( response.data && response.data.html ) { |
| 134 | 138 | // The work is done. |
| 135 | 139 | w.imagify.modal.displayProcessResult( context, id, response.data.html ); |
| @@ -137,8 +141,15 @@ | ||
| 137 | 141 | // Still processing in background: we're waiting for the result by poking Imagifybeat. |
| 138 | 142 | // Set the Imagifybeat interval to 15 seconds. |
| 139 | 143 | w.imagify.beat.interval( 15 ); |
| 140 | 144 | } |
| 145 | + } ) | |
| 146 | + .fail( function() { | |
| 147 | + // The request errored out or timed out: unlock the item and restore the | |
| 148 | + // previous button state instead of leaving it stuck on "Optimizing..." | |
| 149 | + // until Imagifybeat's next tick catches the mismatch. | |
| 150 | + w.imagify.modal.unlockItem( context, id ); | |
| 151 | + $container.html( previousHtml ); | |
| 141 | 152 | } ); |
| 142 | 153 | }, |
| 143 | 154 | |
| 144 | 155 | // Imagifybeat ============================================================================= |
| @@ -273,9 +284,9 @@ | ||
| 273 | 284 | * @param {int|string} id A media ID. |
| 274 | 285 | * @return {int} |
| 275 | 286 | */ |
| 276 | 287 | sanitizeId: function( id ) { |
| 277 | - return parseInt( id, 10 ); | |
| 288 | + return w.imagify.sanitizeId( id ); | |
| 278 | 289 | }, |
| 279 | 290 | |
| 280 | 291 | /** |
| 281 | 292 | * Sanitize a media context. |