Merge "Reduce code duplication in MessageCache"
[lhc/web/wiklou.git] / resources / src / mediawiki.special / mediawiki.special.apisandbox.js
index bd1cad6..3cfc52c 100644 (file)
 
                        // I'm surprised this doesn't seem to exist in jQuery or mw.util.
                        params = {};
-                       hash = hash.replace( '+', '%20' );
+                       hash = hash.replace( /\+/g, '%20' );
                        re = /([^&=#]+)=?([^&#]*)/g;
                        while ( ( m = re.exec( hash ) ) ) {
                                params[ decodeURIComponent( m[ 1 ] ) ] = decodeURIComponent( m[ 2 ] );
                 * Submit button handler
                 */
                sendRequest: function () {
-                       var page, subpages, i, query, $result,
+                       var page, subpages, i, query, $result, $focus,
                                progress, $progressText, progressLoading,
                                deferreds = [],
                                params = {},
                                displayParams = {},
                                checkPages = [ pages.main ];
 
+                       // Blur any focused widget before submit, because
+                       // OO.ui.ButtonWidget doesn't take focus itself (T128054)
+                       $focus = $( '#mw-apisandbox-ui' ).find( document.activeElement );
+                       if ( $focus.length ) {
+                               $focus[ 0 ].blur();
+                       }
+
                        suppressErrors = false;
 
                        while ( checkPages.length ) {
                                                return xhr;
                                        }
                                } )
+                                       .then( null, function ( code, data, result, jqXHR ) {
+                                               if ( code !== 'http' ) {
+                                                       // Not really an error, work around mw.Api thinking it is.
+                                                       return $.Deferred()
+                                                               .resolve( result, jqXHR )
+                                                               .promise();
+                                               }
+                                               return this;
+                                       } )
                                        .fail( function ( code, data ) {
                                                var details = 'HTTP error: ' + data.exception;
                                                $result.empty()