mediawiki-extensions-Visual.../modules/ve/ui/ve.ui.Frame.js
Trevor Parscal ec912dc2d1 Link inspector menu not appearing in the right place
ve.ui.Widget.css
* Adjust menu up a few pixels to match other uses of ve.ui.MenuWidget (the format drop down)

ve.ui.LinkInspector.js
* Moved the form value initialization to a timeout that fires well after the animation of the inspector - this is only important because the first element has a menu that pops up and the menu was rendering in the wrong location

ve.ui.Frame.js
* Added reference to frame within this.$$ by passing it to get$$

ve.ui.Inspector.js
* Removed auto-focus on open from inspector base class - this will be done in a more specific and controlled way instead

ve.ui.js
* Added optional frame argument to get$$ so that it's easy to get the frame from any $$ that's bound to an iframe document

ve.ui.Window.js
* Removed duplicate static member assignments
* Added auto-focus on the window's frame before calling onOpen
* Added auto-blur of anything focused within the iframe after calling onClose

ve.ui.MWLinkTargetInputWidget.js
* Auto-highlight the selected item when populating a menu so that pressing enter always keeps the currently selected item selected

ve.ui.TextInputMenuWidget.js
* Take the frame's position into account when positioning a menu below an input

Change-Id: I334f7db29af6b821bcfc8dc3c0ccba2636d4d9b1
2013-03-14 16:56:04 -07:00

104 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 );
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;
};