Skip to content

Commit

Permalink
revert some experimental code
Browse files Browse the repository at this point in the history
  • Loading branch information
gpoitch committed Feb 26, 2015
1 parent 4e9dcd0 commit acad7cb
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 22 deletions.
27 changes: 16 additions & 11 deletions dist/content-kit-editor.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @overview content-kit-editor: A modern, minimalist WYSIWYG editor.
* @version 0.1.1
* @version 0.1.2
* @author Garth Poitras <garth22@gmail.com> (http://garthpoitras.com/)
* @license MIT
* Last modified: Feb 26, 2015
Expand Down Expand Up @@ -2257,18 +2257,23 @@
})
};

function $$editor$$isNaughtyKeystroke(e) {
return (!e.shiftKey && e.which === $$$utils$keycodes$$default.ENTER) ||
(e.ctrlKey && e.which === $$$utils$keycodes$$default.M) ||
(e.which === $$$utils$keycodes$$default.BKSP);
}

function $$editor$$bindContentEditableTypingListeners(editor) {

editor.element.addEventListener('keydown', function(e) {
if ($$editor$$isNaughtyKeystroke(e)) {
e.preventDefault();
}

editor.element.addEventListener('keyup', function(e) {
// Assure there is always a supported block tag, and not empty text nodes or divs.
// On a carrage return, make sure to always generate a 'p' tag
if (!$$$utils$selection$utils$$getSelectionBlockElement() ||
!editor.element.textContent ||
(!e.shiftKey && e.which === $$$utils$keycodes$$default.ENTER) || (e.ctrlKey && e.which === $$$utils$keycodes$$default.M)) {
document.execCommand('formatBlock', false, node_modules$content$kit$compiler$src$types$type$$default.PARAGRAPH.tag);
} //else if (e.which === Keycodes.BKSP) {
// TODO: Need to rerender when backspacing 2 blocks together
//var cursorIndex = editor.getCursorIndexInCurrentBlock();
//var currentBlockElement = getSelectionBlockElement();
//editor.renderBlockAt(editor.getCurrentBlockIndex(), true);
//setCursorIndexInElement(currentBlockElement, cursorIndex);
//}
});

// On 'PASTE' sanitize and insert
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "content-kit-editor",
"version": "0.1.2",
"version": "0.1.3",
"description": "A modern, minimalist WYSIWYG editor.",
"repository": "https://github.com/bustlelabs/content-kit-editor",
"main": "dist/content-kit-editor.js",
Expand Down
25 changes: 15 additions & 10 deletions src/js/editor/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,23 @@ var defaults = {
})
};

function isNaughtyKeystroke(e) {
return (!e.shiftKey && e.which === Keycodes.ENTER) ||
(e.ctrlKey && e.which === Keycodes.M) ||
(e.which === Keycodes.BKSP);
}

function bindContentEditableTypingListeners(editor) {

editor.element.addEventListener('keydown', function(e) {
if (isNaughtyKeystroke(e)) {
e.preventDefault();
}

editor.element.addEventListener('keyup', function(e) {
// Assure there is always a supported block tag, and not empty text nodes or divs.
// On a carrage return, make sure to always generate a 'p' tag
if (!getSelectionBlockElement() ||
!editor.element.textContent ||
(!e.shiftKey && e.which === Keycodes.ENTER) || (e.ctrlKey && e.which === Keycodes.M)) {
document.execCommand('formatBlock', false, Type.PARAGRAPH.tag);
} //else if (e.which === Keycodes.BKSP) {
// TODO: Need to rerender when backspacing 2 blocks together
//var cursorIndex = editor.getCursorIndexInCurrentBlock();
//var currentBlockElement = getSelectionBlockElement();
//editor.renderBlockAt(editor.getCurrentBlockIndex(), true);
//setCursorIndexInElement(currentBlockElement, cursorIndex);
//}
});

// On 'PASTE' sanitize and insert
Expand Down

0 comments on commit acad7cb

Please sign in to comment.