editor-debug.js revision 15e7d5bd8a8fb4068cc8df277bb857b83a0891f5
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass * Creates a wrapper around an iframe. It loads the content either from a local
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass * file or from script and creates a local YUI instance bound to that new window and document.
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass * @module editor
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass * @submodule frame
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass * Creates a wrapper around an iframe. It loads the content either from a local
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass * file or from script and creates a local YUI instance bound to that new window and document.
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass * @class Frame
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass * @for Frame
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass * @extends Base
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass * @constructor
6dbc2e0b2c23ae7763959af9762fc50c84dbd937Dav Glass var Frame = function() {
6dbc2e0b2c23ae7763959af9762fc50c84dbd937Dav Glass Frame.superclass.constructor.apply(this, arguments);
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass * @property _ready
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass * @description Internal reference set when the content is ready.
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass * @type Boolean
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass * @property _rendered
203b6bcd7107c4154d94395e7664a89ba4145deeDav Glass * @description Internal reference set when render is called.
203b6bcd7107c4154d94395e7664a89ba4145deeDav Glass * @type Boolean
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass * @property _iframe
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass * @description Internal Node reference to the iFrame or the window
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass * @type Node
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass * @property _instance
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass * @description Internal reference to the YUI instance bound to the iFrame or window
0db84e0da684308b0fd9ea9b5906c11bafa7a246Dav Glass * @method _create
0db84e0da684308b0fd9ea9b5906c11bafa7a246Dav Glass * @description Create the iframe or Window and get references to the Document & Window
0db84e0da684308b0fd9ea9b5906c11bafa7a246Dav Glass * @return {Object} Hash table containing references to the new Document & Window
0db84e0da684308b0fd9ea9b5906c11bafa7a246Dav Glass _create: function() {
0db84e0da684308b0fd9ea9b5906c11bafa7a246Dav Glass * @method _resolveWinDoc
0db84e0da684308b0fd9ea9b5906c11bafa7a246Dav Glass * @description Resolves the document and window from an iframe or window instance
0db84e0da684308b0fd9ea9b5906c11bafa7a246Dav Glass * @param {Object} c The YUI Config to add the window and document to
0db84e0da684308b0fd9ea9b5906c11bafa7a246Dav Glass * @return {Object} Object hash of window and document references, if a YUI config was passed, it is returned.
0db84e0da684308b0fd9ea9b5906c11bafa7a246Dav Glass _resolveWinDoc: function(c) {
0db84e0da684308b0fd9ea9b5906c11bafa7a246Dav Glass var config = (c) ? c : {};
0db84e0da684308b0fd9ea9b5906c11bafa7a246Dav Glass config.win = Y.Node.getDOMNode(this._iframe.get('contentWindow'));
0db84e0da684308b0fd9ea9b5906c11bafa7a246Dav Glass config.doc = Y.Node.getDOMNode(this._iframe.get('contentWindow.document'));
162527ab925c04aa8d6bbf78d0484a133a8076f1Dav Glass * @method _onDomEvent
162527ab925c04aa8d6bbf78d0484a133a8076f1Dav Glass * @description Generic handler for all DOM events fired by the iframe or window. This handler
162527ab925c04aa8d6bbf78d0484a133a8076f1Dav Glass * takes the current EventFacade and augments it to fire on the Frame host. It adds two new properties
162527ab925c04aa8d6bbf78d0484a133a8076f1Dav Glass * to the EventFacade called frameX and frameY which adds the scroll and xy position of the iframe
6dbc2e0b2c23ae7763959af9762fc50c84dbd937Dav Glass * to the original pageX and pageY of the event so external nodes can be positioned over the frame.
162527ab925c04aa8d6bbf78d0484a133a8076f1Dav Glass * @param {Event.Facade} e
6dbc2e0b2c23ae7763959af9762fc50c84dbd937Dav Glass _onDomEvent: function(e) {
6dbc2e0b2c23ae7763959af9762fc50c84dbd937Dav Glass //Y.log('onDOMEvent: ' + e.type, 'info', 'frame');
6dbc2e0b2c23ae7763959af9762fc50c84dbd937Dav Glass e.frameX = xy[0] + e.pageX - node.get('scrollLeft');
6dbc2e0b2c23ae7763959af9762fc50c84dbd937Dav Glass e.frameY = xy[1] + e.pageY - node.get('scrollTop');
6dbc2e0b2c23ae7763959af9762fc50c84dbd937Dav Glass //TODO: Not sure why this stopped working!!!
6dbc2e0b2c23ae7763959af9762fc50c84dbd937Dav Glass }, this, e),
6dbc2e0b2c23ae7763959af9762fc50c84dbd937Dav Glass initializer: function() {
6dbc2e0b2c23ae7763959af9762fc50c84dbd937Dav Glass destructor: function() {
6dbc2e0b2c23ae7763959af9762fc50c84dbd937Dav Glass _DOMPaste: function(e) {
6dbc2e0b2c23ae7763959af9762fc50c84dbd937Dav Glass // Verify failure
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass getData: function() {
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass Y.log('Failed to collect clipboard data', 'warn', 'frame');
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass * @method _defReadyFn
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass * @description Binds DOM events, sets the iframe to visible and fires the ready event
0523d0a8daaa474f0214203f8cbb0bc4a88e2964Dav Glass _defReadyFn: function() {
216633e2ad28e9568a902f3763c3bef052c5f908Dav Glass if (v === 1) {
aa2ac226ad6e45232f8416eecc99d2165ce74d03Dav Glass if (k !== 'focus' && k !== 'blur' && k !== 'paste') {
5432371fbb6d790a76159481f0dd16e806812153Dav Glass Y.log('Adding DOM event to frame: ' + k, 'info', 'frame');
5432371fbb6d790a76159481f0dd16e806812153Dav Glass inst.on('paste', Y.bind(this._DOMPaste, this), inst.one('body'));
5432371fbb6d790a76159481f0dd16e806812153Dav Glass //Adding focus/blur to the window object
5432371fbb6d790a76159481f0dd16e806812153Dav Glass * @method _onContentReady
5432371fbb6d790a76159481f0dd16e806812153Dav Glass * @description Called once the content is available in the frame/window and calls the final use call
f7aa62ea2e8cf43fbb9d83db5060db540ff1893fDav Glass * on the internal instance so that the modules are loaded properly.
f7aa62ea2e8cf43fbb9d83db5060db540ff1893fDav Glass _onContentReady: function(e) {
f7aa62ea2e8cf43fbb9d83db5060db540ff1893fDav Glass if (!this._ready) {
6dbc2e0b2c23ae7763959af9762fc50c84dbd937Dav Glass this._ready = true;
f7aa62ea2e8cf43fbb9d83db5060db540ff1893fDav Glass Y.log('On available for body of iframe', 'info', 'frame');
f7aa62ea2e8cf43fbb9d83db5060db540ff1893fDav Glass //TODO Circle around and deal with CSS loading...
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass Y.log('Callback from final internal use call', 'info', 'frame');
96c1e6aab172b57cf3566abee931c26676990044Dav Glass Y.log('Calling use on internal instance: ', 'info', 'frame');
96c1e6aab172b57cf3566abee931c26676990044Dav Glass inst.one('doc').get('documentElement').addClass('yui-js-enabled');
96c1e6aab172b57cf3566abee931c26676990044Dav Glass * @method _resolveBaseHref
96c1e6aab172b57cf3566abee931c26676990044Dav Glass * @description Resolves the basehref of the page the frame is created on. Only applies to dynamic content.
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass * @param {String} href The new value to use, if empty it will be resolved from the current url.
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass * @return {String}
0db84e0da684308b0fd9ea9b5906c11bafa7a246Dav Glass if (href.indexOf('?') !== -1) { //Remove the query string
0db84e0da684308b0fd9ea9b5906c11bafa7a246Dav Glass href = href.substring(0, href.lastIndexOf('/')) + '/';
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass * @method _getHTML
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass * @description Get the content from the iframe
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass * @param {String} html The raw HTML from the body of the iframe.
162527ab925c04aa8d6bbf78d0484a133a8076f1Dav Glass * @return {String}
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass * @method _setHTML
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass * @description Set the content of the iframe
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass * @param {String} html The raw HTML to set the body of the iframe to.
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass * @return {String}
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass //This needs to be wrapped in a contentready callback for the !_ready state
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass this.on('contentready', Y.bind(function(html, e) {
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass * @method _setExtraCSS
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass * @description Set's the extra CSS on the instance..
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass inst.one('head').append('<style id="extra_css">' + css + '</style>');
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass * @method _instanceLoaded
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass * @description Called from the first YUI instance that sets up the internal instance.
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass * This loads the content into the window/frame and attaches the contentready event.
d0bccce76452becc96b65acaaa684aa6fabaf386Dav Glass * @param {YUI} inst The internal YUI instance bound to the frame/window
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass this._instance.on('contentready', Y.bind(this._onContentReady, this), 'body');
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass extra_css = ((this.get('extracss')) ? '<style id="extra_css">' + this.get('extracss') + '</style>' : ''),
d2a5a45ff58ab15a8ee0339edcd03f0243373d59Dav Glass Y.log('Creating the document from javascript', 'info', 'frame');
} 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) {
Y.log('Delegate events can not be attached until after the ready event has fired.', 'error', 'iframe');
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
Y.Selection = function() {
if (this.isCollapsed) {
if (ieNode) {
this.anchorOffset = this.focusOffset = (this.anchorNode.nodeValue) ? this.anchorNode.nodeValue.length : 0 ;
* Performs a prefilter on all nodes in the editor. Looks for nodes with a style: fontFamily or font face
* It then creates a dynamic class assigns it and removed the property. This is so that we don't lose
ls;
v.remove();
if (blocks) {
* Method attempts to replace all "orphined" text nodes in the main body by wrapping them with a <p>. Called from filter.
if (childs) {
doit = true;
doit = false;
if (doit) {
if (!wrapped) {
wrapped = [];
p.remove();
d.remove();
if (wrapped) {
n.remove();
return html;
n = n.parentNode;
return Y.one(n);
text: null,
isCollapsed: null,
anchorNode: null,
anchorOffset: null,
anchorTextNode: null,
focusNode: null,
focusOffset: null,
focusTextNode: null,
_selection: null,
getSelected: function() {
items = [];
* Insert HTML at the current cursor position and return a Node instance of the newly inserted element.
* Insert HTML at the current cursor position, this method gives you control over the text node to insert into and the offset where to put it.
var cur = Y.Node.create('<' + Y.Selection.DEFAULT_TAG + ' class="yui-non"></' + Y.Selection.DEFAULT_TAG + '>'),
node = b;
if (inHTML) {
return newNode;
newNode = b;
return newNode;
* Get all elements inside a selection and wrap them with a new element and return a NodeList of all elements touched.
if (!this.isCollapsed) {
return changed;
return Y.all([]);
return newNode;
remove: function() {
createRange: function() {
if (collapse) {
} catch (err) {
if (collapse) {
setCursor: function() {
getCursor: function() {
* @param {Boolean} keep Setting this to true will keep the node, but remove the unique parts that make it the cursor.
if (cur) {
if (keep) {
return cur;
if (collapse !== false) {
collapse = true;
if (end !== false) {
end = true;
if (cur) {
toString: function() {
var ExecCommand = function() {
_inst: null,
if (fn) {
getInstance: function() {
if (!this._inst) {
return this._inst;
initializer: function() {
ATTRS: {
host: {
value: false
COMMANDS: {
return out;
n = this.command('inserthtml', '<span style="background-color: ' + val + '">' + inst.Selection.CURSOR + '</span>');
n = this.command('inserthtml', '<span style="background-color: ' + val + '"><span> </span> </span>');
hilitecolor: function() {
n = this.command('inserthtml', '<span style="font-family: ' + val + '">' + inst.Selection.CURSOR + '</span>');
var EditorTab = function() {
_onNodeChange: function(e) {
e.preventDefault();
initializer: function() {
ATTRS: {
host: {
value: false
* Adds prompt style link creation. Adds an override for the <a href="Plugin.ExecCommand.html#method_COMMANDS.createlink">createlink execCommand</a>.
* Adds prompt style link creation. Adds an override for the <a href="Plugin.ExecCommand.html#method_COMMANDS.createlink">createlink execCommand</a>.
var CreateLinkBase = {};
* Override for the createlink method from the <a href="Plugin.CreateLinkBase.html">CreateLinkBase</a> plugin.
if (url) {
* Base class for Editor. Handles the business logic of Editor, no GUI involved only utility methods and events.
* Base class for Editor. Handles the business logic of Editor, no GUI involved only utility methods and events.
var EditorBase = function() {
frame: null,
initializer: function() {
designMode: true,
host: this
emitFacade: true,
bubbles: true,
destructor: function() {
this.detachAll();
newStyles = {};
_defNodeChangeFn: function(e) {
switch (e.changedType) {
if (prev) {
while (!found) {
if (lc) {
if (lc2) {
found = true;
found = true;
if (lc) {
if (e.commands) {
if (cmd) {
if (family2) {
if (!e.fontFamily) {
if (!e.fontSize) {
if (!e.fontColor) {
if (!e.backgroundColor) {
var domPath = [],
while (node !== null) {
node = null;
node = null;
node = null;
_afterFrameReady: function() {
_onFrameMouseDown: function(e) {
_onFrameKeyUp: function(e) {
this.fire('nodeChange', { changedNode: sel.anchorNode, changedType: 'keyup', selection: sel, changedEvent: e });
this.fire('nodeChange', { changedNode: sel.anchorNode, changedType: EditorBase.NC_KEYS[e.keyCode] + '-up', selection: sel, changedEvent: e });
_onFrameKeyDown: function(e) {
this.fire('nodeChange', { changedNode: sel.anchorNode, changedType: EditorBase.NC_KEYS[e.keyCode], changedEvent: e });
this.fire('nodeChange', { changedNode: sel.anchorNode, changedType: EditorBase.NC_KEYS[e.keyCode] + '-down', changedEvent: e });
_onFrameKeyPress: function(e) {
this.fire('nodeChange', { changedNode: sel.anchorNode, changedType: EditorBase.NC_KEYS[e.keyCode] + '-press', changedEvent: e });
* @return {Node/NodeList} The Node or Nodelist affected by the command. Only returns on override commands, not browser defined commands.
switch (cmd) {
return ret;
getInstance: function() {
* @param {Selector/HTMLElement/Node} node The node to append the Editor to
show: function() {
hide: function() {
getContent: function() {
return html;
* @description Converts an RGB color string to a hex color, example: rgb(0, 255, 0) converts to #00ff00
var exp = new RegExp("(.*?)rgb\\s*?\\(\\s*?([0-9]+).*?,\\s*?([0-9]+).*?,\\s*?([0-9]+).*?\\)(.*?)", "gi");
return css;
TAG2CMD: {
NC_KEYS: {
STRINGS: {
ATTRS: {
content: {
getter: function() {
dir: {
writeOnce: true,
extracss: {
value: false,
if (this.frame) {
return css;
* <dt>changedType</dt><dd>The type of change: mousedown, mouseup, right, left, backspace, tab, enter, etc..</dd>
* <dt>commands</dt><dd>The list of execCommands that belong to this change and the dompath that's associated with the changedNode</dd>
* <dt>classNames</dt><dd>An array of classNames that are applied to the changedNode and all of it's parents</dd>
* <dt>dompath</dt><dd>A sorted array of node instances that make up the DOM path from the changedNode to body.</dd>
* Handles list manipulation inside the Editor. Adds keyboard manipulation and execCommand support. Adds overrides for the <a href="Plugin.ExecCommand.html#method_COMMANDS.insertorderedlist">insertorderedlist</a> and <a href="Plugin.ExecCommand.html#method_COMMANDS.insertunorderedlist">insertunorderedlist</a> execCommands.
* Handles list manipulation inside the Editor. Adds keyboard manipulation and execCommand support. Adds overrides for the <a href="Plugin.ExecCommand.html#method_COMMANDS.insertorderedlist">insertorderedlist</a> and <a href="Plugin.ExecCommand.html#method_COMMANDS.insertunorderedlist">insertunorderedlist</a> execCommands.
var EditorLists = function() {
* Listener for host's nodeChange event and captures the tabkey interaction only when inside a list node.
_onNodeChange: function(e) {
e.preventDefault();
e.preventDefault();
if (sTab) {
moved = true;
moved = true;
if (moved) {
initializer: function() {
ATTRS: {
host: {
value: false
* Override for the insertunorderedlist method from the <a href="Plugin.EditorLists.html">EditorLists</a> plugin.
return out;
* Override for the insertorderedlist method from the <a href="Plugin.EditorLists.html">EditorLists</a> plugin.
return out;
var EditorBidi = function() {
lastDirection: null,
firstEvent: null,
_checkForChange: function() {
this.lastDirection = null;
_afterNodeChange: function(e) {
this._checkForChange();
this.firstEvent = false;
_afterMouseUp: function(e) {
this._checkForChange();
this.firstEvent = false;
_fixFirstPara: function() {
_onNodeChange: function(e) {
switch (e.changedType) {
this._fixFirstPara();
this._fixFirstPara();
_afterEditorReady: function() {
if (inst) {
_afterContentChange: function() {
if (inst) {
_afterPaste: function() {
initializer: function() {
this.firstEvent = true;
EVENTS: {
if (!parent) {
return parent;
addParent = true;
addParent = false;
if (addParent) {
return nodeArray;
ATTRS: {
host: {
value: false
selectedBlocks = [];
return returnValue;