mediawiki-extensions-Visual.../modules/ve/ui/ve.ui.Frame.js
Trevor Parscal 1572ec1569 Context, frame, window, dialog and inspector refactor
This is a major refactor of user interface context, frame, dialog
and inspector classes, including adding several new classes which
generalize managing inspectors/dialogs (which are now subclasses
of window).

New classes:
* ve.ui.Window.js - base class for inspector and dialog classes
* ve.ui.WindowSet.js - manages mutually exclusive windows, used
  by surface and context for dialogs and inspectors respectively
* ve.ui.DialogFactory - generates dialogs
* ve.ui.IconButtonWidget - used in inspector for buttons in the head

Refactored classes:
* ve.ui.Context - moved inspector management to window set
* ve.ui.Frame - made iframes initialize asynchronously
* ve.ui.Dialog and ve.ui.Inspector - moved initialization to async
  initialize method

Other interesting bits:

ve.ui.*Icons*.css, *.svg, *.png, *.ai
* Merged icon stylesheets so all icons are available inside windows
* Renamed inspector icon to window

ve.ui.*.css
* Reorganized styles so that different windows can include only
  what they need
* Moved things to where they belonged (some things were in strange places)

ve.init.Target.js, ve.init.mw.ViewPageTarget.js, ve.init.sa.Target.js
* Removed dialog management - dialogs are managed by the surface now

ve.ui.*Dialog.js
* Renamed title message static property
* Added registration

ve.ui.*Inspector.js
* Switch to accept surface object rather than context, which conforms
  to the more general window class without losing any functionality
  (in fact, most of the time the surface was what we actually wanted)

ve.ui.MenuWidget.js, ve.ui.MWLinkTargetInputWidget.js
* Using surface overly rather than passing an overlay around
  through constructors

Change-Id: Ifd16a1003ff44c48ee7b2c66928cf9cc858b2564
2013-03-14 00:03:31 +00:00

105 lines
2.3 KiB
JavaScript

/*!
* VisualEditor UserInterface Frame class.
*
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
* @license The MIT License (MIT); see LICENSE.txt
*/
/**
* UserInterface iframe abstraction.
*
* @class
* @extends ve.EventEmitter
*
* @constructor
* @param {Object} [config] Config options
* @cfg {string[]} [stylesheets] List of stylesheet file names, each relative to ve/ui/styles
*/
ve.ui.Frame = function VeUiFrame( config ) {
// Inheritance
ve.EventEmitter.call( this );
// Properties
this.initialized = false;
this.config = config;
this.$ = $( '<iframe>' );
// Events
this.$.load( ve.bind( this.onLoad, this ) );
// Initialize
this.$
.addClass( 've-ui-frame' )
.attr( { 'frameborder': 0, 'scrolling': 'no' } );
};
/* Inheritance */
ve.inheritClass( ve.ui.Frame, ve.EventEmitter );
/* Events */
/**
* @event initialize
*/
/* Methods */
ve.ui.Frame.prototype.onLoad = function () {
var i, len, doc, $head,
promises = [],
stylesheets = this.config.stylesheets,
stylesheetPath = ve.init.platform.getModulesUrl() + '/ve/ui/styles/';
// Initialize contents
doc = this.$.prop( 'contentWindow' ).document;
doc.open();
doc.write(
'<head><base href="' + stylesheetPath + '"></head>' +
'<body style="padding:0;margin:0;"><div class="ve-ui-frame-content"></div></body>'
);
doc.close();
// Properties
this.$$ = ve.ui.get$$( doc );
this.$content = this.$$( '.ve-ui-frame-content' );
// Add stylesheets
$head = this.$$( 'head' );
function embedCss( css ) {
$head.append( '<style>' + css + '</style>' );
}
for ( i = 0, len = stylesheets.length; i < len; i++ ) {
promises.push( $.get( stylesheetPath + stylesheets[i], embedCss ) );
}
$.when.apply( $, promises )
.done( ve.bind( function () {
this.initialized = true;
this.emit( 'initialize' );
}, this ) );
};
/**
*
*/
ve.ui.Frame.prototype.run = function ( callback ) {
if ( this.initialized ) {
callback();
} else {
this.once( 'initialize', callback );
}
};
/**
* Sets the size of the frame.
*
* @method
* @param {number} width Frame width in pixels
* @param {number} height Frame height in pixels
* @chainable
*/
ve.ui.Frame.prototype.setSize = function ( width, height ) {
this.$.css( { 'width': width, 'height': height } );
return this;
};