2 * Live preview script for MediaWiki
5 function setupLivePreview() {
6 var livePreviewButton
= $j('#wpLivePreview');
8 $j('#wpPreview').hide();
9 livePreviewButton
.show();
11 livePreviewButton
.click( doLivePreview
);
14 function doLivePreview( e
) {
16 var previewText
= $j('#wpTextbox1').val();
18 var editToken
= $j( '[name="wpEditToken"]' ).attr( 'value' );
19 var editTime
= $j( '[name="wpEdittime"]' ).attr( 'value' );
20 var startTime
= $j( '[name="wpStarttime"]' ).attr( 'value' );
22 var postData
= { 'action' : 'submit', 'wpTextbox1' : previewText
, 'wpPreview' : true,
23 'wpEditToken' : editToken
, 'wpEdittime': editTime
, 'wpStarttime': startTime
, 'title' : wgPageName
};
25 // Hide active diff, used templates, old preview if shown
26 $j('#wikiDiff').slideUp();
27 $j('#wikiPreview').slideUp();
28 $j('.templatesUsed').slideUp();
29 $j('.hiddencats').slideUp();
31 // Display a loading graphic
32 var loadSpinner
= $j('<div class="mw-ajax-loader"/>');
33 $j('#wikiPreview').before( loadSpinner
);
35 var page
= $j('<html/>');
36 page
.load( wgScript
+'?action=submit',
39 var copyElements
= ['#wikiPreview', '.templatesUsed', '.hiddencats',
42 for( var i
=0; i
<copyElements
.length
; ++i
) {
43 // For all the specified elements, find the elements in the loaded page
44 // and the real page, empty the element in the real page, and fill it
45 // with the content of the loaded page
46 var copyContent
= page
.find( copyElements
[i
] ).contents();
47 $j(copyElements
[i
]).empty().append( copyContent
);
48 var newClasses
= page
.find( copyElements
[i
] ).attr('class');
49 $j(copyElements
[i
]).attr( 'class', newClasses
);
54 $j('#wikiPreview').slideDown();
58 js2AddOnloadHook( setupLivePreview
);