mediawiki-extensions-Visual.../modules/ve/ui/ve.ui.Frame.js
Trevor Parscal 8d33a3de0d Major Documentation Cleanup
* Made method descriptions imperative: "Do this" rather than "Does this"
* Changed use of "this object" to "the object" in method documentation
* Added missing documentation
* Fixed incorrect documentation
* Fixed incorrect debug method names (as in those VeDmClassName tags we add to functions so they make sense when dumped into in the console)
* Normalized use of package names throughout
* Normalized class descriptions
* Removed incorrect @abstract tags
* Added missing @method tags
* Lots of other minor cleanup

Change-Id: I4ea66a2dd107613e2ea3a5f56ff54d675d72957e
2013-01-16 15:37:59 -08:00

94 lines
2.3 KiB
JavaScript

/*!
* VisualEditor UserInterface Frame class.
*
* @copyright 2011-2012 VisualEditor Team and others; see AUTHORS.txt
* @license The MIT License (MIT); see LICENSE.txt
*/
/**
* UserInterface iframe abstraction.
*
* @class
* @constructor
*/
ve.ui.Frame = function VeUiFrame( config, $container ) {
var i, len;
// Properties
this.$frame = $( '<iframe frameborder="0" scrolling="no"></iframe>' );
this.frameDocument = this.attachFrame( this.$frame, $container );
this.$ = this.$$( '.ve-ui-frame-container' );
this.$$ = ve.bind( this.$$, this );
// Initialization
if ( 'stylesheets' in config ) {
for ( i = 0, len = config.stylesheets.length; i < len; i++ ) {
this.loadStylesheet( config.stylesheets[i] );
}
}
};
/* Methods */
/**
* Sets the size of the frame.
*
* @method
* @param {number} width Frame width in pixels
* @param {number} height Frame height in pixels
*/
ve.ui.Frame.prototype.setSize = function ( width, height ) {
this.$frame.css( { 'width': width, 'height': height } );
};
/**
* Execute jQuery function within the context of the frame.
*
* @method
* @param {string} selector jQuery selector
* @returns {jQuery} jQuery selection
*/
ve.ui.Frame.prototype.$$ = function ( selector ) {
return $( selector, this.frameDocument );
};
/**
* Attaches and initializes a frame within a given container.
*
* @method
* @private
* @param {jQuery} $frame Frame to attach and initialize
* @param {jQuery} $container Container to append frame to
* @returns {HTMLDocument} Frame document
*/
ve.ui.Frame.prototype.attachFrame = function ( $frame, $container ) {
var doc;
// Attach to a document to initialze for real
$container.append( $frame );
// Get the frame document
doc = $frame.prop( 'contentWindow' ).document;
// Create an inner frame container
doc.write( '<div class="ve-ui-frame-container"></div>' );
// Finish the frame to make all browsers happy
doc.close();
// Basic styles
$( 'body', doc ).css( {
'padding': 0,
'margin': 0
} );
return doc;
};
/**
* Adds a stylesheet to the frame.
*
* @method
* @param {string} path Full path to stylesheet
*/
ve.ui.Frame.prototype.loadStylesheet = function ( path ) {
// Append style elements to head.
this.$$( 'head' ).append(
this.$$( '<link rel="stylesheet">' ).attr( 'href', path )
);
};