frame-debug.js revision 9e61211d733113b59082340639c872d7fc48747c
/**
* Creates a wrapper around an iframe. It loads the content either from a local
* file or from script and creates a local YUI instance bound to that new window and document.
* @module editor
* @submodule frame
*/
/**
* Creates a wrapper around an iframe. It loads the content either from a local
* file or from script and creates a local YUI instance bound to that new window and document.
* @class Frame
* @for Frame
* @extends Base
* @constructor
*/
var Frame = function() {
};
/**
* @private
* @property _ready
* @description Internal reference set when the content is ready.
* @type Boolean
*/
_ready: null,
/**
* @private
* @property _rendered
* @description Internal reference set when render is called.
* @type Boolean
*/
_rendered: null,
/**
* @private
* @property _iframe
* @description Internal Node reference to the iFrame or the window
* @type Node
*/
_iframe: null,
/**
* @private
* @property _instance
* @description Internal reference to the YUI instance bound to the iFrame or window
* @type YUI
*/
_instance: null,
/**
* @private
* @method _create
* @description Create the iframe or Window and get references to the Document & Window
* @return {Object} Hash table containing references to the new Document & Window
*/
var html = '',
extra_css = ((this.get('extracss')) ? '<style id="extra_css">' + this.get('extracss') + '</style>' : '');
});
} else {
}
res = this._resolveWinDoc();
if (this.get('designMode')) {
}
}
}, null, true);
} else {
}
},
/**
* @private
* @method _resolveWinDoc
* @description Resolves the document and window from an iframe or window instance
* @param {Object} c The YUI Config to add the window and document to
* @return {Object} Object hash of window and document references, if a YUI config was passed, it is returned.
*/
_resolveWinDoc: function(c) {
var config = (c) ? c : {};
}
}
return config;
},
/**
* @private
* @method _onDomEvent
* @description Generic handler for all DOM events fired by the iframe or window. This handler
* takes the current EventFacade and augments it to fire on the Frame host. It adds two new properties
* to the EventFacade called frameX and frameY which adds the scroll and xy position of the iframe
* to the original pageX and pageY of the event so external nodes can be positioned over the frame.
* @param {Event.Facade} e
*/
_onDomEvent: function(e) {
//Y.log('onDOMEvent: ' + e.type, 'info', 'frame');
}
}
e.frameTarget = e.target;
e.frameCurrentTarget = e.currentTarget;
e.frameEvent = e;
},
initializer: function() {
this.publish('ready', {
emitFacade: true,
defaultFn: this._defReadyFn
});
},
destructor: function() {
var inst = this.getInstance();
inst = null;
},
/**
* @private
* @method _DOMPaste
* @description Simple pass thru handler for the paste event so we can do content cleanup
* @param {Event.Facade} e
*/
_DOMPaste: function(e) {
var inst = this.getInstance(),
if (e._event.originalTarget) {
}
if (e._event.clipboardData) {
}
if (win.clipboardData) {
// Verify failure
data = null;
}
}
}
e.frameTarget = e.target;
e.frameCurrentTarget = e.currentTarget;
e.frameEvent = e;
if (data) {
e.clipboardData = {
getData: function() {
return data;
}
};
} else {
e.clipboardData = null;
}
this.fire('dom:paste', e);
},
/**
* @private
* @method _defReadyFn
* @description Binds DOM events, sets the iframe to visible and fires the ready event
*/
_defReadyFn: function() {
var inst = this.getInstance(),
//Y.each(inst.Node.DOM_EVENTS, function(v, k) {
if (v === 1) {
if (k !== 'focus' && k !== 'blur' && k !== 'paste') {
//Y.log('Adding DOM event to frame: ' + k, 'info', 'frame');
} else {
}
}
}
}, this);
visibility: 'inherit'
});
},
/**
* @private
* @method _onContentReady
* @description Called once the content is available in the frame/window and calls the final use call
* on the internal instance so that the modules are loaded properly.
*/
_onContentReady: function(e) {
if (!this._ready) {
this._ready = true;
var inst = this.getInstance(),
this.fire('contentready');
if (e) {
}
//TODO Circle around and deal with CSS loading...
this.fire('ready');
}, this));
}
},
/**
* @private
* @method _resolveBaseHref
* @description Resolves the basehref of the page the frame is created on. Only applies to dynamic content.
* @param {String} href The new value to use, if empty it will be resolved from the current url.
* @return {String}
*/
_resolveBaseHref: function(href) {
}
}
return href;
},
/**
* @private
* @method _getHTML
* @description Get the content from the iframe
* @param {String} html The raw HTML from the body of the iframe.
* @return {String}
*/
if (this._ready) {
var inst = this.getInstance();
}
return html;
},
/**
* @private
* @method _setHTML
* @description Set the content of the iframe
* @param {String} html The raw HTML to set the body of the iframe to.
* @return {String}
*/
if (this._ready) {
var inst = this.getInstance();
} else {
//This needs to be wrapped in a contentready callback for the !_ready state
var inst = this.getInstance();
}, this, html));
}
return html;
},
_getLinkedCSS: function(urls) {
}
var str = '';
if (!this._ready) {
});
} else {
}
return str;
},
_setLinkedCSS: function(css) {
if (this._ready) {
var inst = this.getInstance();
}
return css;
},
/**
* @private
* @method _setExtraCSS
* @description Set's the extra CSS on the instance..
*/
_setExtraCSS: function(css) {
if (this._ready) {
var inst = this.getInstance(),
}
return css;
},
/**
* @private
* @method _instanceLoaded
* @description Called from the first YUI instance that sets up the internal instance.
*/
_instanceLoaded: function(inst) {
this._onContentReady();
if (this.get('designMode')) {
try {
//Force other browsers into non CSS styling
} catch (err) {}
}
}
},
//BEGIN PUBLIC METHODS
/**
* @method use
* @description This is a scoped version of the normal YUI.use method & is bound to this frame/window.
* At setup, the inst.use method is mapped to this method.
*/
use: function() {
var inst = this.getInstance(),
cb = false;
}
if (cb) {
});
}
},
/**
* @method delegate
* @description A delegate method passed to the instance's delegate method
* @param {String} type The type of event to listen for
* @param {Function} fn The method to attach
* @param {String} cont The container to act as a delegate, if no "sel" passed, the body is assumed as the container.
* @param {String} sel The selector to match in the event (optional)
* @return {EventHandle} The Event handle returned from Y.delegate
*/
var inst = this.getInstance();
if (!inst) {
Y.log('Delegate events can not be attached until after the ready event has fired.', 'error', 'iframe');
return false;
}
if (!sel) {
cont = 'body';
}
},
/**
* @method getInstance
* @description Get a reference to the internal YUI instance.
* @return {YUI} The internal YUI instance
*/
getInstance: function() {
return this._instance;
},
/**
* @method render
* @description Render the iframe into the container config option or open the window.
* @param {String/HTMLElement/Node} node The node to render to
* @return {Y.Frame}
* @chainable
*/
if (this._rendered) {
return this;
}
this._rendered = true;
if (node) {
}
this._instanceLoaded(i);
}, this),
config = {
debug: false,
},
try {
if (timer) {
}
} catch (e) {
timer = setInterval(function() {
fn();
}, 350);
}
}, this);
}, this));
return this;
},
/**
* @private
* @method _handleFocus
* @description Does some tricks on focus to set the proper cursor position.
*/
_handleFocus: function() {
var inst = this.getInstance(),
if (sel.anchorNode) {
var n = sel.anchorNode,
c = n.get('childNodes');
if (c.size() == 1) {
sel.selectNode(n, true, false);
}
}
}
},
/**
* @method focus
* @description Set the focus to the iframe
* @param {Function} fn Callback function to execute after focus happens
* @return {Frame}
* @chainable
*/
if (fn === true) {
this._handleFocus();
}
fn();
}
} else {
try {
Y.later(100, this, function() {
if (fn === true) {
this._handleFocus();
}
fn();
}
});
} catch (ferr) {
}
}
return this;
},
/**
* @method show
* @description Show the iframe instance
* @return {Frame}
* @chainable
*/
show: function() {
position: 'static',
left: ''
});
try {
} catch (e) { }
this.focus();
}
return this;
},
/**
* @method hide
* @description Hide the iframe instance
* @return {Frame}
* @chainable
*/
hide: function() {
position: 'absolute',
left: '-999999px'
});
return this;
}
}, {
/**
* @static
* @property DOM_EVENTS
* @description The DomEvents that the frame automatically attaches and bubbles
* @type Object
*/
DOM_EVENTS: {
paste: 1,
mouseup: 1,
mousedown: 1,
keyup: 1,
keydown: 1,
keypress: 1,
activate: 1,
deactivate: 1,
focusin: 1,
focusout: 1
},
/**
* @static
* @property DEFAULT_CSS
* @description The default css used when creating the document.
* @type String
*/
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; } .yui-cursor { *line-height: 0; *height: 0; *width: 0; *font-size: 0; *overflow: hidden; }',
/**
* @static
* @property HTML
* @description The template string used to create the iframe
* @type String
*/
HTML: '<iframe border="0" frameBorder="0" marginWidth="0" marginHeight="0" leftMargin="0" topMargin="0" allowTransparency="true" width="100%" height="99%"></iframe>',
//HTML: '<iframe border="0" frameBorder="0" width="100%" height="99%"></iframe>',
/**
* @static
* @property PAGE_HTML
* @description The template used to create the page when created dynamically.
* @type String
*/
PAGE_HTML: '<html dir="{DIR}" lang="{LANG}"><head><title>{TITLE}</title>{META}<base href="{BASE_HREF}"/>{LINKED_CSS}<style id="editor_css">{DEFAULT_CSS}</style>{EXTRA_CSS}</head><body>{CONTENT}</body></html>',
/**
* @static
* @property DOC_TYPE
* @description The DOCTYPE to prepend to the new document when created. Should match the one on the page being served.
* @type String
*/
DOC_TYPE: '<!DOCTYPE HTML PUBLIC "-/'+'/W3C/'+'/DTD HTML 4.01/'+'/EN" "http:/'+'/www.w3.org/TR/html4/strict.dtd">',
/**
* @static
* @property META
* @description The meta-tag for Content-Type to add to the dynamic document
* @type String
*/
META: '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/><meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7">',
/**
* @static
* @property NAME
* @description The name of the class (frame)
* @type String
*/
NAME: 'frame',
ATTRS: {
/**
* @attribute title
* @description The title to give the blank page.
* @type String
*/
title: {
value: 'Blank Page'
},
/**
* @attribute dir
* @description The default text direction for this new frame. Default: ltr
* @type String
*/
dir: {
value: 'ltr'
},
/**
* @attribute lang
* @description The default language. Default: en-US
* @type String
*/
lang: {
value: 'en-US'
},
/**
* @attribute src
* @type String
*/
src: {
//Hackish, IE needs the false in the Javascript URL
},
/**
* @attribute designMode
* @description Should designMode be turned on after creation.
* @writeonce
* @type Boolean
*/
designMode: {
writeOnce: true,
value: false
},
/**
* @attribute content
* @type String
*/
content: {
value: '<br>',
setter: '_setHTML',
getter: '_getHTML'
},
/**
* @attribute basehref
* @description The base href to use in the iframe.
* @type String
*/
basehref: {
value: false,
getter: '_resolveBaseHref'
},
/**
* @attribute use
* @description Array of modules to include in the scoped YUI instance at render time. Default: ['none', 'selector-css2']
* @writeonce
* @type Array
*/
use: {
writeOnce: true,
},
/**
* @attribute container
* @description The container to append the iFrame to on render.
* @type String/HTMLElement/Node
*/
container: {
value: 'body',
setter: function(n) {
return Y.one(n);
}
},
/**
* @attribute id
* @description Set the id of the new Node. (optional)
* @type String
* @writeonce
*/
id: {
writeOnce: true,
if (!id) {
}
return id;
}
},
/**
* @attribute linkedcss
* @description An array of url's to external linked style sheets
* @type String
*/
linkedcss: {
value: '',
getter: '_getLinkedCSS',
setter: '_setLinkedCSS'
},
/**
* @attribute extracss
* @description A string of CSS to add to the Head of the Editor
* @type String
*/
extracss: {
value: '',
setter: '_setExtraCSS'
},
/**
* @attribute host
* @description A reference to the Editor instance
* @type Object
*/
host: {
value: false
}
}
});