2 * Live preview script for MediaWiki
5 function setupLivePreview() {
6 var livePreviewButton
= $j('#wpLivePreview');
8 livePreviewButton
.click( doLivePreview
);
11 function doLivePreview( e
) {
13 var previewText
= $j('#wpTextbox1').val();
14 var postData
= { 'action' : 'submit', 'wpTextbox1' : previewText
, 'wpPreview' : true,
15 'title' : wgPageName
};
17 // Hide active diff, used templates, old preview if shown
18 $j('#wikiDiff').slideUp();
19 $j('#wikiPreview').slideUp();
20 $j('.templatesUsed').slideUp();
21 $j('.hiddencats').slideUp();
23 // Display a loading graphic
24 var loadSpinner
= $j('<div class="mw-ajax-loader"/>');
25 $j('#wikiPreview').before( loadSpinner
);
27 var page
= $j('<html/>');
28 page
.load( wgScript
+'?action=submit',
31 var copyElements
= ['#wikiPreview', '.templatesUsed', '.hiddencats',
34 for( var i
=0; i
<copyElements
.length
; ++i
) {
35 // For all the specified elements, find the elements in the loaded page
36 // and the real page, empty the element in the real page, and fill it
37 // with the content of the loaded page
38 var copyContent
= page
.find( copyElements
[i
] ).contents();
39 $j(copyElements
[i
]).empty().append( copyContent
);
40 var newClasses
= page
.find( copyElements
[i
] ).attr('class');
41 $j(copyElements
[i
]).attr( 'class', newClasses
);
46 $j('#wikiPreview').slideDown();
50 js2AddOnloadHook( setupLivePreview
);