/** * Handles dynamic Page Preview for Page Forms. * * @author Stephan Gambke */ /*global validateAll */ ( function ( $, mw ) { 'use strict'; var form; var previewpane; var previewHeight; /** * Called when the content is loaded into the preview pane */ var loadFrameHandler = function handleLoadFrame() { var iframe = $( this ); var iframecontents = iframe.contents(); // find div containing the preview var content = iframecontents.find( '#wikiPreview' ); var iframebody = content.closest( 'body' ); var iframedoc = iframebody.parent(); iframedoc.height( 'auto' ); // this is not a normal MW page (or it uses an unknown skin) if ( content.length === 0 ) { content = iframebody; } content.parentsUntil( 'html' ).andSelf() .css( { margin: 0, padding: 0, width: '100%', height: 'auto', minWidth: '0px', minHeight: '0px', 'float': 'none', // Cavendish skin uses floating -> unfloat content border: 'none', background: 'transparent' } ) .siblings() .hide(); // FIXME: Some JS scripts don't like working on hidden elements // and attach event handler to adjust frame size every time the window // size changes $( window ).resize( function () { iframe.height( iframedoc.height() ); } ); previewpane.show(); var newPreviewHeight = iframedoc.height(); iframe.height( newPreviewHeight ); $( 'html, body' ) .scrollTop( $( 'html, body' ).scrollTop() + newPreviewHeight - previewHeight ) .animate( { scrollTop: previewpane.offset().top }, 1000 ); previewHeight = newPreviewHeight; return false; }; /** * Called when the server has sent the preview */ var resultReceivedHandler = function handleResultReceived( result ) { var htm = result.result; var iframe = previewpane.children(); if ( iframe.length === 0 ) { // set initial height of preview area previewHeight = 0; iframe = $( '