Fixes bug 19194 (search box issue in Safari and Chrome)
[lhc/web/wiklou.git] / skins / common / preview.js
1 /**
2 * Live preview script for MediaWiki
3 */
4
5 function doLivePreview( e ) {
6 e.preventDefault();
7 var previewText = $j('#wpTextbox1').val();
8
9 var editToken = $j( '[name="wpEditToken"]' ).attr( 'value' );
10 var editTime = $j( '[name="wpEdittime"]' ).attr( 'value' );
11 var startTime = $j( '[name="wpStarttime"]' ).attr( 'value' );
12
13 var postData = { 'action' : 'submit', 'wpTextbox1' : previewText, 'wpPreview' : true,
14 'wpEditToken' : editToken, 'wpEdittime': editTime, 'wpStarttime': startTime, 'title' : wgPageName };
15
16 // Hide active diff, used templates, old preview if shown
17 var copyElements = ['#wikiPreview', '.templatesUsed', '.hiddencats',
18 '#catlinks'];
19 var copySelector = copyElements.join(',');
20
21 $j.each( copyElements, function(k,v) { $j(v).fadeOut('fast'); } );
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('<div/>');
28 page.load( wgScript+'?action=submit '+copySelector,
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 } );