editor-debug.js revision b7bd9aa409761c479bb0a2e5794295d35ebe24ea
8346e283ad797ef549be70335d3961f4324901baRyan Grove * Creates a wrapper around an iframe. It loads the content either from a local
8346e283ad797ef549be70335d3961f4324901baRyan Grove * file or from script and creates a local YUI instance bound to that new window and document.
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * @module editor
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * @submodule frame
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * Creates a wrapper around an iframe. It loads the content either from a local
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * file or from script and creates a local YUI instance bound to that new window and document.
8346e283ad797ef549be70335d3961f4324901baRyan Grove * @class Frame
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * @for Frame
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * @extends Base
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * @constructor
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney var Frame = function() {
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney Frame.superclass.constructor.apply(this, arguments);
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * @property _ready
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * @description Internal reference set when the content is ready.
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * @type Boolean
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * @property _rendered
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * @description Internal reference set when render is called.
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * @type Boolean
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * @property _iframe
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * @description Internal Node reference to the iFrame or the window
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * @type Node
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * @property _instance
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * @description Internal reference to the YUI instance bound to the iFrame or window
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * @method _create
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * @description Create the iframe or Window and get references to the Document & Window
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * @return {Object} Hash table containing references to the new Document & Window
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney _create: function() {
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * @method _resolveWinDoc
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * @description Resolves the document and window from an iframe or window instance
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * @param {Object} c The YUI Config to add the window and document to
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * @return {Object} Object hash of window and document references, if a YUI config was passed, it is returned.
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney var config = (c) ? c : {};
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney config.win = Y.Node.getDOMNode(this._iframe.get('contentWindow'));
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney config.doc = Y.Node.getDOMNode(this._iframe.get('contentWindow.document'));
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * @method _onDomEvent
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * @description Generic handler for all DOM events fired by the iframe or window. This handler
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * takes the current EventFacade and augments it to fire on the Frame host. It adds two new properties
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * to the EventFacade called frameX and frameY which adds the scroll and xy position of the iframe
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * to the original pageX and pageY of the event so external nodes can be positioned over the frame.
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * @param {Event.Facade} e
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney _onDomEvent: function(e) {
d31dea0ecc7ccd7aed4754eeb5a4e36e063c8e84Luke Smith //Y.log('onDOMEvent: ' + e.type, 'info', 'frame');
d31dea0ecc7ccd7aed4754eeb5a4e36e063c8e84Luke Smith e.frameX = xy[0] + e.pageX - node.get('scrollLeft');
d31dea0ecc7ccd7aed4754eeb5a4e36e063c8e84Luke Smith e.frameY = xy[1] + e.pageY - node.get('scrollTop');
d31dea0ecc7ccd7aed4754eeb5a4e36e063c8e84Luke Smith //TODO: Not sure why this stopped working!!!
d31dea0ecc7ccd7aed4754eeb5a4e36e063c8e84Luke Smith }, this, e),
d31dea0ecc7ccd7aed4754eeb5a4e36e063c8e84Luke Smith destructor: function() {
d31dea0ecc7ccd7aed4754eeb5a4e36e063c8e84Luke Smith * @method _defReadyFn
d31dea0ecc7ccd7aed4754eeb5a4e36e063c8e84Luke Smith * @description Binds DOM events, sets the iframe to visible and fires the ready event
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney if (v === 1) {
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * @method _onContentReady
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * @description Called once the content is available in the frame/window and calls the final use call
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * on the internal instance so that the modules are loaded properly.
d31dea0ecc7ccd7aed4754eeb5a4e36e063c8e84Luke Smith Y.log('On available for body of iframe', 'info', 'frame');
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney //TODO Circle around and deal with CSS loading...
74570091844e16d76ff9ff7b8b2ec79fb9c6aa75Luke Smith Y.log('Callback from final internal use call', 'info', 'frame');
74570091844e16d76ff9ff7b8b2ec79fb9c6aa75Luke Smith Y.log('Calling use on internal instance: ', 'info', 'frame');
74570091844e16d76ff9ff7b8b2ec79fb9c6aa75Luke Smith inst.one('doc').get('documentElement').addClass('yui-js-enabled');
d31dea0ecc7ccd7aed4754eeb5a4e36e063c8e84Luke Smith * @method _resolveBaseHref
d31dea0ecc7ccd7aed4754eeb5a4e36e063c8e84Luke Smith * @description Resolves the basehref of the page the frame is created on. Only applies to dynamic content.
d31dea0ecc7ccd7aed4754eeb5a4e36e063c8e84Luke Smith * @param {String} href The new value to use, if empty it will be resolved from the current url.
74570091844e16d76ff9ff7b8b2ec79fb9c6aa75Luke Smith * @return {String}
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney if (href.indexOf('?') !== -1) { //Remove the query string
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney href = href.substring(0, href.lastIndexOf('/')) + '/';
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * @method _getHTML
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * @description Get the content from the iframe
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * @param {String} html The raw HTML from the body of the iframe.
8ff167b366d7ee96cfc801bb01cd93e3ce573cbfMatt Sweeney * @return {String}
d31dea0ecc7ccd7aed4754eeb5a4e36e063c8e84Luke Smith * @method _setHTML
d31dea0ecc7ccd7aed4754eeb5a4e36e063c8e84Luke Smith * @description Set the content of the iframe
d31dea0ecc7ccd7aed4754eeb5a4e36e063c8e84Luke Smith * @param {String} html The raw HTML to set the body of the iframe to.
d31dea0ecc7ccd7aed4754eeb5a4e36e063c8e84Luke Smith * @return {String}
d31dea0ecc7ccd7aed4754eeb5a4e36e063c8e84Luke Smith //This needs to be wrapped in a contentready callback for the !_ready state
d31dea0ecc7ccd7aed4754eeb5a4e36e063c8e84Luke Smith this.on('contentready', Y.bind(function(html, e) {
d31dea0ecc7ccd7aed4754eeb5a4e36e063c8e84Luke Smith * @method _setExtraCSS
d31dea0ecc7ccd7aed4754eeb5a4e36e063c8e84Luke Smith * @description Set's the extra CSS on the instance..
d31dea0ecc7ccd7aed4754eeb5a4e36e063c8e84Luke Smith inst.one('head').append('<style id="extra_css">' + css + '</style>');
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) {
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();
focus: function() {
} 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();
* 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 = [];
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;
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) {
if (collapse) {
setCursor: function() {
getCursor: function() {
focusCursor: function() {
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: {
bidi: function() {
return blockItem;
n = this.command('inserthtml', '<span style="background-color: ' + val + '"><span> </span> </span>');
hilitecolor: function() {
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 = {};
_fixFirstPara: function() {
} catch (er) {}
_defNodeChangeFn: function(e) {
switch (e.changedType) {
this._fixFirstPara();
this._fixFirstPara();
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
focus: function() {
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;