editor-base.js revision 9a68201f57ed1257e4735227620d7ec556fe99e5
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 * @module editor
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * @submodule editor-base
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
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * @constructor
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass */
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass var EditorBase = function() {
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass EditorBase.superclass.constructor.apply(this, arguments);
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass };
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'),
56fa0b5ce00608c58c7c82cc5341c5fbf8898719Dav Glass host: this
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass }).plug(Y.Plugin.ExecCommand);
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass frame.after('ready', Y.bind(this._afterFrameReady, this));
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass frame.addTarget(this);
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 });
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) {
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 }
f8b3e367f0b400ff8b4feeb35c56d9387a31f9e0Dav Glass to.setStyles(newStyles);
f8b3e367f0b400ff8b4feeb35c56d9387a31f9e0Dav Glass },
b7bd9aa409761c479bb0a2e5794295d35ebe24eaDav 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 */
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass _defNodeChangeFn: function(e) {
a2621d519886de7d60c30c5a0850f5c17fd2fb36Dav Glass //Y.log('Default nodeChange function: ' + e.changedType, 'info', 'editor');
323ca860aba4b2515b560796e2322d5eaae57e5aDav Glass var inst = this.getInstance();
323ca860aba4b2515b560796e2322d5eaae57e5aDav 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) {
9002d9b85f99bb503c702f12a20f829f732d22f8Dav Glass case 'enter':
9002d9b85f99bb503c702f12a20f829f732d22f8Dav Glass if (Y.UA.webkit) {
9002d9b85f99bb503c702f12a20f829f732d22f8Dav Glass //Webkit doesn't support shift+enter as a BR, this fixes that.
9002d9b85f99bb503c702f12a20f829f732d22f8Dav Glass if (e.changedEvent.shiftKey) {
9002d9b85f99bb503c702f12a20f829f732d22f8Dav Glass this.execCommand('insertbr');
9002d9b85f99bb503c702f12a20f829f732d22f8Dav Glass e.changedEvent.preventDefault();
9002d9b85f99bb503c702f12a20f829f732d22f8Dav Glass }
9002d9b85f99bb503c702f12a20f829f732d22f8Dav Glass }
9002d9b85f99bb503c702f12a20f829f732d22f8Dav Glass break;
a2621d519886de7d60c30c5a0850f5c17fd2fb36Dav Glass case 'tab':
a2621d519886de7d60c30c5a0850f5c17fd2fb36Dav Glass if (!e.changedNode.test('li, li *') && !e.changedEvent.shiftKey) {
a2621d519886de7d60c30c5a0850f5c17fd2fb36Dav Glass Y.log('Overriding TAB key to insert HTML', 'info', 'editor');
a2621d519886de7d60c30c5a0850f5c17fd2fb36Dav Glass var sel = new inst.Selection();
a2621d519886de7d60c30c5a0850f5c17fd2fb36Dav Glass sel.setCursor();
a2621d519886de7d60c30c5a0850f5c17fd2fb36Dav Glass var cur = sel.getCursor();
a2621d519886de7d60c30c5a0850f5c17fd2fb36Dav Glass cur.insert(EditorBase.TABKEY, 'before');
a2621d519886de7d60c30c5a0850f5c17fd2fb36Dav Glass sel.focusCursor();
a2621d519886de7d60c30c5a0850f5c17fd2fb36Dav Glass e.changedEvent.preventDefault();
f8b3e367f0b400ff8b4feeb35c56d9387a31f9e0Dav Glass }
f8b3e367f0b400ff8b4feeb35c56d9387a31f9e0Dav Glass break;
f8b3e367f0b400ff8b4feeb35c56d9387a31f9e0Dav Glass case 'enter-up':
f8b3e367f0b400ff8b4feeb35c56d9387a31f9e0Dav Glass if (e.changedNode.test('p')) {
f8b3e367f0b400ff8b4feeb35c56d9387a31f9e0Dav Glass var prev = e.changedNode.previous(), lc, lc2, found = false;
f8b3e367f0b400ff8b4feeb35c56d9387a31f9e0Dav Glass if (prev) {
f8b3e367f0b400ff8b4feeb35c56d9387a31f9e0Dav Glass lc = prev.one(':last-child');
f8b3e367f0b400ff8b4feeb35c56d9387a31f9e0Dav Glass while (!found) {
f8b3e367f0b400ff8b4feeb35c56d9387a31f9e0Dav Glass if (lc) {
f8b3e367f0b400ff8b4feeb35c56d9387a31f9e0Dav Glass lc2 = lc.one(':last-child');
f8b3e367f0b400ff8b4feeb35c56d9387a31f9e0Dav Glass if (lc2) {
f8b3e367f0b400ff8b4feeb35c56d9387a31f9e0Dav Glass lc = lc2;
f8b3e367f0b400ff8b4feeb35c56d9387a31f9e0Dav Glass } else {
f8b3e367f0b400ff8b4feeb35c56d9387a31f9e0Dav Glass found = true;
f8b3e367f0b400ff8b4feeb35c56d9387a31f9e0Dav Glass }
f8b3e367f0b400ff8b4feeb35c56d9387a31f9e0Dav Glass } else {
f8b3e367f0b400ff8b4feeb35c56d9387a31f9e0Dav Glass found = true;
bc94393b95044fcdd7e46fd457bb59badde9391eDav Glass }
f8b3e367f0b400ff8b4feeb35c56d9387a31f9e0Dav Glass }
f8b3e367f0b400ff8b4feeb35c56d9387a31f9e0Dav Glass if (lc) {
f8b3e367f0b400ff8b4feeb35c56d9387a31f9e0Dav Glass this.copyStyles(lc, e.changedNode);
573bad453b98b1e493f4abfcf507f85b22b6bf4aDav Glass }
573bad453b98b1e493f4abfcf507f85b22b6bf4aDav Glass }
573bad453b98b1e493f4abfcf507f85b22b6bf4aDav Glass }
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass break;
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass }
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass var changed = this.getDomPath(e.changedNode),
24e95e1c11b518e1aaaa7f04882febe32de00b5eDav Glass cmds = {}, family, fsize, classes = [],
24e95e1c11b518e1aaaa7f04882febe32de00b5eDav Glass fColor = '', bColor = '';
24e95e1c11b518e1aaaa7f04882febe32de00b5eDav Glass
24e95e1c11b518e1aaaa7f04882febe32de00b5eDav Glass if (e.commands) {
24e95e1c11b518e1aaaa7f04882febe32de00b5eDav Glass cmds = e.commands;
24e95e1c11b518e1aaaa7f04882febe32de00b5eDav Glass }
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass changed.each(function(n) {
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass var tag = n.get('tagName').toLowerCase(),
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass cmd = EditorBase.TAG2CMD[tag],
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass el = Y.Node.getDOMNode(n);
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass if (cmd) {
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass cmds[cmd] = 1;
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass }
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass //Bold and Italic styles
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass var s = el.style;
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass if (s.fontWeight.toLowerCase() == 'bold') {
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass cmds.bold = 1;
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass }
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass if (s.fontStyle.toLowerCase() == 'italic') {
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass cmds.italic = 1;
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass }
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass if (s.textDecoration.toLowerCase() == 'underline') {
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass cmds.underline = 1;
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass }
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass if (s.textDecoration.toLowerCase() == 'line-through') {
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass cmds.strikethrough = 1;
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass }
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass
5cbdc947eb0c9c5e840d59ff8e1dd49a0e2a1887Dav Glass var family2 = n.getStyle('fontFamily').split(',')[0].toLowerCase();
5cbdc947eb0c9c5e840d59ff8e1dd49a0e2a1887Dav Glass if (family2) {
5cbdc947eb0c9c5e840d59ff8e1dd49a0e2a1887Dav Glass family = family2;
5cbdc947eb0c9c5e840d59ff8e1dd49a0e2a1887Dav Glass }
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass fsize = n.getStyle('fontSize');
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass var cls = n.get('className').split(' ');
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass Y.each(cls, function(v) {
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass if (v !== '' && (v.substr(0, 4) !== 'yui_')) {
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass classes.push(v);
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass }
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass });
24e95e1c11b518e1aaaa7f04882febe32de00b5eDav Glass
24e95e1c11b518e1aaaa7f04882febe32de00b5eDav Glass fColor = EditorBase.FILTER_RGB(n.getStyle('color'));
24e95e1c11b518e1aaaa7f04882febe32de00b5eDav Glass var bColor2 = EditorBase.FILTER_RGB(n.getStyle('backgroundColor'));
24e95e1c11b518e1aaaa7f04882febe32de00b5eDav Glass if (bColor2 !== 'transparent') {
24e95e1c11b518e1aaaa7f04882febe32de00b5eDav Glass bColor = bColor2;
24e95e1c11b518e1aaaa7f04882febe32de00b5eDav Glass }
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass });
24e95e1c11b518e1aaaa7f04882febe32de00b5eDav Glass
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass e.dompath = changed;
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass e.classNames = classes;
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass e.commands = cmds;
24e95e1c11b518e1aaaa7f04882febe32de00b5eDav Glass
24e95e1c11b518e1aaaa7f04882febe32de00b5eDav Glass //TODO Dont' like this, not dynamic enough..
24e95e1c11b518e1aaaa7f04882febe32de00b5eDav Glass if (!e.fontFamily) {
24e95e1c11b518e1aaaa7f04882febe32de00b5eDav Glass e.fontFamily = family;
24e95e1c11b518e1aaaa7f04882febe32de00b5eDav Glass }
24e95e1c11b518e1aaaa7f04882febe32de00b5eDav Glass if (!e.fontSize) {
24e95e1c11b518e1aaaa7f04882febe32de00b5eDav Glass e.fontSize = fsize;
24e95e1c11b518e1aaaa7f04882febe32de00b5eDav Glass }
24e95e1c11b518e1aaaa7f04882febe32de00b5eDav Glass if (!e.fontColor) {
24e95e1c11b518e1aaaa7f04882febe32de00b5eDav Glass e.fontColor = fColor;
24e95e1c11b518e1aaaa7f04882febe32de00b5eDav Glass }
24e95e1c11b518e1aaaa7f04882febe32de00b5eDav Glass if (!e.backgroundColor) {
24e95e1c11b518e1aaaa7f04882febe32de00b5eDav Glass e.backgroundColor = bColor;
24e95e1c11b518e1aaaa7f04882febe32de00b5eDav Glass }
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 */
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass getDomPath: function(node) {
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass
5cbdc947eb0c9c5e840d59ff8e1dd49a0e2a1887Dav Glass var domPath = [],
5cbdc947eb0c9c5e840d59ff8e1dd49a0e2a1887Dav Glass inst = this.frame.getInstance();
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass
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 }
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass if (domPath.length === 0) {
5cbdc947eb0c9c5e840d59ff8e1dd49a0e2a1887Dav Glass domPath[0] = inst.config.doc.body;
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass }
b80d65233fd7492f4b6487349f5364b9a8ca019eDav Glass
5cbdc947eb0c9c5e840d59ff8e1dd49a0e2a1887Dav Glass return inst.all(domPath.reverse());
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();
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass this.frame.on('mousedown', Y.bind(this._onFrameMouseDown, this));
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass this.frame.on('keyup', Y.bind(this._onFrameKeyUp, this));
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass this.frame.on('keydown', Y.bind(this._onFrameKeyDown, this));
323ca860aba4b2515b560796e2322d5eaae57e5aDav Glass this.frame.on('keypress', Y.bind(this._onFrameKeyPress, this));
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass inst.Selection.filter();
a2621d519886de7d60c30c5a0850f5c17fd2fb36Dav Glass this.fire('ready');
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass },
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass /**
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * Fires nodeChange event
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * @method _onFrameMouseDown
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * @private
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass */
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass _onFrameMouseDown: function(e) {
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass this.fire('nodeChange', { changedNode: e.frameTarget, changedType: 'mousedown', changedEvent: e });
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass },
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass /**
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * Fires nodeChange event for keyup on specific keys
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * @method _onFrameKeyUp
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * @private
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass */
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass _onFrameKeyUp: function(e) {
7058d70d5189510fab628ef8d64bb50dd726a941Dav Glass var inst = this.frame.getInstance(),
7058d70d5189510fab628ef8d64bb50dd726a941Dav Glass sel = new inst.Selection();
7058d70d5189510fab628ef8d64bb50dd726a941Dav Glass
7058d70d5189510fab628ef8d64bb50dd726a941Dav Glass if (sel.anchorNode) {
7058d70d5189510fab628ef8d64bb50dd726a941Dav Glass this.fire('nodeChange', { changedNode: sel.anchorNode, changedType: 'keyup', selection: sel, changedEvent: e });
7058d70d5189510fab628ef8d64bb50dd726a941Dav Glass if (EditorBase.NC_KEYS[e.keyCode]) {
f8b3e367f0b400ff8b4feeb35c56d9387a31f9e0Dav Glass this.fire('nodeChange', { changedNode: sel.anchorNode, changedType: EditorBase.NC_KEYS[e.keyCode] + '-up', selection: sel, changedEvent: e });
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass }
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass }
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass },
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass /**
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * Fires nodeChange event
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * @method _onFrameKeyDown
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * @private
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass */
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass _onFrameKeyDown: function(e) {
7058d70d5189510fab628ef8d64bb50dd726a941Dav Glass var inst = this.frame.getInstance(),
7058d70d5189510fab628ef8d64bb50dd726a941Dav Glass sel = new inst.Selection();
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass
7058d70d5189510fab628ef8d64bb50dd726a941Dav Glass if (sel.anchorNode) {
7058d70d5189510fab628ef8d64bb50dd726a941Dav Glass this.fire('nodeChange', { changedNode: sel.anchorNode, changedType: 'keydown', changedEvent: e });
7058d70d5189510fab628ef8d64bb50dd726a941Dav Glass if (EditorBase.NC_KEYS[e.keyCode]) {
7058d70d5189510fab628ef8d64bb50dd726a941Dav Glass this.fire('nodeChange', { changedNode: sel.anchorNode, changedType: EditorBase.NC_KEYS[e.keyCode], changedEvent: e });
7058d70d5189510fab628ef8d64bb50dd726a941Dav Glass this.fire('nodeChange', { changedNode: sel.anchorNode, changedType: EditorBase.NC_KEYS[e.keyCode] + '-down', changedEvent: e });
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) {
323ca860aba4b2515b560796e2322d5eaae57e5aDav Glass var inst = this.frame.getInstance(),
323ca860aba4b2515b560796e2322d5eaae57e5aDav Glass sel = new inst.Selection();
323ca860aba4b2515b560796e2322d5eaae57e5aDav Glass
323ca860aba4b2515b560796e2322d5eaae57e5aDav Glass if (sel.anchorNode) {
323ca860aba4b2515b560796e2322d5eaae57e5aDav Glass this.fire('nodeChange', { changedNode: sel.anchorNode, changedType: 'keypress', changedEvent: e });
323ca860aba4b2515b560796e2322d5eaae57e5aDav Glass if (EditorBase.NC_KEYS[e.keyCode]) {
323ca860aba4b2515b560796e2322d5eaae57e5aDav Glass this.fire('nodeChange', { changedNode: sel.anchorNode, changedType: EditorBase.NC_KEYS[e.keyCode] + '-press', changedEvent: e });
323ca860aba4b2515b560796e2322d5eaae57e5aDav Glass }
323ca860aba4b2515b560796e2322d5eaae57e5aDav Glass }
323ca860aba4b2515b560796e2322d5eaae57e5aDav Glass },
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav 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
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * @return {EditorBase}
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * @chainable
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass */
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass focus: function() {
a0c3229e02af852e4b15bf6d4cf4e862440bb00eDav Glass this.frame.focus();
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 }, {
24e95e1c11b518e1aaaa7f04882febe32de00b5eDav Glass /**
9f2068537ef4a78d9a11fb5a136991d9d9e059a0Dav Glass * @static
9f2068537ef4a78d9a11fb5a136991d9d9e059a0Dav Glass * @property TABKEY
9f2068537ef4a78d9a11fb5a136991d9d9e059a0Dav Glass * @description The HTML markup to use for the tabkey
9f2068537ef4a78d9a11fb5a136991d9d9e059a0Dav Glass */
9f2068537ef4a78d9a11fb5a136991d9d9e059a0Dav Glass TABKEY: '<span class="tab">&nbsp;&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 /**
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * Editor Strings
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * @static
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * @property STRINGS
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass */
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass STRINGS: {
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass /**
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * Title of frame document: Rich Text Editor
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * @static
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * @property STRINGS.title
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass */
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: {
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass value: '<br>',
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 === '') {
573bad453b98b1e493f4abfcf507f85b22b6bf4aDav Glass str = '<br>';
573bad453b98b1e493f4abfcf507f85b22b6bf4aDav 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 /**
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 }
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass }
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass }
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass });
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass Y.EditorBase = EditorBase;
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass /**
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * @event nodeChange
dbf2c770f8178b12e8fe3c36bfa29df58ef13959Dav Glass * @description Fired from mouseup & keyup.
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