mediawiki.action.edit.preview: Disable if there is no #wpTextbox1
authorFomafix <fomafix@googlemail.com>
Sun, 29 Mar 2015 13:57:37 +0000 (13:57 +0000)
committer[[mw:User:Fomafix]] <gerritpatchuploader@gmail.com>
Sun, 29 Mar 2015 13:57:37 +0000 (13:57 +0000)
ProofreadPage has custom editforms for Index pages, which are not
supported by the API. These editforms have no #wpTextbox1, so disable
live preview in that case.

Make this check on click avoid T94089.

Bug: T78709
Change-Id: I628d3b226a4294f2878fc4175080a975fd86e507

resources/src/mediawiki.action/mediawiki.action.edit.preview.js

index 4aa839c..f24703a 100644 (file)
@@ -9,15 +9,20 @@
         */
        function doLivePreview( e ) {
                var isDiff, api, request, postData, copySelectors, section,
-                       $wikiPreview, $wikiDiff, $editform, $copyElements, $spinner, $errorBox;
+                       $wikiPreview, $wikiDiff, $editform, $textbox, $summary, $copyElements, $spinner, $errorBox;
 
                isDiff = ( e.target.name === 'wpDiff' );
                $wikiPreview = $( '#wikiPreview' );
                $wikiDiff = $( '#wikiDiff' );
                $editform = $( '#editform' );
+               $textbox = $editform.find( '#wpTextbox1' );
+               $summary = $editform.find( '#wpSummary' );
                $errorBox = $( '.errorbox' );
                section = $editform.find( '[name="wpSection"]' ).val();
 
+               if ( $textbox.length === 0 ) {
+                       return;
+               }
                // Show changes for a new section is not yet supported
                if ( isDiff && section === 'new' ) {
                        return;
@@ -68,8 +73,8 @@
                        action: 'parse',
                        uselang: mw.config.get( 'wgUserLanguage' ),
                        title: mw.config.get( 'wgPageName' ),
-                       text: $editform.find( '#wpTextbox1' ).textSelection( 'getContents' ),
-                       summary: $editform.find( '#wpSummary' ).textSelection( 'getContents' )
+                       text: $textbox.textSelection( 'getContents' ),
+                       summary: $summary.textSelection( 'getContents' )
                };
 
                if ( section !== '' ) {