mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-12-01 17:36:35 +00:00
Simplified iframe initialization
Rather than attach a function to the window and trigger it from a script tag in the document body, it's much simpler to just use the references we already have to execute the code immediately and directly. This also fixes issues in Firefox where reaching in and adding functions to the window wasn't allowed. Change-Id: If7a84edf6ae4549b19ce36a3477311c46dbadea7
This commit is contained in:
parent
cec856032a
commit
17c9aadf8f
|
@ -68,25 +68,30 @@ ve.inheritClass( ve.ui.Frame, ve.EventEmitter );
|
||||||
* @emits initialize
|
* @emits initialize
|
||||||
*/
|
*/
|
||||||
ve.ui.Frame.prototype.onLoad = function () {
|
ve.ui.Frame.prototype.onLoad = function () {
|
||||||
var win = this.$.prop( 'contentWindow' ),
|
var interval, rules,
|
||||||
|
win = this.$.prop( 'contentWindow' ),
|
||||||
doc = win.document,
|
doc = win.document,
|
||||||
stylesheets = this.config.stylesheets,
|
style = doc.createElement( 'style' ),
|
||||||
initialize = ve.bind( function () {
|
initialize = ve.bind( function () {
|
||||||
this.initialized = true;
|
this.initialized = true;
|
||||||
this.emit( 'initialize' );
|
this.emit( 'initialize' );
|
||||||
}, this );
|
}, this );
|
||||||
|
|
||||||
// Initialize contents
|
// Initialize contents
|
||||||
win.setup = function () {
|
doc.open();
|
||||||
var interval, rules,
|
doc.write(
|
||||||
style = doc.createElement( 'style' );
|
'<body style="padding:0;margin:0;">' +
|
||||||
|
'<div class="ve-ui-frame-content"></div>' +
|
||||||
|
'</body>'
|
||||||
|
);
|
||||||
|
doc.close();
|
||||||
|
|
||||||
// Import all stylesheets
|
// Import all stylesheets
|
||||||
style.textContent = '@import "' + stylesheets.join( '";\n@import "' ) + '";';
|
style.textContent = '@import "' + this.config.stylesheets.join( '";\n@import "' ) + '";';
|
||||||
doc.body.appendChild( style );
|
doc.body.appendChild( style );
|
||||||
|
|
||||||
// Poll for access to stylesheet content
|
// Poll for access to stylesheet content
|
||||||
interval = setInterval( function () {
|
interval = setInterval( ve.bind( function () {
|
||||||
try {
|
try {
|
||||||
// MAGIC: only accessible when the stylesheet is loaded
|
// MAGIC: only accessible when the stylesheet is loaded
|
||||||
rules = style.sheet.cssRules;
|
rules = style.sheet.cssRules;
|
||||||
|
@ -97,15 +102,7 @@ ve.ui.Frame.prototype.onLoad = function () {
|
||||||
initialize();
|
initialize();
|
||||||
}
|
}
|
||||||
} catch ( e ) { }
|
} catch ( e ) { }
|
||||||
} );
|
}, this ), 10 );
|
||||||
};
|
|
||||||
doc.open();
|
|
||||||
doc.write(
|
|
||||||
'<body style="padding:0;margin:0;">' +
|
|
||||||
'<div class="ve-ui-frame-content"></div><script>setup();</script>' +
|
|
||||||
'</body>'
|
|
||||||
);
|
|
||||||
doc.close();
|
|
||||||
|
|
||||||
// Properties
|
// Properties
|
||||||
this.$$ = ve.ui.get$$( doc, this );
|
this.$$ = ve.ui.get$$( doc, this );
|
||||||
|
|
Loading…
Reference in a new issue