Update ordinary cat links as well
[lhc/web/wiklou.git] / skins / common / preview.js
1 /**
2 * Live preview script for MediaWiki
3 */
4
5 function setupLivePreview() {
6 var livePreviewButton = $j('#wpLivePreview');
7
8 livePreviewButton.click( doLivePreview );
9 }
10
11 function doLivePreview( e ) {
12 e.preventDefault();
13 var previewText = $j('#wpTextbox1').val();
14 var postData = { 'action' : 'submit', 'wpTextbox1' : previewText, 'wpPreview' : true,
15 'title' : wgPageName };
16
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();
22
23 var page = $j('<html/>');
24 page.load( wgScript+'?action=submit',
25 postData,
26 function() {
27 var copyElements = ['#wikiPreview', '.templatesUsed', '.hiddencats',
28 '#catlinks'];
29
30 for( var i=0; i<copyElements.length; ++i) {
31 // For all the specified elements, find the elements in the loaded page
32 // and the real page, empty the element in the real page, and fill it
33 // with the content of the loaded page
34 var copyContent = page.find( copyElements[i] ).contents();
35 $j(copyElements[i]).empty().append( copyContent );
36 }
37 $j('#wikiPreview').slideDown();
38 } );
39 }
40
41 js2AddOnloadHook( setupLivePreview );