frame.js revision 6e43f558138d36538a82459ec79e0279ffae22e0
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * Creates a wrapper around an iframe. It loads the content either from a local
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * file or from script and creates a local YUI instance bound to that new window and document.
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * @module editor
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * @submodule frame
ddc251b3cf95b0097b6a5ee39ea132bd4d7d5cbcjohanengelen * Creates a wrapper around an iframe. It loads the content either from a local
ddc251b3cf95b0097b6a5ee39ea132bd4d7d5cbcjohanengelen * file or from script and creates a local YUI instance bound to that new window and document.
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * @class Frame
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * @for Frame
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * @extends Base
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * @constructor
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm var Frame = function() {
04c99c338ffdc6e10cb6f5c18f6f06b3f555e8ebcilix * @property _ready
04c99c338ffdc6e10cb6f5c18f6f06b3f555e8ebcilix * @description Internal reference set when the content is ready.
04c99c338ffdc6e10cb6f5c18f6f06b3f555e8ebcilix * @type Boolean
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * @private
d9c673867f424647c1586c356cc0ac1d34d0a98ajohanengelen * @property _rendered
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * @description Internal reference set when render is called.
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * @type Boolean
ddc251b3cf95b0097b6a5ee39ea132bd4d7d5cbcjohanengelen * @property _iframe
ddc251b3cf95b0097b6a5ee39ea132bd4d7d5cbcjohanengelen * @description Internal Node reference to the iFrame or the window
ddc251b3cf95b0097b6a5ee39ea132bd4d7d5cbcjohanengelen * @type Node
dc98accfae7a38326b92d74fa4330ac8ccb5b778jfbarraud * @property _instance
dc98accfae7a38326b92d74fa4330ac8ccb5b778jfbarraud * @description Internal reference to the YUI instance bound to the iFrame or window
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * @type YUI
c169f6cddd2da06cfb761339f445bbd8866f72a8buliabyak * @method _create
0563fd55cbad59e8a878e6d4cbbdd8e47f74488djohanengelen * @description Create the iframe or Window and get references to the Document & Window
0cc5b8d2f7b87c4222ee3662071bef1cb1f22b06bgk * @return {Object} Hash table containing references to the new Document & Window
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm extra_css = ((this.get('extracss')) ? '<style id="extra_css">' + this.get('extracss') + '</style>' : '');
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm Y.log('Creating the document from javascript', 'info', 'frame');
0cc5b8d2f7b87c4222ee3662071bef1cb1f22b06bgk Y.log('DocType skipped because we are in BackCompat Mode.', 'warn', 'frame');
b0c42c0dfcd02cc05126371948489a5a88b2e4b3cilix Y.log('Injecting content into iframe', 'info', 'frame');
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm Y.log('document.documentElement was not found, running timer', 'warn', 'frame');
92fe3142613d000eff89db8a983b3b18b14eee79johanengelen Y.log('document.documentElement found inside timer', 'info', 'frame');
42e99769805c14a5cc01c805faa3c3b03f9dd1c0johanengelen }, null, true);
92fe3142613d000eff89db8a983b3b18b14eee79johanengelen Y.log('document.documentElement found', 'info', 'frame');
dc98accfae7a38326b92d74fa4330ac8ccb5b778jfbarraud * @method _resolveWinDoc
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * @description Resolves the document and window from an iframe or window instance
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * @param {Object} c The YUI Config to add the window and document to
92fe3142613d000eff89db8a983b3b18b14eee79johanengelen * @return {Object} Object hash of window and document references, if a YUI config was passed, it is returned.
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm _resolveWinDoc: function(c) {
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm var config = (c) ? c : {};
92fe3142613d000eff89db8a983b3b18b14eee79johanengelen config.win = Y.Node.getDOMNode(this._iframe.get('contentWindow'));
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm config.doc = Y.Node.getDOMNode(this._iframe.get('contentWindow.document'));
92fe3142613d000eff89db8a983b3b18b14eee79johanengelen * @method _onDomEvent
8d9f5d586a04809427ce1df284a5720112177991cilix * @description Generic handler for all DOM events fired by the iframe or window. This handler
70eb1fc448cb08acf3468f80fa2296c03b32afd2cilix * takes the current EventFacade and augments it to fire on the Frame host. It adds two new properties
92fe3142613d000eff89db8a983b3b18b14eee79johanengelen * to the EventFacade called frameX and frameY which adds the scroll and xy position of the iframe
70eb1fc448cb08acf3468f80fa2296c03b32afd2cilix * to the original pageX and pageY of the event so external nodes can be positioned over the frame.
c169f6cddd2da06cfb761339f445bbd8866f72a8buliabyak * @param {Event.Facade} e
c169f6cddd2da06cfb761339f445bbd8866f72a8buliabyak _onDomEvent: function(e) {
6f4a90e526af850ffc36064f58f09c190f3b633fjohanengelen //Y.log('onDOMEvent: ' + e.type, 'info', 'frame');
b320a8d186114a5122ddc3afbe95110eb6cb10cecilix initializer: function() {
61cfd957cd023c4f432ea0c7307784a56bf978e9cilix destructor: function() {
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * @private
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * @method _DOMPaste
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * @description Simple pass thru handler for the paste event so we can do content cleanup
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * @param {Event.Facade} e
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm _DOMPaste: function(e) {
6656f193fdace606d1b162d6dea0223bc295f0a6cilix // Verify failure
71146abe8aba032d73788a625fee5769a581bd3ccilix getData: function() {
9ce14357bb94b9dd92ad40bf43ef435a257b355acilix Y.log('Failed to collect clipboard data', 'warn', 'frame');
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * @private
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * @method _defReadyFn
eaa9bdc7bf7b73397e536edd47490d84e4420bd8bryce * @description Binds DOM events, sets the iframe to visible and fires the ready event
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm _defReadyFn: function() {
c90010388b0d4045c26e81c2be28beedcb36c7d3cilix //Y.each(inst.Node.DOM_EVENTS, function(v, k) {
77a4a003111bd5cfb771d4849801c898aeb889b0cilix if (v === 1) {
77a4a003111bd5cfb771d4849801c898aeb889b0cilix //Y.log('Adding DOM event to frame: ' + k, 'info', 'frame');
23d859f2ce09c04ed802cb4912cc9c50f512f0a2bgk inst.on('paste', Y.bind(this._DOMPaste, this), inst.one('body'));
23d859f2ce09c04ed802cb4912cc9c50f512f0a2bgk //Adding focus/blur to the window object
77a4a003111bd5cfb771d4849801c898aeb889b0cilix * @method _onContentReady
77a4a003111bd5cfb771d4849801c898aeb889b0cilix * @description Called once the content is available in the frame/window and calls the final use call
77a4a003111bd5cfb771d4849801c898aeb889b0cilix * on the internal instance so that the modules are loaded properly.
77a4a003111bd5cfb771d4849801c898aeb889b0cilix _onContentReady: function(e) {
77a4a003111bd5cfb771d4849801c898aeb889b0cilix if (!this._ready) {
77a4a003111bd5cfb771d4849801c898aeb889b0cilix this._ready = true;
23d859f2ce09c04ed802cb4912cc9c50f512f0a2bgk Y.log('On available for body of iframe', 'info', 'frame');
97a20864afec63a0b7bb757b628ee2ae596cf648cilix //TODO Circle around and deal with CSS loading...
97a20864afec63a0b7bb757b628ee2ae596cf648cilix Y.log('Callback from final internal use call', 'info', 'frame');
97a20864afec63a0b7bb757b628ee2ae596cf648cilix inst.Selection.DEFAULT_BLOCK_TAG = this.get('defaultblock');
77a4a003111bd5cfb771d4849801c898aeb889b0cilix Y.log('Calling use on internal instance: ' + args, 'info', 'frame');
77a4a003111bd5cfb771d4849801c898aeb889b0cilix inst.one('doc').get('documentElement').addClass('yui-js-enabled');
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * @private
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * @method _resolveBaseHref
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * @description Resolves the basehref of the page the frame is created on. Only applies to dynamic content.
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * @param {String} href The new value to use, if empty it will be resolved from the current url.
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * @return {String}
a2fbdfc8e80d3d1845bf0d5df989726ae2ffd5bfjohanengelen if (href.indexOf('?') !== -1) { //Remove the query string
46c4893a7458eda6edcd064121bc000634af7a09johanengelen * @method _getHTML
46c4893a7458eda6edcd064121bc000634af7a09johanengelen * @description Get the content from the iframe
46c4893a7458eda6edcd064121bc000634af7a09johanengelen * @param {String} html The raw HTML from the body of the iframe.
46c4893a7458eda6edcd064121bc000634af7a09johanengelen * @return {String}
46c4893a7458eda6edcd064121bc000634af7a09johanengelen * @method _setHTML
46c4893a7458eda6edcd064121bc000634af7a09johanengelen * @description Set the content of the iframe
46c4893a7458eda6edcd064121bc000634af7a09johanengelen * @param {String} html The raw HTML to set the body of the iframe to.
46c4893a7458eda6edcd064121bc000634af7a09johanengelen * @return {String}
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm if (this._ready) {
ecda720053ff791e35dae3c5c1177bc225b6cdf1johanengelen //This needs to be wrapped in a contentready callback for the !_ready state
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm }, this, html));
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen * @method _setLinkedCSS
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen * @description Set's the linked CSS on the instance..
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen if (v !== '') {
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen str += '<link rel="stylesheet" href="' + v + '" type="text/css">';
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * @method _setLinkedCSS
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen * @description Set's the linked CSS on the instance..
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * @private
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * @method _setExtraCSS
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * @description Set's the extra CSS on the instance..
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm if (this._ready) {
5be124ad592f5c71eca838ad2eaac9ffa953605fcilix inst.one('head').append('<style id="extra_css">' + css + '</style>');
5be124ad592f5c71eca838ad2eaac9ffa953605fcilix * @method _instanceLoaded
5be124ad592f5c71eca838ad2eaac9ffa953605fcilix * @description Called from the first YUI instance that sets up the internal instance.
5be124ad592f5c71eca838ad2eaac9ffa953605fcilix * This loads the content into the window/frame and attaches the contentready event.
5be124ad592f5c71eca838ad2eaac9ffa953605fcilix * @param {YUI} inst The internal YUI instance bound to the frame/window
73d455c08e8062e257dd052d2d690b9300434351cilix //Force other browsers into non CSS styling
1e944d29efb206f5d0b5d1069cb098e22169d548cilix } catch (err) {}
79d46cc367c4181803d9a7a327b163643f23e8a7cilix //BEGIN PUBLIC METHODS
5ce8d034d9fe78f969629cfe65d1a2518f173ba9cilix * @method use
5ce8d034d9fe78f969629cfe65d1a2518f173ba9cilix * @description This is a scoped version of the normal YUI.use method & is bound to this frame/window.
1e944d29efb206f5d0b5d1069cb098e22169d548cilix * At setup, the inst.use method is mapped to this method.
73d455c08e8062e257dd052d2d690b9300434351cilix use: function() {
73d455c08e8062e257dd052d2d690b9300434351cilix Y.log('Calling augmented use after ready', 'info', 'frame');
147c8e03bb214f85cd5906ddc6413c4293c4baa9cilix Y.log('Internal callback from augmented use', 'info', 'frame');
732fb09f9c502000068a77667c3356cbbd5d39d5cilix * @method delegate
732fb09f9c502000068a77667c3356cbbd5d39d5cilix * @description A delegate method passed to the instance's delegate method
732fb09f9c502000068a77667c3356cbbd5d39d5cilix * @param {String} type The type of event to listen for
732fb09f9c502000068a77667c3356cbbd5d39d5cilix * @param {Function} fn The method to attach
732fb09f9c502000068a77667c3356cbbd5d39d5cilix * @param {String} cont The container to act as a delegate, if no "sel" passed, the body is assumed as the container.
732fb09f9c502000068a77667c3356cbbd5d39d5cilix * @param {String} sel The selector to match in the event (optional)
732fb09f9c502000068a77667c3356cbbd5d39d5cilix * @return {EventHandle} The Event handle returned from Y.delegate
04c99c338ffdc6e10cb6f5c18f6f06b3f555e8ebcilix Y.log('Delegate events can not be attached until after the ready event has fired.', 'error', 'iframe');
04c99c338ffdc6e10cb6f5c18f6f06b3f555e8ebcilix return false;
73d455c08e8062e257dd052d2d690b9300434351cilix * @method getInstance
73d455c08e8062e257dd052d2d690b9300434351cilix * @description Get a reference to the internal YUI instance.
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * @return {YUI} The internal YUI instance
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm getInstance: function() {
c0cd5511d3b975ebe07d019c1f5528108725e438johanengelen * @method render
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * @description Render the iframe into the container config option or open the window.
c0cd5511d3b975ebe07d019c1f5528108725e438johanengelen * @param {String/HTMLElement/Node} node The node to render to
c0cd5511d3b975ebe07d019c1f5528108725e438johanengelen * @return {Y.Frame}
c0cd5511d3b975ebe07d019c1f5528108725e438johanengelen * @chainable
c0cd5511d3b975ebe07d019c1f5528108725e438johanengelen Y.log('Frame already rendered.', 'warn', 'frame');
c0cd5511d3b975ebe07d019c1f5528108725e438johanengelen return this;
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm Y.log('Internal instance loaded with node-base', 'info', 'frame');
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm Y.log('New Modules Loaded into main instance', 'info', 'frame');
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm inst.log = Y.log; //Dump the instance logs to the parent instance.
56542e2b97ec8826cc692153b0e2d4f5ac8ef913johanengelen Y.log('Creating new internal instance with node-base only', 'info', 'frame');
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen } catch (e) {
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen Y.log('[TIMER] Internal use call failed, retrying', 'info', 'frame');
93bb287e28a818fd5ba61b99d012e0500a49ccf6johanengelen Y.log('Internal use call failed, retrying', 'info', 'frame');
56542e2b97ec8826cc692153b0e2d4f5ac8ef913johanengelen Y.log('Adding new modules to main instance: ' + args, 'info', 'frame');
af8d25189f88abf89cdbe0e180e271c94079624fbuliabyak return this;
a0334366488989ef25fb812d7030d298c0917c96johanengelen * @method _handleFocus
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen * @description Does some tricks on focus to set the proper cursor position.
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen * @method focus
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen * @description Set the focus to the iframe
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen * @param {Function} fn Callback function to execute after focus happens
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen * @return {Frame}
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen * @chainable
fb5a72174252e0e79107dcad3bf5a2bbd73e349cjohanengelen if (fn === true) {
42e99769805c14a5cc01c805faa3c3b03f9dd1c0johanengelen if (fn === true) {
ddc251b3cf95b0097b6a5ee39ea132bd4d7d5cbcjohanengelen return this;
bdd7add6c064afee52d2eabeaa18f745430e5a4djohanengelen * @method show
ddc251b3cf95b0097b6a5ee39ea132bd4d7d5cbcjohanengelen * @description Show the iframe instance
ddc251b3cf95b0097b6a5ee39ea132bd4d7d5cbcjohanengelen * @return {Frame}
42e99769805c14a5cc01c805faa3c3b03f9dd1c0johanengelen * @chainable
42ba1b712b7b430669fc49aa9facb439181081becilix show: function() {
42ba1b712b7b430669fc49aa9facb439181081becilix } catch (e) { }
42ba1b712b7b430669fc49aa9facb439181081becilix return this;
42ba1b712b7b430669fc49aa9facb439181081becilix * @method hide
42ba1b712b7b430669fc49aa9facb439181081becilix * @description Hide the iframe instance
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * @return {Frame}
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * @chainable
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm hide: function() {
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm return this;
DOM_EVENTS: {
//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: 'body { 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; }',
//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" 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}"/>{LINKED_CSS}<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;
linkedcss: {
extracss: {
host: {
value: false
defaultblock: {