- page.load( target + ' ' + copySelector, postData,
- function() {
-
- for( var i=0; i<copyElements.length; ++i) {
- // For all the specified elements, find the elements in the loaded page
- // and the real page, empty the element in the real page, and fill it
- // with the content of the loaded page
- var copyContent = page.find( copyElements[i] ).contents();
- $(copyElements[i]).empty().append( copyContent );
- var newClasses = page.find( copyElements[i] ).prop('class');
- $(copyElements[i]).prop( 'class', newClasses );
- }
+ // show #wikiPreview if it's hidden to be able to scroll to it
+ // (if it is hidden, it's also empty, so nothing changes in the rendering)
+ $wikiPreview.show();
+ // jump to where the preview will appear
+ $wikiPreview[0].scrollIntoView();
+
+ // list of elements that will be loaded from the preview page
+ // elements absent in the preview page (such as .mw-newarticletext) will be cleared using .empty()
+ var copySelectors = [
+ '#wikiPreview', '#wikiDiff', '#catlinks', '.hiddencats', '#p-lang', // the meat
+ '.templatesUsed', '.mw-summary-preview', // editing-related
+ '.mw-newarticletext' // it is not shown during normal preview, and looks weird with throbber overlaid
+ ];
+ var $copyElements = $( copySelectors.join( ',' ) );
+
+ var $loadSpinner = $( '<div>' ).addClass( 'mw-ajax-loader' );
+ $loadSpinner.css( 'top', '0' ); // move away from header (default is -16px)
+
+ // If the preview is already visible, overlay the spinner on top of it.
+ if ( overlaySpinner ) {
+ $( '#mw-content-text' ).css( 'position', 'relative' ); // FIXME this seems like a bad idea
+
+ $loadSpinner.css( {
+ 'position': 'absolute',
+ 'z-index': '3',
+ 'left': '50%',
+ 'margin-left': '-16px'
+ } );
+ }