editor-base.js revision 10d8bafc5c24f3a4285cf6060a1935ba5cfc4b85
200N/A * Base class for Editor. Handles the business logic of Editor, no GUI involved only utility methods and events.
200N/A * Base class for Editor. Handles the business logic of Editor, no GUI involved only utility methods and events.
200N/A var EditorBase = function() {
618N/A initializer: function() {
200N/A designMode: true,
1625N/A emitFacade: true,
200N/A destructor: function() {
200N/A * Copy certain styles from one node instance to another (used for new paragraph creation mainly)
206N/A _lastBookmark: null,
1625N/A * the event came from the document, it will get the last child of the last child of the document
1625N/A _resolveChangedNode: function(n) {
1625N/A _defNodeChangeFn: function(e) {
200N/A switch (e.changedType) {
if (!EditorBase.NC_KEYS[e.changedEvent.keyCode] && !e.changedEvent.shiftKey && !e.changedEvent.ctrlKey && (e.changedEvent.keyCode !== 13)) {
if (e.commands) {
var normal = false;
if (cmd) {
normal = true;
if (family2) {
if (family) {
if (!e.fontFamily) {
if (!e.fontSize) {
if (!e.fontColor) {
if (!e.backgroundColor) {
while (domNode !== null) {
if ((domNode === inst.config.doc.documentElement) || (domNode === inst.config.doc) || !domNode.tagName) {
domNode = null;
domNode = null;
domNode = null;
if (nodeList) {
_afterFrameReady: function() {
_beforeFrameDeactivate: function(e) {
_onFrameActivate: function(e) {
n.remove();
_onPaste: function(e) {
this.fire('nodeChange', { changedNode: e.frameTarget, changedType: 'paste', changedEvent: e.frameEvent });
_onFrameMouseUp: function(e) {
this.fire('nodeChange', { changedNode: e.frameTarget, changedType: 'mouseup', changedEvent: e.frameEvent });
_onFrameMouseDown: function(e) {
this.fire('nodeChange', { changedNode: e.frameTarget, changedType: 'mousedown', changedEvent: e.frameEvent });
_currentSelection: null,
_currentSelectionTimer: null,
_currentSelectionClear: null,
_onFrameKeyDown: function(e) {
if (!this._currentSelection) {
if (this._currentSelectionTimer) {
this._currentSelectionClear = true;
this.fire('nodeChange', { changedNode: sel.anchorNode, changedType: 'keydown', changedEvent: e.frameEvent });
this.fire('nodeChange', { changedNode: sel.anchorNode, changedType: EditorBase.NC_KEYS[e.keyCode], changedEvent: e.frameEvent });
this.fire('nodeChange', { changedNode: sel.anchorNode, changedType: EditorBase.NC_KEYS[e.keyCode] + '-down', changedEvent: e.frameEvent });
_onFrameKeyPress: function(e) {
this.fire('nodeChange', { changedNode: sel.anchorNode, changedType: 'keypress', changedEvent: e.frameEvent });
this.fire('nodeChange', { changedNode: sel.anchorNode, changedType: EditorBase.NC_KEYS[e.keyCode] + '-press', changedEvent: e.frameEvent });
_onFrameKeyUp: function(e) {
this.fire('nodeChange', { changedNode: sel.anchorNode, changedType: 'keyup', selection: sel, changedEvent: e.frameEvent });
this.fire('nodeChange', { changedNode: sel.anchorNode, changedType: EditorBase.NC_KEYS[e.keyCode] + '-up', selection: sel, changedEvent: e.frameEvent });
if (this._currentSelectionClear) {
* @return {Node/NodeList} The Node or Nodelist affected by the command. Only returns on override commands, not browser defined commands.
switch (cmd) {
return ret;
getInstance: function() {
* @param {Selector/HTMLElement/Node} node The node to append the Editor to
show: function() {
hide: function() {
getContent: function() {
return html;
NORMALIZE_FONTSIZE: function(n) {
switch (size) {
return size;
* @description Converts an RGB color string to a hex color, example: rgb(0, 255, 0) converts to #00ff00
var exp = new RegExp("(.*?)rgb\\s*?\\(\\s*?([0-9]+).*?,\\s*?([0-9]+).*?,\\s*?([0-9]+).*?\\)(.*?)", "gi");
return css;
TAG2CMD: {
NC_KEYS: {
STRINGS: {
ATTRS: {
content: {
getter: function() {
dir: {
writeOnce: true,
linkedcss: {
if (this.frame) {
return css;
extracss: {
value: false,
if (this.frame) {
return css;
defaultblock: {
* <dt>changedType</dt><dd>The type of change: mousedown, mouseup, right, left, backspace, tab, enter, etc..</dd>
* <dt>commands</dt><dd>The list of execCommands that belong to this change and the dompath that's associated with the changedNode</dd>
* <dt>classNames</dt><dd>An array of classNames that are applied to the changedNode and all of it's parents</dd>