Skip to content

Commit

Permalink
eliminated constants file
Browse files Browse the repository at this point in the history
  • Loading branch information
gpoitch committed Sep 14, 2014
1 parent 3c084ce commit f4b6850
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 54 deletions.
5 changes: 3 additions & 2 deletions src/js/content-kit-editor/commands/bold.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import TextFormatCommand from './text-format';
import { RegEx } from '../constants';
import { getSelectionBlockTagName } from '../utils/selection-utils';
import { inherit } from '../../content-kit-utils/object-utils';
import Type from '../../content-kit-compiler/types/type';

var RegExpHeadingTag = /^(h1|h2|h3|h4|h5|h6)$/i;

function BoldCommand() {
TextFormatCommand.call(this, {
name: 'bold',
Expand All @@ -15,7 +16,7 @@ inherit(BoldCommand, TextFormatCommand);

BoldCommand.prototype.exec = function() {
// Don't allow executing bold command on heading tags
if (!RegEx.HEADING_TAG.test(getSelectionBlockTagName())) {
if (!RegExpHeadingTag.test(getSelectionBlockTagName())) {
BoldCommand._super.prototype.exec.call(this);
}
};
Expand Down
5 changes: 3 additions & 2 deletions src/js/content-kit-editor/commands/link.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import TextFormatCommand from './text-format';
import Prompt from '../views/prompt';
import { RegEx } from '../constants';
import { getSelectionTagName } from '../utils/selection-utils';
import { inherit } from '../../content-kit-utils/object-utils';
import Type from '../../content-kit-compiler/types/type';

var RegExpHttp = /^https?:\/\//i;

function LinkCommand() {
TextFormatCommand.call(this, {
name: 'link',
Expand All @@ -24,7 +25,7 @@ LinkCommand.prototype.exec = function(url) {
if(this.tag === getSelectionTagName()) {
this.unexec();
} else {
if (!RegEx.HTTP_PROTOCOL.test(url)) {
if (!RegExpHttp.test(url)) {
url = 'http://' + url;
}
LinkCommand._super.prototype.exec.call(this, url);
Expand Down
37 changes: 0 additions & 37 deletions src/js/content-kit-editor/constants.js

This file was deleted.

5 changes: 3 additions & 2 deletions src/js/content-kit-editor/editor/editor-html-renderer.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { RegEx } from '../constants';
import HTMLRenderer from '../../content-kit-compiler/renderers/html-renderer';
import Type from '../../content-kit-compiler/types/type';
import { inherit } from '../../content-kit-utils/object-utils';

var RegExpHttp = /^https?:\/\//i;

function embedRenderer(model) {
var embedAttrs = model.attributes;
var isVideo = embedAttrs.embed_type === 'video';
Expand All @@ -17,7 +18,7 @@ function embedRenderer(model) {
}

function imageRenderer(model) {
var imagePersisted = RegEx.HTTP_PROTOCOL.test(model.attributes.src);
var imagePersisted = RegExpHttp.test(model.attributes.src);
return '<div class="ck-embed ck-image-embed' + (imagePersisted ? '' : ' ck-image-local') + '" contenteditable="false">' +
'<figure>' + this.render(model) + '</figure>' +
'</div>';
Expand Down
2 changes: 1 addition & 1 deletion src/js/content-kit-editor/editor/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import OrderedListCommand from '../commands/ordered-list';
import ImageCommand from '../commands/image';
import OEmbedCommand from '../commands/oembed';
import TextFormatCommand from '../commands/text-format';
import { Keycodes } from '../constants';
import Keycodes from '../utils/keycodes';
import { getSelectionBlockElement, getSelectionBlockTagName } from '../utils/selection-utils';
import EventEmitter from '../utils/event-emitter';
import { cleanPastedContent } from '../utils/paste-utils';
Expand Down
6 changes: 6 additions & 0 deletions src/js/content-kit-editor/utils/keycodes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default {
BKSP : 8,
ENTER : 13,
ESC : 27,
DEL : 46
};
10 changes: 6 additions & 4 deletions src/js/content-kit-editor/utils/paste-utils.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { RegEx } from '../constants';

var RegExpNewLine = /[\r\n]/g;

function plainTextToBlocks(plainText, tag) {
var blocks = plainText.split(RegEx.NEWLINE),
len = blocks.length,
block, openTag, closeTag, content, i;
var blocks = plainText.split(RegExpNewLine);
var len = blocks.length;
var block, openTag, closeTag, content, i;

if(len < 2) {
return plainText;
} else {
Expand Down
18 changes: 17 additions & 1 deletion src/js/content-kit-editor/utils/selection-utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
import { SelectionDirection, RootTags } from '../constants';
import { nodeIsDescendantOfElement } from './element-utils';
import Type from '../../content-kit-compiler/types/type';

// TODO: remove, pass in Editor's current block set
var RootTags = [
Type.TEXT.tag,
Type.HEADING.tag,
Type.SUBHEADING.tag,
Type.QUOTE.tag,
Type.LIST.tag,
Type.ORDERED_LIST.tag
];

var SelectionDirection = {
LEFT_TO_RIGHT : 1,
RIGHT_TO_LEFT : 2,
SAME_NODE : 3
};

function getDirectionOfSelection(selection) {
var node = selection.anchorNode;
Expand Down
4 changes: 2 additions & 2 deletions src/js/content-kit-editor/views/embed-intent.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Toolbar from './toolbar';
import { inherit } from '../../content-kit-utils/object-utils';
import { getSelectionBlockElement } from '../utils/selection-utils';
import { elementContentIsEmpty, positionElementToLeftOf, positionElementCenteredIn } from '../utils/element-utils';
import { ToolbarDirection, Keycodes } from '../constants';
import Keycodes from '../utils/keycodes';
import { createDiv } from '../utils/element-utils';

var LayoutStyle = {
Expand Down Expand Up @@ -37,7 +37,7 @@ function EmbedIntent(options) {
e.stopPropagation();
});

embedIntent.toolbar = new Toolbar({ embedIntent: embedIntent, editor: embedIntent.editorContext, commands: options.commands, direction: ToolbarDirection.RIGHT });
embedIntent.toolbar = new Toolbar({ embedIntent: embedIntent, editor: embedIntent.editorContext, commands: options.commands, direction: Toolbar.Direction.RIGHT });
embedIntent.isActive = false;

function embedIntentHandler() {
Expand Down
2 changes: 1 addition & 1 deletion src/js/content-kit-editor/views/prompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { inherit } from '../../content-kit-utils/object-utils';
import { inherit } from '../../content-kit-utils/object-utils';
import { restoreRange } from '../utils/selection-utils';
import { createDiv, positionElementToRect } from '../utils/element-utils';
import { Keycodes } from '../constants';
import Keycodes from '../utils/keycodes';

var container = document.body;
var hiliter = createDiv('ck-editor-hilite');
Expand Down
2 changes: 1 addition & 1 deletion src/js/content-kit-editor/views/text-format-toolbar.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Toolbar from './toolbar';
import { inherit } from '../../content-kit-utils/object-utils';
import { selectionIsEditable, selectionIsInElement } from '../utils/selection-utils';
import { Keycodes } from '../constants';
import Keycodes from '../utils/keycodes';

function handleTextSelection(toolbar) {
var selection = window.getSelection();
Expand Down
8 changes: 7 additions & 1 deletion src/js/content-kit-editor/views/toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ import View from './view';
import ToolbarButton from './toolbar-button';
import { inherit } from '../../content-kit-utils/object-utils';
import { tagsInSelection } from '../utils/selection-utils';
import { ToolbarDirection } from '../constants';
import { createDiv, swapElements, positionElementToRightOf, positionElementCenteredAbove } from '../utils/element-utils';

var ToolbarDirection = {
TOP : 1,
RIGHT : 2
};

function updateButtonsForSelection(buttons, selection) {
var selectedTags = tagsInSelection(selection),
len = buttons.length,
Expand Down Expand Up @@ -118,4 +122,6 @@ Toolbar.prototype.setDirection = function(direction) {
}
};

Toolbar.Direction = ToolbarDirection;

export default Toolbar;

0 comments on commit f4b6850

Please sign in to comment.