r62173 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r62172‎ | r62173 | r62174 >
Date:07:39, 9 February 2010
Author:werdna
Status:ok
Tags:
Comment:
Reverse removal of Live Preview in r59446, with the following changes:
* Make Live Preview entirely JS-based. It requires no modification of the HTML.
* Replace annoying slideDown with less annoying fadeIn().
* Ensure that elements not supposed to be shown are not, in fact, shown by fadeIn().
* Remove some redundant lines of code.
* Make compatible with the current jQuery usage in MediaWiki.
Modified paths:
  • /trunk/phase3/includes/EditPage.php (modified) (history)
  • /trunk/phase3/includes/Preferences.php (modified) (history)
  • /trunk/phase3/skins/common/preview.js (added) (history)

Diff [purge]

Index: trunk/phase3/skins/common/preview.js
@@ -0,0 +1,52 @@
 2+/**
 3+ * Live preview script for MediaWiki
 4+ */
 5+
 6+function doLivePreview( e ) {
 7+ e.preventDefault();
 8+ var previewText = $j('#wpTextbox1').val();
 9+
 10+ var editToken = $j( '[name="wpEditToken"]' ).attr( 'value' );
 11+ var editTime = $j( '[name="wpEdittime"]' ).attr( 'value' );
 12+ var startTime = $j( '[name="wpStarttime"]' ).attr( 'value' );
 13+
 14+ var postData = { 'action' : 'submit', 'wpTextbox1' : previewText, 'wpPreview' : true,
 15+ 'wpEditToken' : editToken, 'wpEdittime': editTime, 'wpStarttime': startTime, 'title' : wgPageName };
 16+
 17+ // Hide active diff, used templates, old preview if shown
 18+ var copyElements = ['#wikiPreview', '.templatesUsed', '.hiddencats',
 19+ '#catlinks'];
 20+
 21+ $j.each( copyElements, function(k,v) { $j(v).fadeOut(); } );
 22+
 23+ // Display a loading graphic
 24+ var loadSpinner = $j('<div class="mw-ajax-loader"/>');
 25+ $j('#wikiPreview').before( loadSpinner );
 26+
 27+ var page = $j('<html/>');
 28+ page.load( wgScript+'?action=submit',
 29+ postData,
 30+ function() {
 31+
 32+ for( var i=0; i<copyElements.length; ++i) {
 33+ // For all the specified elements, find the elements in the loaded page
 34+ // and the real page, empty the element in the real page, and fill it
 35+ // with the content of the loaded page
 36+ var copyContent = page.find( copyElements[i] ).contents();
 37+ $j(copyElements[i]).empty().append( copyContent );
 38+ var newClasses = page.find( copyElements[i] ).attr('class');
 39+ $j(copyElements[i]).attr( 'class', newClasses );
 40+ }
 41+
 42+ $j.each( copyElements, function(k,v) {
 43+ // Don't belligerently show elements that are supposed to be hidden
 44+ $j(v).fadeIn( 'fast', function() { $j(this).css('display', ''); } );
 45+ } );
 46+
 47+ loadSpinner.remove();
 48+ } );
 49+}
 50+
 51+$j(document).ready( function() {
 52+ $j('#wpPreview').click( doLivePreview );
 53+} );
Property changes on: trunk/phase3/skins/common/preview.js
___________________________________________________________________
Name: svn:eol-style
154 + native
Name: svn:keywords
255 + Author Date Id Revision
Index: trunk/phase3/includes/EditPage.php
@@ -364,7 +364,7 @@
365365 * the newly-edited page.
366366 */
367367 function edit() {
368 - global $wgOut, $wgRequest;
 368+ global $wgOut, $wgRequest, $wgUser;
369369 // Allow extensions to modify/prevent this form or submission
370370 if ( !wfRunHooks( 'AlternateEdit', array( $this ) ) ) {
371371 return;
@@ -392,6 +392,11 @@
393393 }
394394
395395 $wgOut->addScriptFile( 'edit.js' );
 396+
 397+ if ( $wgUser->getOption( 'uselivepreview', false ) ) {
 398+ $wgOut->includeJQuery();
 399+ $wgOut->addScriptFile( 'preview.js' );
 400+ }
396401
397402 $permErrors = $this->getEditPermissionErrors();
398403 if ( $permErrors ) {
Index: trunk/phase3/includes/Preferences.php
@@ -637,7 +637,7 @@
638638 }
639639
640640 static function editingPreferences( $user, &$defaultPreferences ) {
641 - global $wgUseExternalEditor;
 641+ global $wgUseExternalEditor, $wgLivePreview;
642642
643643 ## Editing #####################################
644644 $defaultPreferences['cols'] =
@@ -739,6 +739,14 @@
740740 'section' => 'editing/advancedediting',
741741 'label-message' => 'tog-forceeditsummary',
742742 );
 743+ if ( $wgLivePreview ) {
 744+ $defaultPreferences['uselivepreview'] =
 745+ array(
 746+ 'type' => 'toggle',
 747+ 'section' => 'editing/advancedediting',
 748+ 'label-message' => 'tog-uselivepreview',
 749+ );
 750+ }
743751 }
744752
745753 static function rcPreferences( $user, &$defaultPreferences ) {

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r59446Removed JS2 work (has been moved to the js2-work branch). Has been lightly te...tstarling12:00, 26 November 2009

Status & tagging log