Merge "Live Preview: Cope with the edit summary being an OOjs UI widget"
[lhc/web/wiklou.git] / resources / src / mediawiki.action / mediawiki.action.edit.preview.js
index 2b6fc9d..c26d915 100644 (file)
@@ -3,12 +3,14 @@
  */
 ( function ( mw, $ ) {
 
+       var oojsuieditform;
+
        /**
         * @ignore
         * @param {jQuery.Event} e
         */
        function doLivePreview( e ) {
-               var isDiff, api, parseRequest, diffRequest, postData, copySelectors, section,
+               var isDiff, api, parseRequest, diffRequest, postData, copySelectors, section, summary,
                        $wikiPreview, $wikiDiff, $editform, $textbox, $summary, $copyElements, $spinner, $errorBox;
 
                isDiff = ( e.target.name === 'wpDiff' );
                $wikiDiff = $( '#wikiDiff' );
                $editform = $( '#editform' );
                $textbox = $editform.find( '#wpTextbox1' );
-               $summary = $editform.find( '#wpSummary' );
+
+               if ( oojsuieditform ) {
+                       summary = OO.ui.infuse( $( '#wpSummaryWidget' ) );
+               } else {
+                       $summary = $editform.find( '#wpSummary' );
+               }
+
                $spinner = $( '.mw-spinner-preview' );
                $errorBox = $( '.errorbox' );
                section = $editform.find( '[name="wpSection"]' ).val();
@@ -78,7 +86,7 @@
                        formatversion: 2,
                        action: 'parse',
                        title: mw.config.get( 'wgPageName' ),
-                       summary: $summary.textSelection( 'getContents' ),
+                       summary: oojsuieditform ? summary.getValue() : $summary.val(),
                        prop: ''
                };
 
                                        newList.push(
                                                $( '<div>' )
                                                        .addClass( 'mw-indicator' )
-                                                       .attr( 'id', mw.util.escapeId( 'mw-indicator-' + name ) )
+                                                       .attr( 'id', mw.util.escapeIdForAttribute( 'mw-indicator-' + name ) )
                                                        .html( indicator )
                                                        .get( 0 ),
                                                // Add a whitespace between the <div>s because
        }
 
        $( function () {
+               oojsuieditform = $( '#editform' ).hasClass( 'mw-editform-ooui' );
+
                // 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 ) {
                }
 
                if ( !$( '.mw-summary-preview' ).length ) {
-                       $( '#wpSummary' ).after(
+                       $( oojsuieditform ? '#wpSummaryWidget' : '#wpSummary' ).after(
                                $( '<div>' ).addClass( 'mw-summary-preview' )
                        );
                }