diff options
author | Pierre Schmitz <pierre@archlinux.de> | 2013-12-08 09:55:49 +0100 |
---|---|---|
committer | Pierre Schmitz <pierre@archlinux.de> | 2013-12-08 09:55:49 +0100 |
commit | 4ac9fa081a7c045f6a9f1cfc529d82423f485b2e (patch) | |
tree | af68743f2f4a47d13f2b0eb05f5c4aaf86d8ea37 /resources/mediawiki.action/mediawiki.action.edit.preview.js | |
parent | af4da56f1ad4d3ef7b06557bae365da2ea27a897 (diff) |
Update to MediaWiki 1.22.0
Diffstat (limited to 'resources/mediawiki.action/mediawiki.action.edit.preview.js')
-rw-r--r-- | resources/mediawiki.action/mediawiki.action.edit.preview.js | 53 |
1 files changed, 24 insertions, 29 deletions
diff --git a/resources/mediawiki.action/mediawiki.action.edit.preview.js b/resources/mediawiki.action/mediawiki.action.edit.preview.js index 602aadb0..c5cd61ef 100644 --- a/resources/mediawiki.action/mediawiki.action.edit.preview.js +++ b/resources/mediawiki.action/mediawiki.action.edit.preview.js @@ -7,14 +7,16 @@ * @param {jQuery.Event} e */ function doLivePreview( e ) { - var $wikiPreview, copySelectors, removeSelectors, $copyElements, $spinner, + var $wikiPreview, $editform, copySelectors, $copyElements, $spinner, targetUrl, postData, $previewDataHolder; e.preventDefault(); + // Deprecated: Use mw.hook instead $( mw ).trigger( 'LivePreviewPrepare' ); $wikiPreview = $( '#wikiPreview' ); + $editform = $( '#editform' ); // Show #wikiPreview if it's hidden to be able to scroll to it // (if it is hidden, it's also empty, so nothing changes in the rendering) @@ -34,16 +36,13 @@ '#p-lang', // Editing-related '.templatesUsed', + '.limitreport', '.mw-summary-preview' ]; $copyElements = $( copySelectors.join( ',' ) ); // Not shown during normal preview, to be removed if present - removeSelectors = [ - '.mw-newarticletext' - ]; - - $( removeSelectors.join( ',' ) ).remove(); + $( '.mw-newarticletext' ).remove(); $spinner = $.createSpinner( { size: 'large', @@ -51,36 +50,29 @@ }); $wikiPreview.before( $spinner ); $spinner.css( { - position: 'absolute', marginTop: $spinner.height() } ); - // Make sure preview area is at least as tall as 2x the height of the spinner. - // 1x because if its smaller, it will spin behind the edit toolbar. - // (this happens on the first preview when editPreview is still empty) - // 2x because the spinner has 1x margin top breathing room. - $wikiPreview.css( 'minHeight', $spinner.height() * 2 ); // Can't use fadeTo because it calls show(), and we might want to keep some elements hidden // (e.g. empty #catlinks) - $copyElements.animate( { - opacity: 0.4 - }, 'fast' ); + $copyElements.animate( { opacity: 0.4 }, 'fast' ); $previewDataHolder = $( '<div>' ); - targetUrl = $( '#editform' ).attr( 'action' ); + targetUrl = $editform.attr( 'action' ); // Gather all the data from the form - postData = $( '#editform' ).formToArray(); + postData = $editform.formToArray(); postData.push( { name: e.target.name, value: '' } ); // Load new preview data. - // TODO: This should use the action=parse API instead of loading the entire page - // Though that requires figuring out how to conver that raw data into proper HTML. + // TODO: This should use the action=parse API instead of loading the entire page, + // although that requires figuring out how to convert that raw data into proper HTML. $previewDataHolder.load( targetUrl + ' ' + copySelectors.join( ',' ), postData, function () { var i, $from; + // Copy the contents of the specified elements from the loaded page to the real page. // Also copy their class attributes. for ( i = 0; i < copySelectors.length; i++ ) { @@ -92,16 +84,19 @@ .attr( 'class', $from.attr( 'class' ) ); } + // Deprecated: Use mw.hook instead + $( mw ).trigger( 'LivePreviewDone', [copySelectors] ); + + mw.hook( 'wikipage.content' ).fire( $wikiPreview ); + $spinner.remove(); $copyElements.animate( { opacity: 1 }, 'fast' ); - - $( mw ).trigger( 'LivePreviewDone', [copySelectors] ); } ); } - $( document ).ready( function () { + $( 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 ) { @@ -109,32 +104,32 @@ } // The following elements can change in a preview but are not output - // by the server when they're empty until the preview reponse. + // by the server when they're empty until the preview response. // TODO: Make the server output these always (in a hidden state), so we don't // have to fish and (hopefully) put them in the right place (since skins // can change where they are output). if ( !document.getElementById( 'p-lang' ) && document.getElementById( 'p-tb' ) ) { $( '#p-tb' ).after( - $( '<div>' ).prop( 'id', 'p-lang' ) + $( '<div>' ).attr( 'id', 'p-lang' ) ); } if ( !$( '.mw-summary-preview' ).length ) { $( '.editCheckboxes' ).before( - $( '<div>' ).prop( 'className', 'mw-summary-preview' ) + $( '<div>' ).addClass( 'mw-summary-preview' ) ); } if ( !document.getElementById( 'wikiDiff' ) && document.getElementById( 'wikiPreview' ) ) { $( '#wikiPreview' ).after( - $( '<div>' ).prop( 'id', 'wikiDiff') + $( '<div>' ).attr( 'id', 'wikiDiff' ) ); } - // Make sure diff styles are loaded - mw.loader.load( 'mediawiki.action.history.diff' ); - + // This should be moved down to '#editform', but is kept on the body for now + // because the LiquidThreads extension is re-using this module with only half + // the EditPage (doesn't include #editform presumably, bug 55463). $( document.body ).on( 'click', '#wpPreview, #wpDiff', doLivePreview ); } ); |