mediawiki.action.edit.preview: Disable if there is no #wpTextbox1
[lhc/web/wiklou.git] / resources / src / mediawiki.action / mediawiki.action.edit.preview.js
index 68fbe33..84bde7d 100644 (file)
                        $.extend( postData, {
                                pst: '',
                                preview: '',
-                               prop: 'text|displaytitle|modules|categorieshtml|templates|langlinks|limitreporthtml'
+                               prop: 'text|displaytitle|modules|categorieshtml|templates|langlinks|limitreporthtml',
+                               disableeditsection: true
                        } );
                        if ( section !== '' ) {
                                postData.sectionpreview = '';
                        }
                        request = api.post( postData );
                        request.done( function ( response ) {
-                               var li, newList, $next, $parent, $list;
+                               var li, newList, $content, $parent, $list;
                                if ( response.parse.modules ) {
                                        mw.loader.load( response.parse.modules.concat(
                                                response.parse.modulescripts,
                                }
 
                                if ( response.parse.text['*'] ) {
-                                       $next = $wikiPreview.next();
-                                       // If there is no next node, use parent instead.
-                                       // Only query parent if needed, false otherwise.
-                                       $parent = !$next.length && $wikiPreview.parent();
-
-                                       $wikiPreview
+                                       $content = $wikiPreview.children( '.mw-content-ltr,.mw-content-rtl' );
+                                       $content
                                                .detach()
                                                .html( response.parse.text['*'] );
 
-                                       mw.hook( 'wikipage.content' ).fire( $wikiPreview );
+                                       mw.hook( 'wikipage.content' ).fire( $content );
 
                                        // Reattach
-                                       if ( $parent ) {
-                                               $parent.append( $wikiPreview );
-                                       } else {
-                                               $next.before( $wikiPreview );
-                                       }
+                                       $wikiPreview.append( $content );
+
                                        $wikiPreview.show();
 
                                }
        $( function () {
                // Do not enable on user .js/.css pages, as there's no sane way of "previewing"
                // the scripts or styles without reloading the page.
-               if ( $( '#mw-userjsyoucanpreview' ).length || $( '#mw-usercssyoucanpreview' ).length ) {
+               // Do not enable for ProofreadPage Index page editors, which have no textbox
+               if ( $( '#mw-userjsyoucanpreview' ).length || $( '#mw-usercssyoucanpreview' ).length || $( '#wpTextbox1' ).length === 0 ) {
                        return;
                }
 
                if ( !document.getElementById( 'wikiDiff' ) && document.getElementById( 'wikiPreview' ) ) {
                        $( '#wikiPreview' ).after(
                                $( '<div>' )
+                                       .hide()
                                        .attr( 'id', 'wikiDiff' )
                                        .html( '<table class="diff"><col class="diff-marker"/><col class="diff-content"/>' +
                                                '<col class="diff-marker"/><col class="diff-content"/><tbody/></table>' )