- if (form.clk) {
- // input type=='image' are not found in elements array! handle it here
- var $input = $(form.clk), input = $input[0], n = input.name;
- if (n && !input.disabled && input.type == 'image') {
- a.push({name: n, value: $input.val()});
- a.push({name: n+'.x', value: form.clk_x}, {name: n+'.y', value: form.clk_y});
+ // fade out the elements and display the throbber
+ $( '#mw-content-text' ).prepend( $loadSpinner );
+ // we can't use fadeTo because it calls show(), and we might want to keep some elements hidden
+ // (e.g. empty #catlinks)
+ $copyElements.animate( { 'opacity': 0.4 }, 'fast' );
+
+ var $previewDataHolder = $( '<div>' );
+ var target = $( '#editform' ).attr( 'action' ) || window.location.href;
+
+ // gather all the data from the form
+ var postData = $( '#editform' ).formToArray(); // formToArray: from jquery.form
+ postData.push( { 'name' : e.target.name, 'value' : '1' } );
+
+ // load new preview data
+ // FIXME this should use the action=parse API instead of loading the entire page
+ $previewDataHolder.load( target + ' ' + copySelectors.join( ',' ), postData, function() {
+ // Copy the contents of the specified elements from the loaded page to the real page.
+ // Also copy their class attributes.
+ for ( var i = 0; i < copySelectors.length; i++ ) {
+ var $from = $previewDataHolder.find( copySelectors[i] );
+ var $to = $( copySelectors[i] );
+
+ $to.empty().append( $from.contents() );
+ $to.attr( 'class', $from.attr( 'class' ) );