/** * Fetch and display a preview of the current editing area. * * Usage: * * var preview = require( 'mediawiki.page.preview' ); * preview.doPreview(); * * @class mw.plugin.page.preview * @singleton */ ( function () { var api = new mw.Api(); /** * Show the edit summary. * * @private * @param {jQuery} $formNode * @param {Object} response */ function showEditSummary( $formNode, response ) { var $summaryPreview = $formNode.find( '.mw-summary-preview' ).empty(); var parse = response.parse; if ( !parse || !parse.parsedsummary ) { return; } $summaryPreview.append( mw.message( 'summary-preview' ).parse(), ' ', $( '' ).addClass( 'comment' ).html( // There is no equivalent to rawParams mw.message( 'parentheses' ).escaped() // .replace() use $ as start of a pattern. // $$ is the pattern for '$'. // The inner .replace() duplicates any $ and // the outer .replace() simplifies the $$. .replace( '$1', parse.parsedsummary.replace( /\$/g, '$$$$' ) ) ) ); } /** * Show status indicators. * * @private * @param {Array} indicators */ function showIndicators( indicators ) { // eslint-disable-next-line no-jquery/no-map-util indicators = $.map( indicators, function ( indicator, name ) { return $( '
' ) .addClass( 'mw-indicator' ) .attr( 'id', mw.util.escapeIdForAttribute( 'mw-indicator-' + name ) ) .html( indicator ) .get( 0 ); } ); if ( indicators.length ) { mw.hook( 'wikipage.indicators' ).fire( $( indicators ) ); } // Add whitespace between the
s because // they get displayed with display: inline-block var newList = []; indicators.forEach( function ( indicator ) { newList.push( indicator, document.createTextNode( '\n' ) ); } ); $( '.mw-indicators' ).empty().append( newList ); } /** * Show the templates used. * * @private * @param {Array} templates */ function showTemplates( templates ) { var newList = templates.map( function ( template ) { return $( '
  • ' ).append( $( '' ) .addClass( template.exists ? '' : 'new' ) .attr( 'href', mw.util.getUrl( template.title ) ) .text( template.title ) ); } ); var $parent = $( '.templatesUsed' ); if ( newList.length ) { var $list = $parent.find( 'ul' ); if ( $list.length ) { $list.detach().empty(); } else { $( '
    ' ) .addClass( 'mw-templatesUsedExplanation' ) .append( '

    ' ) .appendTo( $parent ); $list = $( '