editor-base.js revision 2bbe3ca8cfbb948b9b6356ae16759f1d6245433c
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass /**
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * Base class for Editor. Handles the business logic of Editor, no GUI involved only utility methods and events.
09c638a157dd9d2ed9027215d9e254badfa019b8Dav Glass *
09c638a157dd9d2ed9027215d9e254badfa019b8Dav Glass * var editor = new Y.EditorBase({
09c638a157dd9d2ed9027215d9e254badfa019b8Dav Glass * content: 'Foo'
09c638a157dd9d2ed9027215d9e254badfa019b8Dav Glass * });
09c638a157dd9d2ed9027215d9e254badfa019b8Dav Glass * editor.render('#demo');
09c638a157dd9d2ed9027215d9e254badfa019b8Dav Glass *
09c638a157dd9d2ed9027215d9e254badfa019b8Dav Glass * @main editor
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass */
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass /**
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * Base class for Editor. Handles the business logic of Editor, no GUI involved only utility methods and events.
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * @class EditorBase
daeb6d531149c45a2ceb543ae2cf1e56e5235bbeDav Glass * @for EditorBase
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * @extends Base
09c638a157dd9d2ed9027215d9e254badfa019b8Dav Glass * @module editor
09c638a157dd9d2ed9027215d9e254badfa019b8Dav Glass * @submodule editor-base
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * @constructor
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass */
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass var EditorBase = function() {
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass EditorBase.superclass.constructor.apply(this, arguments);
aa2ac226ad6e45232f8416eecc99d2165ce74d03Dav Glass }, LAST_CHILD = ':last-child', BODY = 'body';
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass Y.extend(EditorBase, Y.Base, {
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass /**
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * Internal reference to the Y.Frame instance
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * @property frame
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass */
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass frame: null,
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass initializer: function() {
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass var frame = new Y.Frame({
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass designMode: true,
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass title: EditorBase.STRINGS.title,
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass use: EditorBase.USE,
f69da96c272d2efe7f43da5150c13c0fe6899646Dav Glass dir: this.get('dir'),
56fa0b5ce00608c58c7c82cc5341c5fbf8898719Dav Glass extracss: this.get('extracss'),
c145dba89e51cac0a247d52f4f4c0c8d8245027dDav Glass linkedcss: this.get('linkedcss'),
162527ab925c04aa8d6bbf78d0484a133a8076f1Dav Glass defaultblock: this.get('defaultblock'),
56fa0b5ce00608c58c7c82cc5341c5fbf8898719Dav Glass host: this
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass }).plug(Y.Plugin.ExecCommand);
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass
162527ab925c04aa8d6bbf78d0484a133a8076f1Dav Glass
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass frame.after('ready', Y.bind(this._afterFrameReady, this));
fe442de8408a276919d26a1110e8121844b1ba11Dav Glass frame.addTarget(this);
9d0be4bedcaad945c505994577198223ffc4ed9eDav Glass
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass this.frame = frame;
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass this.publish('nodeChange', {
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass emitFacade: true,
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass bubbles: true,
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass defaultFn: this._defNodeChangeFn
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass });
a3d67a254e415c93408a9d4314e46e3cb7d87d99Dav Glass
0db84e0da684308b0fd9ea9b5906c11bafa7a246Dav Glass //this.plug(Y.Plugin.EditorPara);
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass },
b7bd9aa409761c479bb0a2e5794295d35ebe24eaDav Glass destructor: function() {
b7bd9aa409761c479bb0a2e5794295d35ebe24eaDav Glass this.frame.destroy();
b7bd9aa409761c479bb0a2e5794295d35ebe24eaDav Glass
b7bd9aa409761c479bb0a2e5794295d35ebe24eaDav Glass this.detachAll();
b7bd9aa409761c479bb0a2e5794295d35ebe24eaDav Glass },
b7bd9aa409761c479bb0a2e5794295d35ebe24eaDav Glass /**
b7bd9aa409761c479bb0a2e5794295d35ebe24eaDav Glass * Copy certain styles from one node instance to another (used for new paragraph creation mainly)
b7bd9aa409761c479bb0a2e5794295d35ebe24eaDav Glass * @method copyStyles
b7bd9aa409761c479bb0a2e5794295d35ebe24eaDav Glass * @param {Node} from The Node instance to copy the styles from
b7bd9aa409761c479bb0a2e5794295d35ebe24eaDav Glass * @param {Node} to The Node instance to copy the styles to
b7bd9aa409761c479bb0a2e5794295d35ebe24eaDav Glass */
f8b3e367f0b400ff8b4feeb35c56d9387a31f9e0Dav Glass copyStyles: function(from, to) {
a2cf1018c8c3c924dd3210ac6d5d796939a87876Dav Glass if (from.test('a')) {
a2cf1018c8c3c924dd3210ac6d5d796939a87876Dav Glass //Don't carry the A styles
a2cf1018c8c3c924dd3210ac6d5d796939a87876Dav Glass return;
a2cf1018c8c3c924dd3210ac6d5d796939a87876Dav Glass }
f8b3e367f0b400ff8b4feeb35c56d9387a31f9e0Dav Glass var styles = ['color', 'fontSize', 'fontFamily', 'backgroundColor', 'fontStyle' ],
f8b3e367f0b400ff8b4feeb35c56d9387a31f9e0Dav Glass newStyles = {};
f8b3e367f0b400ff8b4feeb35c56d9387a31f9e0Dav Glass
f8b3e367f0b400ff8b4feeb35c56d9387a31f9e0Dav Glass Y.each(styles, function(v) {
f8b3e367f0b400ff8b4feeb35c56d9387a31f9e0Dav Glass newStyles[v] = from.getStyle(v);
f8b3e367f0b400ff8b4feeb35c56d9387a31f9e0Dav Glass });
f8b3e367f0b400ff8b4feeb35c56d9387a31f9e0Dav Glass if (from.ancestor('b,strong')) {
f8b3e367f0b400ff8b4feeb35c56d9387a31f9e0Dav Glass newStyles.fontWeight = 'bold';
f8b3e367f0b400ff8b4feeb35c56d9387a31f9e0Dav Glass }
9b5e5f2ec4de2f405fbad1fc7c71325c84feb772Dav Glass if (from.ancestor('u')) {
9b5e5f2ec4de2f405fbad1fc7c71325c84feb772Dav Glass if (!newStyles.textDecoration) {
9b5e5f2ec4de2f405fbad1fc7c71325c84feb772Dav Glass newStyles.textDecoration = 'underline';
9b5e5f2ec4de2f405fbad1fc7c71325c84feb772Dav Glass }
9b5e5f2ec4de2f405fbad1fc7c71325c84feb772Dav Glass }
f8b3e367f0b400ff8b4feeb35c56d9387a31f9e0Dav Glass to.setStyles(newStyles);
f8b3e367f0b400ff8b4feeb35c56d9387a31f9e0Dav Glass },
b7bd9aa409761c479bb0a2e5794295d35ebe24eaDav Glass /**
fe442de8408a276919d26a1110e8121844b1ba11Dav Glass * Holder for the selection bookmark in IE.
fe442de8408a276919d26a1110e8121844b1ba11Dav Glass * @property _lastBookmark
fe442de8408a276919d26a1110e8121844b1ba11Dav Glass * @private
fe442de8408a276919d26a1110e8121844b1ba11Dav Glass */
fe442de8408a276919d26a1110e8121844b1ba11Dav Glass _lastBookmark: null,
aa2ac226ad6e45232f8416eecc99d2165ce74d03Dav Glass /**
aa2ac226ad6e45232f8416eecc99d2165ce74d03Dav Glass * Resolves the e.changedNode in the nodeChange event if it comes from the document. If
aa2ac226ad6e45232f8416eecc99d2165ce74d03Dav Glass * the event came from the document, it will get the last child of the last child of the document
aa2ac226ad6e45232f8416eecc99d2165ce74d03Dav Glass * and return that instead.
aa2ac226ad6e45232f8416eecc99d2165ce74d03Dav Glass * @method _resolveChangedNode
aa2ac226ad6e45232f8416eecc99d2165ce74d03Dav Glass * @param {Node} n The node to resolve
aa2ac226ad6e45232f8416eecc99d2165ce74d03Dav Glass * @private
aa2ac226ad6e45232f8416eecc99d2165ce74d03Dav Glass */
aa2ac226ad6e45232f8416eecc99d2165ce74d03Dav Glass _resolveChangedNode: function(n) {
883d785f73cff98fbe2fe00953621713c1489729Dav Glass var inst = this.getInstance(), lc, lc2, found;
6dbc2e0b2c23ae7763959af9762fc50c84dbd937Dav Glass if (inst && n && n.test('html')) {
883d785f73cff98fbe2fe00953621713c1489729Dav Glass lc = inst.one(BODY).one(LAST_CHILD);
aa2ac226ad6e45232f8416eecc99d2165ce74d03Dav Glass while (!found) {
aa2ac226ad6e45232f8416eecc99d2165ce74d03Dav Glass if (lc) {
aa2ac226ad6e45232f8416eecc99d2165ce74d03Dav Glass lc2 = lc.one(LAST_CHILD);
aa2ac226ad6e45232f8416eecc99d2165ce74d03Dav Glass if (lc2) {
aa2ac226ad6e45232f8416eecc99d2165ce74d03Dav Glass lc = lc2;
aa2ac226ad6e45232f8416eecc99d2165ce74d03Dav Glass } else {
aa2ac226ad6e45232f8416eecc99d2165ce74d03Dav Glass found = true;
aa2ac226ad6e45232f8416eecc99d2165ce74d03Dav Glass }
aa2ac226ad6e45232f8416eecc99d2165ce74d03Dav Glass } else {
aa2ac226ad6e45232f8416eecc99d2165ce74d03Dav Glass found = true;
aa2ac226ad6e45232f8416eecc99d2165ce74d03Dav Glass }
aa2ac226ad6e45232f8416eecc99d2165ce74d03Dav Glass }
aa2ac226ad6e45232f8416eecc99d2165ce74d03Dav Glass if (lc) {
aa2ac226ad6e45232f8416eecc99d2165ce74d03Dav Glass if (lc.test('br')) {
aa2ac226ad6e45232f8416eecc99d2165ce74d03Dav Glass if (lc.previous()) {
aa2ac226ad6e45232f8416eecc99d2165ce74d03Dav Glass lc = lc.previous();
aa2ac226ad6e45232f8416eecc99d2165ce74d03Dav Glass } else {
aa2ac226ad6e45232f8416eecc99d2165ce74d03Dav Glass lc = lc.get('parentNode');
aa2ac226ad6e45232f8416eecc99d2165ce74d03Dav Glass }
aa2ac226ad6e45232f8416eecc99d2165ce74d03Dav Glass }
aa2ac226ad6e45232f8416eecc99d2165ce74d03Dav Glass if (lc) {
aa2ac226ad6e45232f8416eecc99d2165ce74d03Dav Glass n = lc;
aa2ac226ad6e45232f8416eecc99d2165ce74d03Dav Glass }
aa2ac226ad6e45232f8416eecc99d2165ce74d03Dav Glass }
2bbe3ca8cfbb948b9b6356ae16759f1d6245433cDav Glass }
2bbe3ca8cfbb948b9b6356ae16759f1d6245433cDav Glass if (!n) {
2bbe3ca8cfbb948b9b6356ae16759f1d6245433cDav Glass //Fallback to make sure a node is attached to the event
2bbe3ca8cfbb948b9b6356ae16759f1d6245433cDav Glass n = inst.one(BODY);
aa2ac226ad6e45232f8416eecc99d2165ce74d03Dav Glass }
aa2ac226ad6e45232f8416eecc99d2165ce74d03Dav Glass return n;
aa2ac226ad6e45232f8416eecc99d2165ce74d03Dav Glass },
fe442de8408a276919d26a1110e8121844b1ba11Dav Glass /**
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * The default handler for the nodeChange event.
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * @method _defNodeChangeFn
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * @param {Event} e The event
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * @private
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass */
762b21413a7bbc38b5c7b2d94385fb44f26f9d39Dav Glass _defNodeChangeFn: function(e) {
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass var startTime = (new Date()).getTime();
e08067d50c8d5e4692441db53bba084c7a667e0aDav Glass //Y.log('Default nodeChange function: ' + e.changedType, 'info', 'editor');
f7aa62ea2e8cf43fbb9d83db5060db540ff1893fDav Glass var inst = this.getInstance(), sel, cur,
162527ab925c04aa8d6bbf78d0484a133a8076f1Dav Glass btag = inst.Selection.DEFAULT_BLOCK_TAG;
323ca860aba4b2515b560796e2322d5eaae57e5aDav Glass
fe442de8408a276919d26a1110e8121844b1ba11Dav Glass if (Y.UA.ie) {
3499692683cbc70ff10f1844350ff92b1d0eba3fDav Glass try {
3499692683cbc70ff10f1844350ff92b1d0eba3fDav Glass sel = inst.config.doc.selection.createRange();
3499692683cbc70ff10f1844350ff92b1d0eba3fDav Glass if (sel.getBookmark) {
3499692683cbc70ff10f1844350ff92b1d0eba3fDav Glass this._lastBookmark = sel.getBookmark();
3499692683cbc70ff10f1844350ff92b1d0eba3fDav Glass }
3499692683cbc70ff10f1844350ff92b1d0eba3fDav Glass } catch (ie) {}
fe442de8408a276919d26a1110e8121844b1ba11Dav Glass }
edefd42ddde54932d14d9150369570db47822ab5Dav Glass
aa2ac226ad6e45232f8416eecc99d2165ce74d03Dav Glass e.changedNode = this._resolveChangedNode(e.changedNode);
aa2ac226ad6e45232f8416eecc99d2165ce74d03Dav Glass
323ca860aba4b2515b560796e2322d5eaae57e5aDav Glass /*
323ca860aba4b2515b560796e2322d5eaae57e5aDav Glass * @TODO
323ca860aba4b2515b560796e2322d5eaae57e5aDav Glass * This whole method needs to be fixed and made more dynamic.
323ca860aba4b2515b560796e2322d5eaae57e5aDav Glass * Maybe static functions for the e.changeType and an object bag
323ca860aba4b2515b560796e2322d5eaae57e5aDav Glass * to walk through and filter to pass off the event to before firing..
323ca860aba4b2515b560796e2322d5eaae57e5aDav Glass */
323ca860aba4b2515b560796e2322d5eaae57e5aDav Glass
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass switch (e.changedType) {
edefd42ddde54932d14d9150369570db47822ab5Dav Glass case 'keydown':
1e2a941753ef897ca70f03b0c9803795357ad35dDav Glass if (!Y.UA.gecko) {
577da64a9f0680112357f6595f47bfcab32d9adbDav Glass if (!EditorBase.NC_KEYS[e.changedEvent.keyCode] && !e.changedEvent.shiftKey && !e.changedEvent.ctrlKey && (e.changedEvent.keyCode !== 13)) {
1f5da3ee0a7dfb278ab235231e5af6aad13326d4Dav Glass //inst.later(100, inst, inst.Selection.cleanCursor);
577da64a9f0680112357f6595f47bfcab32d9adbDav Glass }
1e2a941753ef897ca70f03b0c9803795357ad35dDav Glass }
edefd42ddde54932d14d9150369570db47822ab5Dav Glass break;
a2621d519886de7d60c30c5a0850f5c17fd2fb36Dav Glass case 'tab':
a2621d519886de7d60c30c5a0850f5c17fd2fb36Dav Glass if (!e.changedNode.test('li, li *') && !e.changedEvent.shiftKey) {
43e2f05871a8e99383b8c1d893d290cd978be81aDav Glass e.changedEvent.frameEvent.preventDefault();
762b21413a7bbc38b5c7b2d94385fb44f26f9d39Dav Glass Y.log('Overriding TAB key to insert HTML: HALTING', 'info', 'editor');
43e2f05871a8e99383b8c1d893d290cd978be81aDav Glass if (Y.UA.webkit) {
43e2f05871a8e99383b8c1d893d290cd978be81aDav Glass this.execCommand('inserttext', '\t');
b357b56da58949fa86ab8e56983972e0db5cbffbDav Glass } else if (Y.UA.gecko) {
d5c8641a4c8bb3bf024ae7fe517387163591d325Dav Glass this.frame.exec._command('inserthtml', EditorBase.TABKEY);
db62bb9907ff4ffe68df2dd2772e8e46f67a2ca1Dav Glass } else if (Y.UA.ie) {
44631472b0626bcab1c9209949a75d069d3abf72Dav Glass this.execCommand('inserthtml', EditorBase.TABKEY);
43e2f05871a8e99383b8c1d893d290cd978be81aDav Glass }
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass }
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass break;
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass }
0db84e0da684308b0fd9ea9b5906c11bafa7a246Dav Glass if (Y.UA.webkit && e.commands && (e.commands.indent || e.commands.outdent)) {
4a1a2714f9de3ac63495afef5c5e50863369d5f2Dav Glass /*
6dbc2e0b2c23ae7763959af9762fc50c84dbd937Dav Glass * When executing execCommand 'indent or 'outdent' Webkit applies
6dbc2e0b2c23ae7763959af9762fc50c84dbd937Dav Glass * a class to the BLOCKQUOTE that adds left/right margin to it
6dbc2e0b2c23ae7763959af9762fc50c84dbd937Dav Glass * This strips that style so it is just a normal BLOCKQUOTE
6dbc2e0b2c23ae7763959af9762fc50c84dbd937Dav Glass */
6dbc2e0b2c23ae7763959af9762fc50c84dbd937Dav Glass var bq = inst.all('.webkit-indent-blockquote');
6dbc2e0b2c23ae7763959af9762fc50c84dbd937Dav Glass if (bq.size()) {
6dbc2e0b2c23ae7763959af9762fc50c84dbd937Dav Glass bq.setStyle('margin', '');
6dbc2e0b2c23ae7763959af9762fc50c84dbd937Dav Glass }
6dbc2e0b2c23ae7763959af9762fc50c84dbd937Dav Glass }
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass
91085c33d52b89808c10ff61e5a94d7b35d57d65Dav Glass var changed = this.getDomPath(e.changedNode, false),
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass cmds = {}, family, fsize, classes = [],
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass fColor = '', bColor = '';
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass if (e.commands) {
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass cmds = e.commands;
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass }
91085c33d52b89808c10ff61e5a94d7b35d57d65Dav Glass
aa2601e36876d3453019dfe96691f3b796cf8e8bDav Glass var normal = false;
aa2601e36876d3453019dfe96691f3b796cf8e8bDav Glass
690dda02d518be26b6ee1c6530ee361081c9eb03Dav Glass Y.each(changed, function(el) {
690dda02d518be26b6ee1c6530ee361081c9eb03Dav Glass var tag = el.tagName.toLowerCase(),
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass cmd = EditorBase.TAG2CMD[tag];
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass if (cmd) {
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass cmds[cmd] = 1;
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass }
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass //Bold and Italic styles
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass var s = el.currentStyle || el.style;
aa2601e36876d3453019dfe96691f3b796cf8e8bDav Glass
aa2601e36876d3453019dfe96691f3b796cf8e8bDav Glass if ((''+s.fontWeight) == 'normal') {
aa2601e36876d3453019dfe96691f3b796cf8e8bDav Glass normal = true;
aa2601e36876d3453019dfe96691f3b796cf8e8bDav Glass }
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass if ((''+s.fontWeight) == 'bold') { //Cast this to a string
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass cmds.bold = 1;
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass }
052dcc53d425df9224bfc720b2feca1e92903382Dav Glass if (Y.UA.ie) {
052dcc53d425df9224bfc720b2feca1e92903382Dav Glass if (s.fontWeight > 400) {
052dcc53d425df9224bfc720b2feca1e92903382Dav Glass cmds.bold = 1;
052dcc53d425df9224bfc720b2feca1e92903382Dav Glass }
052dcc53d425df9224bfc720b2feca1e92903382Dav Glass }
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass if (s.fontStyle == 'italic') {
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass cmds.italic = 1;
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass }
aa2601e36876d3453019dfe96691f3b796cf8e8bDav Glass
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass if (s.textDecoration == 'underline') {
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass cmds.underline = 1;
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass }
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass if (s.textDecoration == 'line-through') {
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass cmds.strikethrough = 1;
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass }
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass
690dda02d518be26b6ee1c6530ee361081c9eb03Dav Glass var n = inst.one(el);
690dda02d518be26b6ee1c6530ee361081c9eb03Dav Glass if (n.getStyle('fontFamily')) {
690dda02d518be26b6ee1c6530ee361081c9eb03Dav Glass var family2 = n.getStyle('fontFamily').split(',')[0].toLowerCase();
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass if (family2) {
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass family = family2;
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass }
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass if (family) {
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass family = family.replace(/'/g, '').replace(/"/g, '');
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass }
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass }
690dda02d518be26b6ee1c6530ee361081c9eb03Dav Glass
f7aa62ea2e8cf43fbb9d83db5060db540ff1893fDav Glass fsize = EditorBase.NORMALIZE_FONTSIZE(n);
f7aa62ea2e8cf43fbb9d83db5060db540ff1893fDav Glass
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass var cls = el.className.split(' ');
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass Y.each(cls, function(v) {
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass if (v !== '' && (v.substr(0, 4) !== 'yui_')) {
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass classes.push(v);
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass }
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass });
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass
d0bccce76452becc96b65acaaa684aa6fabaf386Dav Glass fColor = EditorBase.FILTER_RGB(n.getStyle('color'));
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass var bColor2 = EditorBase.FILTER_RGB(s.backgroundColor);
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass if (bColor2 !== 'transparent') {
d0bccce76452becc96b65acaaa684aa6fabaf386Dav Glass if (bColor2 !== '') {
d0bccce76452becc96b65acaaa684aa6fabaf386Dav Glass bColor = bColor2;
d0bccce76452becc96b65acaaa684aa6fabaf386Dav Glass }
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass }
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass });
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass
aa2601e36876d3453019dfe96691f3b796cf8e8bDav Glass if (normal) {
aa2601e36876d3453019dfe96691f3b796cf8e8bDav Glass delete cmds.bold;
aa2601e36876d3453019dfe96691f3b796cf8e8bDav Glass delete cmds.italic;
aa2601e36876d3453019dfe96691f3b796cf8e8bDav Glass }
aa2601e36876d3453019dfe96691f3b796cf8e8bDav Glass
91085c33d52b89808c10ff61e5a94d7b35d57d65Dav Glass e.dompath = inst.all(changed);
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass e.classNames = classes;
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass e.commands = cmds;
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass //TODO Dont' like this, not dynamic enough..
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass if (!e.fontFamily) {
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass e.fontFamily = family;
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass }
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass if (!e.fontSize) {
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass e.fontSize = fsize;
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass }
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass if (!e.fontColor) {
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass e.fontColor = fColor;
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass }
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass if (!e.backgroundColor) {
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass e.backgroundColor = bColor;
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass }
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass var endTime = (new Date()).getTime();
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass Y.log('_defNodeChangeTimer 2: ' + (endTime - startTime) + 'ms', 'info', 'selection');
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass },
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass /**
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass * Walk the dom tree from this node up to body, returning a reversed array of parents.
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass * @method getDomPath
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass * @param {Node} node The Node to start from
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass */
91085c33d52b89808c10ff61e5a94d7b35d57d65Dav Glass getDomPath: function(node, nodeList) {
e08067d50c8d5e4692441db53bba084c7a667e0aDav Glass var domPath = [], domNode,
5cbdc947eb0c9c5e840d59ff8e1dd49a0e2a1887Dav Glass inst = this.frame.getInstance();
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass
e08067d50c8d5e4692441db53bba084c7a667e0aDav Glass domNode = inst.Node.getDOMNode(node);
e08067d50c8d5e4692441db53bba084c7a667e0aDav Glass //return inst.all(domNode);
e08067d50c8d5e4692441db53bba084c7a667e0aDav Glass
e08067d50c8d5e4692441db53bba084c7a667e0aDav Glass while (domNode !== null) {
e08067d50c8d5e4692441db53bba084c7a667e0aDav Glass
e08067d50c8d5e4692441db53bba084c7a667e0aDav Glass if ((domNode === inst.config.doc.documentElement) || (domNode === inst.config.doc) || !domNode.tagName) {
e08067d50c8d5e4692441db53bba084c7a667e0aDav Glass domNode = null;
e08067d50c8d5e4692441db53bba084c7a667e0aDav Glass break;
e08067d50c8d5e4692441db53bba084c7a667e0aDav Glass }
91085c33d52b89808c10ff61e5a94d7b35d57d65Dav Glass
e08067d50c8d5e4692441db53bba084c7a667e0aDav Glass if (!inst.DOM.inDoc(domNode)) {
e08067d50c8d5e4692441db53bba084c7a667e0aDav Glass domNode = null;
e08067d50c8d5e4692441db53bba084c7a667e0aDav Glass break;
e08067d50c8d5e4692441db53bba084c7a667e0aDav Glass }
91085c33d52b89808c10ff61e5a94d7b35d57d65Dav Glass
e08067d50c8d5e4692441db53bba084c7a667e0aDav Glass //Check to see if we get el.nodeName and nodeType
e08067d50c8d5e4692441db53bba084c7a667e0aDav Glass if (domNode.nodeName && domNode.nodeType && (domNode.nodeType == 1)) {
e08067d50c8d5e4692441db53bba084c7a667e0aDav Glass domPath.push(domNode);
e08067d50c8d5e4692441db53bba084c7a667e0aDav Glass }
e08067d50c8d5e4692441db53bba084c7a667e0aDav Glass
e08067d50c8d5e4692441db53bba084c7a667e0aDav Glass if (domNode == inst.config.doc.body) {
e08067d50c8d5e4692441db53bba084c7a667e0aDav Glass domNode = null;
e08067d50c8d5e4692441db53bba084c7a667e0aDav Glass break;
e08067d50c8d5e4692441db53bba084c7a667e0aDav Glass }
e08067d50c8d5e4692441db53bba084c7a667e0aDav Glass
e08067d50c8d5e4692441db53bba084c7a667e0aDav Glass domNode = domNode.parentNode;
e08067d50c8d5e4692441db53bba084c7a667e0aDav Glass }
e08067d50c8d5e4692441db53bba084c7a667e0aDav Glass
e08067d50c8d5e4692441db53bba084c7a667e0aDav Glass /*{{{ Using Node
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass while (node !== null) {
573bad453b98b1e493f4abfcf507f85b22b6bf4aDav Glass if (node.test('html') || node.test('doc') || !node.get('tagName')) {
a0c3229e02af852e4b15bf6d4cf4e862440bb00eDav Glass node = null;
a0c3229e02af852e4b15bf6d4cf4e862440bb00eDav Glass break;
a0c3229e02af852e4b15bf6d4cf4e862440bb00eDav Glass }
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass if (!node.inDoc()) {
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass node = null;
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass break;
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass }
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass //Check to see if we get el.nodeName and nodeType
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass if (node.get('nodeName') && node.get('nodeType') && (node.get('nodeType') == 1)) {
5cbdc947eb0c9c5e840d59ff8e1dd49a0e2a1887Dav Glass domPath.push(inst.Node.getDOMNode(node));
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass }
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass if (node.test('body')) {
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass node = null;
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass break;
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass }
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass node = node.get('parentNode');
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass }
e08067d50c8d5e4692441db53bba084c7a667e0aDav Glass }}}*/
e08067d50c8d5e4692441db53bba084c7a667e0aDav Glass
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass if (domPath.length === 0) {
5cbdc947eb0c9c5e840d59ff8e1dd49a0e2a1887Dav Glass domPath[0] = inst.config.doc.body;
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass }
e08067d50c8d5e4692441db53bba084c7a667e0aDav Glass
91085c33d52b89808c10ff61e5a94d7b35d57d65Dav Glass if (nodeList) {
91085c33d52b89808c10ff61e5a94d7b35d57d65Dav Glass return inst.all(domPath.reverse());
91085c33d52b89808c10ff61e5a94d7b35d57d65Dav Glass } else {
91085c33d52b89808c10ff61e5a94d7b35d57d65Dav Glass return domPath.reverse();
91085c33d52b89808c10ff61e5a94d7b35d57d65Dav Glass }
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass },
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass /**
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * After frame ready, bind mousedown & keyup listeners
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * @method _afterFrameReady
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * @private
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass */
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass _afterFrameReady: function() {
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass var inst = this.frame.getInstance();
91085c33d52b89808c10ff61e5a94d7b35d57d65Dav Glass
9d0be4bedcaad945c505994577198223ffc4ed9eDav Glass this.frame.on('dom:mouseup', Y.bind(this._onFrameMouseUp, this));
9d0be4bedcaad945c505994577198223ffc4ed9eDav Glass this.frame.on('dom:mousedown', Y.bind(this._onFrameMouseDown, this));
762b21413a7bbc38b5c7b2d94385fb44f26f9d39Dav Glass this.frame.on('dom:keydown', Y.bind(this._onFrameKeyDown, this));
762b21413a7bbc38b5c7b2d94385fb44f26f9d39Dav Glass
406fbc8e9d992226194dfc2353a6ba1c1fd24b3aDav Glass if (Y.UA.ie) {
406fbc8e9d992226194dfc2353a6ba1c1fd24b3aDav Glass this.frame.on('dom:activate', Y.bind(this._onFrameActivate, this));
406fbc8e9d992226194dfc2353a6ba1c1fd24b3aDav Glass this.frame.on('dom:beforedeactivate', Y.bind(this._beforeFrameDeactivate, this));
406fbc8e9d992226194dfc2353a6ba1c1fd24b3aDav Glass }
406fbc8e9d992226194dfc2353a6ba1c1fd24b3aDav Glass this.frame.on('dom:keyup', Y.bind(this._onFrameKeyUp, this));
406fbc8e9d992226194dfc2353a6ba1c1fd24b3aDav Glass this.frame.on('dom:keypress', Y.bind(this._onFrameKeyPress, this));
7a67e82a93bc7dc5bf9a62a3ad321c2424da37f7Dav Glass this.frame.on('dom:paste', Y.bind(this._onPaste, this));
fe442de8408a276919d26a1110e8121844b1ba11Dav Glass
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass inst.Selection.filter();
a2621d519886de7d60c30c5a0850f5c17fd2fb36Dav Glass this.fire('ready');
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass },
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass /**
406fbc8e9d992226194dfc2353a6ba1c1fd24b3aDav Glass * Caches the current cursor position in IE.
406fbc8e9d992226194dfc2353a6ba1c1fd24b3aDav Glass * @method _beforeFrameDeactivate
406fbc8e9d992226194dfc2353a6ba1c1fd24b3aDav Glass * @private
406fbc8e9d992226194dfc2353a6ba1c1fd24b3aDav Glass */
38b0027944b7fe09062a6befbf76146e73661096Dav Glass _beforeFrameDeactivate: function(e) {
38b0027944b7fe09062a6befbf76146e73661096Dav Glass if (e.frameTarget.test('html')) { //Means it came from a scrollbar
38b0027944b7fe09062a6befbf76146e73661096Dav Glass return;
38b0027944b7fe09062a6befbf76146e73661096Dav Glass }
406fbc8e9d992226194dfc2353a6ba1c1fd24b3aDav Glass var inst = this.getInstance(),
406fbc8e9d992226194dfc2353a6ba1c1fd24b3aDav Glass sel = inst.config.doc.selection.createRange();
406fbc8e9d992226194dfc2353a6ba1c1fd24b3aDav Glass
e57824e27f47a76dae7b14c6ff1c7ed1186d16c1Dav Glass if (sel.compareEndPoints && !sel.compareEndPoints('StartToEnd', sel)) {
406fbc8e9d992226194dfc2353a6ba1c1fd24b3aDav Glass sel.pasteHTML('<var id="yui-ie-cursor">');
406fbc8e9d992226194dfc2353a6ba1c1fd24b3aDav Glass }
406fbc8e9d992226194dfc2353a6ba1c1fd24b3aDav Glass },
406fbc8e9d992226194dfc2353a6ba1c1fd24b3aDav Glass /**
fe442de8408a276919d26a1110e8121844b1ba11Dav Glass * Moves the cached selection bookmark back so IE can place the cursor in the right place.
fe442de8408a276919d26a1110e8121844b1ba11Dav Glass * @method _onFrameActivate
fe442de8408a276919d26a1110e8121844b1ba11Dav Glass * @private
fe442de8408a276919d26a1110e8121844b1ba11Dav Glass */
38b0027944b7fe09062a6befbf76146e73661096Dav Glass _onFrameActivate: function(e) {
38b0027944b7fe09062a6befbf76146e73661096Dav Glass if (e.frameTarget.test('html')) { //Means it came from a scrollbar
38b0027944b7fe09062a6befbf76146e73661096Dav Glass return;
38b0027944b7fe09062a6befbf76146e73661096Dav Glass }
406fbc8e9d992226194dfc2353a6ba1c1fd24b3aDav Glass var inst = this.getInstance(),
406fbc8e9d992226194dfc2353a6ba1c1fd24b3aDav Glass sel = new inst.Selection(),
406fbc8e9d992226194dfc2353a6ba1c1fd24b3aDav Glass range = sel.createRange(),
406fbc8e9d992226194dfc2353a6ba1c1fd24b3aDav Glass cur = inst.all('#yui-ie-cursor');
406fbc8e9d992226194dfc2353a6ba1c1fd24b3aDav Glass
406fbc8e9d992226194dfc2353a6ba1c1fd24b3aDav Glass if (cur.size()) {
406fbc8e9d992226194dfc2353a6ba1c1fd24b3aDav Glass cur.each(function(n) {
406fbc8e9d992226194dfc2353a6ba1c1fd24b3aDav Glass n.set('id', '');
0612f6fa2e2192b929d52762deaf45534f6e7509Dav Glass if (range.moveToElementText) {
27a34eacb64bad3093c357e104c7bee249343ec1Dav Glass try {
27a34eacb64bad3093c357e104c7bee249343ec1Dav Glass range.moveToElementText(n._node);
09c638a157dd9d2ed9027215d9e254badfa019b8Dav Glass var moved = range.move('character', -1);
09c638a157dd9d2ed9027215d9e254badfa019b8Dav Glass if (moved === -1) { //Only move up if we actually moved back.
09c638a157dd9d2ed9027215d9e254badfa019b8Dav Glass range.move('character', 1);
09c638a157dd9d2ed9027215d9e254badfa019b8Dav Glass }
27a34eacb64bad3093c357e104c7bee249343ec1Dav Glass range.select();
27a34eacb64bad3093c357e104c7bee249343ec1Dav Glass range.text = '';
27a34eacb64bad3093c357e104c7bee249343ec1Dav Glass } catch (e) {}
0612f6fa2e2192b929d52762deaf45534f6e7509Dav Glass }
406fbc8e9d992226194dfc2353a6ba1c1fd24b3aDav Glass n.remove();
406fbc8e9d992226194dfc2353a6ba1c1fd24b3aDav Glass });
fe442de8408a276919d26a1110e8121844b1ba11Dav Glass }
fe442de8408a276919d26a1110e8121844b1ba11Dav Glass },
fe442de8408a276919d26a1110e8121844b1ba11Dav Glass /**
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * Fires nodeChange event
7a67e82a93bc7dc5bf9a62a3ad321c2424da37f7Dav Glass * @method _onPaste
7a67e82a93bc7dc5bf9a62a3ad321c2424da37f7Dav Glass * @private
7a67e82a93bc7dc5bf9a62a3ad321c2424da37f7Dav Glass */
7a67e82a93bc7dc5bf9a62a3ad321c2424da37f7Dav Glass _onPaste: function(e) {
7a67e82a93bc7dc5bf9a62a3ad321c2424da37f7Dav Glass this.fire('nodeChange', { changedNode: e.frameTarget, changedType: 'paste', changedEvent: e.frameEvent });
7a67e82a93bc7dc5bf9a62a3ad321c2424da37f7Dav Glass },
7a67e82a93bc7dc5bf9a62a3ad321c2424da37f7Dav Glass /**
7a67e82a93bc7dc5bf9a62a3ad321c2424da37f7Dav Glass * Fires nodeChange event
9d0be4bedcaad945c505994577198223ffc4ed9eDav Glass * @method _onFrameMouseUp
9d0be4bedcaad945c505994577198223ffc4ed9eDav Glass * @private
9d0be4bedcaad945c505994577198223ffc4ed9eDav Glass */
9d0be4bedcaad945c505994577198223ffc4ed9eDav Glass _onFrameMouseUp: function(e) {
762b21413a7bbc38b5c7b2d94385fb44f26f9d39Dav Glass this.fire('nodeChange', { changedNode: e.frameTarget, changedType: 'mouseup', changedEvent: e.frameEvent });
9d0be4bedcaad945c505994577198223ffc4ed9eDav Glass },
9d0be4bedcaad945c505994577198223ffc4ed9eDav Glass /**
9d0be4bedcaad945c505994577198223ffc4ed9eDav Glass * Fires nodeChange event
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * @method _onFrameMouseDown
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * @private
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass */
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass _onFrameMouseDown: function(e) {
762b21413a7bbc38b5c7b2d94385fb44f26f9d39Dav Glass this.fire('nodeChange', { changedNode: e.frameTarget, changedType: 'mousedown', changedEvent: e.frameEvent });
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass },
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass /**
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass * Caches a copy of the selection for key events. Only creating the selection on keydown
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass * @property _currentSelection
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * @private
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass */
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass _currentSelection: null,
f7aa62ea2e8cf43fbb9d83db5060db540ff1893fDav Glass /**
f7aa62ea2e8cf43fbb9d83db5060db540ff1893fDav Glass * Holds the timer for selection clearing
f7aa62ea2e8cf43fbb9d83db5060db540ff1893fDav Glass * @property _currentSelectionTimer
f7aa62ea2e8cf43fbb9d83db5060db540ff1893fDav Glass * @private
f7aa62ea2e8cf43fbb9d83db5060db540ff1893fDav Glass */
998d2791b549446db8394dc80d46a94a247857d9Dav Glass _currentSelectionTimer: null,
f7aa62ea2e8cf43fbb9d83db5060db540ff1893fDav Glass /**
f7aa62ea2e8cf43fbb9d83db5060db540ff1893fDav Glass * Flag to determine if we can clear the selection or not.
f7aa62ea2e8cf43fbb9d83db5060db540ff1893fDav Glass * @property _currentSelectionClear
f7aa62ea2e8cf43fbb9d83db5060db540ff1893fDav Glass * @private
f7aa62ea2e8cf43fbb9d83db5060db540ff1893fDav Glass */
998d2791b549446db8394dc80d46a94a247857d9Dav Glass _currentSelectionClear: null,
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass /**
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * Fires nodeChange event
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * @method _onFrameKeyDown
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * @private
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass */
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass _onFrameKeyDown: function(e) {
f7aa62ea2e8cf43fbb9d83db5060db540ff1893fDav Glass var inst, sel;
998d2791b549446db8394dc80d46a94a247857d9Dav Glass if (!this._currentSelection) {
998d2791b549446db8394dc80d46a94a247857d9Dav Glass if (this._currentSelectionTimer) {
998d2791b549446db8394dc80d46a94a247857d9Dav Glass this._currentSelectionTimer.cancel();
998d2791b549446db8394dc80d46a94a247857d9Dav Glass }
998d2791b549446db8394dc80d46a94a247857d9Dav Glass this._currentSelectionTimer = Y.later(850, this, function() {
998d2791b549446db8394dc80d46a94a247857d9Dav Glass this._currentSelectionClear = true;
998d2791b549446db8394dc80d46a94a247857d9Dav Glass });
f7aa62ea2e8cf43fbb9d83db5060db540ff1893fDav Glass
f7aa62ea2e8cf43fbb9d83db5060db540ff1893fDav Glass inst = this.frame.getInstance();
f7aa62ea2e8cf43fbb9d83db5060db540ff1893fDav Glass sel = new inst.Selection(e);
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass
998d2791b549446db8394dc80d46a94a247857d9Dav Glass this._currentSelection = sel;
998d2791b549446db8394dc80d46a94a247857d9Dav Glass } else {
f7aa62ea2e8cf43fbb9d83db5060db540ff1893fDav Glass sel = this._currentSelection;
998d2791b549446db8394dc80d46a94a247857d9Dav Glass }
91085c33d52b89808c10ff61e5a94d7b35d57d65Dav Glass
f7aa62ea2e8cf43fbb9d83db5060db540ff1893fDav Glass inst = this.frame.getInstance();
f7aa62ea2e8cf43fbb9d83db5060db540ff1893fDav Glass sel = new inst.Selection();
f7aa62ea2e8cf43fbb9d83db5060db540ff1893fDav Glass
f7aa62ea2e8cf43fbb9d83db5060db540ff1893fDav Glass this._currentSelection = sel;
da4867ccd00c77094f36f04d4d774757de963c96Dav Glass
998d2791b549446db8394dc80d46a94a247857d9Dav Glass if (sel && sel.anchorNode) {
762b21413a7bbc38b5c7b2d94385fb44f26f9d39Dav Glass this.fire('nodeChange', { changedNode: sel.anchorNode, changedType: 'keydown', changedEvent: e.frameEvent });
7058d70d5189510fab628ef8d64bb50dd726a941Dav Glass if (EditorBase.NC_KEYS[e.keyCode]) {
762b21413a7bbc38b5c7b2d94385fb44f26f9d39Dav Glass this.fire('nodeChange', { changedNode: sel.anchorNode, changedType: EditorBase.NC_KEYS[e.keyCode], changedEvent: e.frameEvent });
762b21413a7bbc38b5c7b2d94385fb44f26f9d39Dav Glass this.fire('nodeChange', { changedNode: sel.anchorNode, changedType: EditorBase.NC_KEYS[e.keyCode] + '-down', changedEvent: e.frameEvent });
7058d70d5189510fab628ef8d64bb50dd726a941Dav Glass }
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass }
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass },
b7bd9aa409761c479bb0a2e5794295d35ebe24eaDav Glass /**
b7bd9aa409761c479bb0a2e5794295d35ebe24eaDav Glass * Fires nodeChange event
b7bd9aa409761c479bb0a2e5794295d35ebe24eaDav Glass * @method _onFrameKeyPress
b7bd9aa409761c479bb0a2e5794295d35ebe24eaDav Glass * @private
b7bd9aa409761c479bb0a2e5794295d35ebe24eaDav Glass */
323ca860aba4b2515b560796e2322d5eaae57e5aDav Glass _onFrameKeyPress: function(e) {
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass var sel = this._currentSelection;
323ca860aba4b2515b560796e2322d5eaae57e5aDav Glass
998d2791b549446db8394dc80d46a94a247857d9Dav Glass if (sel && sel.anchorNode) {
762b21413a7bbc38b5c7b2d94385fb44f26f9d39Dav Glass this.fire('nodeChange', { changedNode: sel.anchorNode, changedType: 'keypress', changedEvent: e.frameEvent });
323ca860aba4b2515b560796e2322d5eaae57e5aDav Glass if (EditorBase.NC_KEYS[e.keyCode]) {
762b21413a7bbc38b5c7b2d94385fb44f26f9d39Dav Glass this.fire('nodeChange', { changedNode: sel.anchorNode, changedType: EditorBase.NC_KEYS[e.keyCode] + '-press', changedEvent: e.frameEvent });
323ca860aba4b2515b560796e2322d5eaae57e5aDav Glass }
323ca860aba4b2515b560796e2322d5eaae57e5aDav Glass }
323ca860aba4b2515b560796e2322d5eaae57e5aDav Glass },
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass /**
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass * Fires nodeChange event for keyup on specific keys
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass * @method _onFrameKeyUp
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass * @private
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass */
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass _onFrameKeyUp: function(e) {
9c0c9c3b0536efd839d996c7e2b83a60b14dd544Dav Glass var inst = this.frame.getInstance(),
9c0c9c3b0536efd839d996c7e2b83a60b14dd544Dav Glass sel = new inst.Selection(e);
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass
998d2791b549446db8394dc80d46a94a247857d9Dav Glass if (sel && sel.anchorNode) {
762b21413a7bbc38b5c7b2d94385fb44f26f9d39Dav Glass this.fire('nodeChange', { changedNode: sel.anchorNode, changedType: 'keyup', selection: sel, changedEvent: e.frameEvent });
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass if (EditorBase.NC_KEYS[e.keyCode]) {
762b21413a7bbc38b5c7b2d94385fb44f26f9d39Dav Glass this.fire('nodeChange', { changedNode: sel.anchorNode, changedType: EditorBase.NC_KEYS[e.keyCode] + '-up', selection: sel, changedEvent: e.frameEvent });
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass }
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass }
998d2791b549446db8394dc80d46a94a247857d9Dav Glass if (this._currentSelectionClear) {
998d2791b549446db8394dc80d46a94a247857d9Dav Glass this._currentSelectionClear = this._currentSelection = null;
998d2791b549446db8394dc80d46a94a247857d9Dav Glass }
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass },
e20a95dc78bf51b6544e7bfb4e53ed190ecec3c9Dav Glass /**
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * Pass through to the frame.execCommand method
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * @method execCommand
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * @param {String} cmd The command to pass: inserthtml, insertimage, bold
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * @param {String} val The optional value of the command: Helvetica
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * @return {Node/NodeList} The Node or Nodelist affected by the command. Only returns on override commands, not browser defined commands.
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass */
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass execCommand: function(cmd, val) {
24e95e1c11b518e1aaaa7f04882febe32de00b5eDav Glass var ret = this.frame.execCommand(cmd, val),
24e95e1c11b518e1aaaa7f04882febe32de00b5eDav Glass inst = this.frame.getInstance(),
24e95e1c11b518e1aaaa7f04882febe32de00b5eDav Glass sel = new inst.Selection(), cmds = {},
24e95e1c11b518e1aaaa7f04882febe32de00b5eDav Glass e = { changedNode: sel.anchorNode, changedType: 'execcommand', nodes: ret };
24e95e1c11b518e1aaaa7f04882febe32de00b5eDav Glass
24e95e1c11b518e1aaaa7f04882febe32de00b5eDav Glass switch (cmd) {
24e95e1c11b518e1aaaa7f04882febe32de00b5eDav Glass case 'forecolor':
24e95e1c11b518e1aaaa7f04882febe32de00b5eDav Glass e.fontColor = val;
24e95e1c11b518e1aaaa7f04882febe32de00b5eDav Glass break;
24e95e1c11b518e1aaaa7f04882febe32de00b5eDav Glass case 'backcolor':
24e95e1c11b518e1aaaa7f04882febe32de00b5eDav Glass e.backgroundColor = val;
24e95e1c11b518e1aaaa7f04882febe32de00b5eDav Glass break;
24e95e1c11b518e1aaaa7f04882febe32de00b5eDav Glass case 'fontsize':
24e95e1c11b518e1aaaa7f04882febe32de00b5eDav Glass e.fontSize = val;
24e95e1c11b518e1aaaa7f04882febe32de00b5eDav Glass break;
24e95e1c11b518e1aaaa7f04882febe32de00b5eDav Glass case 'fontname':
24e95e1c11b518e1aaaa7f04882febe32de00b5eDav Glass e.fontFamily = val;
24e95e1c11b518e1aaaa7f04882febe32de00b5eDav Glass break;
24e95e1c11b518e1aaaa7f04882febe32de00b5eDav Glass }
24e95e1c11b518e1aaaa7f04882febe32de00b5eDav Glass
24e95e1c11b518e1aaaa7f04882febe32de00b5eDav Glass cmds[cmd] = 1;
24e95e1c11b518e1aaaa7f04882febe32de00b5eDav Glass e.commands = cmds;
24e95e1c11b518e1aaaa7f04882febe32de00b5eDav Glass
24e95e1c11b518e1aaaa7f04882febe32de00b5eDav Glass this.fire('nodeChange', e);
24e95e1c11b518e1aaaa7f04882febe32de00b5eDav Glass
24e95e1c11b518e1aaaa7f04882febe32de00b5eDav Glass return ret;
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass },
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass /**
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * Get the YUI instance of the frame
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * @method getInstance
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * @return {YUI} The YUI instance bound to the frame.
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass */
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass getInstance: function() {
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass return this.frame.getInstance();
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass },
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass /**
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * Renders the Y.Frame to the passed node.
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * @method render
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * @param {Selector/HTMLElement/Node} node The node to append the Editor to
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * @return {EditorBase}
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * @chainable
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass */
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass render: function(node) {
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass this.frame.set('content', this.get('content'));
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass this.frame.render(node);
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass return this;
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass },
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass /**
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * Focus the contentWindow of the iframe
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * @method focus
15e7d5bd8a8fb4068cc8df277bb857b83a0891f5Dav Glass * @param {Function} fn Callback function to execute after focus happens
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * @return {EditorBase}
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * @chainable
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass */
15e7d5bd8a8fb4068cc8df277bb857b83a0891f5Dav Glass focus: function(fn) {
15e7d5bd8a8fb4068cc8df277bb857b83a0891f5Dav Glass this.frame.focus(fn);
a0c3229e02af852e4b15bf6d4cf4e862440bb00eDav Glass return this;
a0c3229e02af852e4b15bf6d4cf4e862440bb00eDav Glass },
a0c3229e02af852e4b15bf6d4cf4e862440bb00eDav Glass /**
a0c3229e02af852e4b15bf6d4cf4e862440bb00eDav Glass * Handles the showing of the Editor instance. Currently only handles the iframe
a0c3229e02af852e4b15bf6d4cf4e862440bb00eDav Glass * @method show
a0c3229e02af852e4b15bf6d4cf4e862440bb00eDav Glass * @return {EditorBase}
a0c3229e02af852e4b15bf6d4cf4e862440bb00eDav Glass * @chainable
a0c3229e02af852e4b15bf6d4cf4e862440bb00eDav Glass */
a0c3229e02af852e4b15bf6d4cf4e862440bb00eDav Glass show: function() {
a0c3229e02af852e4b15bf6d4cf4e862440bb00eDav Glass this.frame.show();
a0c3229e02af852e4b15bf6d4cf4e862440bb00eDav Glass return this;
a0c3229e02af852e4b15bf6d4cf4e862440bb00eDav Glass },
a0c3229e02af852e4b15bf6d4cf4e862440bb00eDav Glass /**
a0c3229e02af852e4b15bf6d4cf4e862440bb00eDav Glass * Handles the hiding of the Editor instance. Currently only handles the iframe
a0c3229e02af852e4b15bf6d4cf4e862440bb00eDav Glass * @method hide
a0c3229e02af852e4b15bf6d4cf4e862440bb00eDav Glass * @return {EditorBase}
a0c3229e02af852e4b15bf6d4cf4e862440bb00eDav Glass * @chainable
a0c3229e02af852e4b15bf6d4cf4e862440bb00eDav Glass */
a0c3229e02af852e4b15bf6d4cf4e862440bb00eDav Glass hide: function() {
a0c3229e02af852e4b15bf6d4cf4e862440bb00eDav Glass this.frame.hide();
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass return this;
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass },
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass /**
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * (Un)Filters the content of the Editor, cleaning YUI related code. //TODO better filtering
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * @method getContent
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * @return {String} The filtered content of the Editor
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass */
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass getContent: function() {
74508273e502d40de8fc4bd810859c1d0c453c6cDav Glass var html = '', inst = this.getInstance();
74508273e502d40de8fc4bd810859c1d0c453c6cDav Glass if (inst && inst.Selection) {
74508273e502d40de8fc4bd810859c1d0c453c6cDav Glass html = inst.Selection.unfilter();
74508273e502d40de8fc4bd810859c1d0c453c6cDav Glass }
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass //Removing the _yuid from the objects in IE
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass html = html.replace(/ _yuid="([^>]*)"/g, '');
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass return html;
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass }
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass }, {
f7aa62ea2e8cf43fbb9d83db5060db540ff1893fDav Glass /**
f7aa62ea2e8cf43fbb9d83db5060db540ff1893fDav Glass * @static
f7aa62ea2e8cf43fbb9d83db5060db540ff1893fDav Glass * @method NORMALIZE_FONTSIZE
f7aa62ea2e8cf43fbb9d83db5060db540ff1893fDav Glass * @description Pulls the fontSize from a node, then checks for string values (x-large, x-small)
f7aa62ea2e8cf43fbb9d83db5060db540ff1893fDav Glass * and converts them to pixel sizes. If the parsed size is different from the original, it calls
f7aa62ea2e8cf43fbb9d83db5060db540ff1893fDav Glass * node.setStyle to update the node with a pixel size for normalization.
f7aa62ea2e8cf43fbb9d83db5060db540ff1893fDav Glass */
f7aa62ea2e8cf43fbb9d83db5060db540ff1893fDav Glass NORMALIZE_FONTSIZE: function(n) {
f7aa62ea2e8cf43fbb9d83db5060db540ff1893fDav Glass var size = n.getStyle('fontSize'), oSize = size;
f7aa62ea2e8cf43fbb9d83db5060db540ff1893fDav Glass
f7aa62ea2e8cf43fbb9d83db5060db540ff1893fDav Glass switch (size) {
f7aa62ea2e8cf43fbb9d83db5060db540ff1893fDav Glass case '-webkit-xxx-large':
f7aa62ea2e8cf43fbb9d83db5060db540ff1893fDav Glass size = '48px';
f7aa62ea2e8cf43fbb9d83db5060db540ff1893fDav Glass break;
f7aa62ea2e8cf43fbb9d83db5060db540ff1893fDav Glass case 'xx-large':
f7aa62ea2e8cf43fbb9d83db5060db540ff1893fDav Glass size = '32px';
f7aa62ea2e8cf43fbb9d83db5060db540ff1893fDav Glass break;
f7aa62ea2e8cf43fbb9d83db5060db540ff1893fDav Glass case 'x-large':
f7aa62ea2e8cf43fbb9d83db5060db540ff1893fDav Glass size = '24px';
f7aa62ea2e8cf43fbb9d83db5060db540ff1893fDav Glass break;
f7aa62ea2e8cf43fbb9d83db5060db540ff1893fDav Glass case 'large':
f7aa62ea2e8cf43fbb9d83db5060db540ff1893fDav Glass size = '18px';
f7aa62ea2e8cf43fbb9d83db5060db540ff1893fDav Glass break;
f7aa62ea2e8cf43fbb9d83db5060db540ff1893fDav Glass case 'medium':
f7aa62ea2e8cf43fbb9d83db5060db540ff1893fDav Glass size = '16px';
f7aa62ea2e8cf43fbb9d83db5060db540ff1893fDav Glass break;
f7aa62ea2e8cf43fbb9d83db5060db540ff1893fDav Glass case 'small':
f7aa62ea2e8cf43fbb9d83db5060db540ff1893fDav Glass size = '13px';
f7aa62ea2e8cf43fbb9d83db5060db540ff1893fDav Glass break;
f7aa62ea2e8cf43fbb9d83db5060db540ff1893fDav Glass case 'x-small':
f7aa62ea2e8cf43fbb9d83db5060db540ff1893fDav Glass size = '10px';
f7aa62ea2e8cf43fbb9d83db5060db540ff1893fDav Glass break;
f7aa62ea2e8cf43fbb9d83db5060db540ff1893fDav Glass }
f7aa62ea2e8cf43fbb9d83db5060db540ff1893fDav Glass if (oSize !== size) {
f7aa62ea2e8cf43fbb9d83db5060db540ff1893fDav Glass n.setStyle('fontSize', size);
f7aa62ea2e8cf43fbb9d83db5060db540ff1893fDav Glass }
f7aa62ea2e8cf43fbb9d83db5060db540ff1893fDav Glass return size;
f7aa62ea2e8cf43fbb9d83db5060db540ff1893fDav Glass },
24e95e1c11b518e1aaaa7f04882febe32de00b5eDav Glass /**
9f2068537ef4a78d9a11fb5a136991d9d9e059a0Dav Glass * @static
9f2068537ef4a78d9a11fb5a136991d9d9e059a0Dav Glass * @property TABKEY
9f2068537ef4a78d9a11fb5a136991d9d9e059a0Dav Glass * @description The HTML markup to use for the tabkey
9f2068537ef4a78d9a11fb5a136991d9d9e059a0Dav Glass */
d5c8641a4c8bb3bf024ae7fe517387163591d325Dav Glass TABKEY: '<span class="tab">&nbsp;&nbsp;&nbsp;&nbsp;</span>',
9f2068537ef4a78d9a11fb5a136991d9d9e059a0Dav Glass /**
9f2068537ef4a78d9a11fb5a136991d9d9e059a0Dav Glass * @static
9f2068537ef4a78d9a11fb5a136991d9d9e059a0Dav Glass * @method FILTER_RGB
24e95e1c11b518e1aaaa7f04882febe32de00b5eDav Glass * @param String css The CSS string containing rgb(#,#,#);
24e95e1c11b518e1aaaa7f04882febe32de00b5eDav Glass * @description Converts an RGB color string to a hex color, example: rgb(0, 255, 0) converts to #00ff00
24e95e1c11b518e1aaaa7f04882febe32de00b5eDav Glass * @return String
24e95e1c11b518e1aaaa7f04882febe32de00b5eDav Glass */
24e95e1c11b518e1aaaa7f04882febe32de00b5eDav Glass FILTER_RGB: function(css) {
24e95e1c11b518e1aaaa7f04882febe32de00b5eDav Glass if (css.toLowerCase().indexOf('rgb') != -1) {
24e95e1c11b518e1aaaa7f04882febe32de00b5eDav Glass var exp = new RegExp("(.*?)rgb\\s*?\\(\\s*?([0-9]+).*?,\\s*?([0-9]+).*?,\\s*?([0-9]+).*?\\)(.*?)", "gi");
24e95e1c11b518e1aaaa7f04882febe32de00b5eDav Glass var rgb = css.replace(exp, "$1,$2,$3,$4,$5").split(',');
24e95e1c11b518e1aaaa7f04882febe32de00b5eDav Glass
24e95e1c11b518e1aaaa7f04882febe32de00b5eDav Glass if (rgb.length == 5) {
24e95e1c11b518e1aaaa7f04882febe32de00b5eDav Glass var r = parseInt(rgb[1], 10).toString(16);
24e95e1c11b518e1aaaa7f04882febe32de00b5eDav Glass var g = parseInt(rgb[2], 10).toString(16);
24e95e1c11b518e1aaaa7f04882febe32de00b5eDav Glass var b = parseInt(rgb[3], 10).toString(16);
24e95e1c11b518e1aaaa7f04882febe32de00b5eDav Glass
24e95e1c11b518e1aaaa7f04882febe32de00b5eDav Glass r = r.length == 1 ? '0' + r : r;
24e95e1c11b518e1aaaa7f04882febe32de00b5eDav Glass g = g.length == 1 ? '0' + g : g;
24e95e1c11b518e1aaaa7f04882febe32de00b5eDav Glass b = b.length == 1 ? '0' + b : b;
24e95e1c11b518e1aaaa7f04882febe32de00b5eDav Glass
24e95e1c11b518e1aaaa7f04882febe32de00b5eDav Glass css = "#" + r + g + b;
24e95e1c11b518e1aaaa7f04882febe32de00b5eDav Glass }
24e95e1c11b518e1aaaa7f04882febe32de00b5eDav Glass }
24e95e1c11b518e1aaaa7f04882febe32de00b5eDav Glass return css;
24e95e1c11b518e1aaaa7f04882febe32de00b5eDav Glass },
9f2068537ef4a78d9a11fb5a136991d9d9e059a0Dav Glass /**
9f2068537ef4a78d9a11fb5a136991d9d9e059a0Dav Glass * @static
9f2068537ef4a78d9a11fb5a136991d9d9e059a0Dav Glass * @property TAG2CMD
9f2068537ef4a78d9a11fb5a136991d9d9e059a0Dav Glass * @description A hash table of tags to their execcomand's
9f2068537ef4a78d9a11fb5a136991d9d9e059a0Dav Glass */
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass TAG2CMD: {
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass 'b': 'bold',
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass 'strong': 'bold',
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass 'i': 'italic',
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass 'em': 'italic',
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass 'u': 'underline',
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass 'sup': 'superscript',
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass 'sub': 'subscript',
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass 'img': 'insertimage',
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass 'a' : 'createlink',
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass 'ul' : 'insertunorderedlist',
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass 'ol' : 'insertorderedlist'
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass },
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass /**
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * Hash table of keys to fire a nodeChange event for.
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * @static
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * @property NC_KEYS
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * @type Object
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass */
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass NC_KEYS: {
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass 8: 'backspace',
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass 9: 'tab',
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass 13: 'enter',
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass 32: 'space',
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass 33: 'pageup',
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass 34: 'pagedown',
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass 35: 'end',
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass 36: 'home',
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass 37: 'left',
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass 38: 'up',
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass 39: 'right',
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass 40: 'down',
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass 46: 'delete'
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass },
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass /**
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * The default modules to use inside the Frame
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * @static
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * @property USE
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * @type Array
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass */
9a68201f57ed1257e4735227620d7ec556fe99e5Dav Glass USE: ['substitute', 'node', 'selector-css3', 'selection', 'stylesheet'],
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass /**
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * The Class Name: editorBase
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * @static
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * @property NAME
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass */
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass NAME: 'editorBase',
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass /**
10d8bafc5c24f3a4285cf6060a1935ba5cfc4b85Luke Smith * Editor Strings. By default contains only the `title` property for the
10d8bafc5c24f3a4285cf6060a1935ba5cfc4b85Luke Smith * Title of frame document (default "Rich Text Editor").
10d8bafc5c24f3a4285cf6060a1935ba5cfc4b85Luke Smith *
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * @static
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * @property STRINGS
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass */
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass STRINGS: {
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass title: 'Rich Text Editor'
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass },
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass ATTRS: {
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass /**
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * The content to load into the Editor Frame
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * @attribute content
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass */
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass content: {
840fa3af908837f29008e2b1b24b45dca3484f92Dav Glass value: '<br class="yui-cursor">',
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass setter: function(str) {
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass if (str.substr(0, 1) === "\n") {
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass Y.log('Stripping first carriage return from content before injecting', 'warn', 'editor');
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass str = str.substr(1);
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass }
573bad453b98b1e493f4abfcf507f85b22b6bf4aDav Glass if (str === '') {
840fa3af908837f29008e2b1b24b45dca3484f92Dav Glass str = '<br class="yui-cursor">';
573bad453b98b1e493f4abfcf507f85b22b6bf4aDav Glass }
958d1f7fa2c13f0298c1da8fb4465dd758db36ccDav Glass if (str === ' ') {
958d1f7fa2c13f0298c1da8fb4465dd758db36ccDav Glass if (Y.UA.gecko) {
958d1f7fa2c13f0298c1da8fb4465dd758db36ccDav Glass str = '<br class="yui-cursor">';
958d1f7fa2c13f0298c1da8fb4465dd758db36ccDav Glass }
958d1f7fa2c13f0298c1da8fb4465dd758db36ccDav Glass }
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass return this.frame.set('content', str);
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass },
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass getter: function() {
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass return this.frame.get('content');
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass }
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass },
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass /**
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * The value of the dir attribute on the HTML element of the frame. Default: ltr
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * @attribute dir
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass */
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass dir: {
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass writeOnce: true,
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass value: 'ltr'
f69da96c272d2efe7f43da5150c13c0fe6899646Dav Glass },
f69da96c272d2efe7f43da5150c13c0fe6899646Dav Glass /**
c145dba89e51cac0a247d52f4f4c0c8d8245027dDav Glass * @attribute linkedcss
c145dba89e51cac0a247d52f4f4c0c8d8245027dDav Glass * @description An array of url's to external linked style sheets
c145dba89e51cac0a247d52f4f4c0c8d8245027dDav Glass * @type String
c145dba89e51cac0a247d52f4f4c0c8d8245027dDav Glass */
c145dba89e51cac0a247d52f4f4c0c8d8245027dDav Glass linkedcss: {
ac74069ae9518fdedd0b905ef28c965177ca6d4fDav Glass value: '',
c145dba89e51cac0a247d52f4f4c0c8d8245027dDav Glass setter: function(css) {
c145dba89e51cac0a247d52f4f4c0c8d8245027dDav Glass if (this.frame) {
c145dba89e51cac0a247d52f4f4c0c8d8245027dDav Glass this.frame.set('linkedcss', css);
c145dba89e51cac0a247d52f4f4c0c8d8245027dDav Glass }
c145dba89e51cac0a247d52f4f4c0c8d8245027dDav Glass return css;
c145dba89e51cac0a247d52f4f4c0c8d8245027dDav Glass }
c145dba89e51cac0a247d52f4f4c0c8d8245027dDav Glass },
c145dba89e51cac0a247d52f4f4c0c8d8245027dDav Glass /**
f69da96c272d2efe7f43da5150c13c0fe6899646Dav Glass * @attribute extracss
f69da96c272d2efe7f43da5150c13c0fe6899646Dav Glass * @description A string of CSS to add to the Head of the Editor
f69da96c272d2efe7f43da5150c13c0fe6899646Dav Glass * @type String
f69da96c272d2efe7f43da5150c13c0fe6899646Dav Glass */
f69da96c272d2efe7f43da5150c13c0fe6899646Dav Glass extracss: {
f69da96c272d2efe7f43da5150c13c0fe6899646Dav Glass value: false,
f69da96c272d2efe7f43da5150c13c0fe6899646Dav Glass setter: function(css) {
f69da96c272d2efe7f43da5150c13c0fe6899646Dav Glass if (this.frame) {
f69da96c272d2efe7f43da5150c13c0fe6899646Dav Glass this.frame.set('extracss', css);
f69da96c272d2efe7f43da5150c13c0fe6899646Dav Glass }
f69da96c272d2efe7f43da5150c13c0fe6899646Dav Glass return css;
f69da96c272d2efe7f43da5150c13c0fe6899646Dav Glass }
162527ab925c04aa8d6bbf78d0484a133a8076f1Dav Glass },
162527ab925c04aa8d6bbf78d0484a133a8076f1Dav Glass /**
162527ab925c04aa8d6bbf78d0484a133a8076f1Dav Glass * @attribute defaultblock
162527ab925c04aa8d6bbf78d0484a133a8076f1Dav Glass * @description The default tag to use for block level items, defaults to: p
162527ab925c04aa8d6bbf78d0484a133a8076f1Dav Glass * @type String
162527ab925c04aa8d6bbf78d0484a133a8076f1Dav Glass */
162527ab925c04aa8d6bbf78d0484a133a8076f1Dav Glass defaultblock: {
162527ab925c04aa8d6bbf78d0484a133a8076f1Dav Glass value: 'p'
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass }
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass }
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass });
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass Y.EditorBase = EditorBase;
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass /**
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * @event nodeChange
7a67e82a93bc7dc5bf9a62a3ad321c2424da37f7Dav Glass * @description Fired from several mouse/key/paste event points.
daeb6d531149c45a2ceb543ae2cf1e56e5235bbeDav Glass * @param {Event.Facade} event An Event Facade object with the following specific properties added:
daeb6d531149c45a2ceb543ae2cf1e56e5235bbeDav Glass * <dl>
daeb6d531149c45a2ceb543ae2cf1e56e5235bbeDav Glass * <dt>changedEvent</dt><dd>The event that caused the nodeChange</dd>
daeb6d531149c45a2ceb543ae2cf1e56e5235bbeDav Glass * <dt>changedNode</dt><dd>The node that was interacted with</dd>
daeb6d531149c45a2ceb543ae2cf1e56e5235bbeDav Glass * <dt>changedType</dt><dd>The type of change: mousedown, mouseup, right, left, backspace, tab, enter, etc..</dd>
daeb6d531149c45a2ceb543ae2cf1e56e5235bbeDav Glass * <dt>commands</dt><dd>The list of execCommands that belong to this change and the dompath that's associated with the changedNode</dd>
daeb6d531149c45a2ceb543ae2cf1e56e5235bbeDav Glass * <dt>classNames</dt><dd>An array of classNames that are applied to the changedNode and all of it's parents</dd>
daeb6d531149c45a2ceb543ae2cf1e56e5235bbeDav Glass * <dt>dompath</dt><dd>A sorted array of node instances that make up the DOM path from the changedNode to body.</dd>
daeb6d531149c45a2ceb543ae2cf1e56e5235bbeDav Glass * <dt>backgroundColor</dt><dd>The cascaded backgroundColor of the changedNode</dd>
daeb6d531149c45a2ceb543ae2cf1e56e5235bbeDav Glass * <dt>fontColor</dt><dd>The cascaded fontColor of the changedNode</dd>
daeb6d531149c45a2ceb543ae2cf1e56e5235bbeDav Glass * <dt>fontFamily</dt><dd>The cascaded fontFamily of the changedNode</dd>
daeb6d531149c45a2ceb543ae2cf1e56e5235bbeDav Glass * <dt>fontSize</dt><dd>The cascaded fontSize of the changedNode</dd>
daeb6d531149c45a2ceb543ae2cf1e56e5235bbeDav Glass * </dl>
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * @type {Event.Custom}
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass */
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass
a2621d519886de7d60c30c5a0850f5c17fd2fb36Dav Glass /**
a2621d519886de7d60c30c5a0850f5c17fd2fb36Dav Glass * @event ready
a2621d519886de7d60c30c5a0850f5c17fd2fb36Dav Glass * @description Fired after the frame is ready.
a2621d519886de7d60c30c5a0850f5c17fd2fb36Dav Glass * @param {Event.Facade} event An Event Facade object.
a2621d519886de7d60c30c5a0850f5c17fd2fb36Dav Glass * @type {Event.Custom}
a2621d519886de7d60c30c5a0850f5c17fd2fb36Dav Glass */
a2621d519886de7d60c30c5a0850f5c17fd2fb36Dav Glass
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass