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 |
1 | 54 | + native |
Name: svn:keywords |
2 | 55 | + Author Date Id Revision |
Index: trunk/phase3/includes/EditPage.php |
— | — | @@ -364,7 +364,7 @@ |
365 | 365 | * the newly-edited page. |
366 | 366 | */ |
367 | 367 | function edit() { |
368 | | - global $wgOut, $wgRequest; |
| 368 | + global $wgOut, $wgRequest, $wgUser; |
369 | 369 | // Allow extensions to modify/prevent this form or submission |
370 | 370 | if ( !wfRunHooks( 'AlternateEdit', array( $this ) ) ) { |
371 | 371 | return; |
— | — | @@ -392,6 +392,11 @@ |
393 | 393 | } |
394 | 394 | |
395 | 395 | $wgOut->addScriptFile( 'edit.js' ); |
| 396 | + |
| 397 | + if ( $wgUser->getOption( 'uselivepreview', false ) ) { |
| 398 | + $wgOut->includeJQuery(); |
| 399 | + $wgOut->addScriptFile( 'preview.js' ); |
| 400 | + } |
396 | 401 | |
397 | 402 | $permErrors = $this->getEditPermissionErrors(); |
398 | 403 | if ( $permErrors ) { |
Index: trunk/phase3/includes/Preferences.php |
— | — | @@ -637,7 +637,7 @@ |
638 | 638 | } |
639 | 639 | |
640 | 640 | static function editingPreferences( $user, &$defaultPreferences ) { |
641 | | - global $wgUseExternalEditor; |
| 641 | + global $wgUseExternalEditor, $wgLivePreview; |
642 | 642 | |
643 | 643 | ## Editing ##################################### |
644 | 644 | $defaultPreferences['cols'] = |
— | — | @@ -739,6 +739,14 @@ |
740 | 740 | 'section' => 'editing/advancedediting', |
741 | 741 | 'label-message' => 'tog-forceeditsummary', |
742 | 742 | ); |
| 743 | + if ( $wgLivePreview ) { |
| 744 | + $defaultPreferences['uselivepreview'] = |
| 745 | + array( |
| 746 | + 'type' => 'toggle', |
| 747 | + 'section' => 'editing/advancedediting', |
| 748 | + 'label-message' => 'tog-uselivepreview', |
| 749 | + ); |
| 750 | + } |
743 | 751 | } |
744 | 752 | |
745 | 753 | static function rcPreferences( $user, &$defaultPreferences ) { |