frame.js revision 5e41377074f3a800d125e664578b36234bf28f7d
8d1240fc6300f6769711557511f6882f0a3d3139Matt Sweeney * Creates a wrapper around an iframe. It loads the content either from a local
8d1240fc6300f6769711557511f6882f0a3d3139Matt Sweeney * file or from script and creates a local YUI instance bound to that new window and document.
8d1240fc6300f6769711557511f6882f0a3d3139Matt Sweeney * @module editor
8d1240fc6300f6769711557511f6882f0a3d3139Matt Sweeney * @submodule frame
1e4299e83b45ff5cf2fc6b545f0186ecf831ec87Matt Sweeney * Creates a wrapper around an iframe. It loads the content either from a local
1e4299e83b45ff5cf2fc6b545f0186ecf831ec87Matt Sweeney * file or from script and creates a local YUI instance bound to that new window and document.
1e4299e83b45ff5cf2fc6b545f0186ecf831ec87Matt Sweeney * @class Frame
1e4299e83b45ff5cf2fc6b545f0186ecf831ec87Matt Sweeney * @for Frame
1e4299e83b45ff5cf2fc6b545f0186ecf831ec87Matt Sweeney * @extends Base
1e4299e83b45ff5cf2fc6b545f0186ecf831ec87Matt Sweeney * @constructor
1e4299e83b45ff5cf2fc6b545f0186ecf831ec87Matt Sweeney var Frame = function() {
1e4299e83b45ff5cf2fc6b545f0186ecf831ec87Matt Sweeney Frame.superclass.constructor.apply(this, arguments);
1e4299e83b45ff5cf2fc6b545f0186ecf831ec87Matt Sweeney * @property _ready
c8f1f836d21a6cf4eebc3146bf626f10943db48dMatt Sweeney * @description Internal reference set when the content is ready.
1e4299e83b45ff5cf2fc6b545f0186ecf831ec87Matt Sweeney * @type Boolean
1e4299e83b45ff5cf2fc6b545f0186ecf831ec87Matt Sweeney * @property _rendered
1e4299e83b45ff5cf2fc6b545f0186ecf831ec87Matt Sweeney * @description Internal reference set when render is called.
1e4299e83b45ff5cf2fc6b545f0186ecf831ec87Matt Sweeney * @type Boolean
1e4299e83b45ff5cf2fc6b545f0186ecf831ec87Matt Sweeney * @property _iframe
1e4299e83b45ff5cf2fc6b545f0186ecf831ec87Matt Sweeney * @description Internal Node reference to the iFrame or the window
1e4299e83b45ff5cf2fc6b545f0186ecf831ec87Matt Sweeney * @type Node
1e4299e83b45ff5cf2fc6b545f0186ecf831ec87Matt Sweeney * @property _instance
1e4299e83b45ff5cf2fc6b545f0186ecf831ec87Matt Sweeney * @description Internal reference to the YUI instance bound to the iFrame or window
1e4299e83b45ff5cf2fc6b545f0186ecf831ec87Matt Sweeney * @method _create
1e4299e83b45ff5cf2fc6b545f0186ecf831ec87Matt Sweeney * @description Create the iframe or Window and get references to the Document & Window
1e4299e83b45ff5cf2fc6b545f0186ecf831ec87Matt Sweeney * @return {Object} Hash table containing references to the new Document & Window
1e4299e83b45ff5cf2fc6b545f0186ecf831ec87Matt Sweeney _create: function() {
1e4299e83b45ff5cf2fc6b545f0186ecf831ec87Matt Sweeney * @method _resolveWinDoc
1e4299e83b45ff5cf2fc6b545f0186ecf831ec87Matt Sweeney * @description Resolves the document and window from an iframe or window instance
1e4299e83b45ff5cf2fc6b545f0186ecf831ec87Matt Sweeney * @param {Object} c The YUI Config to add the window and document to
1e4299e83b45ff5cf2fc6b545f0186ecf831ec87Matt Sweeney * @return {Object} Object hash of window and document references, if a YUI config was passed, it is returned.
1e4299e83b45ff5cf2fc6b545f0186ecf831ec87Matt Sweeney var config = (c) ? c : {};
1e4299e83b45ff5cf2fc6b545f0186ecf831ec87Matt Sweeney config.win = Y.Node.getDOMNode(this._iframe.get('contentWindow'));
1e4299e83b45ff5cf2fc6b545f0186ecf831ec87Matt Sweeney config.doc = Y.Node.getDOMNode(this._iframe.get('contentWindow.document'));
1e4299e83b45ff5cf2fc6b545f0186ecf831ec87Matt Sweeney * @method _onDomEvent
1e4299e83b45ff5cf2fc6b545f0186ecf831ec87Matt Sweeney * @description Generic handler for all DOM events fired by the iframe or window. This handler
1e4299e83b45ff5cf2fc6b545f0186ecf831ec87Matt Sweeney * takes the current EventFacade and augments it to fire on the Frame host. It adds two new properties
1e4299e83b45ff5cf2fc6b545f0186ecf831ec87Matt Sweeney * to the EventFacade called frameX and frameY which adds the scroll and xy position of the iframe
1e4299e83b45ff5cf2fc6b545f0186ecf831ec87Matt Sweeney * to the original pageX and pageY of the event so external nodes can be positioned over the frame.
1e4299e83b45ff5cf2fc6b545f0186ecf831ec87Matt Sweeney * @param {Event.Facade} e
1e4299e83b45ff5cf2fc6b545f0186ecf831ec87Matt Sweeney _onDomEvent: function(e) {
1e4299e83b45ff5cf2fc6b545f0186ecf831ec87Matt Sweeney e.frameX = xy[0] + e.pageX - node.get('scrollLeft');
1e4299e83b45ff5cf2fc6b545f0186ecf831ec87Matt Sweeney e.frameY = xy[1] + e.pageY - node.get('scrollTop');
1e4299e83b45ff5cf2fc6b545f0186ecf831ec87Matt Sweeney //TODO: Not sure why this stopped working!!!
1e4299e83b45ff5cf2fc6b545f0186ecf831ec87Matt Sweeney }, this, e),
1e4299e83b45ff5cf2fc6b545f0186ecf831ec87Matt Sweeney _DOMPaste: function(e) {
data = null;
e.frameEvent = e;
if (data) {
e.clipboardData = {
getData: function() {
return data;
e.clipboardData = null;
_defReadyFn: function() {
* @description Called once the content is available in the frame/window and calls the final use call
_onContentReady: function(e) {
if (!this._ready) {
this._ready = true;
* @description Resolves the basehref of the page the frame is created on. Only applies to dynamic content.
return href;
if (this._ready) {
return html;
if (this._ready) {
}, this, html));
return html;
if (this._ready) {
return css;
extra_css = ((this.get('extracss')) ? '<style id="extra_css">' + this.get('extracss') + '</style>' : ''),
} catch (err) {}
* @description This is a scoped version of the normal YUI.use method & is bound to this frame/window.
use: function() {
cb = false;
if (cb) {
* @param {String} cont The container to act as a delegate, if no "sel" passed, the body is assumed as the container.
if (!inst) {
if (!sel) {
getInstance: function() {
return this._instance;
* @param {String/HTMLElement/Node} node The node to render to
if (this._rendered) {
this._rendered = true;
if (node) {
this._instanceLoaded(i);
config = {
debug: false,
bootstrap: false,
if (timer) {
fn();
if (fn) {
fn();
if (fn) {
fn();
} catch (ferr) {
show: function() {
this.focus();
hide: function() {
DEFAULT_CSS: 'html { height: 95%; } body { padding: 7px; background-color: #fff; font: 13px/1.22 arial,helvetica,clean,sans-serif;*font-size:small;*font:x-small; } a, a:visited, a:hover { color: blue !important; text-decoration: underline !important; cursor: text !important; } img { cursor: pointer !important; border: none; }',
//DEFAULT_CSS: 'html { } body { margin: -15px 0 0 -15px; padding: 7px 0 0 15px; display: block; background-color: #fff; font: 13px/1.22 arial,helvetica,clean,sans-serif;*font-size:small;*font:x-small; }',
//DEFAULT_CSS: 'html { height: 95%; } body { height: 100%; padding: 7px; margin: 0 0 0 -7px; postion: relative; background-color: #fff; font: 13px/1.22 arial,helvetica,clean,sans-serif;*font-size:small;*font:x-small; } a, a:visited, a:hover { color: blue !important; text-decoration: underline !important; cursor: text !important; } img { cursor: pointer !important; border: none; }',
//DEFAULT_CSS: 'html { margin: 0; padding: 0; border: none; border-size: 0; } body { height: 97%; margin: 0; padding: 0; display: block; background-color: gray; font: 13px/1.22 arial,helvetica,clean,sans-serif;*font-size:small;*font:x-small; }',
HTML: '<iframe border="0" frameBorder="0" marginWidth="0" marginHeight="0" leftMargin="0" topMargin="0" allowTransparency="true" width="100%" height="99%"></iframe>',
PAGE_HTML: '<html dir="{DIR}" lang="{LANG}"><head><title>{TITLE}</title>{META}<base href="{BASE_HREF}"/><style id="editor_css">{DEFAULT_CSS}</style>{EXTRA_CSS}</head><body>{CONTENT}</body></html>',
* @description The DOCTYPE to prepend to the new document when created. Should match the one on the page being served.
DOC_TYPE: '<!DOCTYPE HTML PUBLIC "-/'+'/W3C/'+'/DTD HTML 4.01/'+'/EN" "http:/'+'/www.w3.org/TR/html4/strict.dtd">',
META: '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/><meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7">',
ATTRS: {
title: {
dir: {
lang: {
src: {
designMode: {
writeOnce: true,
value: false
content: {
basehref: {
value: false,
* @description Array of modules to include in the scoped YUI instance at render time. Default: ['none', 'selector-css2']
use: {
writeOnce: true,
* @type String/HTMLElement/Node
container: {
setter: function(n) {
return Y.one(n);
id: {
writeOnce: true,
if (!id) {
return id;
extracss: {
host: {
value: false