2 * Live preview script for MediaWiki
5 function doLivePreview( e
) {
7 var previewText
= $j('#wpTextbox1').val();
9 var editToken
= $j( '[name="wpEditToken"]' ).attr( 'value' );
10 var editTime
= $j( '[name="wpEdittime"]' ).attr( 'value' );
11 var startTime
= $j( '[name="wpStarttime"]' ).attr( 'value' );
13 var postData
= { 'action' : 'submit', 'wpTextbox1' : previewText
, 'wpPreview' : true,
14 'wpEditToken' : editToken
, 'wpEdittime': editTime
, 'wpStarttime': startTime
, 'title' : wgPageName
};
16 // Hide active diff, used templates, old preview if shown
17 var copyElements
= ['#wikiPreview', '.templatesUsed', '.hiddencats',
19 var copySelector
= copyElements
.join(',');
21 $j
.each( copyElements
, function(k
,v
) { $j(v
).fadeOut('fast'); } );
23 // Display a loading graphic
24 var loadSpinner
= $j('<div class="mw-ajax-loader"/>');
25 $j('#wikiPreview').before( loadSpinner
);
27 var page
= $j('<div/>');
28 page
.load( wgScript
+'?action=submit '+copySelector
,
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
);
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', ''); } );
51 $j(document
).ready( function() {
52 $j('#wpPreview').click( doLivePreview
);