mediawiki.page.preview

Fetch and display a preview of the current editing area.

Example

var preview = require( 'mediawiki.page.preview' );
preview.doPreview();

Methods

doPreview(config) → {jQuery.Promise|undefined}static #

Fetch and display a preview of the current editing area.

Parameters:

Name Type Description
config Object

Configuration options.

Properties:
Name Type Attributes Default Description
$previewNode jQuery optional
$( '#wikiPreview' )

Where the preview should be displayed.

$diffNode jQuery optional
$( '#wikiDiff' )

Where diffs should be displayed (if showDiff is set).

$formNode jQuery optional
$( '#editform' )

The form node.

$textareaNode jQuery optional
$( '#wpTextbox1' )

The edit form's textarea.

$spinnerNode jQuery optional
$( '.mw-spinner-preview' )

The loading indicator. This will be shown/hidden accordingly while waiting for the XMLHttpRequest to complete. Ignored if it doesn't exist in the document and createSpinner is false.

summary string optional
null

The edit summary. If no value is given, the summary is fetched from $( '#wpSummaryWidget' ).

showDiff boolean optional
false

Shows a diff in the preview area instead of the content.

isLivePreview boolean optional
false

Instructs the module to replicate the server-side preview as much as possible. Specifically:

  • Before initiating the preview, some alerts and error messages at the top of the page will be removed, and the browser will scroll to the preview.
  • After finishing the preview, a reminder that it's only a preview, or an error message in case a request has failed, will be shown at the top of the preview.
previewHeader Node | Array.<Node> | jQuery | string optional
null

Content of <h2> element at the top of the preview notes. Required if isLivePreview is true.

previewNote Node | Array.<Node> | jQuery | string optional
null

Main text of the first preview note. Required if isLivePreview is true.

title string optional
mw.config.get( 'wgPageName' )

The title of the page being previewed.

titleParam string optional
'title'

Name of the parse API parameter to pass title to.

textParam string optional
'text'

Name of the parse API parameter to pass the content of $textareaNode to. Ignored if showDiff is true.

parseParams Object optional
null

Additional parse API parameters. This can override any parameter set by the module.

responseHandler module:mediawiki.page.preview~responseHandler optional
null

Callback to run right after the API responses are received. This allows the config and response objects to be modified before the preview is shown.

createSpinner boolean optional
false

Creates $spinnerNode and inserts it before $previewNode if one doesn't already exist and the module jquery.spinner is loaded.

loadingSelectors Array.<string> optional
getLoadingSelectors()

An array of query selectors (i.e. '#catlinks') that should be grayed out while the preview is being generated.

Source:

Fires:

Returns:

jQuery.Promise or undefined if no $textareaNode was provided in the config.

Type
jQuery.Promise | undefined
Fetch and display a preview of the current editing area.

getLoadingSelectors() → {Array.<string>}static #

Get the selectors of elements that should be grayed out while the preview is being generated.

Source:

Returns:

Type
Array.<string>
Get the selectors of elements that should be grayed out while the preview is being generated.

Type Definitions

responseHandler(config, parseResponse, diffResponse) #

Parameters:

Name Type Attributes Description
config Object

Options for live preview API

parseResponse Object

Parse API response

diffResponse Object optional

Compare API response

Source: