From 458c834dc9c907b479b73feeac6950481b2918c5 Mon Sep 17 00:00:00 2001 From: khaydarov Date: Wed, 7 Dec 2016 21:25:31 +0300 Subject: [PATCH] new redactor version (#94) * new redactor version * update * update * bundler config updated * clear bundler without plugins --- .gitignore | 5 +- codex-editor.css | 414 ++ codex-editor.js | 6336 ++++++++++++++++++++---------- codex-editor.js.map | 1 + editor.css | 267 -- editor.js | 129 + example.html | 448 +-- fonts/codex_editor/icon-plus.svg | 16 + icons.css | 63 + index.js | 8 + modules/callbacks.js | 758 ++++ modules/caret.js | 241 ++ modules/content.js | 631 +++ modules/core.js | 181 + modules/draw.js | 311 ++ modules/notifications.js | 45 + modules/parser.js | 261 ++ modules/renderer.js | 171 + modules/saver.js | 111 + modules/toolbar/inline.js | 485 +++ modules/toolbar/settings.js | 249 ++ modules/toolbar/toolbar.js | 104 + modules/toolbar/toolbox.js | 152 + modules/tools.js | 10 + modules/transport.js | 101 + modules/ui.js | 383 ++ package.json | 16 + plugins/code/code.css | 7 - plugins/code/code.js | 74 - plugins/header/header.css | 19 - plugins/header/header.js | 182 - plugins/images/images.css | 99 - plugins/images/images.js | 353 -- plugins/link/link.css | 75 - plugins/link/link.js | 321 -- plugins/link/loading.gif | Bin 329 -> 0 bytes plugins/list/list.css | 15 - plugins/list/list.js | 179 - plugins/paragraph/paragraph.css | 0 plugins/paragraph/paragraph.js | 69 - plugins/quote/img/01.jpg | Bin 4033 -> 0 bytes plugins/quote/img/codex.png | Bin 12934 -> 0 bytes plugins/quote/img/upload.png | Bin 1853 -> 0 bytes plugins/quote/quote.css | 172 - plugins/quote/quote.js | 403 -- webpack.config.js | 68 + 46 files changed, 9181 insertions(+), 4752 deletions(-) create mode 100644 codex-editor.css create mode 100644 codex-editor.js.map delete mode 100644 editor.css create mode 100644 editor.js create mode 100644 fonts/codex_editor/icon-plus.svg create mode 100644 icons.css create mode 100644 index.js create mode 100644 modules/callbacks.js create mode 100644 modules/caret.js create mode 100644 modules/content.js create mode 100644 modules/core.js create mode 100644 modules/draw.js create mode 100644 modules/notifications.js create mode 100644 modules/parser.js create mode 100644 modules/renderer.js create mode 100644 modules/saver.js create mode 100644 modules/toolbar/inline.js create mode 100644 modules/toolbar/settings.js create mode 100644 modules/toolbar/toolbar.js create mode 100644 modules/toolbar/toolbox.js create mode 100644 modules/tools.js create mode 100644 modules/transport.js create mode 100644 modules/ui.js create mode 100644 package.json delete mode 100644 plugins/code/code.css delete mode 100644 plugins/code/code.js delete mode 100644 plugins/header/header.css delete mode 100644 plugins/header/header.js delete mode 100644 plugins/images/images.css delete mode 100644 plugins/images/images.js delete mode 100644 plugins/link/link.css delete mode 100644 plugins/link/link.js delete mode 100644 plugins/link/loading.gif delete mode 100644 plugins/list/list.css delete mode 100644 plugins/list/list.js delete mode 100644 plugins/paragraph/paragraph.css delete mode 100644 plugins/paragraph/paragraph.js delete mode 100755 plugins/quote/img/01.jpg delete mode 100644 plugins/quote/img/codex.png delete mode 100644 plugins/quote/img/upload.png delete mode 100644 plugins/quote/quote.css delete mode 100644 plugins/quote/quote.js create mode 100644 webpack.config.js diff --git a/.gitignore b/.gitignore index e2cccc2a..4129319d 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,7 @@ Thumbs.db /.idea/ /*.sublime-project -/*.sublime-workspace \ No newline at end of file +/*.sublime-workspace + +node_modules/* +plugins/* \ No newline at end of file diff --git a/codex-editor.css b/codex-editor.css new file mode 100644 index 00000000..987309bc --- /dev/null +++ b/codex-editor.css @@ -0,0 +1,414 @@ +/** +* CodeX Editor stylesheets +* @author CodeX Team https://ifmo.su +* +* https://github.com/codex-team/codex.editor +*/ + + +@import url('icons.css'); + + +/** +* Editor wrapper +*/ +.codex-editor{ + position: relative; +} + +/** +* Working zone - redactor +*/ +.ce-redactor{ + position: relative; + padding-bottom: 120px; + min-height: 350px; +} + +/*.ce-redactor * { + box-sizing: border-box; +}*/ + +/** +* Remove outlines from inputs +*/ +.ce-redactor [contenteditable]{ + outline: none !important; +} + +/** +* Toolbar +*/ +.ce-toolbar{ + position: absolute; + z-index: 2; + width: 100%; + + /* hidden by default */ + display: none; +} +.ce-toolbar.opened{ + display: block; +} + + .ce-toolbar__content { + position: relative; + max-width: 600px; + margin: 0 auto; + } +/** +* Plus button +*/ +.ce-toolbar__plus{ + background-image: url('fonts/codex_editor/icon-plus.svg'); + background-position: center center; + background-repeat: no-repeat; + text-align: center; + transition: transform 100ms ease; + will-change: transform; + + margin-left: -50px; +} +.ce-toolbar__plus.clicked{ + transform: rotate(45deg); +} + +/** +* Tools list +*/ +.ce-toolbar__tools{ + position: absolute; + top: 0; + left: 0; + + /* hidden by default */ + opacity: 0; + visibility: hidden; + transform: translateX(-100px); + transition: all 150ms cubic-bezier(0.600, -0.280, 0.735, 0.045); +} +.ce-toolbar__tools.opened{ + opacity: 1; + visibility: visible; + transform: none; +} + +.ce-toolbar__plus, +.ce-toolbar__tools li { + display: inline-block; + width: 32px; + height: 32px; + background-color: #eff2f5; + /*box-shadow: 0 0 0 1px #6d748c;*/ + margin-right: 17px; + border-radius: 16px; + text-align: center; + cursor: pointer; + font-size: 14px; + + will-change: transform, margin-right; + transition: transform 200ms cubic-bezier(0.600, -0.280, 0.735, 0.045), margin 200ms ease-out; +} +.ce-toolbar__tools li i{ + line-height: 32px; +} +.ce-toolbar__tools li:hover, +.ce-toolbar__tools .selected{ + background: #383b5d; + box-shadow: none; + color: #fff; +} + +/* animation for tools opening */ +.ce-toolbar__tools li{ + transform: rotate(-180deg) scale(.7); + margin-right: -15px; +} +.ce-toolbar__tools.opened li{ + transform: none; + margin-right: 17px; +} + +/** +* Toolbar right zone with SETTINGS and DELETE +*/ +.ce-toolbar__actions{ + position: absolute; + right: 10px; + border-radius: 2px; + padding: 2px 4px; + /*background: #f9f9fb;*/ +} + +/** +* Settings button +*/ +.ce-toolbar__settings-btn{ + margin-right: .3em; + cursor: pointer; +} +.ce-toolbar__settings-btn, +.ce-toolbar__remove-btn{ + color: #5e6475; +} +.ce-toolbar__settings-btn:hover, +.ce-toolbar__remove-btn:hover{ + color: #272b35 +} + +/** +* Settigns pane +*/ +.ce-settings, +.ce-toolbar__remove-confirmation{ + position: absolute; + right: 0; + margin-top: 10px; + min-width: 200px; + background: #FFFFFF; + border: 1px solid #e7e9f1; + box-shadow: 0px 2px 5px 0px rgba(16, 23, 49, 0.05); + border-radius: 3px; + white-space: nowrap; + color: #707684; + font-size: 13.4px; + + /* hidden by default */ + display: none; +} + +/** +* Settings and remove-confirmation corner +*/ +.ce-settings:before, +.ce-toolbar__remove-confirmation:before, +.ce-settings:after, +.ce-toolbar__remove-confirmation:after{ + content: ""; + position: absolute; + top: -14px; + right: 10px; + border-style: solid; +} + +.ce-settings:before, +.ce-toolbar__remove-confirmation:before { + margin: -2px -1px 0; + border-width: 8px; + border-color: transparent transparent #e7e9f1 transparent; +} +.ce-settings:after, +.ce-toolbar__remove-confirmation:after { + border-width: 7px; + border-color: transparent transparent #fff transparent; +} +.ce-settings:before, +.ce-settings:after{ + right: 31px; +} +.ce-toolbar__remove-confirmation:before, +.ce-toolbar__remove-confirmation:after{ + right: 10px; +} +.ce-toolbar__remove-confirmation{ + right: -3px; +} + + + +.ce-settings__item, +.ce-toolbar__remove-confirm +.ce-toolbar__remove-cancel { + cursor: pointer; +} + +.ce-settings.opened, +.ce-toolbar__remove-confirmation.opened{ + display: block; +} + +.ce-settings_plugin{ + padding: 20px; + border-bottom: 1px solid #E8EAEE; +} +.ce-settings_plugin:empty{ + display: none; +} +.ce-settings_default{ + padding: 20px; +} +.ce-settings__item i { + margin-right: 1.3em; +} + + +/** + * Trash button + */ +.ce-toolbar__remove-btn { + cursor: pointer; +} +.ce-toolbar__remove-confirmation{ + padding: 5px 0; +} +.ce-toolbar__remove-confirm, +.ce-toolbar__remove-cancel{ + padding: 10px 20px; +} +.ce-toolbar__remove-confirm{ + color: #ea5c5c; +} +.ce-toolbar__remove-confirm:hover{ + background: #e23d3d; + color: #fff; +} +.ce-toolbar__remove-cancel:hover{ + background: #edf0f5; +} + + + +/** +* Overlayed inline toolbar +*/ +.ce-toolbar-inline{ + position: absolute; + left: 0; + top: 0; + z-index: 3; + background: #242533; + border-radius: 3px; + padding: 0 5px; + margin-top: -.5em; + + will-change: transform; + transition: transform .2s cubic-bezier(0.600, -0.280, 0.735, 0.045); + + color: #fff; + + /* hidden by default */ + display: none; +} +.ce-toolbar-inline.opened { + display: block; +} +.ce-toolbar-inline__buttons{ +} +.ce-toolbar-inline__buttons button{ + background: none; + border: 0; + height: auto !important; + padding: 12px 8px; + color: inherit; + font-size: 12px; + cursor: pointer; +} +.ce-toolbar-inline__buttons button:hover{ + background: #171827; + color: #428bff; +} +.ce-toolbar-inline__actions{ + position: absolute; + left: 0; + top: 0; + bottom: 0; + right: 0; + border-radius: 3px; + background: #242533; + display: none; +} + .ce-toolbar-inline__actions.opened{ + display: block; + } + .ce-toolbar-inline__actions input{ + background: transparent !important; + border : 0 !important; + box-sizing: border-box !important; + padding: 10px; + width: 100%; + color: #fff; + outline: none; + } + + .ce-toolbar-inline__actions input::-moz-placeholder{ color: #afb4c3 !important;} + .ce-toolbar-inline__actions input::-webkit-input-placeholder{ color: #afb4c3 !important;} + + + + +/** +* Base blocks +*/ +.ce-block{ + margin: 0 5px; + border-radius: 3px; +} +.ce-block--focused{ + background: #f9f9fb; +} + +.ce-block--feed-mode{ + position: relative; +} +.ce-block--feed-mode:before { + content: '\e81b'; + font-family: "codex_editor"; + display: inline-block; + position: absolute; + + left: 17px; + top: 13px; + font-size: 16px; + color: #ef4a4a; +} + +/** +* Block content holder +*/ +.ce-block__content{ + max-width: 600px; + margin: 0 auto; + padding: 1px; +} +.ce-block--stretched{ + max-width: none; + padding: 0; +} + +/** +* Typographycs +*/ +.ce-redactor p{ + margin: 0; +} + +/** +* Loading bar class +*/ +.ce-redactor__loader{ + background-image: repeating-linear-gradient(-45deg, transparent, transparent 4px, #f5f9ff 4px, #eaedef 8px) !important; + background-size: 56px 56px; + animation: loading-bar 1.3s infinite linear; +} + +@keyframes loading-bar { + 100% { background-position: -56% 0 } +} + + +/** +* Mobile viewport styles +* ================================= +*/ +@media all and (max-width: 800px){ + + .ce-block{ + margin: 0; + padding-left: 5px; + padding-right: 5px; + } + .ce-block__content{ + margin: 0 15px; + } + +} \ No newline at end of file diff --git a/codex-editor.js b/codex-editor.js index 4093dcdb..8157dd4f 100644 --- a/codex-editor.js +++ b/codex-editor.js @@ -1,2083 +1,4253 @@ -/** -* CodeX Editor -* https://ifmo.su/editor -* @author CodeX team team@ifmo.su -*/ - -var cEditor = (function (cEditor) { - - // Default settings - cEditor.settings = { - tools : ['paragraph', 'header', 'picture', 'list', 'quote', 'code', 'twitter', 'instagram', 'smile'], - textareaId : 'codex-editor', - - // First-level tags viewing as separated blocks. Other'll be inserted as child - blockTags : ['P','BLOCKQUOTE','UL','CODE','OL','H1','H2','H3','H4','H5','H6'], - uploadImagesUrl : '/editor/transport/', - }; - - // Static nodes - cEditor.nodes = { - textarea : null, - wrapper : null, - toolbar : null, - notifications : null, - showSettingsButton : null, - blockSettings : null, - toolbarButtons : {}, // { type : DomEl, ... } - redactor : null, - }; - - // Current editor state - cEditor.state = { - jsonOutput : [], - blocks : [], - inputs : [], - }; - - /** - * Initialization - * @uses Promise cEditor.core.prepare - * @param {} userSettings are : - * - tools [], - * - textareaId String - * ... - */ - cEditor.start = function (userSettings) { - - // Prepare editor settings - this.core.prepare(userSettings) - - // If all ok, make UI, bind events and parse initial-content - .then(this.ui.make) - .then(this.ui.addTools) - .then(this.ui.bindEvents) - .then(this.transport.prepare) - // .then(this.parser.parseTextareaContent) - .then(this.renderer.makeBlocksFromData) - .then(this.ui.saveInputs) - .catch(function (error) { - cEditor.core.log('Initialization failed with error: %o', 'warn', error); - }); - - }; - - return cEditor; - -})({}); - - -/** -* Redactor core methods -* Methods: -* - init -* - log -* - insertAfter -* - isDomNode -*/ -cEditor.core = { - - /** - * Editor preparing method - * @return Promise - */ - prepare : function (userSettings) { - - return new Promise(function(resolve, reject){ - - if ( userSettings ) { - - cEditor.settings.tools = userSettings.tools || cEditor.settings.tools; - - } - - if (userSettings.data) { - cEditor.state.blocks = userSettings.data; - } - - cEditor.nodes.textarea = document.getElementById(userSettings.textareaId || cEditor.settings.textareaId); - - if (typeof cEditor.nodes.textarea === undefined || cEditor.nodes.textarea === null) { - reject(Error("Textarea wasn't found by ID: #" + userSettings.textareaId)); - } else { - resolve(); - } - - }); - - }, - - /** - * Logging method - * @param type = ['log', 'info', 'warn'] - */ - log : function (msg, type, arg) { - - type = type || 'log'; - - if (!arg) { - arg = msg || 'undefined'; - msg = '[codex-editor]: %o'; - } else { - msg = '[codex-editor]: ' + msg; - } - - try{ - if ( 'console' in window && console[ type ] ){ - if ( arg ) console[ type ]( msg , arg ); - else console[ type ]( msg ); - } - - }catch(e){} - - }, - - /** - * @protected - * Helper for insert one element after another - */ - insertAfter : function (target, element) { - target.parentNode.insertBefore(element, target.nextSibling); - }, - - /** - * @const - * Readable DOM-node types map - */ - nodeTypes : { - TAG : 1, - TEXT : 3, - COMMENT : 8 - }, - - /** - * @const - * Readable keys map - */ - keys : { BACKSPACE: 8, TAB: 9, ENTER: 13, SHIFT: 16, CTRL: 17, ALT: 18, ESC: 27, SPACE: 32, LEFT: 37, UP: 38, DOWN: 40, RIGHT: 39, DELETE: 46, META: 91 }, - - /** - * @protected - * Check object for DOM node - */ - isDomNode : function (el) { - return el && typeof el === 'object' && el.nodeType && el.nodeType == this.nodeTypes.TAG; - } - -}; - - -/** -* Methods for parsing JSON reactor data to HTML blocks -*/ -cEditor.renderer = { - - /** - * Asyncronously parses input JSON to redactor blocks - */ - makeBlocksFromData : function () { - - - Promise.resolve() - - /** First, get JSON from state */ - .then(function() { - return cEditor.state.blocks; - }) - - /** Then, start to iterate they */ - .then(cEditor.renderer.appendBlocks) - - /** Write log if something goes wrong */ - .catch(function(error) { - cEditor.core.log('Error while parsing JSON: %o', 'error', error); - }); - - }, - - /** - * Parses JSON to blocks - * @param {object} data - * @return Primise -> nodeList - */ - appendBlocks : function (data) { - - var blocks = data.items; - - /** - * Sequence of one-by-one blocks appending - * Uses to save blocks order after async-handler - */ - var nodeSequence = Promise.resolve(); - - for (var index = 0; index < blocks.length ; index++ ) { - - /** Add node to sequence at specified index */ - cEditor.renderer.appendNodeAtIndex(nodeSequence, blocks, index); - - } - - }, - - /** - * Append node at specified index - */ - appendNodeAtIndex : function (nodeSequence, blocks, index) { - - /** We need to append node to sequence */ - nodeSequence - - /** first, get node async-aware */ - .then(function() { - - return cEditor.renderer.getNodeAsync(blocks , index); - - }) - - /** - * second, compose editor-block from JSON object - */ - .then(cEditor.renderer.createBlockFromData) - - /** - * now insert block to redactor - */ - .then(function(blockData){ - - /** - * blockData has 'block' and 'type' information - */ - cEditor.content.insertBlock(blockData.block, blockData.type); - - /** Pass created block to next step */ - return blockData.block; - - }) - - /** Log if something wrong with node */ - .catch(function(error) { - cEditor.core.log('Node skipped while parsing because %o', 'error', error); - }); - - }, - - - /** - * Asynchronously returns block data from blocksList by index - * @return Promise to node - */ - getNodeAsync : function (blocksList, index) { - - return Promise.resolve().then(function() { - - return blocksList[index]; - - }); - }, - - /** - * Creates editor block by JSON-data - * - * @uses render method of each plugin - * - * @param {object} blockData looks like - * { header : { - * text: '', - * type: 'H3', ... - * } - * } - * @return {object} with type and Element - */ - createBlockFromData : function (blockData) { - - /** New parser */ - var pluginName = blockData.type; - - /** Get first key of object that stores plugin name */ - // for (var pluginName in blockData) break; - - /** Check for plugin existance */ - if (!cEditor.tools[pluginName]) { - throw Error(`Plugin «${pluginName}» not found`); - } - - /** Check for plugin having render method */ - if (typeof cEditor.tools[pluginName].render != 'function') { - - throw Error(`Plugin «${pluginName}» must have «render» method`); - } - - /** New Parser */ - var block = cEditor.tools[pluginName].render(blockData.data); - - /** Fire the render method with data */ - // var block = cEditor.tools[pluginName].render(blockData[pluginName]); - - /** Retrun type and block */ - return { - type : pluginName, - block : block - }; - - }, - -}; - -/** -* Methods for saving HTML blocks to JSON object -*/ -cEditor.saver = { - - /** - * Saves blocks - */ - saveBlocks : function () { - - /** Save html content of redactor to memory */ - // cEditor.state.html = cEditor.nodes.redactor.innerHTML; - - Promise.resolve() - - .then(function() { - return cEditor.nodes.redactor.childNodes; - }) - /** Making a sequence from separate blocks */ - .then(cEditor.saver.makeQueue) - - .catch( function(error) { - console.log('Something happend'); - }); - - }, - - makeQueue : function(blocks) { - - var queue = Promise.resolve(); - - for(var index = 0; index < blocks.length; index++) { - - /** Add node to sequence at specified index */ - cEditor.saver.getBlockData(queue, blocks, index); - - } - - }, - /** Gets every block and makes From Data */ - getBlockData : function(queue, blocks, index) { - - queue.then(function() { - return cEditor.saver.getNodeAsync(blocks, index); - }) - - .then(cEditor.saver.makeFormDataFromBlocks); - - }, - - - /** - * Asynchronously returns block data from blocksList by index - * @return Promise to node - */ - getNodeAsync : function (blocksList, index) { - - return Promise.resolve().then(function() { - - return blocksList[index]; - - }); - }, - - makeFormDataFromBlocks : function(block) { - - var pluginName = block.dataset.type; - - /** Check for plugin existance */ - if (!cEditor.tools[pluginName]) { - throw Error(`Plugin «${pluginName}» not found`); - } - - /** Check for plugin having render method */ - if (typeof cEditor.tools[pluginName].save != 'function') { - - throw Error(`Plugin «${pluginName}» must have save method`); - } - - /** Result saver */ - var blockContent = block.childNodes, - savedData = cEditor.tools[pluginName].save(blockContent); - - cEditor.state.jsonOutput.push(savedData); - } - -}; - -/** -* Methods: -* - make -* - addTools -* - bindEvents -* - addBlockHandlers -* - saveInputs -*/ - -cEditor.ui = { - - /** - * @const {string} BLOCK_CLASSNAME - redactor blocks name - */ - BLOCK_CLASSNAME : 'ce_block', - - /** - * @private - * Making main interface - */ - make : function () { - - var wrapper, - toolbar, - redactor, - notifications, - blockSettings, - showSettingsButton; - - /** Make editor wrapper */ - wrapper = cEditor.draw.wrapper(); - - /** Append editor wrapper after initial textarea */ - cEditor.core.insertAfter(cEditor.nodes.textarea, wrapper); - - /** Append block with notifications to the document */ - notifications = cEditor.draw.alertsHolder(); - cEditor.nodes.notifications = document.body.appendChild(notifications); - - /** Make toolbar and content-editable redactor */ - toolbar = cEditor.draw.toolbar(); - showSettingsButton = cEditor.draw.settingsButton(); - blockSettings = cEditor.draw.blockSettings(); - redactor = cEditor.draw.redactor(); - - toolbar.appendChild(showSettingsButton); - toolbar.appendChild(blockSettings); - - wrapper.appendChild(toolbar); - wrapper.appendChild(redactor); - - /** Save created ui-elements to static nodes state */ - cEditor.nodes.wrapper = wrapper; - cEditor.nodes.toolbar = toolbar; - cEditor.nodes.blockSettings = blockSettings; - cEditor.nodes.showSettingsButton = showSettingsButton; - - cEditor.nodes.redactor = redactor; - - }, - - /** - * @private - * Append tools passed in cEditor.tools - */ - addTools : function () { - - var tool, - tool_button; - - /** Make toolbar buttons */ - for (var name in cEditor.tools){ - - tool = cEditor.tools[name]; - - if (!tool.iconClassname) { - cEditor.core.log('Toolbar icon classname missed. Tool %o skipped', 'warn', name); - continue; - } - - if (typeof tool.make != 'function') { - cEditor.core.log('make method missed. Tool %o skipped', 'warn', name); - continue; - } - - tool_button = cEditor.draw.toolbarButton(name, tool.iconClassname); - cEditor.nodes.toolbar.appendChild(tool_button); - - /** Save tools to static nodes */ - cEditor.nodes.toolbarButtons[name] = tool_button; - - } - - }, - - /** - * @private - * Bind editor UI events - */ - bindEvents : function () { - - cEditor.core.log('ui.bindEvents fired', 'info'); - - window.addEventListener('error', function (errorMsg, url, lineNumber) { - cEditor.notifications.errorThrown(errorMsg, event); - }, false ); - - /** All keydowns on Document */ - document.addEventListener('keydown', function (event) { - cEditor.callback.globalKeydown(event); - }, false ); - - /** All keydowns on Document */ - document.addEventListener('keyup', function (event) { - cEditor.callback.globalKeyup(event); - }, false ); - - /** Mouse click to radactor */ - cEditor.nodes.redactor.addEventListener('click', function (event) { - - cEditor.callback.redactorClicked(event); - - }, false ); - - /** Clicks to SETTINGS button in toolbar */ - cEditor.nodes.showSettingsButton.addEventListener('click', function (event) { - - cEditor.callback.showSettingsButtonClicked(event); - - }, false ); - - /** - * @deprecated; - * Any redactor changes: keyboard input, mouse cut/paste, drag-n-drop text - */ - cEditor.nodes.redactor.addEventListener('input', function (event) { - - cEditor.callback.redactorInputEvent(event); - - }, false ); - - /** Bind click listeners on toolbar buttons */ - for (var button in cEditor.nodes.toolbarButtons){ - cEditor.nodes.toolbarButtons[button].addEventListener('click', function (event) { - cEditor.callback.toolbarButtonClicked(event, this); - }, false); - } - - }, - - addBlockHandlers : function(block) { - - if (!block) return; - - block.addEventListener('keydown', function(event) { - - cEditor.callback.blockKeydown(event, block); - - }, false); - - block.addEventListener('paste', function (event) { - cEditor.callback.blockPaste(event, block); - }, false); - - }, - - /** getting all contenteditable elements */ - saveInputs : function() { - - var redactor = cEditor.nodes.redactor, - elements = []; - - setTimeout(function () { - - /** Save all inputs in global variable state */ - cEditor.state.inputs = redactor.querySelectorAll('[contenteditable]'); - - }, 10); - - } - -}; - -cEditor.callback = { - - - redactorSyncTimeout : null, - - globalKeydown : function(event){ - - switch (event.keyCode){ - case cEditor.core.keys.TAB : this.tabKeyPressed(event); break; - case cEditor.core.keys.ENTER : this.enterKeyPressed(event); break; - case cEditor.core.keys.ESC : this.escapeKeyPressed(event); break; - } - - }, - - globalKeyup : function(event){ - - switch (event.keyCode){ - case cEditor.core.keys.UP : - case cEditor.core.keys.LEFT : - case cEditor.core.keys.RIGHT : - case cEditor.core.keys.DOWN : this.arrowKeyPressed(event); break; - } - - }, - - - tabKeyPressed : function(event){ - - if ( !cEditor.toolbar.opened ) { - cEditor.toolbar.open(); - } else { - cEditor.toolbar.leaf(); - } - - event.preventDefault(); - - }, - - enterKeyPressed : function(event){ - - cEditor.content.workingNodeChanged(); - - var index = cEditor.caret.getCurrentInputIndex(); - var isEnterPressedOnToolbar = cEditor.toolbar.opened && - cEditor.toolbar.current && - event.target == cEditor.state.inputs[index]; - - if ( isEnterPressedOnToolbar ) { - event.preventDefault(); - - cEditor.toolbar.toolClicked(event); - cEditor.toolbar.close(); - - } - - }, - - escapeKeyPressed : function(event){ - - cEditor.toolbar.close(); - - event.preventDefault(); - - }, - - arrowKeyPressed : function(event){ - - cEditor.content.workingNodeChanged(); - - /* Closing toolbar */ - cEditor.toolbar.close(); - cEditor.toolbar.move(); - - }, - - redactorClicked : function (event) { - - if ( cEditor.parser.isFirstLevelBlock(event.target) ) { - - /** If clicked on editor first-level block, set event target*/ - cEditor.content.workingNodeChanged(event.target); - - } else { - - /** Otherwise get current node from selection */ - cEditor.content.workingNodeChanged(); - } - - cEditor.toolbar.move(); - - cEditor.toolbar.open(); - cEditor.toolbar.settings.close(); - - }, - - /** - * Toolbar button click handler - * @param this - cursor to the button - */ - toolbarButtonClicked : function (event, button) { - - cEditor.toolbar.current = button.dataset.type; - - cEditor.toolbar.toolClicked(event); - cEditor.toolbar.close(); - - }, - - redactorInputEvent : function (event) { - - /** - * Clear previous sync-timeout - */ - if (this.redactorSyncTimeout){ - clearTimeout(this.redactorSyncTimeout); - } - - /** - * Start waiting to input finish and sync redactor - */ - this.redactorSyncTimeout = setTimeout(function() { - - cEditor.content.sync(); - - }, 500); - - }, - - /** - * Block handlers for KeyDown events - */ - blockKeydown : function(event, block) { - - switch (event.keyCode){ - - case cEditor.core.keys.DOWN: - case cEditor.core.keys.RIGHT: - cEditor.callback.blockRightOrDownArrowPressed(block); - break; - - case cEditor.core.keys.ENTER: - cEditor.callback.enterPressedOnBlock(block, event); - break; - - case cEditor.core.keys.BACKSPACE: - cEditor.callback.backspacePressed(block); - break; - - case cEditor.core.keys.UP: - case cEditor.core.keys.LEFT: - cEditor.callback.blockLeftOrUpArrowPressed(block); - break; - - } - }, - - /** - * RIGHT or DOWN keydowns on block - */ - blockRightOrDownArrowPressed : function (block) { - - var selection = window.getSelection(), - inputs = cEditor.state.inputs, - focusedNode = selection.anchorNode, - focusedNodeHolder; - - /** Check for caret existance */ - if (!focusedNode){ - return false; - } - - /** Looking for closest (parent) contentEditable element of focused node */ - while (focusedNode.contentEditable != 'true') { - - focusedNodeHolder = focusedNode.parentNode; - focusedNode = focusedNodeHolder; - } - - /** Input index in DOM level */ - var editableElementIndex = 0; - while (focusedNode != inputs[editableElementIndex]) { - editableElementIndex ++; - } - - /** - * Founded contentEditable element doesn't have childs - * Or maybe New created block - */ - if (!focusedNode.textContent) - { - cEditor.caret.setToNextBlock(editableElementIndex); - return; - } - - /** - * Do nothing when caret doesn not reaches the end of last child - */ - var caretInLastChild = false, - caretAtTheEndOfText = false; - - var lastChild, - deepestTextnode; - - lastChild = focusedNode.childNodes[focusedNode.childNodes.length - 1 ]; - - if (cEditor.core.isDomNode(lastChild)) { - - deepestTextnode = cEditor.content.getDeepestTextNodeFromPosition(lastChild, lastChild.childNodes.length); - - } else { - - deepestTextnode = lastChild; - - } - - caretInLastChild = selection.anchorNode == deepestTextnode; - caretAtTheEndOfText = deepestTextnode.length == selection.anchorOffset; - - if ( !caretInLastChild || !caretAtTheEndOfText ) { - cEditor.core.log('arrow [down|right] : caret does not reached the end'); - return false; - } - - cEditor.caret.setToNextBlock(editableElementIndex); - - }, - - /** - * LEFT or UP keydowns on block - */ - blockLeftOrUpArrowPressed : function (block) { - - var selection = window.getSelection(), - inputs = cEditor.state.inputs, - focusedNode = selection.anchorNode, - focusedNodeHolder; - - /** Check for caret existance */ - if (!focusedNode){ - return false; - } - - /** - * LEFT or UP not at the beginning - */ - if ( selection.anchorOffset !== 0) { - return false; - } - - /** Looking for parent contentEditable block */ - while (focusedNode.contentEditable != 'true') { - focusedNodeHolder = focusedNode.parentNode; - focusedNode = focusedNodeHolder; - } - - /** Input index in DOM level */ - var editableElementIndex = 0; - while (focusedNode != inputs[editableElementIndex]) { - editableElementIndex ++; - } - - /** - * Do nothing if caret is not at the beginning of first child - */ - var caretInFirstChild = false, - caretAtTheBeginning = false; - - var firstChild, - deepestTextnode; - - /** - * Founded contentEditable element doesn't have childs - * Or maybe New created block - */ - if (!focusedNode.textContent) { - cEditor.caret.setToPreviousBlock(editableElementIndex); - return; - } - - firstChild = focusedNode.childNodes[0]; - - if (cEditor.core.isDomNode(firstChild)) { - - deepestTextnode = cEditor.content.getDeepestTextNodeFromPosition(firstChild, 0); - - } else { - - deepestTextnode = firstChild; - - } - - caretInFirstChild = selection.anchorNode == deepestTextnode; - caretAtTheBeginning = selection.anchorOffset === 0; - - if ( caretInFirstChild && caretAtTheBeginning ) { - - cEditor.caret.setToPreviousBlock(editableElementIndex); - - } - - }, - - enterPressedOnBlock: function (block, event) { - - var selection = window.getSelection(), - currentNode = selection.anchorNode, - parentOfFocusedNode = currentNode.parentNode; - - /** - * We add new block with contentEditable property if enter key is pressed. - * First we check, if caret is at the end of last node and offset is legth of text node - * focusedNodeIndex + 1, because that we compare non-arrays index. - */ - if ( currentNode.length === cEditor.caret.offset && - parentOfFocusedNode.childNodes.length == cEditor.caret.focusedNodeIndex + 1) { - - /** Prevent
creation */ - event.preventDefault(); - - /** Create new Block and append it after current */ - var newBlock = cEditor.draw.block('p'); - - newBlock.contentEditable = "true"; - newBlock.classList.add(cEditor.ui.BLOCK_CLASSNAME); - - /** Add event listeners (Keydown) for new created block */ - cEditor.ui.addBlockHandlers(newBlock); - - cEditor.core.insertAfter(block, newBlock); - - /** set focus to the current (created) block */ - cEditor.caret.setToNextBlock(block); - - cEditor.toolbar.move(); - } - }, - - backspacePressed: function (block) { - - cEditor.ui.saveInputs(); - - if (block.textContent.trim()) return; - - block.remove(); - - cEditor.toolbar.close(); - cEditor.toolbar.move(); - - event.preventDefault(); - - }, - - blockPaste: function(event, block) { - - var clipboardData, pastedData, nodeContent; - - /** Prevent Default Browser behaviour */ - event.preventDefault(); - - clipboardData = event.clipboardData || window.clipboardData; - pastedData = clipboardData.getData('Text'); - - nodeContent = document.createTextNode(pastedData); - - var index = cEditor.caret.getCurrentInputIndex(); - - /** Insert parsed content to the editable block */ - var editableElement = cEditor.state.inputs[index]; - editableElement.appendChild(nodeContent); - }, - - /** - * Clicks on block settings button - */ - showSettingsButtonClicked : function(){ - - /** - * Get type of current block - * It uses to append settings from tool.settings property. - * ... - * Type is stored in data-type attribute on block - */ - var currentToolType = cEditor.content.currentNode.dataset.type; - - cEditor.toolbar.settings.toggle(currentToolType); - - } - -}; - -cEditor.content = { - - currentNode : null, - - /** - * Synchronizes redactor with original textarea - */ - sync : function () { - - cEditor.core.log('syncing...'); - - /** - * Save redactor content to cEditor.state - */ - cEditor.state.html = cEditor.nodes.redactor.innerHTML; - - /** - * Put it to the textarea - */ - cEditor.nodes.textarea.value = cEditor.state.html; - - }, - - getNodeFocused : function() { - - var selection = window.getSelection(), - focused; - - if (selection.anchorNode === null) { - return null; - } - - if ( selection.anchorNode.nodeType == cEditor.core.nodeTypes.TAG ) { - focused = selection.anchorNode; - } else { - focused = selection.focusNode.parentElement; - } - - if ( !cEditor.parser.isFirstLevelBlock(focused) ) { - - /** Iterate with parent nodes to find first-level*/ - var parent = focused.parentNode; - - while (parent && !cEditor.parser.isFirstLevelBlock(parent)){ - parent = parent.parentNode; - } - - focused = parent; - } - - if (focused != cEditor.nodes.redactor){ - return focused; - } - - return null; - - }, - - /** - * Trigger this event when working node changed - */ - workingNodeChanged : function (setCurrent) { - - var nodeWithSelection = this.getNodeFocused(); - - if (!setCurrent && !nodeWithSelection) { - return; - } - - this.currentNode = setCurrent || nodeWithSelection; - - }, - - /** - * Replaces one redactor block with another - * @protected - * @param {Element} targetBlock - block to replace. Mostly currentNode. - * @param {Element} newBlock - * @param {string} newBlockType - type of new block; we need to store it to data-attribute - * - * [!] Function does not saves old block content. - * You can get it manually and pass with newBlock.innerHTML - */ - replaceBlock : function function_name(targetBlock, newBlock, newBlockType) { - - if (!targetBlock || !newBlock || !newBlockType){ - cEditor.core.log('replaceBlock: missed params'); - return; - } - - /** Store block type */ - newBlock.dataset.type = newBlockType; - - /** If target-block is not a frist-level block, then we iterate parents to find it */ - while(!targetBlock.classList.contains(cEditor.ui.BLOCK_CLASSNAME)) { - targetBlock = targetBlock.parentNode; - } - - /** Replacing */ - cEditor.nodes.redactor.replaceChild(newBlock, targetBlock); - - /** - * Set new node as current - */ - cEditor.content.workingNodeChanged(newBlock); - - /** - * Add block handlers - */ - cEditor.ui.addBlockHandlers(newBlock); - - /** - * Save changes - */ - cEditor.ui.saveInputs(); - - }, - - /** - * Inserts new block to redactor - * Wrapps block into a DIV with BLOCK_CLASSNAME class - * @protected - */ - insertBlock : function(newBlockContent, blockType) { - - var workingBlock = cEditor.content.currentNode; - - var newBlock = cEditor.content.composeNewBlock(newBlockContent, blockType); - - if (workingBlock) { - - cEditor.core.insertAfter(workingBlock, newBlock); - - } else { - - /** - * If redactor is empty, append as first child - */ - cEditor.nodes.redactor.appendChild(newBlock); - - } - /** - * Save changes - */ - cEditor.ui.saveInputs(); - - /** - * Block handler - */ - cEditor.ui.addBlockHandlers(newBlock); - - /** - * Set new node as current - */ - cEditor.content.workingNodeChanged(newBlock); - - }, - - /** - * Replaces blocks with saving content - * @protected - * @param {Element} noteToReplace - * @param {Element} newNode - * @param {Element} blockType - */ - switchBlock : function(blockToReplace, newBlock, blockType){ - - var oldBlockEditable = blockToReplace.querySelector('[contenteditable]'); - - /** Saving content */ - if (oldBlockEditable) { - newBlock.innerHTML = oldBlockEditable.innerHTML; - } - - var newBlockComposed = cEditor.content.composeNewBlock(newBlock, blockType); - - /** Replacing */ - cEditor.content.replaceBlock(blockToReplace, newBlockComposed, blockType); - - /** Save new Inputs when block is changed */ - cEditor.ui.saveInputs(); - - }, - - - /** - * Iterates between child noted and looking for #text node on deepest level - * @private - * @param {Element} block - node where find - * @param {int} postiton - starting postion - * Example: childNodex.length to find from the end - * or 0 to find from the start - * @return {Text} block - * @uses DFS - */ - getDeepestTextNodeFromPosition : function (block, position) { - - /** - * Clear Block from empty and useless spaces with trim. - * Such nodes we should remove - */ - var index, - blockChilds = block.childNodes; - - for(index = 0; index < blockChilds.length; index++) - { - var node = blockChilds[index]; - - if (node.nodeType == cEditor.core.nodeTypes.TEXT) { - - text = node.textContent.trim(); - - /** Text is empty. We should remove this child from node before we start DFS - * decrease the quantity of childs. - */ - if (text === '') { - - block.removeChild(node); - position--; - } - } - } - - if (block.childNodes.length === 0) { - return document.createTextNode(''); - } - - /** Setting default position when we deleted all empty nodes */ - if ( position < 0 ) - position = 1; - - var looking_from_start = false; - - /** For looking from START */ - if (position === 0) { - looking_from_start = true; - position = 1; - } - - while ( position ) { - - /** initial verticle of node. */ - if ( looking_from_start ) { - block = block.childNodes[0]; - } else { - block = block.childNodes[position - 1]; - } - - if ( block.nodeType == cEditor.core.nodeTypes.TAG ){ - - position = block.childNodes.length; - - } else if (block.nodeType == cEditor.core.nodeTypes.TEXT ){ - - position = 0; - } - - } - - return block; - }, - - /** - * @private - */ - composeNewBlock : function (block, blockType) { - - newBlock = cEditor.draw.block('DIV'); - - newBlock.classList.add(cEditor.ui.BLOCK_CLASSNAME); - newBlock.dataset.type = blockType; - - newBlock.appendChild(block); - - return newBlock; - - } - -}; - -cEditor.caret = { - - /** - * @var {int} InputIndex - editable element in DOM - */ - inputIndex : null, - - /** - * @var {int} offset - caret position in a text node. - */ - - offset : null, - - /** - * @var {int} focusedNodeIndex - we get index of child node from first-level block - */ - - focusedNodeIndex: null, - - /** - * Creates Document Range and sets caret to the element. - * @protected - * @uses caret.save — if you need to save caret position - * @param {Element} el - Changed Node. - */ - set : function( el , index, offset) { - - offset = offset || this.offset || 0; - index = index || this.focusedNodeIndex || 0; - - var childs = el.childNodes, - nodeToSet; - - if ( childs.length === 0 ) { - - nodeToSet = el; - - } else { - - nodeToSet = childs[index]; - - } - - if (cEditor.core.isDomNode(nodeToSet)) { - - nodeToSet = cEditor.content.getDeepestTextNodeFromPosition(nodeToSet, nodeToSet.childNodes.length); - } - - var range = document.createRange(), - selection = window.getSelection(); - - setTimeout(function() { - - range.setStart(nodeToSet, offset); - range.setEnd(nodeToSet, offset); - - selection.removeAllRanges(); - selection.addRange(range); - - }, 20); - }, - - /** - * @protected - * @return current index of input and saves it in caret object - */ - getCurrentInputIndex : function () { - - /** Index of Input that we paste sanitized content */ - var selection = window.getSelection(), - inputs = cEditor.state.inputs, - focusedNode = selection.anchorNode, - focusedNodeHolder; - - /** Looking for parent contentEditable block */ - while (focusedNode.contentEditable != 'true') { - focusedNodeHolder = focusedNode.parentNode; - focusedNode = focusedNodeHolder; - } - - /** Input index in DOM level */ - var editableElementIndex = 0; - - while (focusedNode != inputs[editableElementIndex]) { - editableElementIndex ++; - } - - this.inputIndex = editableElementIndex; - return this.inputIndex; - }, - - /** - * @param {Element} block - element from which we take next block - */ - setToNextBlock : function(index) { - - var inputs = cEditor.state.inputs, - nextInput = inputs[index + 1]; - - /** - * When new Block created or deleted content of input - * We should add some text node to set caret - */ - if (!nextInput.childNodes.length) { - var emptyTextElement = document.createTextNode(''); - nextInput.appendChild(emptyTextElement); - } - - cEditor.caret.inputIndex = nextInput; - cEditor.caret.set(nextInput, 0, 0); - cEditor.content.workingNodeChanged(nextInput); - - }, - - setToPreviousBlock : function(index) { - - var inputs = cEditor.state.inputs, - previousInput = inputs[index - 1]; - - var lastChildNode = cEditor.content.getDeepestTextNodeFromPosition(previousInput, previousInput.childNodes.length), - lengthOfLastChildNode = lastChildNode.length; - - /** - * When new Block created or deleted content of input - * We should add some text node to set caret - */ - if (!previousInput.childNodes.length) { - var emptyTextElement = document.createTextNode(''); - previousInput.appendChild(emptyTextElement); - } - - cEditor.caret.inputIndex = previousInput; - cEditor.caret.set(previousInput, previousInput.childNodes.length - 1, lengthOfLastChildNode); - cEditor.content.workingNodeChanged(inputs[index - 1]); - }, -}; - -cEditor.toolbar = { - - /** - * Margin between focused node and toolbar - */ - defaultToolbarHeight : 43, - - defaultOffset : 10, - - opened : false, - - current : null, - - /** - * @protected - */ - open : function (){ - - if (this.opened) { - return; - } - - cEditor.nodes.toolbar.classList.add('opened'); - this.opened = true; - - }, - - /** - * @protected - */ - close : function(){ - - cEditor.nodes.toolbar.classList.remove('opened'); - - this.opened = false; - this.current = null; - for (var button in cEditor.nodes.toolbarButtons){ - cEditor.nodes.toolbarButtons[button].classList.remove('selected'); - } - - }, - - toggle : function(){ - - if ( !this.opened ){ - - this.open(); - - } else { - - this.close(); - - } - - }, - - leaf : function(){ - - var currentTool = this.current, - tools = Object.keys(cEditor.tools), - barButtons = cEditor.nodes.toolbarButtons, - nextToolIndex, - toolToSelect; - - if ( !currentTool ) { - - /** Get first tool from object*/ - for (toolToSelect in barButtons) break; - - } else { - - nextToolIndex = tools.indexOf(currentTool) + 1; - - if ( nextToolIndex == tools.length) nextToolIndex = 0; - - toolToSelect = tools[nextToolIndex]; - - } - - for (var button in barButtons) barButtons[button].classList.remove('selected'); - - barButtons[toolToSelect].classList.add('selected'); - - this.current = toolToSelect; - - }, - - /** - * Transforming selected node type into selected toolbar element type - * @param {event} event - */ - toolClicked : function() { - - var REPLACEBLE_TOOLS = ['paragraph', 'header', 'code'], - tool = cEditor.tools[cEditor.toolbar.current], - workingNode = cEditor.content.currentNode, - appendCallback, - newBlockContent; - - /** Make block from plugin */ - newBlockContent = tool.make(); - - /** Can replace? */ - if (REPLACEBLE_TOOLS.indexOf(tool.type) != -1 && workingNode) { - - /** Replace current block */ - cEditor.content.switchBlock(workingNode, newBlockContent, tool.type); - - - } else { - - /** Insert new Block from plugin */ - cEditor.content.insertBlock(newBlockContent, tool.type); - - } - - /** Fire tool append callback */ - appendCallback = cEditor.tools[cEditor.toolbar.current].appendCallback; - - if (appendCallback && typeof appendCallback == 'function') { - appendCallback.call(); - } - - setTimeout(function () { - /** Save new changes */ - cEditor.ui.saveInputs(); - }, 50); - - }, - - - /** - * Moving toolbar to the specified node - */ - move : function() { - - if (!cEditor.content.currentNode) { - return; - } - - var toolbarHeight = cEditor.nodes.toolbar.clientHeight || cEditor.toolbar.defaultToolbarHeight, - newYCoordinate = cEditor.content.currentNode.offsetTop - cEditor.toolbar.defaultOffset - toolbarHeight; - - cEditor.nodes.toolbar.style.transform = "translateY(" + newYCoordinate + "px)"; - - }, - - /** - * Block settings methods - */ - settings : { - - opened : false, - - /** - * Append and open settings - */ - open : function(toolType){ - - /** - * Append settings content - * It's stored in tool.settings - */ - if (!cEditor.tools[toolType] || !cEditor.core.isDomNode(cEditor.tools[toolType].settings) ) { - - cEditor.core.log('Wrong tool type', 'warn'); - cEditor.nodes.blockSettings.innerHTML = `Плагин «${toolType}» не имеет настроек`; - - } else { - - cEditor.nodes.blockSettings.appendChild(cEditor.tools[toolType].settings); - - } - - cEditor.nodes.blockSettings.classList.add('opened'); - this.opened = true; - - }, - - /** - * Close and clear settings - */ - close : function(){ - - cEditor.nodes.blockSettings.classList.remove('opened'); - cEditor.nodes.blockSettings.innerHTML = ''; - - this.opened = false; - - }, - - /** - * @param {string} toolType - plugin type - */ - toggle : function( toolType ){ - - if ( !this.opened ){ - - this.open(toolType); - - } else { - - this.close(); - - } - - }, - - } - -}; - -/** -* File transport module -*/ -cEditor.transport = { - - input : null, - - /** - * @property {Object} arguments - keep plugin settings and defined callbacks - */ - arguments : null, - - prepare : function(){ - - var input = document.createElement('INPUT'); - - input.type = 'file'; - input.addEventListener('change', cEditor.transport.fileSelected); - - cEditor.transport.input = input; - - }, - - /** - * Callback for file selection - */ - fileSelected : function(event){ - - var input = this, - files = input.files, - filesLength = files.length, - formdData = new FormData(), - file, - i; - - formdData.append('files', files[0], files[0].name); - - cEditor.transport.ajax({ - data : formdData, - success : cEditor.transport.arguments.success, - error : cEditor.transport.arguments.error, - }); - - }, - - /** - * Use plugin callbacks - * @protected - */ - selectAndUpload : function (args) { - - this.arguments = args; - this.input.click(); - - }, - - /** - * Ajax requests module - */ - ajax : function(params){ - - var xhr = new XMLHttpRequest(), - success = typeof params.success == 'function' ? params.success : function(){}, - error = typeof params.error == 'function' ? params.error : function(){}; - - xhr.open('POST', cEditor.settings.uploadImagesUrl, true); - - xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest"); - - xhr.onload = function () { - if (xhr.status === 200) { - success(xhr.responseText); - } else { - console.log("request error: %o", xhr); - } - }; - - xhr.send(params.data); - - } - -}; - - -/** -* Content parsing module -*/ -cEditor.parser = { - - /** - * Asynchronously parses textarea input string to HTML editor blocks - */ - parseTextareaContent : function () { - - var initialContent = cEditor.nodes.textarea.value; - - if ( initialContent.trim().length === 0 ) return true; - - - cEditor.parser - - /** Get child nodes async-aware */ - .getNodesFromString(initialContent) - - /** Then append nodes to the redactor */ - .then(cEditor.parser.appendNodesToRedactor) - - /** Write log if something goes wrong */ - .catch(function(error) { - cEditor.core.log('Error while parsing content: %o', 'warn', error); - }); - - }, - - /** - * Parses string to nodeList - * @param string inputString - * @return Primise -> nodeList - */ - getNodesFromString : function (inputString) { - - return Promise.resolve().then(function() { - - var contentHolder = document.createElement('div'); - - contentHolder.innerHTML = inputString; - - /** - * Returning childNodes will include: - * - Elements (html-tags), - * - Texts (empty-spaces or non-wrapped strings ) - * - Comments and other - */ - return contentHolder.childNodes; - - }); - }, - - /** - * Appends nodes to the redactor - * @param nodeList nodes - list for nodes to append - */ - appendNodesToRedactor : function(nodes) { - - /** - * Sequence of one-by-one nodes appending - * Uses to save blocks order after async-handler - */ - var nodeSequence = Promise.resolve(); - - - for (var index = 0; index < nodes.length ; index++ ) { - - /** Add node to sequence at specified index */ - cEditor.parser.appendNodeAtIndex(nodeSequence, nodes, index); - - } - - }, - - /** - * Append node at specified index - */ - appendNodeAtIndex : function (nodeSequence, nodes, index) { - - /** We need to append node to sequence */ - nodeSequence - - /** first, get node async-aware */ - .then(function() { - - return cEditor.parser.getNodeAsync(nodes , index); - - }) - - /** - * second, compose editor-block from node - * and append it to redactor - */ - .then(function(node){ - - var block = cEditor.parser.createBlockByDomNode(node); - - if ( cEditor.core.isDomNode(block) ) { - - block.contentEditable = "true"; - - /** Mark node as redactor block*/ - block.classList.add('ce_block'); - - /** Append block to the redactor */ - cEditor.nodes.redactor.appendChild(block); - - /** Save block to the cEditor.state array */ - cEditor.state.blocks.push(block); - - return block; - - } - return null; - }) - - .then(cEditor.ui.addBlockHandlers) - - /** Log if something wrong with node */ - .catch(function(error) { - cEditor.core.log('Node skipped while parsing because %o', 'warn', error); - }); - - }, - - /** - * Asynchronously returns node from nodeList by index - * @return Promise to node - */ - getNodeAsync : function (nodeList, index) { - - return Promise.resolve().then(function() { - - return nodeList.item(index); - - }); - }, - - /** - * Creates editor block by DOM node - * - * First-level blocks (see cEditor.settings.blockTags) saves as-is, - * other wrapps with

-tag - * - * @param DOMnode node - * @return First-level node (paragraph) - */ - createBlockByDomNode : function (node) { - - /** First level nodes already appears as blocks */ - if ( cEditor.parser.isFirstLevelBlock(node) ){ - - /** Save plugin type in data-type */ - node = this.storeBlockType(node); - - return node; - } - - /** Other nodes wraps into parent block (paragraph-tag) */ - var parentBlock, - nodeContent = node.textContent.trim(), - isPlainTextNode = node.nodeType != cEditor.core.nodeTypes.TAG; - - - /** Skip empty textNodes with space-symbols */ - if (isPlainTextNode && !nodeContent.length) return null; - - /** Make

tag */ - parentBlock = cEditor.draw.block('P'); - - if (isPlainTextNode){ - parentBlock.textContent = nodeContent.replace(/(\s){2,}/, '$1'); // remove double spaces - } else { - parentBlock.appendChild(node); - } - - /** Save plugin type in data-type */ - parentBlock = this.storeBlockType(parentBlock); - - return parentBlock; - - }, - - /** - * It's a crutch - * - - - - - - - - * We need block type stored as data-attr - * Now supports only simple blocks : P, HEADER, QUOTE, CODE - * Remove it after updating parser module for the block-oriented structure: - * - each block must have stored type - * @param {Element} node - */ - storeBlockType : function (node) { - - switch (node.tagName) { - case 'P' : node.dataset.type = 'paragraph'; break; - case 'H1': - case 'H2': - case 'H3': - case 'H4': - case 'H5': - case 'H6': node.dataset.type = 'header'; break; - case 'BLOCKQUOTE': node.dataset.type = 'quote'; break; - case 'CODE': node.dataset.type = 'code'; break; - } - - return node; - - }, - - /** - * Check DOM node for display style: separated block or child-view - */ - isFirstLevelBlock : function (node) { - - return node.nodeType == cEditor.core.nodeTypes.TAG && - node.classList.contains(cEditor.ui.BLOCK_CLASSNAME); - - } - -}; - -/** -* Creates HTML elements -*/ -cEditor.draw = { - - /** - * Base editor wrapper - */ - wrapper : function () { - - var wrapper = document.createElement('div'); - - wrapper.className += 'ce_wrapper'; - - return wrapper; - - }, - - /** - * Content-editable holder - */ - redactor : function () { - - var redactor = document.createElement('div'); - - redactor.className += 'ce_redactor'; - - return redactor; - - }, - - /** - * Empty toolbar with toggler - */ - toolbar : function () { - - var bar = document.createElement('div'); - - bar.className += 'ce_toolbar'; - - return bar; - }, - - /** - * Block with notifications - */ - alertsHolder : function() { - - var block = document.createElement('div'); - - block.classList.add('ce_notifications-block'); - - return block; - - }, - - /** - * Block settings panel - */ - blockSettings : function () { - - var settings = document.createElement('div'); - - settings.className += 'ce_block_settings'; - - return settings; - }, - - /** - * Settings button in toolbar - */ - settingsButton : function () { - - var toggler = document.createElement('span'); - - toggler.className = 'toggler'; - - /** Toggler button*/ - toggler.innerHTML = ''; - - return toggler; - }, - - /** - * Toolbar button - */ - toolbarButton : function (type, classname) { - - var button = document.createElement("li"); - - button.dataset.type = type; - button.innerHTML = ''; - - return button; - - }, - - /** - * Redactor block - */ - block : function (tagName, content) { - - var node = document.createElement(tagName); - - node.innerHTML = content || ''; - - return node; - - } - -}; - -/** Module which extends notifications and make different animations for logs */ -cEditor.notifications = { - - /** - * Error notificator. Shows block with message - * @protected - */ - errorThrown : function(errorMsg, event) { - - cEditor.notifications.send('This action is not available currently', event.type, false); - - }, - - /** - * Appends notification with different types - * @param message {string} - Error or alert message - * @param type {string} - Type of message notification. Ex: Error, Warning, Danger ... - * @param append {boolean} - can be True or False when notification should be inserted after - */ - send : function(message, type, append) { - - var notification = cEditor.draw.block('div'); - - notification.textContent = message; - notification.classList.add('ce_notification-item', 'ce_notification-' + type, 'flipInX'); - - if (!append) { - cEditor.nodes.notifications.innerHTML = ''; - } - - cEditor.nodes.notifications.appendChild(notification); - - setTimeout(function () { - notification.remove(); - }, 3000); - - }, -} - - -/** -* Developer plugins -*/ - -cEditor.tools = { - -}; +var codex = +/******/ (function(modules) { // webpackBootstrap +/******/ // The module cache +/******/ var installedModules = {}; +/******/ +/******/ // The require function +/******/ function __webpack_require__(moduleId) { +/******/ +/******/ // Check if module is in cache +/******/ if(installedModules[moduleId]) +/******/ return installedModules[moduleId].exports; +/******/ +/******/ // Create a new module (and put it into the cache) +/******/ var module = installedModules[moduleId] = { +/******/ exports: {}, +/******/ id: moduleId, +/******/ loaded: false +/******/ }; +/******/ +/******/ // Execute the module function +/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); +/******/ +/******/ // Flag the module as loaded +/******/ module.loaded = true; +/******/ +/******/ // Return the exports of the module +/******/ return module.exports; +/******/ } +/******/ +/******/ +/******/ // expose the modules object (__webpack_modules__) +/******/ __webpack_require__.m = modules; +/******/ +/******/ // expose the module cache +/******/ __webpack_require__.c = installedModules; +/******/ +/******/ // __webpack_public_path__ +/******/ __webpack_require__.p = ""; +/******/ +/******/ // Load entry module and return exports +/******/ return __webpack_require__(0); +/******/ }) +/************************************************************************/ +/******/ ([ +/* 0 */ +/***/ function(module, exports, __webpack_require__) { + + /** + * + */ + + 'use strict'; + + var editor = __webpack_require__(1); + module.exports = editor; + +/***/ }, +/* 1 */ +/***/ function(module, exports, __webpack_require__) { + + 'use strict'; + + var codex = function (codex) { + + var init = function init() { + + __webpack_require__(2); + __webpack_require__(3); + __webpack_require__(4); + __webpack_require__(5); + __webpack_require__(6); + __webpack_require__(7); + __webpack_require__(8); + __webpack_require__(12); + __webpack_require__(13); + __webpack_require__(14); + __webpack_require__(15); + __webpack_require__(16); + __webpack_require__(17); + }; + + /** + * @public + * + * holds initial settings + */ + codex.settings = { + tools: ['paragraph', 'header', 'picture', 'list', 'quote', 'code', 'twitter', 'instagram', 'smile'], + textareaId: 'codex-editor', + uploadImagesUrl: '/editor/transport/', + + // Type of block showing on empty editor + initialBlockPlugin: "paragraph" + }; + + /** + * public + * + * Static nodes + */ + codex.nodes = { + textarea: null, + wrapper: null, + toolbar: null, + inlineToolbar: { + wrapper: null, + buttons: null, + actions: null + }, + toolbox: null, + notifications: null, + plusButton: null, + showSettingsButton: null, + showTrashButton: null, + blockSettings: null, + pluginSettings: null, + defaultSettings: null, + toolbarButtons: {}, // { type : DomEl, ... } + redactor: null + }; + + /** + * @public + * + * Output state + */ + codex.state = { + jsonOutput: [], + blocks: [], + inputs: [] + }; + + /** + * Initialization + * @uses Promise cEditor.core.prepare + * @param {} userSettings are : + * - tools [], + * - textareaId String + * ... + * + * Load user defined tools + * Tools must contain this important objects : + * @param {String} type - this is a type of plugin. It can be used as plugin name + * @param {String} iconClassname - this a icon in toolbar + * @param {Object} make - what should plugin do, when it is clicked + * @param {Object} appendCallback - callback after clicking + * @param {Element} settings - what settings does it have + * @param {Object} render - plugin get JSON, and should return HTML + * @param {Object} save - plugin gets HTML content, returns JSON + * @param {Boolean} displayInToolbox - will be displayed in toolbox. Default value is TRUE + * @param {Boolean} enableLineBreaks - inserts new block or break lines. Default value is FALSE + * + * @example + * - type : 'header', + * - iconClassname : 'ce-icon-header', + * - make : headerTool.make, + * - appendCallback : headerTool.appendCallback, + * - settings : headerTool.makeSettings(), + * - render : headerTool.render, + * - save : headerTool.save, + * - displayInToolbox : true, + * - enableLineBreaks : false + */ + codex.start = function (userSettings) { + + init(); + + this.core.prepare(userSettings) + + // If all ok, make UI, bind events and parse initial-content + .then(this.ui.make).then(this.ui.addTools).then(this.ui.bindEvents).then(this.ui.preparePlugins).then(this.transport.prepare).then(this.renderer.makeBlocksFromData).then(this.ui.saveInputs).catch(function (error) { + codex.core.log('Initialization failed with error: %o', 'warn', error); + }); + }; + + return codex; + }({}); + + module.exports = codex; + +/***/ }, +/* 2 */ +/***/ function(module, exports, __webpack_require__) { + + 'use strict'; + + var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; + + var codex = __webpack_require__(1); + + var core = function (core) { + + /** + * @public + * + * Editor preparing method + * @return Promise + */ + core.prepare = function (userSettings) { + + return new Promise(function (resolve, reject) { + + if (userSettings) { + + codex.settings.tools = userSettings.tools || codex.settings.tools; + } + + if (userSettings.data) { + codex.state.blocks = userSettings.data; + } + + codex.nodes.textarea = document.getElementById(userSettings.textareaId || codex.settings.textareaId); + + if (_typeof(codex.nodes.textarea) === undefined || codex.nodes.textarea === null) { + reject(Error("Textarea wasn't found by ID: #" + userSettings.textareaId)); + } else { + resolve(); + } + }); + }; + + /** + * Logging method + * @param type = ['log', 'info', 'warn'] + */ + core.log = function (msg, type, arg) { + + type = type || 'log'; + + if (!arg) { + arg = msg || 'undefined'; + msg = '[codex-editor]: %o'; + } else { + msg = '[codex-editor]: ' + msg; + } + + try { + if ('console' in window && console[type]) { + if (arg) console[type](msg, arg);else console[type](msg); + } + } catch (e) {} + }; + + /** + * @protected + * + * Helper for insert one element after another + */ + core.insertAfter = function (target, element) { + target.parentNode.insertBefore(element, target.nextSibling); + }; + + /** + * @const + * + * Readable DOM-node types map + */ + core.nodeTypes = { + TAG: 1, + TEXT: 3, + COMMENT: 8 + }; + + /** + * @const + * Readable keys map + */ + core.keys = { BACKSPACE: 8, TAB: 9, ENTER: 13, SHIFT: 16, CTRL: 17, ALT: 18, ESC: 27, SPACE: 32, LEFT: 37, UP: 38, DOWN: 40, RIGHT: 39, DELETE: 46, META: 91 }; + + /** + * @protected + * + * Check object for DOM node + */ + core.isDomNode = function (el) { + return el && (typeof el === 'undefined' ? 'undefined' : _typeof(el)) === 'object' && el.nodeType && el.nodeType == this.nodeTypes.TAG; + }; + + /** + * Native Ajax + */ + core.ajax = function (data) { + + if (!data || !data.url) { + return; + } + + var XMLHTTP = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP"), + success_function = function success_function() {}, + params = '', + obj; + + data.async = true; + data.type = data.type || 'GET'; + data.data = data.data || ''; + data['content-type'] = data['content-type'] || 'application/json; charset=utf-8'; + success_function = data.success || success_function; + + if (data.type == 'GET' && data.data) { + + data.url = /\?/.test(data.url) ? data.url + '&' + data.data : data.url + '?' + data.data; + } else { + + for (obj in data.data) { + params += obj + '=' + encodeURIComponent(data.data[obj]) + '&'; + } + } + + if (data.withCredentials) { + XMLHTTP.withCredentials = true; + } + + if (data.beforeSend && typeof data.beforeSend == 'function') { + data.beforeSend.call(); + } + + XMLHTTP.open(data.type, data.url, data.async); + XMLHTTP.setRequestHeader("X-Requested-With", "XMLHttpRequest"); + XMLHTTP.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); + + XMLHTTP.onreadystatechange = function () { + if (XMLHTTP.readyState == 4 && XMLHTTP.status == 200) { + success_function(XMLHTTP.responseText); + } + }; + + XMLHTTP.send(params); + }; + + /** Appends script to head of document */ + core.importScript = function (scriptPath, instanceName) { + + /** Script is already loaded */ + if (!instanceName || instanceName && document.getElementById('ce-script-' + instanceName)) { + codex.core.log("Instance name of script is missed or script is already loaded", "warn"); + return; + } + + var script = document.createElement('SCRIPT'); + script.type = "text/javascript"; + script.src = scriptPath; + script.async = true; + script.defer = true; + + if (instanceName) { + script.id = "ce-script-" + instanceName; + } + + document.head.appendChild(script); + return script; + }; + + return core; + }({}); + + codex.core = core; + + module.exports = core; + +/***/ }, +/* 3 */ +/***/ function(module, exports, __webpack_require__) { + + 'use strict'; + + var codex = __webpack_require__(1); + + var ui = function (ui) { + + /** + * Basic editor classnames + */ + ui.className = { + + /** + * @const {string} BLOCK_CLASSNAME - redactor blocks name + */ + BLOCK_CLASSNAME: 'ce-block', + + /** + * @const {String} wrapper for plugins content + */ + BLOCK_CONTENT: 'ce-block__content', + + /** + * @const {String} BLOCK_STRETCHED - makes block stretched + */ + BLOCK_STRETCHED: 'ce-block--stretched', + + /** + * @const {String} BLOCK_HIGHLIGHTED - adds background + */ + BLOCK_HIGHLIGHTED: 'ce-block--focused', + + /** + * @const {String} - highlights covered blocks + */ + BLOCK_IN_FEED_MODE: 'ce-block--feed-mode', + + /** + * @const {String} - for all default settings + */ + SETTINGS_ITEM: 'ce-settings__item' + + }; + + /** + * @protected + * + * Making main interface + */ + ui.make = function () { + + var wrapper, toolbar, toolbarContent, inlineToolbar, redactor, ceBlock, notifications, blockButtons, blockSettings, showSettingsButton, showTrashButton, toolbox, plusButton; + + /** Make editor wrapper */ + wrapper = codex.draw.wrapper(); + + /** Append editor wrapper after initial textarea */ + codex.core.insertAfter(codex.nodes.textarea, wrapper); + + /** Append block with notifications to the document */ + notifications = codex.draw.alertsHolder(); + codex.nodes.notifications = document.body.appendChild(notifications); + + /** Make toolbar and content-editable redactor */ + toolbar = codex.draw.toolbar(); + toolbarContent = codex.draw.toolbarContent(); + inlineToolbar = codex.draw.inlineToolbar(); + plusButton = codex.draw.plusButton(); + showSettingsButton = codex.draw.settingsButton(); + showTrashButton = codex.toolbar.settings.makeRemoveBlockButton(); + blockSettings = codex.draw.blockSettings(); + blockButtons = codex.draw.blockButtons(); + toolbox = codex.draw.toolbox(); + redactor = codex.draw.redactor(); + + /** settings */ + var defaultSettings = codex.draw.defaultSettings(), + pluginSettings = codex.draw.pluginsSettings(); + + /** Add default and plugins settings */ + blockSettings.appendChild(pluginSettings); + blockSettings.appendChild(defaultSettings); + + /** Make blocks buttons + * This block contains settings button and remove block button + */ + blockButtons.appendChild(showSettingsButton); + blockButtons.appendChild(showTrashButton); + blockButtons.appendChild(blockSettings); + + /** Append plus button */ + toolbarContent.appendChild(plusButton); + + /** Appending toolbar tools */ + toolbarContent.appendChild(toolbox); + + /** Appending first-level block buttons */ + toolbar.appendChild(blockButtons); + + /** Append toolbarContent to toolbar */ + toolbar.appendChild(toolbarContent); + + wrapper.appendChild(toolbar); + + wrapper.appendChild(redactor); + + /** Save created ui-elements to static nodes state */ + codex.nodes.wrapper = wrapper; + codex.nodes.toolbar = toolbar; + codex.nodes.plusButton = plusButton; + codex.nodes.toolbox = toolbox; + codex.nodes.blockSettings = blockSettings; + codex.nodes.pluginSettings = pluginSettings; + codex.nodes.defaultSettings = defaultSettings; + codex.nodes.showSettingsButton = showSettingsButton; + codex.nodes.showTrashButton = showTrashButton; + + codex.nodes.redactor = redactor; + + codex.ui.makeInlineToolbar(inlineToolbar); + + /** fill in default settings */ + codex.toolbar.settings.addDefaultSettings(); + }; + + ui.makeInlineToolbar = function (container) { + + /** Append to redactor new inline block */ + codex.nodes.inlineToolbar.wrapper = container; + + /** Draw toolbar buttons */ + codex.nodes.inlineToolbar.buttons = codex.draw.inlineToolbarButtons(); + + /** Buttons action or settings */ + codex.nodes.inlineToolbar.actions = codex.draw.inlineToolbarActions(); + + /** Append to inline toolbar buttons as part of it */ + codex.nodes.inlineToolbar.wrapper.appendChild(codex.nodes.inlineToolbar.buttons); + codex.nodes.inlineToolbar.wrapper.appendChild(codex.nodes.inlineToolbar.actions); + + codex.nodes.wrapper.appendChild(codex.nodes.inlineToolbar.wrapper); + }; + + /** + * @private + * Append tools passed in codex.tools + */ + ui.addTools = function () { + + var tool, tool_button; + + for (var name in codex.settings.tools) { + tool = codex.settings.tools[name]; + codex.tools[name] = tool;; + } + + /** Make toolbar buttons */ + for (var name in codex.tools) { + + tool = codex.tools[name]; + + if (tool.displayInToolbox == false) { + continue; + } + + if (!tool.iconClassname) { + codex.core.log('Toolbar icon classname missed. Tool %o skipped', 'warn', name); + continue; + } + + if (typeof tool.make != 'function') { + codex.core.log('make method missed. Tool %o skipped', 'warn', name); + continue; + } + + /** + * if tools is for toolbox + */ + tool_button = codex.draw.toolbarButton(name, tool.iconClassname); + + codex.nodes.toolbox.appendChild(tool_button); + + /** Save tools to static nodes */ + codex.nodes.toolbarButtons[name] = tool_button; + } + + /** + * Add inline toolbar tools + */ + codex.ui.addInlineToolbarTools(); + }; + + ui.addInlineToolbarTools = function () { + + var tools = { + + bold: { + icon: 'ce-icon-bold', + command: 'bold' + }, + + italic: { + icon: 'ce-icon-italic', + command: 'italic' + }, + + underline: { + icon: 'ce-icon-underline', + command: 'underline' + }, + + link: { + icon: 'ce-icon-link', + command: 'createLink' + } + }; + + var toolButton, tool; + + for (var name in tools) { + + tool = tools[name]; + + toolButton = codex.draw.toolbarButtonInline(name, tool.icon); + + codex.nodes.inlineToolbar.buttons.appendChild(toolButton); + /** + * Add callbacks to this buttons + */ + codex.ui.setInlineToolbarButtonBehaviour(toolButton, tool.command); + } + }; + + /** + * @private + * Bind editor UI events + */ + ui.bindEvents = function () { + + codex.core.log('ui.bindEvents fired', 'info'); + + window.addEventListener('error', function (errorMsg, url, lineNumber) { + codex.notifications.errorThrown(errorMsg, event); + }, false); + + /** All keydowns on Document */ + codex.nodes.redactor.addEventListener('keydown', codex.callback.globalKeydown, false); + + /** All keydowns on Document */ + document.addEventListener('keyup', codex.callback.globalKeyup, false); + + /** + * Mouse click to radactor + */ + codex.nodes.redactor.addEventListener('click', codex.callback.redactorClicked, false); + + /** + * Clicks to the Plus button + */ + codex.nodes.plusButton.addEventListener('click', codex.callback.plusButtonClicked, false); + + /** + * Clicks to SETTINGS button in toolbar + */ + codex.nodes.showSettingsButton.addEventListener('click', codex.callback.showSettingsButtonClicked, false); + /** + * @deprecated ( but now in use for syncronization ); + * Any redactor changes: keyboard input, mouse cut/paste, drag-n-drop text + */ + codex.nodes.redactor.addEventListener('input', codex.callback.redactorInputEvent, false); + + /** Bind click listeners on toolbar buttons */ + for (var button in codex.nodes.toolbarButtons) { + codex.nodes.toolbarButtons[button].addEventListener('click', codex.callback.toolbarButtonClicked, false); + } + }; + + /** + * Initialize plugins before using + * Ex. Load scripts or call some internal methods + */ + ui.preparePlugins = function () { + + for (var tool in codex.tools) { + + if (typeof codex.tools[tool].prepare != 'function') continue; + + codex.tools[tool].prepare(); + } + }, ui.addBlockHandlers = function (block) { + + if (!block) return; + + /** + * Block keydowns + */ + block.addEventListener('keydown', function (event) { + codex.callback.blockKeydown(event, block); + }, false); + + /** + * Pasting content from another source + */ + block.addEventListener('paste', function (event) { + codex.callback.blockPaste(event); + }, false); + + block.addEventListener('mouseup', function () { + codex.toolbar.inline.show(); + }, false); + }; + + /** getting all contenteditable elements */ + ui.saveInputs = function () { + + var redactor = codex.nodes.redactor, + elements = []; + + /** Save all inputs in global variable state */ + codex.state.inputs = redactor.querySelectorAll('[contenteditable], input'); + }; + + /** + * Adds first initial block on empty redactor + */ + ui.addInitialBlock = function () { + + var initialBlockType = codex.settings.initialBlockPlugin, + initialBlock; + + if (!codex.tools[initialBlockType]) { + codex.core.log('Plugin %o was not implemented and can\'t be used as initial block', 'warn', initialBlockType); + return; + } + + initialBlock = codex.tools[initialBlockType].render(); + + initialBlock.setAttribute('data-placeholder', 'Write your story...'); + + codex.content.insertBlock({ + type: initialBlockType, + block: initialBlock + }); + + codex.content.workingNodeChanged(initialBlock); + }; + + ui.setInlineToolbarButtonBehaviour = function (button, type) { + + button.addEventListener('mousedown', function (event) { + + codex.toolbar.inline.toolClicked(event, type); + }, false); + }; + + return ui; + }({}); + + codex.ui = ui; + module.exports = codex; + +/***/ }, +/* 4 */ +/***/ function(module, exports, __webpack_require__) { + + 'use strict'; + + var codex = __webpack_require__(1); + + var transport = function (transport) { + + transport.input = null; + + /** + * @property {Object} arguments - keep plugin settings and defined callbacks + */ + transport.arguments = null; + + transport.prepare = function () { + + var input = document.createElement('INPUT'); + + input.type = 'file'; + input.addEventListener('change', codex.transport.fileSelected); + + codex.transport.input = input; + }; + + /** Clear input when files is uploaded */ + transport.clearInput = function () { + + /** Remove old input */ + this.input = null; + + /** Prepare new one */ + this.prepare(); + }; + + /** + * Callback for file selection + */ + transport.fileSelected = function (event) { + + var input = this, + files = input.files, + filesLength = files.length, + formdData = new FormData(), + file, + i; + + formdData.append('files', files[0], files[0].name); + + codex.transport.ajax({ + data: formdData, + beforeSend: codex.transport.arguments.beforeSend, + success: codex.transport.arguments.success, + error: codex.transport.arguments.error + }); + }; + + /** + * Use plugin callbacks + * @protected + */ + transport.selectAndUpload = function (args) { + + this.arguments = args; + this.input.click(); + }; + + /** + * Ajax requests module + */ + transport.ajax = function (params) { + + var xhr = new XMLHttpRequest(), + beforeSend = typeof params.beforeSend == 'function' ? params.beforeSend : function () {}, + success = typeof params.success == 'function' ? params.success : function () {}, + error = typeof params.error == 'function' ? params.error : function () {}; + + beforeSend(); + + xhr.open('POST', codex.settings.uploadImagesUrl, true); + + xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest"); + + xhr.onload = function () { + if (xhr.status === 200) { + success(xhr.responseText); + } else { + console.log("request error: %o", xhr); + error(); + } + }; + + xhr.send(params.data); + this.clearInput(); + }; + + return transport; + }({}); + + codex.transport = transport; + module.exports = transport; + +/***/ }, +/* 5 */ +/***/ function(module, exports, __webpack_require__) { + + 'use strict'; + + var codex = __webpack_require__(1); + + var renderer = function (renderer) { + + /** + * Asyncronously parses input JSON to redactor blocks + */ + renderer.makeBlocksFromData = function () { + + /** + * If redactor is empty, add first paragraph to start writing + */ + if (!codex.state.blocks.items.length) { + + codex.ui.addInitialBlock(); + return; + } + + Promise.resolve() + + /** First, get JSON from state */ + .then(function () { + return codex.state.blocks; + }) + + /** Then, start to iterate they */ + .then(codex.renderer.appendBlocks) + + /** Write log if something goes wrong */ + .catch(function (error) { + codex.core.log('Error while parsing JSON: %o', 'error', error); + }); + }; + + /** + * Parses JSON to blocks + * @param {object} data + * @return Primise -> nodeList + */ + renderer.appendBlocks = function (data) { + + var blocks = data.items; + + /** + * Sequence of one-by-one blocks appending + * Uses to save blocks order after async-handler + */ + var nodeSequence = Promise.resolve(); + + for (var index = 0; index < blocks.length; index++) { + + /** Add node to sequence at specified index */ + codex.renderer.appendNodeAtIndex(nodeSequence, blocks, index); + } + }; + + /** + * Append node at specified index + */ + renderer.appendNodeAtIndex = function (nodeSequence, blocks, index) { + + /** We need to append node to sequence */ + nodeSequence + + /** first, get node async-aware */ + .then(function () { + + return codex.renderer.getNodeAsync(blocks, index); + }) + + /** + * second, compose editor-block from JSON object + */ + .then(codex.renderer.createBlockFromData) + + /** + * now insert block to redactor + */ + .then(function (blockData) { + + /** + * blockData has 'block', 'type' and 'stretched' information + */ + codex.content.insertBlock(blockData); + + /** Pass created block to next step */ + return blockData.block; + }) + + /** Log if something wrong with node */ + .catch(function (error) { + codex.core.log('Node skipped while parsing because %o', 'error', error); + }); + }; + + /** + * Asynchronously returns block data from blocksList by index + * @return Promise to node + */ + renderer.getNodeAsync = function (blocksList, index) { + + return Promise.resolve().then(function () { + + return blocksList[index]; + }); + }; + + /** + * Creates editor block by JSON-data + * + * @uses render method of each plugin + * + * @param {object} blockData looks like + * { header : { + * text: '', + * type: 'H3', ... + * } + * } + * @return {object} with type and Element + */ + renderer.createBlockFromData = function (blockData) { + + /** New parser */ + var pluginName = blockData.type; + + /** Get first key of object that stores plugin name */ + // for (var pluginName in blockData) break; + + /** Check for plugin existance */ + if (!codex.tools[pluginName]) { + throw Error('Plugin \xAB' + pluginName + '\xBB not found'); + } + + /** Check for plugin having render method */ + if (typeof codex.tools[pluginName].render != 'function') { + + throw Error('Plugin \xAB' + pluginName + '\xBB must have \xABrender\xBB method'); + } + + /** New Parser */ + var block = codex.tools[pluginName].render(blockData.data); + + /** Fire the render method with data */ + // var block = codex.tools[pluginName].render(blockData[pluginName]); + + /** is first-level block stretched */ + var stretched = codex.tools[pluginName].isStretched || false; + + /** Retrun type and block */ + return { + type: pluginName, + block: block, + stretched: stretched + }; + }; + + return renderer; + }({}); + + codex.renderer = renderer; + module.exports = renderer; + +/***/ }, +/* 6 */ +/***/ function(module, exports, __webpack_require__) { + + 'use strict'; + + var codex = __webpack_require__(1); + + var saver = function (saver) { + + /** + * Saves blocks + * @private + */ + saver.saveBlocks = function () { + + /** Save html content of redactor to memory */ + codex.state.html = codex.nodes.redactor.innerHTML; + + /** Empty jsonOutput state */ + codex.state.jsonOutput = []; + + Promise.resolve().then(function () { + return codex.nodes.redactor.childNodes; + }) + /** Making a sequence from separate blocks */ + .then(codex.saver.makeQueue).then(function () { + // codex.nodes.textarea.innerHTML = codex.state.html; + }).catch(function (error) { + console.log('Something happend'); + }); + }; + + saver.makeQueue = function (blocks) { + + var queue = Promise.resolve(); + + for (var index = 0; index < blocks.length; index++) { + + /** Add node to sequence at specified index */ + codex.saver.getBlockData(queue, blocks, index); + } + }; + + /** Gets every block and makes From Data */ + saver.getBlockData = function (queue, blocks, index) { + + queue.then(function () { + return codex.saver.getNodeAsync(blocks, index); + }).then(codex.saver.makeFormDataFromBlocks); + }; + + /** + * Asynchronously returns block data from blocksList by index + * @return Promise to node + */ + saver.getNodeAsync = function (blocksList, index) { + + return Promise.resolve().then(function () { + + return blocksList[index]; + }); + }; + + saver.makeFormDataFromBlocks = function (block) { + + var pluginName = block.dataset.tool; + + /** Check for plugin existance */ + if (!codex.tools[pluginName]) { + throw Error('Plugin \xAB' + pluginName + '\xBB not found'); + } + + /** Check for plugin having render method */ + if (typeof codex.tools[pluginName].save != 'function') { + + throw Error('Plugin \xAB' + pluginName + '\xBB must have save method'); + } + + /** Result saver */ + var blockContent = block.childNodes[0], + pluginsContent = blockContent.childNodes[0], + savedData = codex.tools[pluginName].save(pluginsContent), + output; + + output = { + type: pluginName, + data: savedData + }; + + /** Marks Blocks that will be in main page */ + output.cover = block.classList.contains(codex.ui.className.BLOCK_IN_FEED_MODE); + + codex.state.jsonOutput.push(output); + }; + + return saver; + }({}); + + codex.saver = saver; + module.exports = saver; + +/***/ }, +/* 7 */ +/***/ function(module, exports, __webpack_require__) { + + 'use strict'; + + var codex = __webpack_require__(1); + + var content = function (content) { + + content.currentNode = null; + + /** + * Synchronizes redactor with original textarea + */ + content.sync = function () { + + codex.core.log('syncing...'); + + /** + * Save redactor content to codex.state + */ + codex.state.html = codex.nodes.redactor.innerHTML; + }; + + /** + * @deprecated + */ + content.getNodeFocused = function () { + + var selection = window.getSelection(), + focused; + + if (selection.anchorNode === null) { + return null; + } + + if (selection.anchorNode.nodeType == codex.core.nodeTypes.TAG) { + focused = selection.anchorNode; + } else { + focused = selection.focusNode.parentElement; + } + + if (!codex.parser.isFirstLevelBlock(focused)) { + + /** Iterate with parent nodes to find first-level*/ + var parent = focused.parentNode; + + while (parent && !codex.parser.isFirstLevelBlock(parent)) { + parent = parent.parentNode; + } + + focused = parent; + } + + if (focused != codex.nodes.redactor) { + return focused; + } + + return null; + }; + + /** + * Appends background to the block + */ + content.markBlock = function () { + + codex.content.currentNode.classList.add(codex.ui.className.BLOCK_HIGHLIGHTED); + }; + + /** + * Clear background + */ + content.clearMark = function () { + + if (codex.content.currentNode) { + codex.content.currentNode.classList.remove(codex.ui.className.BLOCK_HIGHLIGHTED); + } + }; + + /** + * @private + * + * Finds first-level block + * @param {Element} node - selected or clicked in redactors area node + */ + content.getFirstLevelBlock = function (node) { + + if (!codex.core.isDomNode(node)) { + node = node.parentNode; + } + + if (node === codex.nodes.redactor || node === document.body) { + + return null; + } else { + + while (!node.classList.contains(codex.ui.className.BLOCK_CLASSNAME)) { + node = node.parentNode; + } + + return node; + } + }; + + /** + * Trigger this event when working node changed + * @param {Element} targetNode - first-level of this node will be current + * If targetNode is first-level then we set it as current else we look for parents to find first-level + */ + content.workingNodeChanged = function (targetNode) { + + /** Clear background from previous marked block before we change */ + codex.content.clearMark(); + + if (!targetNode) { + return; + } + + this.currentNode = this.getFirstLevelBlock(targetNode); + }; + + /** + * Replaces one redactor block with another + * @protected + * @param {Element} targetBlock - block to replace. Mostly currentNode. + * @param {Element} newBlock + * @param {string} newBlockType - type of new block; we need to store it to data-attribute + * + * [!] Function does not saves old block content. + * You can get it manually and pass with newBlock.innerHTML + */ + content.replaceBlock = function function_name(targetBlock, newBlock) { + + if (!targetBlock || !newBlock) { + codex.core.log('replaceBlock: missed params'); + return; + } + + /** If target-block is not a frist-level block, then we iterate parents to find it */ + while (!targetBlock.classList.contains(codex.ui.className.BLOCK_CLASSNAME)) { + targetBlock = targetBlock.parentNode; + } + + /** Replacing */ + codex.nodes.redactor.replaceChild(newBlock, targetBlock); + + /** + * Set new node as current + */ + codex.content.workingNodeChanged(newBlock); + + /** + * Add block handlers + */ + codex.ui.addBlockHandlers(newBlock); + + /** + * Save changes + */ + codex.ui.saveInputs(); + }; + + /** + * @private + * + * Inserts new block to redactor + * Wrapps block into a DIV with BLOCK_CLASSNAME class + * + * @param blockData {object} + * @param blockData.block {Element} element with block content + * @param blockData.type {string} block plugin + * @param needPlaceCaret {bool} pass true to set caret in new block + * + */ + content.insertBlock = function (blockData, needPlaceCaret) { + + var workingBlock = codex.content.currentNode, + newBlockContent = blockData.block, + blockType = blockData.type, + isStretched = blockData.stretched; + + var newBlock = codex.content.composeNewBlock(newBlockContent, blockType, isStretched); + + if (workingBlock) { + + codex.core.insertAfter(workingBlock, newBlock); + } else { + /** + * If redactor is empty, append as first child + */ + codex.nodes.redactor.appendChild(newBlock); + } + + /** + * Block handler + */ + codex.ui.addBlockHandlers(newBlock); + + /** + * Set new node as current + */ + codex.content.workingNodeChanged(newBlock); + + /** + * Save changes + */ + codex.ui.saveInputs(); + + if (needPlaceCaret) { + + /** + * If we don't know input index then we set default value -1 + */ + var currentInputIndex = codex.caret.getCurrentInputIndex() || -1; + + if (currentInputIndex == -1) { + + var editableElement = newBlock.querySelector('[contenteditable]'), + emptyText = document.createTextNode(''); + + editableElement.appendChild(emptyText); + codex.caret.set(editableElement, 0, 0); + + codex.toolbar.move(); + codex.toolbar.showPlusButton(); + } else { + + /** Timeout for browsers execution */ + setTimeout(function () { + + /** Setting to the new input */ + codex.caret.setToNextBlock(currentInputIndex); + codex.toolbar.move(); + codex.toolbar.open(); + }, 10); + } + } + }; + + /** + * Replaces blocks with saving content + * @protected + * @param {Element} noteToReplace + * @param {Element} newNode + * @param {Element} blockType + */ + content.switchBlock = function (blockToReplace, newBlock, tool) { + + var newBlockComposed = codex.content.composeNewBlock(newBlock, tool); + + /** Replacing */ + codex.content.replaceBlock(blockToReplace, newBlockComposed); + + /** Save new Inputs when block is changed */ + codex.ui.saveInputs(); + }; + + /** + * Iterates between child noted and looking for #text node on deepest level + * @private + * @param {Element} block - node where find + * @param {int} postiton - starting postion + * Example: childNodex.length to find from the end + * or 0 to find from the start + * @return {Text} block + * @uses DFS + */ + content.getDeepestTextNodeFromPosition = function (block, position) { + + /** + * Clear Block from empty and useless spaces with trim. + * Such nodes we should remove + */ + var blockChilds = block.childNodes, + index, + node, + text; + + for (index = 0; index < blockChilds.length; index++) { + node = blockChilds[index]; + + if (node.nodeType == codex.core.nodeTypes.TEXT) { + + text = node.textContent.trim(); + + /** Text is empty. We should remove this child from node before we start DFS + * decrease the quantity of childs. + */ + if (text === '') { + + block.removeChild(node); + position--; + } + } + } + + if (block.childNodes.length === 0) { + return document.createTextNode(''); + } + + /** Setting default position when we deleted all empty nodes */ + if (position < 0) position = 1; + + var looking_from_start = false; + + /** For looking from START */ + if (position === 0) { + looking_from_start = true; + position = 1; + } + + while (position) { + + /** initial verticle of node. */ + if (looking_from_start) { + block = block.childNodes[0]; + } else { + block = block.childNodes[position - 1]; + } + + if (block.nodeType == codex.core.nodeTypes.TAG) { + + position = block.childNodes.length; + } else if (block.nodeType == codex.core.nodeTypes.TEXT) { + + position = 0; + } + } + + return block; + }; + + /** + * @private + */ + content.composeNewBlock = function (block, tool, isStretched) { + + var newBlock = codex.draw.node('DIV', codex.ui.className.BLOCK_CLASSNAME, {}), + blockContent = codex.draw.node('DIV', codex.ui.className.BLOCK_CONTENT, {}); + + blockContent.appendChild(block); + newBlock.appendChild(blockContent); + + if (isStretched) { + blockContent.classList.add(codex.ui.className.BLOCK_STRETCHED); + } + + newBlock.dataset.tool = tool; + return newBlock; + }; + + /** + * Returns Range object of current selection + */ + content.getRange = function () { + + var selection = window.getSelection().getRangeAt(0); + + return selection; + }; + + /** + * Divides block in two blocks (after and before caret) + * @private + * @param {Int} inputIndex - target input index + */ + content.splitBlock = function (inputIndex) { + + var selection = window.getSelection(), + anchorNode = selection.anchorNode, + anchorNodeText = anchorNode.textContent, + caretOffset = selection.anchorOffset, + textBeforeCaret, + textNodeBeforeCaret, + textAfterCaret, + textNodeAfterCaret; + + var currentBlock = codex.content.currentNode.querySelector('[contentEditable]'); + + textBeforeCaret = anchorNodeText.substring(0, caretOffset); + textAfterCaret = anchorNodeText.substring(caretOffset); + + textNodeBeforeCaret = document.createTextNode(textBeforeCaret); + + if (textAfterCaret) { + textNodeAfterCaret = document.createTextNode(textAfterCaret); + } + + var previousChilds = [], + nextChilds = [], + reachedCurrent = false; + + if (textNodeAfterCaret) { + nextChilds.push(textNodeAfterCaret); + } + + for (var i = 0, child; !!(child = currentBlock.childNodes[i]); i++) { + + if (child != anchorNode) { + if (!reachedCurrent) { + previousChilds.push(child); + } else { + nextChilds.push(child); + } + } else { + reachedCurrent = true; + } + } + + /** Clear current input */ + codex.state.inputs[inputIndex].innerHTML = ''; + + /** + * Append all childs founded before anchorNode + */ + var previousChildsLength = previousChilds.length; + + for (i = 0; i < previousChildsLength; i++) { + codex.state.inputs[inputIndex].appendChild(previousChilds[i]); + } + + codex.state.inputs[inputIndex].appendChild(textNodeBeforeCaret); + + /** + * Append text node which is after caret + */ + var nextChildsLength = nextChilds.length, + newNode = document.createElement('div'); + + for (i = 0; i < nextChildsLength; i++) { + newNode.appendChild(nextChilds[i]); + } + + newNode = newNode.innerHTML; + + /** This type of block creates when enter is pressed */ + var NEW_BLOCK_TYPE = 'paragraph'; + + /** + * Make new paragraph with text after caret + */ + codex.content.insertBlock({ + type: NEW_BLOCK_TYPE, + block: codex.tools[NEW_BLOCK_TYPE].render({ + text: newNode + }) + }, true); + }; + + /** + * Merges two blocks — current and target + * If target index is not exist, then previous will be as target + */ + content.mergeBlocks = function (currentInputIndex, targetInputIndex) { + + /** If current input index is zero, then prevent method execution */ + if (currentInputIndex === 0) { + return; + } + + var targetInput, + currentInputContent = codex.state.inputs[currentInputIndex].innerHTML; + + if (!targetInputIndex) { + + targetInput = codex.state.inputs[currentInputIndex - 1]; + } else { + + targetInput = codex.state.inputs[targetInputIndex]; + } + + targetInput.innerHTML += currentInputContent; + }; + + /** + * @private + * + * Callback for HTML Mutations + * @param {Array} mutation - Mutation Record + */ + content.paste = function (mutation) { + + var workingNode = codex.content.currentNode, + tool = workingNode.dataset.tool; + + if (codex.tools[tool].allowedToPaste) { + codex.content.sanitize(mutation.addedNodes); + } else { + codex.content.pasteTextContent(mutation.addedNodes); + } + }; + + /** + * @private + * + * gets only text/plain content of node + * @param {Element} target - HTML node + */ + content.pasteTextContent = function (nodes) { + + var node = nodes[0], + textNode = document.createTextNode(node.textContent); + + if (codex.core.isDomNode(node)) { + node.parentNode.replaceChild(textNode, node); + } + }; + + /** + * @private + * + * Sanitizes HTML content + * @param {Element} target - inserted element + * @uses DFS function for deep searching + */ + content.sanitize = function (target) { + + if (!target) { + return; + } + + for (var i = 0; i < target.childNodes.length; i++) { + this.dfs(target.childNodes[i]); + } + }; + + /** + * Clears styles + * @param {Element|Text} + */ + content.clearStyles = function (target) { + + var href, + newNode = null, + blockTags = ['P', 'BLOCKQUOTE', 'UL', 'CODE', 'OL', 'LI', 'H1', 'H2', 'H3', 'H4', 'H5', 'H6', 'DIV', 'PRE', 'HEADER', 'SECTION'], + allowedTags = ['P', 'B', 'I', 'A', 'U', 'BR'], + needReplace = !allowedTags.includes(target.tagName), + isDisplayedAsBlock = blockTags.includes(target.tagName); + + if (!codex.core.isDomNode(target)) { + return target; + } + + if (!target.parentNode) { + return target; + } + + if (needReplace) { + + if (isDisplayedAsBlock) { + + newNode = document.createElement('P'); + newNode.innerHTML = target.innerHTML; + target.parentNode.replaceChild(newNode, target); + target = newNode; + } else { + + newNode = document.createTextNode(' ' + target.textContent + ' '); + newNode.textContent = newNode.textContent.replace(/\s{2,}/g, ' '); + target.parentNode.replaceChild(newNode, target); + } + } + + /** keep href attributes of tag A */ + if (target.tagName == 'A') { + href = target.getAttribute('href'); + } + + /** Remove all tags */ + while (target.attributes.length > 0) { + target.removeAttribute(target.attributes[0].name); + } + + /** return href */ + if (href) { + target.setAttribute('href', href); + } + + return target; + }; + + /** + * Depth-first search Algorithm + * returns all childs + * @param {Element} + */ + content.dfs = function (el) { + + if (!codex.core.isDomNode(el)) return; + + var sanitized = this.clearStyles(el); + + for (var i = 0; i < sanitized.childNodes.length; i++) { + this.dfs(sanitized.childNodes[i]); + } + }; + + return content; + }({}); + + codex.content = content; + module.exports = content; + +/***/ }, +/* 8 */ +/***/ function(module, exports, __webpack_require__) { + + 'use strict'; + + var codex = __webpack_require__(1); + + var toolbar = function (toolbar) { + + toolbar.init = function () { + toolbar.settings = __webpack_require__(9); + toolbar.inline = __webpack_require__(10); + toolbar.toolbox = __webpack_require__(11); + }; + + /** + * Margin between focused node and toolbar + */ + toolbar.defaultToolbarHeight = 49; + + toolbar.defaultOffset = 34; + + toolbar.opened = false; + + toolbar.current = null; + + /** + * @protected + */ + toolbar.open = function () { + + codex.nodes.toolbar.classList.add('opened'); + this.opened = true; + }; + + /** + * @protected + */ + toolbar.close = function () { + + codex.nodes.toolbar.classList.remove('opened'); + this.opened = false; + + this.current = null; + + for (var button in codex.nodes.toolbarButtons) { + codex.nodes.toolbarButtons[button].classList.remove('selected'); + } + + /** Close toolbox when toolbar is not displayed */ + codex.toolbar.toolbox.close(); + codex.toolbar.settings.close(); + }; + + toolbar.toggle = function () { + + if (!this.opened) { + + this.open(); + } else { + + this.close(); + } + }; + + toolbar.hidePlusButton = function () { + codex.nodes.plusButton.classList.add('hide'); + }; + + toolbar.showPlusButton = function () { + codex.nodes.plusButton.classList.remove('hide'); + }; + + /** + * Moving toolbar to the specified node + */ + toolbar.move = function () { + + /** Close Toolbox when we move toolbar */ + codex.toolbar.toolbox.close(); + + if (!codex.content.currentNode) { + return; + } + + var toolbarHeight = codex.nodes.toolbar.clientHeight || codex.toolbar.defaultToolbarHeight, + newYCoordinate = codex.content.currentNode.offsetTop - codex.toolbar.defaultToolbarHeight / 2 + codex.toolbar.defaultOffset; + + codex.nodes.toolbar.style.transform = 'translate3D(0, ' + Math.floor(newYCoordinate) + 'px, 0)'; + + /** Close trash actions */ + codex.toolbar.settings.hideRemoveActions(); + }; + + return toolbar; + }({}); + + toolbar.init(); + + codex.toolbar = toolbar; + module.exports = toolbar; + +/***/ }, +/* 9 */ +/***/ function(module, exports, __webpack_require__) { + + 'use strict'; + + var codex = __webpack_require__(1); + + var settings = function (settings) { + + settings.init = function () { + __webpack_require__(7); + }; + + settings.opened = false; + + settings.setting = null; + settings.actions = null; + + settings.cover = null; + + /** + * Append and open settings + */ + settings.open = function (toolType) { + + /** + * Append settings content + * It's stored in tool.settings + */ + if (!codex.tools[toolType] || !codex.core.isDomNode(codex.tools[toolType].settings)) { + + codex.core.log('Plugin \xAB' + toolType + '\xBB has no settings', 'warn'); + // codex.nodes.pluginSettings.innerHTML = `Плагин «${toolType}» не имеет настроек`; + } else { + + codex.nodes.pluginSettings.appendChild(codex.tools[toolType].settings); + } + + var currentBlock = codex.content.currentNode; + + /** Open settings block */ + codex.nodes.blockSettings.classList.add('opened'); + codex.toolbar.settings.addDefaultSettings(); + this.opened = true; + }; + + /** + * Close and clear settings + */ + settings.close = function () { + + codex.nodes.blockSettings.classList.remove('opened'); + codex.nodes.pluginSettings.innerHTML = ''; + + this.opened = false; + }; + + /** + * @param {string} toolType - plugin type + */ + settings.toggle = function (toolType) { + + if (!this.opened) { + + this.open(toolType); + } else { + + this.close(); + } + }; + + /** + * This function adds default core settings + */ + settings.addDefaultSettings = function () { + + /** list of default settings */ + var feedModeToggler; + + /** Clear block and append initialized settings */ + codex.nodes.defaultSettings.innerHTML = ''; + + /** Init all default setting buttons */ + feedModeToggler = codex.toolbar.settings.makeFeedModeToggler(); + + /** + * Fill defaultSettings + */ + + /** + * Button that enables/disables Feed-mode + * Feed-mode means that block will be showed in articles-feed like cover + */ + codex.nodes.defaultSettings.appendChild(feedModeToggler); + }; + + /** + * Cover setting. + * This tune highlights block, so that it may be used for showing target block on main page + * Draw different setting when block is marked for main page + * If TRUE, then we show button that removes this selection + * Also defined setting "Click" events will be listened and have separate callbacks + * + * @return {Element} node/button that we place in default settings block + */ + settings.makeFeedModeToggler = function () { + + var isFeedModeActivated = codex.toolbar.settings.isFeedModeActivated(), + setting, + data; + + if (!isFeedModeActivated) { + + data = { + innerHTML: 'Вывести в ленте' + }; + } else { + + data = { + innerHTML: 'Не выводить в ленте' + }; + } + + setting = codex.draw.node('DIV', codex.ui.className.SETTINGS_ITEM, data); + setting.addEventListener('click', codex.toolbar.settings.updateFeedMode, false); + + return setting; + }; + + /** + * Updates Feed-mode + */ + settings.updateFeedMode = function () { + + var currentNode = codex.content.currentNode; + + currentNode.classList.toggle(codex.ui.className.BLOCK_IN_FEED_MODE); + + codex.toolbar.settings.close(); + }; + + settings.isFeedModeActivated = function () { + + var currentBlock = codex.content.currentNode; + + if (currentBlock) { + return currentBlock.classList.contains(codex.ui.className.BLOCK_IN_FEED_MODE); + } else { + return false; + } + }; + + /** + * Here we will draw buttons and add listeners to components + */ + settings.makeRemoveBlockButton = function () { + + var removeBlockWrapper = codex.draw.node('SPAN', 'ce-toolbar__remove-btn', {}), + settingButton = codex.draw.node('SPAN', 'ce-toolbar__remove-setting', { innerHTML: '' }), + actionWrapper = codex.draw.node('DIV', 'ce-toolbar__remove-confirmation', {}), + confirmAction = codex.draw.node('DIV', 'ce-toolbar__remove-confirm', { textContent: 'Удалить блок' }), + cancelAction = codex.draw.node('DIV', 'ce-toolbar__remove-cancel', { textContent: 'Отменить удаление' }); + + settingButton.addEventListener('click', codex.toolbar.settings.removeButtonClicked, false); + + confirmAction.addEventListener('click', codex.toolbar.settings.confirmRemovingRequest, false); + + cancelAction.addEventListener('click', codex.toolbar.settings.cancelRemovingRequest, false); + + actionWrapper.appendChild(confirmAction); + actionWrapper.appendChild(cancelAction); + + removeBlockWrapper.appendChild(settingButton); + removeBlockWrapper.appendChild(actionWrapper); + + /** Save setting */ + codex.toolbar.settings.setting = settingButton; + codex.toolbar.settings.actions = actionWrapper; + + return removeBlockWrapper; + }; + + settings.removeButtonClicked = function () { + + var action = codex.toolbar.settings.actions; + + if (action.classList.contains('opened')) { + codex.toolbar.settings.hideRemoveActions(); + } else { + codex.toolbar.settings.showRemoveActions(); + } + + codex.toolbar.toolbox.close(); + codex.toolbar.settings.close(); + }; + + settings.cancelRemovingRequest = function () { + + codex.toolbar.settings.actions.classList.remove('opened'); + }; + + settings.confirmRemovingRequest = function () { + + var currentBlock = codex.content.currentNode, + firstLevelBlocksCount; + + currentBlock.remove(); + + firstLevelBlocksCount = codex.nodes.redactor.childNodes.length; + + /** + * If all blocks are removed + */ + if (firstLevelBlocksCount === 0) { + + /** update currentNode variable */ + codex.content.currentNode = null; + + /** Inserting new empty initial block */ + codex.ui.addInitialBlock(); + } + + codex.ui.saveInputs(); + + codex.toolbar.close(); + }; + + settings.showRemoveActions = function () { + codex.toolbar.settings.actions.classList.add('opened'); + }; + + settings.hideRemoveActions = function () { + codex.toolbar.settings.actions.classList.remove('opened'); + }; + + return settings; + }({}); + + settings.init(); + + module.exports = settings; + +/***/ }, +/* 10 */ +/***/ function(module, exports, __webpack_require__) { + + 'use strict'; + + var codex = __webpack_require__(1); + + var inline = function (inline) { + + inline.init = function () {}; + + inline.buttonsOpened = null; + inline.actionsOpened = null; + inline.wrappersOffset = null; + + /** + * saving selection that need for execCommand for styling + * + */ + inline.storedSelection = null, + + /** + * @protected + * + * Open inline toobar + */ + inline.show = function () { + + var selectedText = this.getSelectionText(), + toolbar = codex.nodes.inlineToolbar.wrapper, + buttons = codex.nodes.inlineToolbar.buttons; + + if (selectedText.length > 0) { + + /** Move toolbar and open */ + codex.toolbar.inline.move(); + + /** Open inline toolbar */ + toolbar.classList.add('opened'); + + /** show buttons of inline toolbar */ + codex.toolbar.inline.showButtons(); + } + }; + + /** + * @protected + * + * Closes inline toolbar + */ + inline.close = function () { + var toolbar = codex.nodes.inlineToolbar.wrapper; + toolbar.classList.remove('opened'); + }; + + /** + * @private + * + * Moving toolbar + */ + inline.move = function () { + + if (!this.wrappersOffset) { + this.wrappersOffset = this.getWrappersOffset(); + } + + var coords = this.getSelectionCoords(), + defaultOffset = 0, + toolbar = codex.nodes.inlineToolbar.wrapper, + newCoordinateX, + newCoordinateY; + + if (toolbar.offsetHeight === 0) { + defaultOffset = 40; + } + + newCoordinateX = coords.x - this.wrappersOffset.left; + newCoordinateY = coords.y + window.scrollY - this.wrappersOffset.top - defaultOffset - toolbar.offsetHeight; + + toolbar.style.transform = 'translate3D(' + Math.floor(newCoordinateX) + 'px, ' + Math.floor(newCoordinateY) + 'px, 0)'; + + /** Close everything */ + codex.toolbar.inline.closeButtons(); + codex.toolbar.inline.closeAction(); + }; + + /** + * @private + * + * Tool Clicked + */ + + inline.toolClicked = function (event, type) { + + /** + * For simple tools we use default browser function + * For more complicated tools, we should write our own behavior + */ + switch (type) { + case 'createLink': + codex.toolbar.inline.createLinkAction(event, type);break; + default: + codex.toolbar.inline.defaultToolAction(type);break; + } + + /** + * highlight buttons + * after making some action + */ + codex.nodes.inlineToolbar.buttons.childNodes.forEach(codex.toolbar.inline.hightlight); + }; + + /** + * @private + * + * Saving wrappers offset in DOM + */ + inline.getWrappersOffset = function () { + + var wrapper = codex.nodes.wrapper, + offset = this.getOffset(wrapper); + + this.wrappersOffset = offset; + return offset; + }; + + /** + * @private + * + * Calculates offset of DOM element + * + * @param el + * @returns {{top: number, left: number}} + */ + inline.getOffset = function (el) { + + var _x = 0; + var _y = 0; + + while (el && !isNaN(el.offsetLeft) && !isNaN(el.offsetTop)) { + _x += el.offsetLeft + el.clientLeft; + _y += el.offsetTop + el.clientTop; + el = el.offsetParent; + } + return { top: _y, left: _x }; + }; + + /** + * @private + * + * Calculates position of selected text + * @returns {{x: number, y: number}} + */ + inline.getSelectionCoords = function () { + + var sel = document.selection, + range; + var x = 0, + y = 0; + + if (sel) { + + if (sel.type != "Control") { + range = sel.createRange(); + range.collapse(true); + x = range.boundingLeft; + y = range.boundingTop; + } + } else if (window.getSelection) { + + sel = window.getSelection(); + + if (sel.rangeCount) { + + range = sel.getRangeAt(0).cloneRange(); + if (range.getClientRects) { + range.collapse(true); + var rect = range.getClientRects()[0]; + x = rect.left; + y = rect.top; + } + } + } + return { x: x, y: y }; + }; + + /** + * @private + * + * Returns selected text as String + * @returns {string} + */ + inline.getSelectionText = function getSelectionText() { + + var selectedText = ""; + + if (window.getSelection) { + // all modern browsers and IE9+ + selectedText = window.getSelection().toString(); + } + + return selectedText; + }; + + /** Opens buttons block */ + inline.showButtons = function () { + + var buttons = codex.nodes.inlineToolbar.buttons; + buttons.classList.add('opened'); + + codex.toolbar.inline.buttonsOpened = true; + + /** highlight buttons */ + codex.nodes.inlineToolbar.buttons.childNodes.forEach(codex.toolbar.inline.hightlight); + }; + + /** Makes buttons disappear */ + inline.closeButtons = function () { + var buttons = codex.nodes.inlineToolbar.buttons; + buttons.classList.remove('opened'); + + codex.toolbar.inline.buttonsOpened = false; + }; + + /** Open buttons defined action if exist */ + inline.showActions = function () { + var action = codex.nodes.inlineToolbar.actions; + action.classList.add('opened'); + + codex.toolbar.inline.actionsOpened = true; + }; + + /** Close actions block */ + inline.closeAction = function () { + var action = codex.nodes.inlineToolbar.actions; + action.innerHTML = ''; + action.classList.remove('opened'); + codex.toolbar.inline.actionsOpened = false; + }; + + /** Action for link creation or for setting anchor */ + inline.createLinkAction = function (event, type) { + + var isActive = this.isLinkActive(); + + var editable = codex.content.currentNode, + storedSelection = codex.toolbar.inline.storedSelection; + + if (isActive) { + + var selection = window.getSelection(), + anchorNode = selection.anchorNode; + + storedSelection = codex.toolbar.inline.saveSelection(editable); + + /** + * Changing stored selection. if we want to remove anchor from word + * we should remove anchor from whole word, not only selected part. + * The solution is than we get the length of current link + * Change start position to - end of selection minus length of anchor + */ + codex.toolbar.inline.restoreSelection(editable, storedSelection); + + codex.toolbar.inline.defaultToolAction('unlink'); + } else { + + /** Create input and close buttons */ + var action = codex.draw.inputForLink(); + codex.nodes.inlineToolbar.actions.appendChild(action); + + codex.toolbar.inline.closeButtons(); + codex.toolbar.inline.showActions(); + + storedSelection = codex.toolbar.inline.saveSelection(editable); + + /** + * focus to input + * Solution: https://developer.mozilla.org/ru/docs/Web/API/HTMLElement/focus + * Prevents event after showing input and when we need to focus an input which is in unexisted form + */ + action.focus(); + event.preventDefault(); + + /** Callback to link action */ + action.addEventListener('keydown', function (event) { + + if (event.keyCode == codex.core.keys.ENTER) { + + codex.toolbar.inline.restoreSelection(editable, storedSelection); + codex.toolbar.inline.setAnchor(action.value); + + /** + * Preventing events that will be able to happen + */ + event.preventDefault(); + event.stopImmediatePropagation(); + + codex.toolbar.inline.clearRange(); + } + }, false); + } + }; + + inline.isLinkActive = function () { + + var isActive = false; + + codex.nodes.inlineToolbar.buttons.childNodes.forEach(function (tool) { + var dataType = tool.dataset.type; + + if (dataType == 'link' && tool.classList.contains('hightlighted')) { + isActive = true; + } + }); + + return isActive; + }; + + /** default action behavior of tool */ + inline.defaultToolAction = function (type) { + document.execCommand(type, false, null); + }; + + /** + * @private + * + * Sets URL + * + * @param {String} url - URL + */ + inline.setAnchor = function (url) { + + document.execCommand('createLink', false, url); + + /** Close after URL inserting */ + codex.toolbar.inline.closeAction(); + }; + + /** + * @private + * + * Saves selection + */ + inline.saveSelection = function (containerEl) { + + var range = window.getSelection().getRangeAt(0), + preSelectionRange = range.cloneRange(), + start; + + preSelectionRange.selectNodeContents(containerEl); + preSelectionRange.setEnd(range.startContainer, range.startOffset); + + start = preSelectionRange.toString().length; + + return { + start: start, + end: start + range.toString().length + }; + }; + + /** + * @private + * + * Sets to previous selection (Range) + * + * @param {Element} containerEl - editable element where we restore range + * @param {Object} savedSel - range basic information to restore + */ + inline.restoreSelection = function (containerEl, savedSel) { + + var range = document.createRange(), + charIndex = 0; + + range.setStart(containerEl, 0); + range.collapse(true); + + var nodeStack = [containerEl], + node, + foundStart = false, + stop = false, + nextCharIndex; + + while (!stop && (node = nodeStack.pop())) { + + if (node.nodeType == 3) { + + nextCharIndex = charIndex + node.length; + + if (!foundStart && savedSel.start >= charIndex && savedSel.start <= nextCharIndex) { + range.setStart(node, savedSel.start - charIndex); + foundStart = true; + } + if (foundStart && savedSel.end >= charIndex && savedSel.end <= nextCharIndex) { + range.setEnd(node, savedSel.end - charIndex); + stop = true; + } + charIndex = nextCharIndex; + } else { + var i = node.childNodes.length; + while (i--) { + nodeStack.push(node.childNodes[i]); + } + } + } + + var sel = window.getSelection(); + sel.removeAllRanges(); + sel.addRange(range); + }; + + /** + * @private + * + * Removes all ranges from window selection + */ + inline.clearRange = function () { + var selection = window.getSelection(); + selection.removeAllRanges(); + }; + + /** + * @private + * + * sets or removes hightlight + */ + inline.hightlight = function (tool) { + var dataType = tool.dataset.type; + + if (document.queryCommandState(dataType)) { + codex.toolbar.inline.setButtonHighlighted(tool); + } else { + codex.toolbar.inline.removeButtonsHighLight(tool); + } + + /** + * + * hightlight for anchors + */ + var selection = window.getSelection(), + tag = selection.anchorNode.parentNode; + + if (tag.tagName == 'A' && dataType == 'link') { + codex.toolbar.inline.setButtonHighlighted(tool); + } + }; + + /** + * @private + * + * Mark button if text is already executed + */ + inline.setButtonHighlighted = function (button) { + button.classList.add('hightlighted'); + + /** At link tool we also change icon */ + if (button.dataset.type == 'link') { + var icon = button.childNodes[0]; + icon.classList.remove('ce-icon-link'); + icon.classList.add('ce-icon-unlink'); + } + }; + + /** + * @private + * + * Removes hightlight + */ + inline.removeButtonsHighLight = function (button) { + button.classList.remove('hightlighted'); + + /** At link tool we also change icon */ + if (button.dataset.type == 'link') { + var icon = button.childNodes[0]; + icon.classList.remove('ce-icon-unlink'); + icon.classList.add('ce-icon-link'); + } + }; + + return inline; + }({}); + + inline.init(); + + module.exports = inline; + +/***/ }, +/* 11 */ +/***/ function(module, exports, __webpack_require__) { + + 'use strict'; + + var codex = __webpack_require__(1); + + var toolbox = function (toolbox) { + + toolbox.init = function () { + __webpack_require__(8); + }; + + toolbox.opened = false; + + /** Shows toolbox */ + toolbox.open = function () { + + /** Close setting if toolbox is opened */ + if (codex.toolbar.settings.opened) { + codex.toolbar.settings.close(); + } + + /** display toolbox */ + codex.nodes.toolbox.classList.add('opened'); + + /** Animate plus button */ + codex.nodes.plusButton.classList.add('clicked'); + + /** toolbox state */ + codex.toolbar.toolbox.opened = true; + }; + + /** Closes toolbox */ + toolbox.close = function () { + + /** Makes toolbox disapear */ + codex.nodes.toolbox.classList.remove('opened'); + + /** Rotate plus button */ + codex.nodes.plusButton.classList.remove('clicked'); + + /** toolbox state */ + codex.toolbar.toolbox.opened = false; + }; + + toolbox.leaf = function () { + + var currentTool = codex.toolbar.current, + tools = Object.keys(codex.tools), + barButtons = codex.nodes.toolbarButtons, + nextToolIndex, + toolToSelect; + + if (!currentTool) { + + /** Get first tool from object*/ + for (toolToSelect in barButtons) { + break; + } + } else { + + nextToolIndex = tools.indexOf(currentTool) + 1; + + if (nextToolIndex == tools.length) nextToolIndex = 0; + + toolToSelect = tools[nextToolIndex]; + } + + for (var button in barButtons) { + barButtons[button].classList.remove('selected'); + }barButtons[toolToSelect].classList.add('selected'); + + codex.toolbar.current = toolToSelect; + }; + + /** + * Transforming selected node type into selected toolbar element type + * @param {event} event + */ + toolbox.toolClicked = function () { + + /** + * UNREPLACEBLE_TOOLS this types of tools are forbidden to replace even they are empty + */ + var UNREPLACEBLE_TOOLS = ['image', 'link', 'list', 'instagram', 'twitter'], + tool = codex.tools[codex.toolbar.current], + workingNode = codex.content.currentNode, + currentInputIndex = codex.caret.inputIndex, + newBlockContent, + appendCallback, + blockData; + + /** Make block from plugin */ + newBlockContent = tool.make(); + + /** information about block */ + blockData = { + block: newBlockContent, + type: tool.type, + stretched: false + }; + + if (workingNode && UNREPLACEBLE_TOOLS.indexOf(workingNode.dataset.tool) === -1 && workingNode.textContent.trim() === '') { + /** Replace current block */ + codex.content.switchBlock(workingNode, newBlockContent, tool.type); + } else { + + /** Insert new Block from plugin */ + codex.content.insertBlock(blockData); + + /** increase input index */ + currentInputIndex++; + } + + /** Fire tool append callback */ + appendCallback = tool.appendCallback; + + if (appendCallback && typeof appendCallback == 'function') { + appendCallback.call(event); + } + + setTimeout(function () { + + /** Set caret to current block */ + codex.caret.setToBlock(currentInputIndex); + }, 10); + + /** + * Changing current Node + */ + codex.content.workingNodeChanged(); + + /** + * Move toolbar when node is changed + */ + codex.toolbar.move(); + }; + + return toolbox; + }({}); + + toolbox.init(); + + module.exports = toolbox; + +/***/ }, +/* 12 */ +/***/ function(module, exports, __webpack_require__) { + + 'use strict'; + + var codex = __webpack_require__(1); + + var tools = function (tools) { + + return tools; + }({}); + + codex.tools = tools; + module.exports = tools; + +/***/ }, +/* 13 */ +/***/ function(module, exports, __webpack_require__) { + + 'use strict'; + + var codex = __webpack_require__(1); + + var callbacks = function (callbacks) { + + callbacks.redactorSyncTimeout = null; + + callbacks.globalKeydown = function (event) { + switch (event.keyCode) { + case codex.core.keys.TAB: + codex.callback.tabKeyPressed(event);break; + case codex.core.keys.ENTER: + codex.callback.enterKeyPressed(event);break; + case codex.core.keys.ESC: + codex.callback.escapeKeyPressed(event);break; + default: + codex.callback.defaultKeyPressed(event);break; + } + }; + + callbacks.globalKeyup = function (event) { + switch (event.keyCode) { + case codex.core.keys.UP: + case codex.core.keys.LEFT: + case codex.core.keys.RIGHT: + case codex.core.keys.DOWN: + codex.callback.arrowKeyPressed(event);break; + } + }; + + callbacks.tabKeyPressed = function (event) { + + if (!codex.toolbar.opened) { + codex.toolbar.open(); + } + + if (codex.toolbar.opened && !codex.toolbar.toolbox.opened) { + codex.toolbar.toolbox.open(); + } else { + codex.toolbar.toolbox.leaf(); + } + + event.preventDefault(); + }; + + /** + * ENTER key handler + * Makes new paragraph block + */ + callbacks.enterKeyPressed = function (event) { + + /** Set current node */ + var firstLevelBlocksArea = codex.callback.clickedOnFirstLevelBlockArea(); + + if (firstLevelBlocksArea) { + event.preventDefault(); + + /** + * it means that we lose input index, saved index before is not correct + * therefore we need to set caret when we insert new block + */ + codex.caret.inputIndex = -1; + + codex.callback.enterPressedOnBlock(); + return; + } + + if (event.target.contentEditable == 'true') { + + /** Update input index */ + codex.caret.saveCurrentInputIndex(); + } + + if (!codex.content.currentNode) { + /** + * Enter key pressed in first-level block area + */ + codex.callback.enterPressedOnBlock(event); + return; + } + + var currentInputIndex = codex.caret.getCurrentInputIndex() || 0, + workingNode = codex.content.currentNode, + tool = workingNode.dataset.tool, + isEnterPressedOnToolbar = codex.toolbar.opened && codex.toolbar.current && event.target == codex.state.inputs[currentInputIndex]; + + /** The list of tools which needs the default browser behaviour */ + var enableLineBreaks = codex.tools[tool].enableLineBreaks; + + /** This type of block creates when enter is pressed */ + var NEW_BLOCK_TYPE = 'paragraph'; + + /** + * When toolbar is opened, select tool instead of making new paragraph + */ + if (isEnterPressedOnToolbar) { + + event.preventDefault(); + + codex.toolbar.toolbox.toolClicked(event); + + codex.toolbar.close(); + + return; + } + + /** + * Allow making new

in same block by SHIFT+ENTER and forbids to prevent default browser behaviour + */ + if (event.shiftKey && !enableLineBreaks) { + codex.callback.enterPressedOnBlock(codex.content.currentBlock, event); + event.preventDefault(); + } else if (event.shiftKey && !enableLineBreaks || !event.shiftKey && enableLineBreaks) { + /** XOR */ + return; + } + + var isLastTextNode = false, + currentSelection = window.getSelection(), + currentSelectedNode = currentSelection.anchorNode, + caretAtTheEndOfText = codex.caret.position.atTheEnd(), + isTextNodeHasParentBetweenContenteditable = false; + + /** + * Workaround situation when caret at the Text node that has some wrapper Elements + * Split block cant handle this. + * We need to save default behavior + */ + isTextNodeHasParentBetweenContenteditable = currentSelectedNode && currentSelectedNode.parentNode.contentEditable != "true"; + + /** + * Split blocks when input has several nodes and caret placed in textNode + */ + if (currentSelectedNode.nodeType == codex.core.nodeTypes.TEXT && !isTextNodeHasParentBetweenContenteditable && !caretAtTheEndOfText) { + + event.preventDefault(); + + codex.core.log('Splitting Text node...'); + + codex.content.splitBlock(currentInputIndex); + + /** Show plus button when next input after split is empty*/ + if (!codex.state.inputs[currentInputIndex + 1].textContent.trim()) { + codex.toolbar.showPlusButton(); + } + } else { + + if (currentSelectedNode && currentSelectedNode.parentNode) { + + isLastTextNode = !currentSelectedNode.parentNode.nextSibling; + } + + if (isLastTextNode && caretAtTheEndOfText) { + + event.preventDefault(); + + codex.core.log('ENTER clicked in last textNode. Create new BLOCK'); + + codex.content.insertBlock({ + type: NEW_BLOCK_TYPE, + block: codex.tools[NEW_BLOCK_TYPE].render() + }, true); + + codex.toolbar.move(); + codex.toolbar.open(); + + /** Show plus button with empty block */ + codex.toolbar.showPlusButton(); + } else { + + codex.core.log('Default ENTER behavior.'); + } + } + + /** get all inputs after new appending block */ + codex.ui.saveInputs(); + }; + + callbacks.escapeKeyPressed = function (event) { + + /** Close all toolbar */ + codex.toolbar.close(); + + /** Close toolbox */ + codex.toolbar.toolbox.close(); + + event.preventDefault(); + }; + + callbacks.arrowKeyPressed = function (event) { + + codex.content.workingNodeChanged(); + + /* Closing toolbar */ + codex.toolbar.close(); + codex.toolbar.move(); + }; + + callbacks.defaultKeyPressed = function (event) { + + codex.toolbar.close(); + + if (!codex.toolbar.inline.actionsOpened) { + codex.toolbar.inline.close(); + codex.content.clearMark(); + } + }; + + callbacks.redactorClicked = function (event) { + + codex.content.workingNodeChanged(event.target); + + codex.ui.saveInputs(); + + var selectedText = codex.toolbar.inline.getSelectionText(); + + /** + * If selection range took off, then we hide inline toolbar + */ + if (selectedText.length === 0) { + codex.toolbar.inline.close(); + } + + /** Update current input index in memory when caret focused into existed input */ + if (event.target.contentEditable == 'true') { + + codex.caret.saveCurrentInputIndex(); + } + + if (codex.content.currentNode === null) { + + /** + * If inputs in redactor does not exits, then we put input index 0 not -1 + */ + var indexOfLastInput = codex.state.inputs.length > 0 ? codex.state.inputs.length - 1 : 0; + + /** If we have any inputs */ + if (codex.state.inputs.length) { + + /** getting firstlevel parent of input */ + var firstLevelBlock = codex.content.getFirstLevelBlock(codex.state.inputs[indexOfLastInput]); + } + + /** If input is empty, then we set caret to the last input */ + if (codex.state.inputs.length && codex.state.inputs[indexOfLastInput].textContent === '' && firstLevelBlock.dataset.tool == 'paragraph') { + + codex.caret.setToBlock(indexOfLastInput); + } else { + + /** Create new input when caret clicked in redactors area */ + var NEW_BLOCK_TYPE = 'paragraph'; + + codex.content.insertBlock({ + type: NEW_BLOCK_TYPE, + block: codex.tools[NEW_BLOCK_TYPE].render() + }); + + /** If there is no inputs except inserted */ + if (codex.state.inputs.length === 1) { + + codex.caret.setToBlock(indexOfLastInput); + } else { + + /** Set caret to this appended input */ + codex.caret.setToNextBlock(indexOfLastInput); + } + } + + /** + * Move toolbar to the right position and open + */ + codex.toolbar.move(); + + codex.toolbar.open(); + } else { + + /** + * Move toolbar to the new position and open + */ + codex.toolbar.move(); + + codex.toolbar.open(); + + /** Close all panels */ + codex.toolbar.settings.close(); + codex.toolbar.toolbox.close(); + } + + var inputIsEmpty = !codex.content.currentNode.textContent.trim(); + + if (inputIsEmpty) { + + /** Show plus button */ + codex.toolbar.showPlusButton(); + } else { + + /** Hide plus buttons */ + codex.toolbar.hidePlusButton(); + } + + var currentNodeType = codex.content.currentNode.dataset.tool; + + /** Mark current block*/ + if (currentNodeType != 'paragraph' || !inputIsEmpty) { + + codex.content.markBlock(); + } + }; + + /** + * This method allows to define, is caret in contenteditable element or not. + * Otherwise, if we get TEXT node from range container, that will means we have input index. + * In this case we use default browsers behaviour (if plugin allows that) or overwritten action. + * Therefore, to be sure that we've clicked first-level block area, we should have currentNode, which always + * specifies to the first-level block. Other cases we just ignore. + */ + callbacks.clickedOnFirstLevelBlockArea = function () { + + var selection = window.getSelection(), + anchorNode = selection.anchorNode, + flag = false; + + if (selection.rangeCount == 0) { + + return true; + } else { + + if (!codex.core.isDomNode(anchorNode)) { + anchorNode = anchorNode.parentNode; + } + + /** Already founded, without loop */ + if (anchorNode.contentEditable == 'true') { + flag = true; + } + + while (anchorNode.contentEditable != 'true') { + anchorNode = anchorNode.parentNode; + + if (anchorNode.contentEditable == 'true') { + flag = true; + } + + if (anchorNode == document.body) { + break; + } + } + + /** If editable element founded, flag is "TRUE", Therefore we return "FALSE" */ + return flag ? false : true; + } + }; + + /** + * Toolbar button click handler + * @param this - cursor to the button + */ + callbacks.toolbarButtonClicked = function (event) { + + var button = this; + + codex.toolbar.current = button.dataset.type; + + codex.toolbar.toolbox.toolClicked(event); + codex.toolbar.close(); + }; + + callbacks.redactorInputEvent = function (event) { + + /** + * Clear previous sync-timeout + */ + if (this.redactorSyncTimeout) { + clearTimeout(this.redactorSyncTimeout); + } + + /** + * Start waiting to input finish and sync redactor + */ + this.redactorSyncTimeout = setTimeout(function () { + + codex.content.sync(); + }, 500); + }; + + /** Show or Hide toolbox when plus button is clicked */ + callbacks.plusButtonClicked = function () { + + if (!codex.nodes.toolbox.classList.contains('opened')) { + + codex.toolbar.toolbox.open(); + } else { + + codex.toolbar.toolbox.close(); + } + }; + + /** + * Block handlers for KeyDown events + */ + callbacks.blockKeydown = function (event, block) { + + switch (event.keyCode) { + + case codex.core.keys.DOWN: + case codex.core.keys.RIGHT: + codex.callback.blockRightOrDownArrowPressed(block); + break; + + case codex.core.keys.BACKSPACE: + codex.callback.backspacePressed(block); + break; + + case codex.core.keys.UP: + case codex.core.keys.LEFT: + codex.callback.blockLeftOrUpArrowPressed(block); + break; + + } + }; + + /** + * RIGHT or DOWN keydowns on block + */ + callbacks.blockRightOrDownArrowPressed = function (block) { + + var selection = window.getSelection(), + inputs = codex.state.inputs, + focusedNode = selection.anchorNode, + focusedNodeHolder; + + /** Check for caret existance */ + if (!focusedNode) { + return false; + } + + /** Looking for closest (parent) contentEditable element of focused node */ + while (focusedNode.contentEditable != 'true') { + + focusedNodeHolder = focusedNode.parentNode; + focusedNode = focusedNodeHolder; + } + + /** Input index in DOM level */ + var editableElementIndex = 0; + while (focusedNode != inputs[editableElementIndex]) { + editableElementIndex++; + } + + /** + * Founded contentEditable element doesn't have childs + * Or maybe New created block + */ + if (!focusedNode.textContent) { + codex.caret.setToNextBlock(editableElementIndex); + return; + } + + /** + * Do nothing when caret doesn not reaches the end of last child + */ + var caretInLastChild = false, + caretAtTheEndOfText = false; + + var lastChild, deepestTextnode; + + lastChild = focusedNode.childNodes[focusedNode.childNodes.length - 1]; + + if (codex.core.isDomNode(lastChild)) { + + deepestTextnode = codex.content.getDeepestTextNodeFromPosition(lastChild, lastChild.childNodes.length); + } else { + + deepestTextnode = lastChild; + } + + caretInLastChild = selection.anchorNode == deepestTextnode; + caretAtTheEndOfText = deepestTextnode.length == selection.anchorOffset; + + if (!caretInLastChild || !caretAtTheEndOfText) { + codex.core.log('arrow [down|right] : caret does not reached the end'); + return false; + } + + codex.caret.setToNextBlock(editableElementIndex); + }; + + /** + * LEFT or UP keydowns on block + */ + callbacks.blockLeftOrUpArrowPressed = function (block) { + + var selection = window.getSelection(), + inputs = codex.state.inputs, + focusedNode = selection.anchorNode, + focusedNodeHolder; + + /** Check for caret existance */ + if (!focusedNode) { + return false; + } + + /** + * LEFT or UP not at the beginning + */ + if (selection.anchorOffset !== 0) { + return false; + } + + /** Looking for parent contentEditable block */ + while (focusedNode.contentEditable != 'true') { + focusedNodeHolder = focusedNode.parentNode; + focusedNode = focusedNodeHolder; + } + + /** Input index in DOM level */ + var editableElementIndex = 0; + while (focusedNode != inputs[editableElementIndex]) { + editableElementIndex++; + } + + /** + * Do nothing if caret is not at the beginning of first child + */ + var caretInFirstChild = false, + caretAtTheBeginning = false; + + var firstChild, deepestTextnode; + + /** + * Founded contentEditable element doesn't have childs + * Or maybe New created block + */ + if (!focusedNode.textContent) { + codex.caret.setToPreviousBlock(editableElementIndex); + return; + } + + firstChild = focusedNode.childNodes[0]; + + if (codex.core.isDomNode(firstChild)) { + + deepestTextnode = codex.content.getDeepestTextNodeFromPosition(firstChild, 0); + } else { + + deepestTextnode = firstChild; + } + + caretInFirstChild = selection.anchorNode == deepestTextnode; + caretAtTheBeginning = selection.anchorOffset === 0; + + if (caretInFirstChild && caretAtTheBeginning) { + + codex.caret.setToPreviousBlock(editableElementIndex); + } + }; + + /** + * Callback for enter key pressing in first-level block area + */ + callbacks.enterPressedOnBlock = function (event) { + + var NEW_BLOCK_TYPE = 'paragraph'; + + codex.content.insertBlock({ + type: NEW_BLOCK_TYPE, + block: codex.tools[NEW_BLOCK_TYPE].render() + }, true); + + codex.toolbar.move(); + codex.toolbar.open(); + }; + + callbacks.backspacePressed = function (block) { + + var currentInputIndex = codex.caret.getCurrentInputIndex(), + range, + selectionLength, + firstLevelBlocksCount; + + if (block.textContent.trim()) { + + range = codex.content.getRange(); + selectionLength = range.endOffset - range.startOffset; + + if (codex.caret.position.atStart() && !selectionLength) { + + codex.content.mergeBlocks(currentInputIndex); + } else { + + return; + } + } + + if (!selectionLength) { + block.remove(); + } + + firstLevelBlocksCount = codex.nodes.redactor.childNodes.length; + + /** + * If all blocks are removed + */ + if (firstLevelBlocksCount === 0) { + + /** update currentNode variable */ + codex.content.currentNode = null; + + /** Inserting new empty initial block */ + codex.ui.addInitialBlock(); + + /** Updating inputs state after deleting last block */ + codex.ui.saveInputs(); + + /** Set to current appended block */ + setTimeout(function () { + + codex.caret.setToPreviousBlock(1); + }, 10); + } else { + + if (codex.caret.inputIndex !== 0) { + + /** Target block is not first */ + codex.caret.setToPreviousBlock(codex.caret.inputIndex); + } else { + + /** If we try to delete first block */ + codex.caret.setToNextBlock(codex.caret.inputIndex); + } + } + + codex.toolbar.move(); + + if (!codex.toolbar.opened) { + codex.toolbar.open(); + } + + /** Updating inputs state */ + codex.ui.saveInputs(); + + /** Prevent default browser behaviour */ + event.preventDefault(); + }; + + callbacks.blockPaste = function (event) { + + var currentInputIndex = codex.caret.getCurrentInputIndex(), + node = codex.state.inputs[currentInputIndex]; + + setTimeout(function () { + + codex.content.sanitize(node); + }, 10); + }; + + callbacks._blockPaste = function (event) { + + var currentInputIndex = codex.caret.getCurrentInputIndex(); + + /** + * create an observer instance + */ + var observer = new MutationObserver(codex.callback.handlePasteEvents); + + /** + * configuration of the observer: + */ + var config = { attributes: true, childList: true, characterData: false }; + + // pass in the target node, as well as the observer options + observer.observe(codex.state.inputs[currentInputIndex], config); + }; + + /** + * Sends all mutations to paste handler + */ + callbacks.handlePasteEvents = function (mutations) { + mutations.forEach(codex.content.paste); + }; + + /** + * Clicks on block settings button + */ + callbacks.showSettingsButtonClicked = function () { + + /** + * Get type of current block + * It uses to append settings from tool.settings property. + * ... + * Type is stored in data-type attribute on block + */ + var currentToolType = codex.content.currentNode.dataset.tool; + + codex.toolbar.settings.toggle(currentToolType); + + /** Close toolbox when settings button is active */ + codex.toolbar.toolbox.close(); + codex.toolbar.settings.hideRemoveActions(); + }; + + return callbacks; + }({}); + + codex.callback = callbacks; + module.exports = callbacks; + +/***/ }, +/* 14 */ +/***/ function(module, exports, __webpack_require__) { + + 'use strict'; + + var codex = __webpack_require__(1); + + var draw = function (draw) { + + /** + * Base editor wrapper + */ + draw.wrapper = function () { + + var wrapper = document.createElement('div'); + + wrapper.className += 'codex-editor'; + + return wrapper; + }; + + /** + * Content-editable holder + */ + draw.redactor = function () { + + var redactor = document.createElement('div'); + + redactor.className += 'ce-redactor'; + + return redactor; + }; + + draw.ceBlock = function () { + + var block = document.createElement('DIV'); + + block.className += 'ce_block'; + + return block; + }; + + /** + * Empty toolbar with toggler + */ + draw.toolbar = function () { + + var bar = document.createElement('div'); + + bar.className += 'ce-toolbar'; + + return bar; + }; + + draw.toolbarContent = function () { + + var wrapper = document.createElement('DIV'); + wrapper.classList.add('ce-toolbar__content'); + + return wrapper; + }; + + /** + * Inline toolbar + */ + draw.inlineToolbar = function () { + + var bar = document.createElement('DIV'); + + bar.className += 'ce-toolbar-inline'; + + return bar; + }; + + /** + * Wrapper for inline toobar buttons + */ + draw.inlineToolbarButtons = function () { + + var wrapper = document.createElement('DIV'); + + wrapper.className += 'ce-toolbar-inline__buttons'; + + return wrapper; + }; + + /** + * For some actions + */ + draw.inlineToolbarActions = function () { + + var wrapper = document.createElement('DIV'); + + wrapper.className += 'ce-toolbar-inline__actions'; + + return wrapper; + }; + + draw.inputForLink = function () { + + var input = document.createElement('INPUT'); + + input.type = 'input'; + input.className += 'inputForLink'; + input.placeholder = 'Type URL ...'; + input.setAttribute('form', 'defaultForm'); + + input.setAttribute('autofocus', 'autofocus'); + + return input; + }; + + /** + * Block with notifications + */ + draw.alertsHolder = function () { + + var block = document.createElement('div'); + + block.classList.add('ce_notifications-block'); + + return block; + }; + + /** + * @todo Desc + */ + draw.blockButtons = function () { + + var block = document.createElement('div'); + + block.className += 'ce-toolbar__actions'; + + return block; + }; + + /** + * Block settings panel + */ + draw.blockSettings = function () { + + var settings = document.createElement('div'); + + settings.className += 'ce-settings'; + + return settings; + }; + + draw.defaultSettings = function () { + + var div = document.createElement('div'); + + div.classList.add('ce-settings_default'); + + return div; + }, draw.pluginsSettings = function () { + + var div = document.createElement('div'); + + div.classList.add('ce-settings_plugin'); + + return div; + }; + + draw.plusButton = function () { + + var button = document.createElement('span'); + + button.className = 'ce-toolbar__plus'; + // button.innerHTML = ''; + + return button; + }; + + /** + * Settings button in toolbar + */ + draw.settingsButton = function () { + + var toggler = document.createElement('span'); + + toggler.className = 'ce-toolbar__settings-btn'; + + /** Toggler button*/ + toggler.innerHTML = ''; + + return toggler; + }; + + /** + * Redactor tools wrapper + */ + + draw.toolbox = function () { + + var wrapper = document.createElement('div'); + + wrapper.className = 'ce-toolbar__tools'; + + return wrapper; + }; + + /** + * @protected + * + * Draws tool buttons for toolbox + * + * @param {String} type + * @param {String} classname + * @returns {Element} + */ + draw.toolbarButton = function (type, classname) { + + var button = document.createElement("li"), + tool_icon = document.createElement("i"), + tool_title = document.createElement("span"); + + button.dataset.type = type; + button.setAttribute('title', type); + + tool_icon.classList.add(classname); + tool_title.classList.add('ce_toolbar_tools--title'); + + button.appendChild(tool_icon); + button.appendChild(tool_title); + + return button; + }; + + /** + * @protected + * + * Draws tools for inline toolbar + * + * @param {String} type + * @param {String} classname + */ + draw.toolbarButtonInline = function (type, classname) { + var button = document.createElement("BUTTON"), + tool_icon = document.createElement("I"); + + button.type = "button"; + button.dataset.type = type; + tool_icon.classList.add(classname); + + button.appendChild(tool_icon); + + return button; + }; + + /** + * Redactor block + */ + draw.block = function (tagName, content) { + + var node = document.createElement(tagName); + + node.innerHTML = content || ''; + + return node; + }; + + /** + * Creates Node with passed tagName and className + * @param {string} tagName + * @param {string} className + * @param {object} properties - allow to assign properties + */ + draw.node = function (tagName, className, properties) { + + var el = document.createElement(tagName); + + if (className) el.className = className; + + if (properties) { + + for (var name in properties) { + el[name] = properties[name]; + } + } + + return el; + }; + + draw.pluginsRender = function (type, content) { + + return { + type: type, + block: cEditor.tools[type].render({ + text: content + }) + }; + }; + + return draw; + }({}); + + codex.draw = draw; + + module.exports = draw; + +/***/ }, +/* 15 */ +/***/ function(module, exports, __webpack_require__) { + + 'use strict'; + + var codex = __webpack_require__(1); + + var caret = function (caret) { + + /** + * @var {int} InputIndex - editable element in DOM + */ + caret.inputIndex = null; + + /** + * @var {int} offset - caret position in a text node. + */ + caret.offset = null; + + /** + * @var {int} focusedNodeIndex - we get index of child node from first-level block + */ + caret.focusedNodeIndex = null; + + /** + * Creates Document Range and sets caret to the element. + * @protected + * @uses caret.save — if you need to save caret position + * @param {Element} el - Changed Node. + */ + caret.set = function (el, index, offset) { + + offset = offset || this.offset || 0; + index = index || this.focusedNodeIndex || 0; + + var childs = el.childNodes, + nodeToSet; + + if (childs.length === 0) { + + nodeToSet = el; + } else { + + nodeToSet = childs[index]; + } + + /** If Element is INPUT */ + if (el.tagName == 'INPUT') { + el.focus(); + return; + } + + if (codex.core.isDomNode(nodeToSet)) { + + nodeToSet = codex.content.getDeepestTextNodeFromPosition(nodeToSet, nodeToSet.childNodes.length); + } + + var range = document.createRange(), + selection = window.getSelection(); + + setTimeout(function () { + + range.setStart(nodeToSet, offset); + range.setEnd(nodeToSet, offset); + + selection.removeAllRanges(); + selection.addRange(range); + + codex.caret.saveCurrentInputIndex(); + }, 20); + }; + + /** + * @protected + * Updates index of input and saves it in caret object + */ + caret.saveCurrentInputIndex = function () { + + /** Index of Input that we paste sanitized content */ + var selection = window.getSelection(), + inputs = codex.state.inputs, + focusedNode = selection.anchorNode, + focusedNodeHolder; + + if (!focusedNode) { + return; + } + + /** Looking for parent contentEditable block */ + while (focusedNode.contentEditable != 'true') { + focusedNodeHolder = focusedNode.parentNode; + focusedNode = focusedNodeHolder; + } + + /** Input index in DOM level */ + var editableElementIndex = 0; + + while (focusedNode != inputs[editableElementIndex]) { + editableElementIndex++; + } + + this.inputIndex = editableElementIndex; + }; + + /** + * Returns current input index (caret object) + */ + caret.getCurrentInputIndex = function () { + return this.inputIndex; + }; + + /** + * @param {int} index - index of first-level block after that we set caret into next input + */ + caret.setToNextBlock = function (index) { + + var inputs = codex.state.inputs, + nextInput = inputs[index + 1]; + + if (!nextInput) { + codex.core.log('We are reached the end'); + return; + } + + /** + * When new Block created or deleted content of input + * We should add some text node to set caret + */ + if (!nextInput.childNodes.length) { + var emptyTextElement = document.createTextNode(''); + nextInput.appendChild(emptyTextElement); + } + + codex.caret.inputIndex = index + 1; + codex.caret.set(nextInput, 0, 0); + codex.content.workingNodeChanged(nextInput); + }; + + /** + * @param {int} index - index of target input. + * Sets caret to input with this index + */ + caret.setToBlock = function (index) { + + var inputs = codex.state.inputs, + targetInput = inputs[index]; + + console.assert(targetInput, 'caret.setToBlock: target input does not exists'); + + if (!targetInput) { + return; + } + + /** + * When new Block created or deleted content of input + * We should add some text node to set caret + */ + if (!targetInput.childNodes.length) { + var emptyTextElement = document.createTextNode(''); + targetInput.appendChild(emptyTextElement); + } + + codex.caret.inputIndex = index; + codex.caret.set(targetInput, 0, 0); + codex.content.workingNodeChanged(targetInput); + }; + + /** + * @param {int} index - index of input + */ + caret.setToPreviousBlock = function (index) { + + index = index || 0; + + var inputs = codex.state.inputs, + previousInput = inputs[index - 1], + lastChildNode, + lengthOfLastChildNode, + emptyTextElement; + + if (!previousInput) { + codex.core.log('We are reached first node'); + return; + } + + lastChildNode = codex.content.getDeepestTextNodeFromPosition(previousInput, previousInput.childNodes.length); + lengthOfLastChildNode = lastChildNode.length; + + /** + * When new Block created or deleted content of input + * We should add some text node to set caret + */ + if (!previousInput.childNodes.length) { + + emptyTextElement = document.createTextNode(''); + previousInput.appendChild(emptyTextElement); + } + codex.caret.inputIndex = index - 1; + codex.caret.set(previousInput, previousInput.childNodes.length - 1, lengthOfLastChildNode); + codex.content.workingNodeChanged(inputs[index - 1]); + }; + + caret.position = { + + atStart: function atStart() { + + var selection = window.getSelection(), + anchorOffset = selection.anchorOffset, + anchorNode = selection.anchorNode, + firstLevelBlock = codex.content.getFirstLevelBlock(anchorNode), + pluginsRender = firstLevelBlock.childNodes[0]; + + if (!codex.core.isDomNode(anchorNode)) { + anchorNode = anchorNode.parentNode; + } + + var isFirstNode = anchorNode === pluginsRender.childNodes[0], + isOffsetZero = anchorOffset === 0; + + return isFirstNode && isOffsetZero; + }, + + atTheEnd: function atTheEnd() { + + var selection = window.getSelection(), + anchorOffset = selection.anchorOffset, + anchorNode = selection.anchorNode; + + /** Caret is at the end of input */ + return !anchorNode || !anchorNode.length || anchorOffset === anchorNode.length; + } + }; + + return caret; + }({}); + + codex.caret = caret; + module.exports = caret; + +/***/ }, +/* 16 */ +/***/ function(module, exports, __webpack_require__) { + + 'use strict'; + + var codex = __webpack_require__(1); + + var notifications = function (notifications) { + + /** + * Error notificator. Shows block with message + * @protected + */ + notifications.errorThrown = function (errorMsg, event) { + + codex.notifications.send('This action is not available currently', event.type, false); + }, + + /** + * Appends notification with different types + * @param message {string} - Error or alert message + * @param type {string} - Type of message notification. Ex: Error, Warning, Danger ... + * @param append {boolean} - can be True or False when notification should be inserted after + */ + notifications.send = function (message, type, append) { + + var notification = codex.draw.block('div'); + + notification.textContent = message; + notification.classList.add('ce_notification-item', 'ce_notification-' + type, 'flipInX'); + + if (!append) { + codex.nodes.notifications.innerHTML = ''; + } + + codex.nodes.notifications.appendChild(notification); + + setTimeout(function () { + notification.remove(); + }, 3000); + }; + + return notifications; + }({}); + + codex.notifications = notifications; + module.exports = notifications; + +/***/ }, +/* 17 */ +/***/ function(module, exports, __webpack_require__) { + + 'use strict'; + + var codex = __webpack_require__(1); + + var parser = function (parser) { + + parser.init = function () {}; + + /** + * Splits content by `\n` and returns blocks + */ + parser.getSeparatedTexttSeparatedTextFromContent = function (content) { + return content.split('\n'); + }; + + /** inserting text */ + parser.insertPastedContent = function (content) { + + var blocks = this.getSeparatedTextFromContent(content), + i, + inputIndex = cEditor.caret.getCurrentInputIndex(), + textNode, + parsedTextContent; + + for (i = 0; i < blocks.length; i++) { + + blocks[i].trim(); + + if (blocks[i]) { + var data = cEditor.draw.pluginsRender('paragraph', blocks[i]); + cEditor.content.insertBlock(data); + } + } + }; + + /** + * Asynchronously parses textarea input string to HTML editor blocks + */ + parser.parseTextareaContent = function () { + + var initialContent = cEditor.nodes.textarea.value; + + if (initialContent.trim().length === 0) return true; + + cEditor.parser + + /** Get child nodes async-aware */ + .getNodesFromString(initialContent) + + /** Then append nodes to the redactor */ + .then(cEditor.parser.appendNodesToRedactor) + + /** Write log if something goes wrong */ + .catch(function (error) { + cEditor.core.log('Error while parsing content: %o', 'warn', error); + }); + }; + + /** + * Parses string to nodeList + * @param string inputString + * @return Primise -> nodeList + */ + parser.getNodesFromString = function (inputString) { + + return Promise.resolve().then(function () { + + var contentHolder = document.createElement('div'); + + contentHolder.innerHTML = inputString; + + /** + * Returning childNodes will include: + * - Elements (html-tags), + * - Texts (empty-spaces or non-wrapped strings ) + * - Comments and other + */ + return contentHolder.childNodes; + }); + }; + + /** + * Appends nodes to the redactor + * @param nodeList nodes - list for nodes to append + */ + parser.appendNodesToRedactor = function (nodes) { + + /** + * Sequence of one-by-one nodes appending + * Uses to save blocks order after async-handler + */ + var nodeSequence = Promise.resolve(); + + for (var index = 0; index < nodes.length; index++) { + + /** Add node to sequence at specified index */ + cEditor.parser.appendNodeAtIndex(nodeSequence, nodes, index); + } + }; + + /** + * Append node at specified index + */ + parser.appendNodeAtIndex = function (nodeSequence, nodes, index) { + + /** We need to append node to sequence */ + nodeSequence + + /** first, get node async-aware */ + .then(function () { + + return cEditor.parser.getNodeAsync(nodes, index); + }) + + /** + * second, compose editor-block from node + * and append it to redactor + */ + .then(function (node) { + + var block = cEditor.parser.createBlockByDomNode(node); + + if (cEditor.core.isDomNode(block)) { + + block.contentEditable = "true"; + + /** Mark node as redactor block*/ + block.classList.add('ce-block'); + + /** Append block to the redactor */ + cEditor.nodes.redactor.appendChild(block); + + /** Save block to the cEditor.state array */ + cEditor.state.blocks.push(block); + + return block; + } + return null; + }).then(cEditor.ui.addBlockHandlers) + + /** Log if something wrong with node */ + .catch(function (error) { + cEditor.core.log('Node skipped while parsing because %o', 'warn', error); + }); + }; + + /** + * Asynchronously returns node from nodeList by index + * @return Promise to node + */ + parser.getNodeAsync = function (nodeList, index) { + + return Promise.resolve().then(function () { + + return nodeList.item(index); + }); + }; + + /** + * Creates editor block by DOM node + * + * First-level blocks (see cEditor.settings.blockTags) saves as-is, + * other wrapps with

-tag + * + * @param DOMnode node + * @return First-level node (paragraph) + */ + parser.createBlockByDomNode = function (node) { + + /** First level nodes already appears as blocks */ + if (cEditor.parser.isFirstLevelBlock(node)) { + + /** Save plugin type in data-type */ + node = this.storeBlockType(node); + + return node; + } + + /** Other nodes wraps into parent block (paragraph-tag) */ + var parentBlock, + nodeContent = node.textContent.trim(), + isPlainTextNode = node.nodeType != cEditor.core.nodeTypes.TAG; + + /** Skip empty textNodes with space-symbols */ + if (isPlainTextNode && !nodeContent.length) return null; + + /** Make

tag */ + parentBlock = cEditor.draw.block('P'); + + if (isPlainTextNode) { + parentBlock.textContent = nodeContent.replace(/(\s){2,}/, '$1'); // remove double spaces + } else { + parentBlock.appendChild(node); + } + + /** Save plugin type in data-type */ + parentBlock = this.storeBlockType(parentBlock); + + return parentBlock; + }; + + /** + * It's a crutch + * - - - - - - - + * We need block type stored as data-attr + * Now supports only simple blocks : P, HEADER, QUOTE, CODE + * Remove it after updating parser module for the block-oriented structure: + * - each block must have stored type + * @param {Element} node + */ + parser.storeBlockType = function (node) { + + switch (node.tagName) { + case 'P': + node.dataset.tool = 'paragraph';break; + case 'H1': + case 'H2': + case 'H3': + case 'H4': + case 'H5': + case 'H6': + node.dataset.tool = 'header';break; + case 'BLOCKQUOTE': + node.dataset.tool = 'quote';break; + case 'CODE': + node.dataset.tool = 'code';break; + } + + return node; + }; + + /** + * Check DOM node for display style: separated block or child-view + */ + parser.isFirstLevelBlock = function (node) { + + return node.nodeType == cEditor.core.nodeTypes.TAG && node.classList.contains(cEditor.ui.className.BLOCK_CLASSNAME); + }; + + return parser; + }({}); + + parser.init(); + + codex.parser = parser; + module.exports = parser; + +/***/ } +/******/ ]); +//# sourceMappingURL=codex-editor.js.map \ No newline at end of file diff --git a/codex-editor.js.map b/codex-editor.js.map new file mode 100644 index 00000000..6f844ba6 --- /dev/null +++ b/codex-editor.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["webpack:///webpack/bootstrap 2637f25dac40d95fed4c","webpack:///./index.js","webpack:///./editor.js","webpack:///./modules/core.js","webpack:///./modules/ui.js","webpack:///./modules/transport.js","webpack:///./modules/renderer.js","webpack:///./modules/saver.js","webpack:///./modules/content.js","webpack:///./modules/toolbar/toolbar.js","webpack:///./modules/toolbar/settings.js","webpack:///./modules/toolbar/inline.js","webpack:///./modules/toolbar/toolbox.js","webpack:///./modules/tools.js","webpack:///./modules/callbacks.js","webpack:///./modules/draw.js","webpack:///./modules/caret.js","webpack:///./modules/notifications.js","webpack:///./modules/parser.js"],"names":["editor","require","module","exports","codex","init","settings","tools","textareaId","uploadImagesUrl","initialBlockPlugin","nodes","textarea","wrapper","toolbar","inlineToolbar","buttons","actions","toolbox","notifications","plusButton","showSettingsButton","showTrashButton","blockSettings","pluginSettings","defaultSettings","toolbarButtons","redactor","state","jsonOutput","blocks","inputs","start","userSettings","core","prepare","then","ui","make","addTools","bindEvents","preparePlugins","transport","renderer","makeBlocksFromData","saveInputs","catch","error","log","Promise","resolve","reject","data","document","getElementById","undefined","Error","msg","type","arg","window","console","e","insertAfter","target","element","parentNode","insertBefore","nextSibling","nodeTypes","TAG","TEXT","COMMENT","keys","BACKSPACE","TAB","ENTER","SHIFT","CTRL","ALT","ESC","SPACE","LEFT","UP","DOWN","RIGHT","DELETE","META","isDomNode","el","nodeType","ajax","url","XMLHTTP","XMLHttpRequest","ActiveXObject","success_function","params","obj","async","success","test","encodeURIComponent","withCredentials","beforeSend","call","open","setRequestHeader","onreadystatechange","readyState","status","responseText","send","importScript","scriptPath","instanceName","script","createElement","src","defer","id","head","appendChild","className","BLOCK_CLASSNAME","BLOCK_CONTENT","BLOCK_STRETCHED","BLOCK_HIGHLIGHTED","BLOCK_IN_FEED_MODE","SETTINGS_ITEM","toolbarContent","ceBlock","blockButtons","draw","alertsHolder","body","settingsButton","makeRemoveBlockButton","pluginsSettings","makeInlineToolbar","addDefaultSettings","container","inlineToolbarButtons","inlineToolbarActions","tool","tool_button","name","displayInToolbox","iconClassname","toolbarButton","addInlineToolbarTools","bold","icon","command","italic","underline","link","toolButton","toolbarButtonInline","setInlineToolbarButtonBehaviour","addEventListener","errorMsg","lineNumber","errorThrown","event","callback","globalKeydown","globalKeyup","redactorClicked","plusButtonClicked","showSettingsButtonClicked","redactorInputEvent","button","toolbarButtonClicked","addBlockHandlers","block","blockKeydown","blockPaste","inline","show","elements","querySelectorAll","addInitialBlock","initialBlockType","initialBlock","render","setAttribute","content","insertBlock","workingNodeChanged","toolClicked","input","arguments","fileSelected","clearInput","files","filesLength","length","formdData","FormData","file","i","append","selectAndUpload","args","click","xhr","onload","items","appendBlocks","nodeSequence","index","appendNodeAtIndex","getNodeAsync","createBlockFromData","blockData","blocksList","pluginName","stretched","isStretched","saver","saveBlocks","html","innerHTML","childNodes","makeQueue","queue","getBlockData","makeFormDataFromBlocks","dataset","save","blockContent","pluginsContent","savedData","output","cover","classList","contains","push","currentNode","sync","getNodeFocused","selection","getSelection","focused","anchorNode","focusNode","parentElement","parser","isFirstLevelBlock","parent","markBlock","add","clearMark","remove","getFirstLevelBlock","node","targetNode","replaceBlock","function_name","targetBlock","newBlock","replaceChild","needPlaceCaret","workingBlock","newBlockContent","blockType","composeNewBlock","currentInputIndex","caret","getCurrentInputIndex","editableElement","querySelector","emptyText","createTextNode","set","move","showPlusButton","setTimeout","setToNextBlock","switchBlock","blockToReplace","newBlockComposed","getDeepestTextNodeFromPosition","position","blockChilds","text","textContent","trim","removeChild","looking_from_start","getRange","getRangeAt","splitBlock","inputIndex","anchorNodeText","caretOffset","anchorOffset","textBeforeCaret","textNodeBeforeCaret","textAfterCaret","textNodeAfterCaret","currentBlock","substring","previousChilds","nextChilds","reachedCurrent","child","previousChildsLength","nextChildsLength","newNode","NEW_BLOCK_TYPE","mergeBlocks","targetInputIndex","targetInput","currentInputContent","paste","mutation","workingNode","allowedToPaste","sanitize","addedNodes","pasteTextContent","textNode","dfs","clearStyles","href","blockTags","allowedTags","needReplace","includes","tagName","isDisplayedAsBlock","replace","getAttribute","attributes","removeAttribute","sanitized","defaultToolbarHeight","defaultOffset","opened","current","close","toggle","hidePlusButton","toolbarHeight","clientHeight","newYCoordinate","offsetTop","style","transform","Math","floor","hideRemoveActions","setting","toolType","feedModeToggler","makeFeedModeToggler","isFeedModeActivated","updateFeedMode","removeBlockWrapper","settingButton","actionWrapper","confirmAction","cancelAction","removeButtonClicked","confirmRemovingRequest","cancelRemovingRequest","action","showRemoveActions","firstLevelBlocksCount","buttonsOpened","actionsOpened","wrappersOffset","storedSelection","selectedText","getSelectionText","showButtons","getWrappersOffset","coords","getSelectionCoords","newCoordinateX","newCoordinateY","offsetHeight","x","left","y","scrollY","top","closeButtons","closeAction","createLinkAction","defaultToolAction","forEach","hightlight","offset","getOffset","_x","_y","isNaN","offsetLeft","clientLeft","clientTop","offsetParent","sel","range","createRange","collapse","boundingLeft","boundingTop","rangeCount","cloneRange","getClientRects","rect","toString","showActions","isActive","isLinkActive","editable","saveSelection","restoreSelection","inputForLink","focus","preventDefault","keyCode","setAnchor","value","stopImmediatePropagation","clearRange","dataType","execCommand","containerEl","preSelectionRange","selectNodeContents","setEnd","startContainer","startOffset","end","savedSel","charIndex","setStart","nodeStack","foundStart","stop","nextCharIndex","pop","removeAllRanges","addRange","queryCommandState","setButtonHighlighted","removeButtonsHighLight","tag","leaf","currentTool","Object","barButtons","nextToolIndex","toolToSelect","indexOf","UNREPLACEBLE_TOOLS","appendCallback","setToBlock","callbacks","redactorSyncTimeout","tabKeyPressed","enterKeyPressed","escapeKeyPressed","defaultKeyPressed","arrowKeyPressed","firstLevelBlocksArea","clickedOnFirstLevelBlockArea","enterPressedOnBlock","contentEditable","saveCurrentInputIndex","isEnterPressedOnToolbar","enableLineBreaks","shiftKey","isLastTextNode","currentSelection","currentSelectedNode","caretAtTheEndOfText","atTheEnd","isTextNodeHasParentBetweenContenteditable","indexOfLastInput","firstLevelBlock","inputIsEmpty","currentNodeType","flag","clearTimeout","blockRightOrDownArrowPressed","backspacePressed","blockLeftOrUpArrowPressed","focusedNode","focusedNodeHolder","editableElementIndex","caretInLastChild","lastChild","deepestTextnode","caretInFirstChild","caretAtTheBeginning","firstChild","setToPreviousBlock","selectionLength","endOffset","atStart","_blockPaste","observer","MutationObserver","handlePasteEvents","config","childList","characterData","observe","mutations","currentToolType","bar","placeholder","div","toggler","classname","tool_icon","tool_title","properties","pluginsRender","cEditor","focusedNodeIndex","childs","nodeToSet","nextInput","emptyTextElement","assert","previousInput","lastChildNode","lengthOfLastChildNode","isFirstNode","isOffsetZero","message","notification","getSeparatedTexttSeparatedTextFromContent","split","insertPastedContent","getSeparatedTextFromContent","parsedTextContent","parseTextareaContent","initialContent","getNodesFromString","appendNodesToRedactor","inputString","contentHolder","createBlockByDomNode","nodeList","item","storeBlockType","parentBlock","nodeContent","isPlainTextNode"],"mappings":";;AAAA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA,uBAAe;AACf;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;;AAGA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;AACA;;;;;;;ACtCA;;;;AAIA;;AAEA,KAAIA,SAAS,mBAAAC,CAAQ,CAAR,CAAb;AACAC,QAAOC,OAAP,GAAiBH,MAAjB,C;;;;;;;;ACPA,KAAII,QAAS,UAASA,KAAT,EAAe;;AAExB,SAAIC,OAAO,SAAPA,IAAO,GAAW;;AAElBJ,SAAA,mBAAAA,CAAQ,CAAR;A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sBAAK3B,OAAL,CAAarF,IAAb,GAAoB,QAApB,CAA8B;AAClD,kBAAK,YAAL;AAAoBgH,sBAAK3B,OAAL,CAAarF,IAAb,GAAoB,OAApB,CAA6B;AACjD,kBAAK,MAAL;AAAoBgH,sBAAK3B,OAAL,CAAarF,IAAb,GAAoB,MAApB,CAA4B;AATpD;;AAYA,gBAAOgH,IAAP;AAEH,MAhBD;;AAkBA;;;AAGAR,YAAOC,iBAAP,GAA2B,UAAUO,IAAV,EAAgB;;AAEvC,gBAAOA,KAAKtK,QAAL,IAAiBkb,QAAQ1e,IAAR,CAAamC,SAAb,CAAuBC,GAAxC,IACH0L,KAAKpB,SAAL,CAAeC,QAAf,CAAwB+R,QAAQve,EAAR,CAAWsF,SAAX,CAAqBC,eAA7C,CADJ;AAGH,MALD;;AAOA,YAAO4H,MAAP;AAEH,EA7PY,CA6PV,EA7PU,CAAb;;AA+PAA,QAAOnP,IAAP;;AAEAD,OAAMoP,MAAN,GAAeA,MAAf;AACAtP,QAAOC,OAAP,GAAiBqP,MAAjB,C","file":"./codex-editor.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId])\n \t\t\treturn installedModules[moduleId].exports;\n\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\texports: {},\n \t\t\tid: moduleId,\n \t\t\tloaded: false\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.loaded = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(0);\n\n\n\n/** WEBPACK FOOTER **\n ** webpack/bootstrap 2637f25dac40d95fed4c\n **/","/**\n *\n */\n\n'use strict';\n\nvar editor = require('./editor');\nmodule.exports = editor;\n\n\n\n/** WEBPACK FOOTER **\n ** ./index.js\n **/","var codex = (function(codex){\n\n var init = function() {\n\n require('./modules/core');\n require('./modules/ui');\n require('./modules/transport');\n require('./modules/renderer');\n require('./modules/saver');\n require('./modules/content');\n require('./modules/toolbar/toolbar');\n require('./modules/tools');\n require('./modules/callbacks');\n require('./modules/draw');\n require('./modules/caret');\n require('./modules/notifications');\n require('./modules/parser');\n };\n\n /**\n * @public\n *\n * holds initial settings\n */\n codex.settings = {\n tools : ['paragraph', 'header', 'picture', 'list', 'quote', 'code', 'twitter', 'instagram', 'smile'],\n textareaId: 'codex-editor',\n uploadImagesUrl: '/editor/transport/',\n\n // Type of block showing on empty editor\n initialBlockPlugin: \"paragraph\"\n };\n\n /**\n * public\n *\n * Static nodes\n */\n codex.nodes = {\n textarea : null,\n wrapper : null,\n toolbar : null,\n inlineToolbar : {\n wrapper : null,\n buttons : null,\n actions : null\n },\n toolbox : null,\n notifications : null,\n plusButton : null,\n showSettingsButton: null,\n showTrashButton : null,\n blockSettings : null,\n pluginSettings : null,\n defaultSettings : null,\n toolbarButtons : {}, // { type : DomEl, ... }\n redactor : null\n };\n\n /**\n * @public\n *\n * Output state\n */\n codex.state = {\n jsonOutput: [],\n blocks : [],\n inputs : []\n };\n\n /**\n * Initialization\n * @uses Promise cEditor.core.prepare\n * @param {} userSettings are :\n * - tools [],\n * - textareaId String\n * ...\n *\n * Load user defined tools\n * Tools must contain this important objects :\n * @param {String} type - this is a type of plugin. It can be used as plugin name\n * @param {String} iconClassname - this a icon in toolbar\n * @param {Object} make - what should plugin do, when it is clicked\n * @param {Object} appendCallback - callback after clicking\n * @param {Element} settings - what settings does it have\n * @param {Object} render - plugin get JSON, and should return HTML\n * @param {Object} save - plugin gets HTML content, returns JSON\n * @param {Boolean} displayInToolbox - will be displayed in toolbox. Default value is TRUE\n * @param {Boolean} enableLineBreaks - inserts new block or break lines. Default value is FALSE\n *\n * @example\n * - type : 'header',\n * - iconClassname : 'ce-icon-header',\n * - make : headerTool.make,\n * - appendCallback : headerTool.appendCallback,\n * - settings : headerTool.makeSettings(),\n * - render : headerTool.render,\n * - save : headerTool.save,\n * - displayInToolbox : true,\n * - enableLineBreaks : false\n */\n codex.start = function (userSettings) {\n\n init();\n\n this.core.prepare(userSettings)\n\n // If all ok, make UI, bind events and parse initial-content\n .then(this.ui.make)\n .then(this.ui.addTools)\n .then(this.ui.bindEvents)\n .then(this.ui.preparePlugins)\n .then(this.transport.prepare)\n .then(this.renderer.makeBlocksFromData)\n .then(this.ui.saveInputs)\n .catch(function (error) {\n codex.core.log('Initialization failed with error: %o', 'warn', error);\n });\n\n };\n\n return codex;\n\n})({});\n\nmodule.exports = codex;\n\n\n\n\n\n\n/** WEBPACK FOOTER **\n ** ./editor.js\n **/","var codex = require('./../editor');\n\nvar core = (function(core) {\n\n /**\n * @public\n *\n * Editor preparing method\n * @return Promise\n */\n core.prepare = function (userSettings) {\n\n return new Promise(function(resolve, reject) {\n\n if ( userSettings ){\n\n codex.settings.tools = userSettings.tools || codex.settings.tools;\n\n }\n\n if (userSettings.data) {\n codex.state.blocks = userSettings.data;\n }\n\n codex.nodes.textarea = document.getElementById(userSettings.textareaId || codex.settings.textareaId);\n\n if (typeof codex.nodes.textarea === undefined || codex.nodes.textarea === null) {\n reject(Error(\"Textarea wasn't found by ID: #\" + userSettings.textareaId));\n } else {\n resolve();\n }\n\n });\n\n };\n\n /**\n * Logging method\n * @param type = ['log', 'info', 'warn']\n */\n core.log = function (msg, type, arg) {\n\n type = type || 'log';\n\n if (!arg) {\n arg = msg || 'undefined';\n msg = '[codex-editor]: %o';\n } else {\n msg = '[codex-editor]: ' + msg;\n }\n\n try{\n if ( 'console' in window && console[ type ] ){\n if ( arg ) console[ type ]( msg , arg );\n else console[ type ]( msg );\n }\n\n }catch(e){}\n\n };\n\n /**\n * @protected\n *\n * Helper for insert one element after another\n */\n core.insertAfter = function (target, element) {\n target.parentNode.insertBefore(element, target.nextSibling);\n };\n\n /**\n * @const\n *\n * Readable DOM-node types map\n */\n core.nodeTypes = {\n TAG : 1,\n TEXT : 3,\n COMMENT : 8\n };\n\n /**\n * @const\n * Readable keys map\n */\n core.keys = { BACKSPACE: 8, TAB: 9, ENTER: 13, SHIFT: 16, CTRL: 17, ALT: 18, ESC: 27, SPACE: 32, LEFT: 37, UP: 38, DOWN: 40, RIGHT: 39, DELETE: 46, META: 91 };\n\n /**\n * @protected\n *\n * Check object for DOM node\n */\n core.isDomNode = function (el) {\n return el && typeof el === 'object' && el.nodeType && el.nodeType == this.nodeTypes.TAG;\n };\n\n /**\n * Native Ajax\n */\n core.ajax = function (data) {\n\n if (!data || !data.url){\n return;\n }\n\n var XMLHTTP = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject(\"Microsoft.XMLHTTP\"),\n success_function = function(){},\n params = '',\n obj;\n\n data.async = true;\n data.type = data.type || 'GET';\n data.data = data.data || '';\n data['content-type'] = data['content-type'] || 'application/json; charset=utf-8';\n success_function = data.success || success_function ;\n\n if (data.type == 'GET' && data.data) {\n\n data.url = /\\?/.test(data.url) ? data.url + '&' + data.data : data.url + '?' + data.data;\n\n } else {\n\n for(obj in data.data) {\n params += (obj + '=' + encodeURIComponent(data.data[obj]) + '&');\n }\n }\n\n if (data.withCredentials) {\n XMLHTTP.withCredentials = true;\n }\n\n if (data.beforeSend && typeof data.beforeSend == 'function') {\n data.beforeSend.call();\n }\n\n XMLHTTP.open( data.type, data.url, data.async );\n XMLHTTP.setRequestHeader(\"X-Requested-With\", \"XMLHttpRequest\");\n XMLHTTP.setRequestHeader(\"Content-type\", \"application/x-www-form-urlencoded\");\n\n XMLHTTP.onreadystatechange = function() {\n if (XMLHTTP.readyState == 4 && XMLHTTP.status == 200) {\n success_function(XMLHTTP.responseText);\n }\n };\n\n XMLHTTP.send(params);\n };\n\n /** Appends script to head of document */\n core.importScript = function(scriptPath, instanceName) {\n\n /** Script is already loaded */\n if ( !instanceName || (instanceName && document.getElementById('ce-script-' + instanceName)) ) {\n codex.core.log(\"Instance name of script is missed or script is already loaded\", \"warn\");\n return;\n }\n\n\n var script = document.createElement('SCRIPT');\n script.type = \"text/javascript\";\n script.src = scriptPath;\n script.async = true;\n script.defer = true;\n\n if (instanceName) {\n script.id = \"ce-script-\" + instanceName;\n }\n\n document.head.appendChild(script);\n return script;\n };\n\n return core;\n\n})({});\n\ncodex.core = core;\n\nmodule.exports = core;\n\n\n\n\n\n/** WEBPACK FOOTER **\n ** ./modules/core.js\n **/","var codex = require('../editor');\n\nvar ui = (function(ui){\n\n /**\n * Basic editor classnames\n */\n ui.className = {\n\n /**\n * @const {string} BLOCK_CLASSNAME - redactor blocks name\n */\n BLOCK_CLASSNAME : 'ce-block',\n\n /**\n * @const {String} wrapper for plugins content\n */\n BLOCK_CONTENT : 'ce-block__content',\n\n /**\n * @const {String} BLOCK_STRETCHED - makes block stretched\n */\n BLOCK_STRETCHED : 'ce-block--stretched',\n\n /**\n * @const {String} BLOCK_HIGHLIGHTED - adds background\n */\n BLOCK_HIGHLIGHTED : 'ce-block--focused',\n\n /**\n * @const {String} - highlights covered blocks\n */\n BLOCK_IN_FEED_MODE : 'ce-block--feed-mode',\n\n /**\n * @const {String} - for all default settings\n */\n SETTINGS_ITEM : 'ce-settings__item'\n\n };\n\n /**\n * @protected\n *\n * Making main interface\n */\n ui.make = function () {\n\n var wrapper,\n toolbar,\n toolbarContent,\n inlineToolbar,\n redactor,\n ceBlock,\n notifications,\n blockButtons,\n blockSettings,\n showSettingsButton,\n showTrashButton,\n toolbox,\n plusButton;\n\n /** Make editor wrapper */\n wrapper = codex.draw.wrapper();\n\n /** Append editor wrapper after initial textarea */\n codex.core.insertAfter(codex.nodes.textarea, wrapper);\n\n /** Append block with notifications to the document */\n notifications = codex.draw.alertsHolder();\n codex.nodes.notifications = document.body.appendChild(notifications);\n\n /** Make toolbar and content-editable redactor */\n toolbar = codex.draw.toolbar();\n toolbarContent = codex.draw.toolbarContent();\n inlineToolbar = codex.draw.inlineToolbar();\n plusButton = codex.draw.plusButton();\n showSettingsButton = codex.draw.settingsButton();\n showTrashButton = codex.toolbar.settings.makeRemoveBlockButton();\n blockSettings = codex.draw.blockSettings();\n blockButtons = codex.draw.blockButtons();\n toolbox = codex.draw.toolbox();\n redactor = codex.draw.redactor();\n\n /** settings */\n var defaultSettings = codex.draw.defaultSettings(),\n pluginSettings = codex.draw.pluginsSettings();\n\n /** Add default and plugins settings */\n blockSettings.appendChild(pluginSettings);\n blockSettings.appendChild(defaultSettings);\n\n /** Make blocks buttons\n * This block contains settings button and remove block button\n */\n blockButtons.appendChild(showSettingsButton);\n blockButtons.appendChild(showTrashButton);\n blockButtons.appendChild(blockSettings);\n\n /** Append plus button */\n toolbarContent.appendChild(plusButton);\n\n /** Appending toolbar tools */\n toolbarContent.appendChild(toolbox);\n\n /** Appending first-level block buttons */\n toolbar.appendChild(blockButtons);\n\n /** Append toolbarContent to toolbar */\n toolbar.appendChild(toolbarContent);\n\n wrapper.appendChild(toolbar);\n\n wrapper.appendChild(redactor);\n\n /** Save created ui-elements to static nodes state */\n codex.nodes.wrapper = wrapper;\n codex.nodes.toolbar = toolbar;\n codex.nodes.plusButton = plusButton;\n codex.nodes.toolbox = toolbox;\n codex.nodes.blockSettings = blockSettings;\n codex.nodes.pluginSettings = pluginSettings;\n codex.nodes.defaultSettings = defaultSettings;\n codex.nodes.showSettingsButton = showSettingsButton;\n codex.nodes.showTrashButton = showTrashButton;\n\n codex.nodes.redactor = redactor;\n\n codex.ui.makeInlineToolbar(inlineToolbar);\n\n /** fill in default settings */\n codex.toolbar.settings.addDefaultSettings();\n };\n\n ui.makeInlineToolbar = function(container) {\n\n /** Append to redactor new inline block */\n codex.nodes.inlineToolbar.wrapper = container;\n\n /** Draw toolbar buttons */\n codex.nodes.inlineToolbar.buttons = codex.draw.inlineToolbarButtons();\n\n /** Buttons action or settings */\n codex.nodes.inlineToolbar.actions = codex.draw.inlineToolbarActions();\n\n /** Append to inline toolbar buttons as part of it */\n codex.nodes.inlineToolbar.wrapper.appendChild(codex.nodes.inlineToolbar.buttons);\n codex.nodes.inlineToolbar.wrapper.appendChild(codex.nodes.inlineToolbar.actions);\n\n codex.nodes.wrapper.appendChild(codex.nodes.inlineToolbar.wrapper);\n };\n\n /**\n * @private\n * Append tools passed in codex.tools\n */\n ui.addTools = function () {\n\n var tool,\n tool_button;\n\n for(var name in codex.settings.tools) {\n tool = codex.settings.tools[name];\n codex.tools[name] = tool;;\n }\n\n /** Make toolbar buttons */\n for (var name in codex.tools){\n\n tool = codex.tools[name];\n\n if (tool.displayInToolbox == false) {\n continue;\n }\n\n if (!tool.iconClassname) {\n codex.core.log('Toolbar icon classname missed. Tool %o skipped', 'warn', name);\n continue;\n }\n\n if (typeof tool.make != 'function') {\n codex.core.log('make method missed. Tool %o skipped', 'warn', name);\n continue;\n }\n\n /**\n * if tools is for toolbox\n */\n tool_button = codex.draw.toolbarButton(name, tool.iconClassname);\n\n codex.nodes.toolbox.appendChild(tool_button);\n\n /** Save tools to static nodes */\n codex.nodes.toolbarButtons[name] = tool_button;\n }\n\n\n /**\n * Add inline toolbar tools\n */\n codex.ui.addInlineToolbarTools();\n\n\n };\n\n ui.addInlineToolbarTools = function() {\n\n var tools = {\n\n bold: {\n icon : 'ce-icon-bold',\n command : 'bold'\n },\n\n italic: {\n icon : 'ce-icon-italic',\n command : 'italic'\n },\n\n underline: {\n icon : 'ce-icon-underline',\n command : 'underline'\n },\n\n link: {\n icon : 'ce-icon-link',\n command : 'createLink',\n }\n };\n\n var toolButton,\n tool;\n\n for(var name in tools) {\n\n tool = tools[name];\n\n toolButton = codex.draw.toolbarButtonInline(name, tool.icon);\n\n codex.nodes.inlineToolbar.buttons.appendChild(toolButton);\n /**\n * Add callbacks to this buttons\n */\n codex.ui.setInlineToolbarButtonBehaviour(toolButton, tool.command);\n }\n\n };\n\n /**\n * @private\n * Bind editor UI events\n */\n ui.bindEvents = function () {\n\n codex.core.log('ui.bindEvents fired', 'info');\n\n window.addEventListener('error', function (errorMsg, url, lineNumber) {\n codex.notifications.errorThrown(errorMsg, event);\n }, false );\n\n /** All keydowns on Document */\n codex.nodes.redactor.addEventListener('keydown', codex.callback.globalKeydown, false );\n\n /** All keydowns on Document */\n document.addEventListener('keyup', codex.callback.globalKeyup, false );\n\n /**\n * Mouse click to radactor\n */\n codex.nodes.redactor.addEventListener('click', codex.callback.redactorClicked, false );\n\n /**\n * Clicks to the Plus button\n */\n codex.nodes.plusButton.addEventListener('click', codex.callback.plusButtonClicked, false);\n\n /**\n * Clicks to SETTINGS button in toolbar\n */\n codex.nodes.showSettingsButton.addEventListener('click', codex.callback.showSettingsButtonClicked, false );\n /**\n * @deprecated ( but now in use for syncronization );\n * Any redactor changes: keyboard input, mouse cut/paste, drag-n-drop text\n */\n codex.nodes.redactor.addEventListener('input', codex.callback.redactorInputEvent, false );\n\n /** Bind click listeners on toolbar buttons */\n for (var button in codex.nodes.toolbarButtons){\n codex.nodes.toolbarButtons[button].addEventListener('click', codex.callback.toolbarButtonClicked, false);\n }\n\n };\n\n /**\n * Initialize plugins before using\n * Ex. Load scripts or call some internal methods\n */\n ui.preparePlugins = function() {\n\n for(var tool in codex.tools) {\n\n if (typeof codex.tools[tool].prepare != 'function')\n continue;\n\n codex.tools[tool].prepare();\n }\n },\n\n ui.addBlockHandlers = function(block) {\n\n if (!block) return;\n\n /**\n * Block keydowns\n */\n block.addEventListener('keydown', function(event) {\n codex.callback.blockKeydown(event, block);\n }, false);\n\n /**\n * Pasting content from another source\n */\n block.addEventListener('paste', function (event) {\n codex.callback.blockPaste(event);\n }, false);\n\n block.addEventListener('mouseup', function(){\n codex.toolbar.inline.show();\n }, false);\n\n };\n\n /** getting all contenteditable elements */\n ui.saveInputs = function() {\n\n var redactor = codex.nodes.redactor,\n elements = [];\n\n /** Save all inputs in global variable state */\n codex.state.inputs = redactor.querySelectorAll('[contenteditable], input');\n };\n\n /**\n * Adds first initial block on empty redactor\n */\n ui.addInitialBlock = function(){\n\n var initialBlockType = codex.settings.initialBlockPlugin,\n initialBlock;\n\n if ( !codex.tools[initialBlockType] ){\n codex.core.log('Plugin %o was not implemented and can\\'t be used as initial block', 'warn', initialBlockType);\n return;\n }\n\n initialBlock = codex.tools[initialBlockType].render();\n\n initialBlock.setAttribute('data-placeholder', 'Write your story...');\n\n codex.content.insertBlock({\n type : initialBlockType,\n block : initialBlock\n });\n\n codex.content.workingNodeChanged(initialBlock);\n\n };\n\n ui.setInlineToolbarButtonBehaviour = function(button, type) {\n\n button.addEventListener('mousedown', function(event) {\n\n codex.toolbar.inline.toolClicked(event, type);\n\n }, false);\n };\n\n return ui;\n\n})({});\n\ncodex.ui = ui;\nmodule.exports = codex;\n\n\n/** WEBPACK FOOTER **\n ** ./modules/ui.js\n **/","var codex = require('../editor');\n\nvar transport = (function(transport){\n\n transport.input = null;\n\n /**\n * @property {Object} arguments - keep plugin settings and defined callbacks\n */\n transport.arguments = null;\n\n transport.prepare = function(){\n\n var input = document.createElement('INPUT');\n\n input.type = 'file';\n input.addEventListener('change', codex.transport.fileSelected);\n\n codex.transport.input = input;\n\n };\n\n /** Clear input when files is uploaded */\n transport.clearInput = function() {\n\n /** Remove old input */\n this.input = null;\n\n /** Prepare new one */\n this.prepare();\n };\n\n /**\n * Callback for file selection\n */\n transport.fileSelected = function(event){\n\n var input = this,\n files = input.files,\n filesLength = files.length,\n formdData = new FormData(),\n file,\n i;\n\n formdData.append('files', files[0], files[0].name);\n\n codex.transport.ajax({\n data : formdData,\n beforeSend : codex.transport.arguments.beforeSend,\n success : codex.transport.arguments.success,\n error : codex.transport.arguments.error\n });\n };\n\n /**\n * Use plugin callbacks\n * @protected\n */\n transport.selectAndUpload = function (args) {\n\n this.arguments = args;\n this.input.click();\n\n };\n\n /**\n * Ajax requests module\n */\n transport.ajax = function(params){\n\n var xhr = new XMLHttpRequest(),\n beforeSend = typeof params.beforeSend == 'function' ? params.beforeSend : function(){},\n success = typeof params.success == 'function' ? params.success : function(){},\n error = typeof params.error == 'function' ? params.error : function(){};\n\n beforeSend();\n\n xhr.open('POST', codex.settings.uploadImagesUrl, true);\n\n xhr.setRequestHeader(\"X-Requested-With\", \"XMLHttpRequest\");\n\n xhr.onload = function () {\n if (xhr.status === 200) {\n success(xhr.responseText);\n } else {\n console.log(\"request error: %o\", xhr);\n error();\n }\n };\n\n xhr.send(params.data);\n this.clearInput();\n\n };\n\n return transport;\n\n})({});\n\ncodex.transport = transport;\nmodule.exports = transport;\n\n\n/** WEBPACK FOOTER **\n ** ./modules/transport.js\n **/","var codex = require('../editor');\n\nvar renderer = (function(renderer) {\n\n /**\n * Asyncronously parses input JSON to redactor blocks\n */\n renderer.makeBlocksFromData = function () {\n\n /**\n * If redactor is empty, add first paragraph to start writing\n */\n if (!codex.state.blocks.items.length) {\n\n codex.ui.addInitialBlock();\n return;\n\n }\n\n Promise.resolve()\n\n /** First, get JSON from state */\n .then(function() {\n return codex.state.blocks;\n })\n\n /** Then, start to iterate they */\n .then(codex.renderer.appendBlocks)\n\n /** Write log if something goes wrong */\n .catch(function(error) {\n codex.core.log('Error while parsing JSON: %o', 'error', error);\n });\n\n };\n\n /**\n * Parses JSON to blocks\n * @param {object} data\n * @return Primise -> nodeList\n */\n renderer.appendBlocks = function (data) {\n\n var blocks = data.items;\n\n /**\n * Sequence of one-by-one blocks appending\n * Uses to save blocks order after async-handler\n */\n var nodeSequence = Promise.resolve();\n\n for (var index = 0; index < blocks.length ; index++ ) {\n\n /** Add node to sequence at specified index */\n codex.renderer.appendNodeAtIndex(nodeSequence, blocks, index);\n\n }\n\n };\n\n /**\n * Append node at specified index\n */\n renderer.appendNodeAtIndex = function (nodeSequence, blocks, index) {\n\n /** We need to append node to sequence */\n nodeSequence\n\n /** first, get node async-aware */\n .then(function() {\n\n return codex.renderer.getNodeAsync(blocks , index);\n\n })\n\n /**\n * second, compose editor-block from JSON object\n */\n .then(codex.renderer.createBlockFromData)\n\n /**\n * now insert block to redactor\n */\n .then(function(blockData){\n\n /**\n * blockData has 'block', 'type' and 'stretched' information\n */\n codex.content.insertBlock(blockData);\n\n /** Pass created block to next step */\n return blockData.block;\n\n })\n\n /** Log if something wrong with node */\n .catch(function(error) {\n codex.core.log('Node skipped while parsing because %o', 'error', error);\n });\n\n };\n\n /**\n * Asynchronously returns block data from blocksList by index\n * @return Promise to node\n */\n renderer.getNodeAsync = function (blocksList, index) {\n\n return Promise.resolve().then(function() {\n\n return blocksList[index];\n\n });\n };\n\n /**\n * Creates editor block by JSON-data\n *\n * @uses render method of each plugin\n *\n * @param {object} blockData looks like\n * { header : {\n * text: '',\n * type: 'H3', ...\n * }\n * }\n * @return {object} with type and Element\n */\n renderer.createBlockFromData = function (blockData) {\n\n /** New parser */\n var pluginName = blockData.type;\n\n /** Get first key of object that stores plugin name */\n // for (var pluginName in blockData) break;\n\n /** Check for plugin existance */\n if (!codex.tools[pluginName]) {\n throw Error(`Plugin «${pluginName}» not found`);\n }\n\n /** Check for plugin having render method */\n if (typeof codex.tools[pluginName].render != 'function') {\n\n throw Error(`Plugin «${pluginName}» must have «render» method`);\n }\n\n /** New Parser */\n var block = codex.tools[pluginName].render(blockData.data);\n\n /** Fire the render method with data */\n // var block = codex.tools[pluginName].render(blockData[pluginName]);\n\n /** is first-level block stretched */\n var stretched = codex.tools[pluginName].isStretched || false;\n\n /** Retrun type and block */\n return {\n type : pluginName,\n block : block,\n stretched : stretched\n };\n\n };\n\n return renderer;\n\n})({});\n\ncodex.renderer = renderer;\nmodule.exports = renderer;\n\n\n/** WEBPACK FOOTER **\n ** ./modules/renderer.js\n **/","var codex = require('../editor');\n\nvar saver = (function(saver) {\n\n /**\n * Saves blocks\n * @private\n */\n saver.saveBlocks = function () {\n\n /** Save html content of redactor to memory */\n codex.state.html = codex.nodes.redactor.innerHTML;\n\n /** Empty jsonOutput state */\n codex.state.jsonOutput = [];\n\n Promise.resolve()\n\n .then(function() {\n return codex.nodes.redactor.childNodes;\n })\n /** Making a sequence from separate blocks */\n .then(codex.saver.makeQueue)\n\n .then(function() {\n // codex.nodes.textarea.innerHTML = codex.state.html;\n })\n\n .catch( function(error) {\n console.log('Something happend');\n });\n\n };\n\n saver.makeQueue = function(blocks) {\n\n var queue = Promise.resolve();\n\n for(var index = 0; index < blocks.length; index++) {\n\n /** Add node to sequence at specified index */\n codex.saver.getBlockData(queue, blocks, index);\n\n }\n\n };\n\n /** Gets every block and makes From Data */\n saver.getBlockData = function(queue, blocks, index) {\n\n queue.then(function() {\n return codex.saver.getNodeAsync(blocks, index);\n })\n\n .then(codex.saver.makeFormDataFromBlocks);\n\n };\n\n\n /**\n * Asynchronously returns block data from blocksList by index\n * @return Promise to node\n */\n saver.getNodeAsync = function (blocksList, index) {\n\n return Promise.resolve().then(function() {\n\n return blocksList[index];\n\n });\n };\n\n saver.makeFormDataFromBlocks = function(block) {\n\n var pluginName = block.dataset.tool;\n\n /** Check for plugin existance */\n if (!codex.tools[pluginName]) {\n throw Error(`Plugin «${pluginName}» not found`);\n }\n\n /** Check for plugin having render method */\n if (typeof codex.tools[pluginName].save != 'function') {\n\n throw Error(`Plugin «${pluginName}» must have save method`);\n }\n\n /** Result saver */\n var blockContent = block.childNodes[0],\n pluginsContent = blockContent.childNodes[0],\n savedData = codex.tools[pluginName].save(pluginsContent),\n output;\n\n\n output = {\n type: pluginName,\n data: savedData\n };\n\n /** Marks Blocks that will be in main page */\n output.cover = block.classList.contains(codex.ui.className.BLOCK_IN_FEED_MODE);\n\n codex.state.jsonOutput.push(output);\n };\n\n return saver;\n\n})({});\n\ncodex.saver = saver;\nmodule.exports = saver;\n\n\n/** WEBPACK FOOTER **\n ** ./modules/saver.js\n **/","var codex = require('../editor');\n\nvar content = (function(content) {\n\n content.currentNode = null;\n\n /**\n * Synchronizes redactor with original textarea\n */\n content.sync = function () {\n\n codex.core.log('syncing...');\n\n /**\n * Save redactor content to codex.state\n */\n codex.state.html = codex.nodes.redactor.innerHTML;\n\n };\n\n /**\n * @deprecated\n */\n content.getNodeFocused = function() {\n\n var selection = window.getSelection(),\n focused;\n\n if (selection.anchorNode === null) {\n return null;\n }\n\n if ( selection.anchorNode.nodeType == codex.core.nodeTypes.TAG ) {\n focused = selection.anchorNode;\n } else {\n focused = selection.focusNode.parentElement;\n }\n\n if ( !codex.parser.isFirstLevelBlock(focused) ) {\n\n /** Iterate with parent nodes to find first-level*/\n var parent = focused.parentNode;\n\n while (parent && !codex.parser.isFirstLevelBlock(parent)){\n parent = parent.parentNode;\n }\n\n focused = parent;\n }\n\n if (focused != codex.nodes.redactor){\n return focused;\n }\n\n return null;\n\n };\n\n /**\n * Appends background to the block\n */\n content.markBlock = function() {\n\n codex.content.currentNode.classList.add(codex.ui.className.BLOCK_HIGHLIGHTED);\n };\n\n /**\n * Clear background\n */\n content.clearMark = function() {\n\n if (codex.content.currentNode) {\n codex.content.currentNode.classList.remove(codex.ui.className.BLOCK_HIGHLIGHTED);\n }\n\n };\n\n /**\n * @private\n *\n * Finds first-level block\n * @param {Element} node - selected or clicked in redactors area node\n */\n content.getFirstLevelBlock = function(node) {\n\n if (!codex.core.isDomNode(node)) {\n node = node.parentNode;\n }\n\n if (node === codex.nodes.redactor || node === document.body) {\n\n return null;\n\n } else {\n\n while(!node.classList.contains(codex.ui.className.BLOCK_CLASSNAME)) {\n node = node.parentNode;\n }\n\n return node;\n }\n\n };\n\n /**\n * Trigger this event when working node changed\n * @param {Element} targetNode - first-level of this node will be current\n * If targetNode is first-level then we set it as current else we look for parents to find first-level\n */\n content.workingNodeChanged = function (targetNode) {\n\n /** Clear background from previous marked block before we change */\n codex.content.clearMark();\n\n if (!targetNode) {\n return;\n }\n\n this.currentNode = this.getFirstLevelBlock(targetNode);\n\n };\n\n /**\n * Replaces one redactor block with another\n * @protected\n * @param {Element} targetBlock - block to replace. Mostly currentNode.\n * @param {Element} newBlock\n * @param {string} newBlockType - type of new block; we need to store it to data-attribute\n *\n * [!] Function does not saves old block content.\n * You can get it manually and pass with newBlock.innerHTML\n */\n content.replaceBlock = function function_name(targetBlock, newBlock) {\n\n if (!targetBlock || !newBlock){\n codex.core.log('replaceBlock: missed params');\n return;\n }\n\n /** If target-block is not a frist-level block, then we iterate parents to find it */\n while(!targetBlock.classList.contains(codex.ui.className.BLOCK_CLASSNAME)) {\n targetBlock = targetBlock.parentNode;\n }\n\n /** Replacing */\n codex.nodes.redactor.replaceChild(newBlock, targetBlock);\n\n /**\n * Set new node as current\n */\n codex.content.workingNodeChanged(newBlock);\n\n /**\n * Add block handlers\n */\n codex.ui.addBlockHandlers(newBlock);\n\n /**\n * Save changes\n */\n codex.ui.saveInputs();\n\n };\n\n /**\n * @private\n *\n * Inserts new block to redactor\n * Wrapps block into a DIV with BLOCK_CLASSNAME class\n *\n * @param blockData {object}\n * @param blockData.block {Element} element with block content\n * @param blockData.type {string} block plugin\n * @param needPlaceCaret {bool} pass true to set caret in new block\n *\n */\n content.insertBlock = function( blockData, needPlaceCaret ) {\n\n var workingBlock = codex.content.currentNode,\n newBlockContent = blockData.block,\n blockType = blockData.type,\n isStretched = blockData.stretched;\n\n var newBlock = codex.content.composeNewBlock(newBlockContent, blockType, isStretched);\n\n if (workingBlock) {\n\n codex.core.insertAfter(workingBlock, newBlock);\n\n } else {\n /**\n * If redactor is empty, append as first child\n */\n codex.nodes.redactor.appendChild(newBlock);\n\n }\n\n /**\n * Block handler\n */\n codex.ui.addBlockHandlers(newBlock);\n\n /**\n * Set new node as current\n */\n codex.content.workingNodeChanged(newBlock);\n\n /**\n * Save changes\n */\n codex.ui.saveInputs();\n\n\n if ( needPlaceCaret ) {\n\n /**\n * If we don't know input index then we set default value -1\n */\n var currentInputIndex = codex.caret.getCurrentInputIndex() || -1;\n\n\n if (currentInputIndex == -1) {\n\n\n var editableElement = newBlock.querySelector('[contenteditable]'),\n emptyText = document.createTextNode('');\n\n editableElement.appendChild(emptyText);\n codex.caret.set(editableElement, 0, 0);\n\n codex.toolbar.move();\n codex.toolbar.showPlusButton();\n\n\n } else {\n\n /** Timeout for browsers execution */\n setTimeout(function () {\n\n /** Setting to the new input */\n codex.caret.setToNextBlock(currentInputIndex);\n codex.toolbar.move();\n codex.toolbar.open();\n\n }, 10);\n\n }\n\n }\n\n };\n\n /**\n * Replaces blocks with saving content\n * @protected\n * @param {Element} noteToReplace\n * @param {Element} newNode\n * @param {Element} blockType\n */\n content.switchBlock = function(blockToReplace, newBlock, tool){\n\n var newBlockComposed = codex.content.composeNewBlock(newBlock, tool);\n\n /** Replacing */\n codex.content.replaceBlock(blockToReplace, newBlockComposed);\n\n /** Save new Inputs when block is changed */\n codex.ui.saveInputs();\n };\n\n /**\n * Iterates between child noted and looking for #text node on deepest level\n * @private\n * @param {Element} block - node where find\n * @param {int} postiton - starting postion\n * Example: childNodex.length to find from the end\n * or 0 to find from the start\n * @return {Text} block\n * @uses DFS\n */\n content.getDeepestTextNodeFromPosition = function (block, position) {\n\n /**\n * Clear Block from empty and useless spaces with trim.\n * Such nodes we should remove\n */\n var blockChilds = block.childNodes,\n index,\n node,\n text;\n\n for(index = 0; index < blockChilds.length; index++)\n {\n node = blockChilds[index];\n\n if (node.nodeType == codex.core.nodeTypes.TEXT) {\n\n text = node.textContent.trim();\n\n /** Text is empty. We should remove this child from node before we start DFS\n * decrease the quantity of childs.\n */\n if (text === '') {\n\n block.removeChild(node);\n position--;\n }\n }\n }\n\n if (block.childNodes.length === 0) {\n return document.createTextNode('');\n }\n\n /** Setting default position when we deleted all empty nodes */\n if ( position < 0 )\n position = 1;\n\n var looking_from_start = false;\n\n /** For looking from START */\n if (position === 0) {\n looking_from_start = true;\n position = 1;\n }\n\n while ( position ) {\n\n /** initial verticle of node. */\n if ( looking_from_start ) {\n block = block.childNodes[0];\n } else {\n block = block.childNodes[position - 1];\n }\n\n if ( block.nodeType == codex.core.nodeTypes.TAG ){\n\n position = block.childNodes.length;\n\n } else if (block.nodeType == codex.core.nodeTypes.TEXT ){\n\n position = 0;\n }\n\n }\n\n return block;\n };\n\n /**\n * @private\n */\n content.composeNewBlock = function (block, tool, isStretched) {\n\n var newBlock = codex.draw.node('DIV', codex.ui.className.BLOCK_CLASSNAME, {}),\n blockContent = codex.draw.node('DIV', codex.ui.className.BLOCK_CONTENT, {});\n\n blockContent.appendChild(block);\n newBlock.appendChild(blockContent);\n\n if (isStretched) {\n blockContent.classList.add(codex.ui.className.BLOCK_STRETCHED);\n }\n\n newBlock.dataset.tool = tool;\n return newBlock;\n };\n\n /**\n * Returns Range object of current selection\n */\n content.getRange = function() {\n\n var selection = window.getSelection().getRangeAt(0);\n\n return selection;\n };\n\n /**\n * Divides block in two blocks (after and before caret)\n * @private\n * @param {Int} inputIndex - target input index\n */\n content.splitBlock = function(inputIndex) {\n\n var selection = window.getSelection(),\n anchorNode = selection.anchorNode,\n anchorNodeText = anchorNode.textContent,\n caretOffset = selection.anchorOffset,\n textBeforeCaret,\n textNodeBeforeCaret,\n textAfterCaret,\n textNodeAfterCaret;\n\n var currentBlock = codex.content.currentNode.querySelector('[contentEditable]');\n\n\n textBeforeCaret = anchorNodeText.substring(0, caretOffset);\n textAfterCaret = anchorNodeText.substring(caretOffset);\n\n textNodeBeforeCaret = document.createTextNode(textBeforeCaret);\n\n if (textAfterCaret) {\n textNodeAfterCaret = document.createTextNode(textAfterCaret);\n }\n\n var previousChilds = [],\n nextChilds = [],\n reachedCurrent = false;\n\n if (textNodeAfterCaret) {\n nextChilds.push(textNodeAfterCaret);\n }\n\n for ( var i = 0, child; !!(child = currentBlock.childNodes[i]); i++) {\n\n if ( child != anchorNode ) {\n if ( !reachedCurrent ){\n previousChilds.push(child);\n } else {\n nextChilds.push(child);\n }\n } else {\n reachedCurrent = true;\n }\n\n }\n\n /** Clear current input */\n codex.state.inputs[inputIndex].innerHTML = '';\n\n /**\n * Append all childs founded before anchorNode\n */\n var previousChildsLength = previousChilds.length;\n\n for(i = 0; i < previousChildsLength; i++) {\n codex.state.inputs[inputIndex].appendChild(previousChilds[i]);\n }\n\n codex.state.inputs[inputIndex].appendChild(textNodeBeforeCaret);\n\n /**\n * Append text node which is after caret\n */\n var nextChildsLength = nextChilds.length,\n newNode = document.createElement('div');\n\n for(i = 0; i < nextChildsLength; i++) {\n newNode.appendChild(nextChilds[i]);\n }\n\n newNode = newNode.innerHTML;\n\n /** This type of block creates when enter is pressed */\n var NEW_BLOCK_TYPE = 'paragraph';\n\n /**\n * Make new paragraph with text after caret\n */\n codex.content.insertBlock({\n type : NEW_BLOCK_TYPE,\n block : codex.tools[NEW_BLOCK_TYPE].render({\n text : newNode,\n })\n }, true );\n\n };\n\n /**\n * Merges two blocks — current and target\n * If target index is not exist, then previous will be as target\n */\n content.mergeBlocks = function(currentInputIndex, targetInputIndex) {\n\n /** If current input index is zero, then prevent method execution */\n if (currentInputIndex === 0) {\n return;\n }\n\n var targetInput,\n currentInputContent = codex.state.inputs[currentInputIndex].innerHTML;\n\n if (!targetInputIndex) {\n\n targetInput = codex.state.inputs[currentInputIndex - 1];\n\n } else {\n\n targetInput = codex.state.inputs[targetInputIndex];\n\n }\n\n targetInput.innerHTML += currentInputContent;\n };\n\n /**\n * @private\n *\n * Callback for HTML Mutations\n * @param {Array} mutation - Mutation Record\n */\n content.paste = function(mutation) {\n\n var workingNode = codex.content.currentNode,\n tool = workingNode.dataset.tool;\n\n if (codex.tools[tool].allowedToPaste) {\n codex.content.sanitize(mutation.addedNodes);\n } else {\n codex.content.pasteTextContent(mutation.addedNodes);\n }\n\n };\n\n /**\n * @private\n *\n * gets only text/plain content of node\n * @param {Element} target - HTML node\n */\n content.pasteTextContent = function(nodes) {\n\n var node = nodes[0],\n textNode = document.createTextNode(node.textContent);\n\n if (codex.core.isDomNode(node)) {\n node.parentNode.replaceChild(textNode, node);\n }\n };\n\n /**\n * @private\n *\n * Sanitizes HTML content\n * @param {Element} target - inserted element\n * @uses DFS function for deep searching\n */\n content.sanitize = function(target) {\n\n if (!target) {\n return;\n }\n\n for (var i = 0; i < target.childNodes.length; i++) {\n this.dfs(target.childNodes[i]);\n }\n };\n\n /**\n * Clears styles\n * @param {Element|Text}\n */\n content.clearStyles = function(target) {\n\n var href,\n newNode = null,\n blockTags = ['P', 'BLOCKQUOTE', 'UL', 'CODE', 'OL', 'LI', 'H1', 'H2', 'H3', 'H4', 'H5', 'H6', 'DIV', 'PRE', 'HEADER', 'SECTION'],\n allowedTags = ['P', 'B', 'I', 'A', 'U', 'BR'],\n needReplace = !allowedTags.includes(target.tagName),\n isDisplayedAsBlock = blockTags.includes(target.tagName);\n\n if (!codex.core.isDomNode(target)){\n return target;\n }\n\n if (!target.parentNode){\n return target;\n }\n\n if (needReplace) {\n\n if (isDisplayedAsBlock) {\n\n newNode = document.createElement('P');\n newNode.innerHTML = target.innerHTML;\n target.parentNode.replaceChild(newNode, target);\n target = newNode;\n\n } else {\n\n newNode = document.createTextNode(` ${target.textContent} `);\n newNode.textContent = newNode.textContent.replace(/\\s{2,}/g, ' ');\n target.parentNode.replaceChild(newNode, target);\n\n }\n }\n\n /** keep href attributes of tag A */\n if (target.tagName == 'A') {\n href = target.getAttribute('href');\n }\n\n /** Remove all tags */\n while(target.attributes.length > 0) {\n target.removeAttribute(target.attributes[0].name);\n }\n\n /** return href */\n if (href) {\n target.setAttribute('href', href);\n }\n\n return target;\n\n };\n\n /**\n * Depth-first search Algorithm\n * returns all childs\n * @param {Element}\n */\n content.dfs = function(el) {\n\n if (!codex.core.isDomNode(el))\n return;\n\n var sanitized = this.clearStyles(el);\n\n for(var i = 0; i < sanitized.childNodes.length; i++) {\n this.dfs(sanitized.childNodes[i]);\n }\n\n };\n\n return content;\n\n})({});\n\ncodex.content = content;\nmodule.exports = content;\n\n\n/** WEBPACK FOOTER **\n ** ./modules/content.js\n **/","var codex = require('../../editor');\n\nvar toolbar = (function(toolbar) {\n\n toolbar.init = function() {\n toolbar.settings = require('./settings');\n toolbar.inline = require('./inline');\n toolbar.toolbox = require('./toolbox');\n };\n\n /**\n * Margin between focused node and toolbar\n */\n toolbar.defaultToolbarHeight = 49;\n\n toolbar.defaultOffset = 34;\n\n toolbar.opened = false;\n\n toolbar.current = null;\n\n /**\n * @protected\n */\n toolbar.open = function (){\n\n codex.nodes.toolbar.classList.add('opened');\n this.opened = true;\n\n };\n\n /**\n * @protected\n */\n toolbar.close = function(){\n\n codex.nodes.toolbar.classList.remove('opened');\n this.opened = false;\n\n this.current = null;\n\n for (var button in codex.nodes.toolbarButtons){\n codex.nodes.toolbarButtons[button].classList.remove('selected');\n }\n\n /** Close toolbox when toolbar is not displayed */\n codex.toolbar.toolbox.close();\n codex.toolbar.settings.close();\n\n };\n\n toolbar.toggle = function(){\n\n if ( !this.opened ){\n\n this.open();\n\n } else {\n\n this.close();\n\n }\n\n };\n\n toolbar.hidePlusButton = function() {\n codex.nodes.plusButton.classList.add('hide');\n };\n\n toolbar.showPlusButton = function() {\n codex.nodes.plusButton.classList.remove('hide');\n };\n\n /**\n * Moving toolbar to the specified node\n */\n toolbar.move = function() {\n\n /** Close Toolbox when we move toolbar */\n codex.toolbar.toolbox.close();\n\n if (!codex.content.currentNode) {\n return;\n }\n\n var toolbarHeight = codex.nodes.toolbar.clientHeight || codex.toolbar.defaultToolbarHeight,\n newYCoordinate = codex.content.currentNode.offsetTop - (codex.toolbar.defaultToolbarHeight / 2) + codex.toolbar.defaultOffset;\n\n codex.nodes.toolbar.style.transform = `translate3D(0, ${Math.floor(newYCoordinate)}px, 0)`;\n\n /** Close trash actions */\n codex.toolbar.settings.hideRemoveActions();\n\n };\n\n return toolbar;\n\n})({});\n\ntoolbar.init();\n\ncodex.toolbar = toolbar;\nmodule.exports = toolbar;\n\n\n\n\n/** WEBPACK FOOTER **\n ** ./modules/toolbar/toolbar.js\n **/","var codex = require('../../editor');\n\nvar settings = (function(settings) {\n\n settings.init = function() {\n require('../content');\n };\n\n settings.opened = false;\n\n settings.setting = null;\n settings.actions = null;\n\n settings.cover = null;\n\n /**\n * Append and open settings\n */\n settings.open = function(toolType){\n\n /**\n * Append settings content\n * It's stored in tool.settings\n */\n if (!codex.tools[toolType] || !codex.core.isDomNode(codex.tools[toolType].settings) ) {\n\n codex.core.log(`Plugin «${toolType}» has no settings`, 'warn');\n // codex.nodes.pluginSettings.innerHTML = `Плагин «${toolType}» не имеет настроек`;\n\n } else {\n\n codex.nodes.pluginSettings.appendChild(codex.tools[toolType].settings);\n\n }\n\n var currentBlock = codex.content.currentNode;\n\n /** Open settings block */\n codex.nodes.blockSettings.classList.add('opened');\n codex.toolbar.settings.addDefaultSettings();\n this.opened = true;\n };\n\n /**\n * Close and clear settings\n */\n settings.close = function(){\n\n codex.nodes.blockSettings.classList.remove('opened');\n codex.nodes.pluginSettings.innerHTML = '';\n\n this.opened = false;\n\n };\n\n /**\n * @param {string} toolType - plugin type\n */\n settings.toggle = function( toolType ){\n\n if ( !this.opened ){\n\n this.open(toolType);\n\n } else {\n\n this.close();\n\n }\n\n };\n\n /**\n * This function adds default core settings\n */\n settings.addDefaultSettings = function() {\n\n /** list of default settings */\n var feedModeToggler;\n\n /** Clear block and append initialized settings */\n codex.nodes.defaultSettings.innerHTML = '';\n\n\n /** Init all default setting buttons */\n feedModeToggler = codex.toolbar.settings.makeFeedModeToggler();\n\n /**\n * Fill defaultSettings\n */\n\n /**\n * Button that enables/disables Feed-mode\n * Feed-mode means that block will be showed in articles-feed like cover\n */\n codex.nodes.defaultSettings.appendChild(feedModeToggler);\n\n };\n\n /**\n * Cover setting.\n * This tune highlights block, so that it may be used for showing target block on main page\n * Draw different setting when block is marked for main page\n * If TRUE, then we show button that removes this selection\n * Also defined setting \"Click\" events will be listened and have separate callbacks\n *\n * @return {Element} node/button that we place in default settings block\n */\n settings.makeFeedModeToggler = function() {\n\n var isFeedModeActivated = codex.toolbar.settings.isFeedModeActivated(),\n setting,\n data;\n\n if (!isFeedModeActivated) {\n\n data = {\n innerHTML : 'Вывести в ленте'\n };\n\n } else {\n\n data = {\n innerHTML : 'Не выводить в ленте'\n };\n\n }\n\n setting = codex.draw.node('DIV', codex.ui.className.SETTINGS_ITEM, data);\n setting.addEventListener('click', codex.toolbar.settings.updateFeedMode, false);\n\n return setting;\n };\n\n /**\n * Updates Feed-mode\n */\n settings.updateFeedMode = function() {\n\n var currentNode = codex.content.currentNode;\n\n currentNode.classList.toggle(codex.ui.className.BLOCK_IN_FEED_MODE);\n\n codex.toolbar.settings.close();\n };\n\n settings.isFeedModeActivated = function() {\n\n var currentBlock = codex.content.currentNode;\n\n if (currentBlock) {\n return currentBlock.classList.contains(codex.ui.className.BLOCK_IN_FEED_MODE);\n } else {\n return false;\n }\n };\n\n /**\n * Here we will draw buttons and add listeners to components\n */\n settings.makeRemoveBlockButton = function() {\n\n var removeBlockWrapper = codex.draw.node('SPAN', 'ce-toolbar__remove-btn', {}),\n settingButton = codex.draw.node('SPAN', 'ce-toolbar__remove-setting', { innerHTML : '' }),\n actionWrapper = codex.draw.node('DIV', 'ce-toolbar__remove-confirmation', {}),\n confirmAction = codex.draw.node('DIV', 'ce-toolbar__remove-confirm', { textContent : 'Удалить блок' }),\n cancelAction = codex.draw.node('DIV', 'ce-toolbar__remove-cancel', { textContent : 'Отменить удаление' });\n\n settingButton.addEventListener('click', codex.toolbar.settings.removeButtonClicked, false);\n\n confirmAction.addEventListener('click', codex.toolbar.settings.confirmRemovingRequest, false);\n\n cancelAction.addEventListener('click', codex.toolbar.settings.cancelRemovingRequest, false);\n\n actionWrapper.appendChild(confirmAction);\n actionWrapper.appendChild(cancelAction);\n\n removeBlockWrapper.appendChild(settingButton);\n removeBlockWrapper.appendChild(actionWrapper);\n\n /** Save setting */\n codex.toolbar.settings.setting = settingButton;\n codex.toolbar.settings.actions = actionWrapper;\n\n return removeBlockWrapper;\n\n };\n\n settings.removeButtonClicked = function() {\n\n var action = codex.toolbar.settings.actions;\n\n if (action.classList.contains('opened')) {\n codex.toolbar.settings.hideRemoveActions();\n } else {\n codex.toolbar.settings.showRemoveActions();\n }\n\n codex.toolbar.toolbox.close();\n codex.toolbar.settings.close();\n\n };\n\n settings.cancelRemovingRequest = function() {\n\n codex.toolbar.settings.actions.classList.remove('opened');\n };\n\n settings.confirmRemovingRequest = function() {\n\n var currentBlock = codex.content.currentNode,\n firstLevelBlocksCount;\n\n currentBlock.remove();\n\n firstLevelBlocksCount = codex.nodes.redactor.childNodes.length;\n\n /**\n * If all blocks are removed\n */\n if (firstLevelBlocksCount === 0) {\n\n /** update currentNode variable */\n codex.content.currentNode = null;\n\n /** Inserting new empty initial block */\n codex.ui.addInitialBlock();\n }\n\n codex.ui.saveInputs();\n\n codex.toolbar.close();\n };\n\n settings.showRemoveActions = function() {\n codex.toolbar.settings.actions.classList.add('opened');\n };\n\n settings.hideRemoveActions = function() {\n codex.toolbar.settings.actions.classList.remove('opened');\n };\n\n return settings;\n\n})({});\n\nsettings.init();\n\nmodule.exports = settings;\n\n\n/** WEBPACK FOOTER **\n ** ./modules/toolbar/settings.js\n **/","var codex = require('../../editor');\n\nvar inline = (function(inline) {\n\n inline.init = function() {\n\n };\n\n inline.buttonsOpened = null;\n inline.actionsOpened = null;\n inline.wrappersOffset = null;\n\n /**\n * saving selection that need for execCommand for styling\n *\n */\n inline.storedSelection = null,\n\n /**\n * @protected\n *\n * Open inline toobar\n */\n inline.show = function() {\n\n var selectedText = this.getSelectionText(),\n toolbar = codex.nodes.inlineToolbar.wrapper,\n buttons = codex.nodes.inlineToolbar.buttons;\n\n if (selectedText.length > 0) {\n\n /** Move toolbar and open */\n codex.toolbar.inline.move();\n\n /** Open inline toolbar */\n toolbar.classList.add('opened');\n\n /** show buttons of inline toolbar */\n codex.toolbar.inline.showButtons();\n }\n\n };\n\n /**\n * @protected\n *\n * Closes inline toolbar\n */\n inline.close = function() {\n var toolbar = codex.nodes.inlineToolbar.wrapper;\n toolbar.classList.remove('opened');\n };\n\n /**\n * @private\n *\n * Moving toolbar\n */\n inline.move = function() {\n\n if (!this.wrappersOffset) {\n this.wrappersOffset = this.getWrappersOffset();\n }\n\n var coords = this.getSelectionCoords(),\n defaultOffset = 0,\n toolbar = codex.nodes.inlineToolbar.wrapper,\n newCoordinateX,\n newCoordinateY;\n\n if (toolbar.offsetHeight === 0) {\n defaultOffset = 40;\n }\n\n newCoordinateX = coords.x - this.wrappersOffset.left;\n newCoordinateY = coords.y + window.scrollY - this.wrappersOffset.top - defaultOffset - toolbar.offsetHeight;\n\n toolbar.style.transform = `translate3D(${Math.floor(newCoordinateX)}px, ${Math.floor(newCoordinateY)}px, 0)`;\n\n /** Close everything */\n codex.toolbar.inline.closeButtons();\n codex.toolbar.inline.closeAction();\n\n };\n\n /**\n * @private\n *\n * Tool Clicked\n */\n\n inline.toolClicked = function(event, type) {\n\n /**\n * For simple tools we use default browser function\n * For more complicated tools, we should write our own behavior\n */\n switch (type) {\n case 'createLink' : codex.toolbar.inline.createLinkAction(event, type); break;\n default : codex.toolbar.inline.defaultToolAction(type); break;\n }\n\n /**\n * highlight buttons\n * after making some action\n */\n codex.nodes.inlineToolbar.buttons.childNodes.forEach(codex.toolbar.inline.hightlight);\n };\n\n /**\n * @private\n *\n * Saving wrappers offset in DOM\n */\n inline.getWrappersOffset = function() {\n\n var wrapper = codex.nodes.wrapper,\n offset = this.getOffset(wrapper);\n\n this.wrappersOffset = offset;\n return offset;\n\n };\n\n /**\n * @private\n *\n * Calculates offset of DOM element\n *\n * @param el\n * @returns {{top: number, left: number}}\n */\n inline.getOffset = function ( el ) {\n\n var _x = 0;\n var _y = 0;\n\n while( el && !isNaN( el.offsetLeft ) && !isNaN( el.offsetTop ) ) {\n _x += (el.offsetLeft + el.clientLeft);\n _y += (el.offsetTop + el.clientTop);\n el = el.offsetParent;\n }\n return { top: _y, left: _x };\n };\n\n /**\n * @private\n *\n * Calculates position of selected text\n * @returns {{x: number, y: number}}\n */\n inline.getSelectionCoords = function() {\n\n var sel = document.selection, range;\n var x = 0, y = 0;\n\n if (sel) {\n\n if (sel.type != \"Control\") {\n range = sel.createRange();\n range.collapse(true);\n x = range.boundingLeft;\n y = range.boundingTop;\n }\n\n } else if (window.getSelection) {\n\n sel = window.getSelection();\n\n if (sel.rangeCount) {\n\n range = sel.getRangeAt(0).cloneRange();\n if (range.getClientRects) {\n range.collapse(true);\n var rect = range.getClientRects()[0];\n x = rect.left;\n y = rect.top;\n }\n\n }\n }\n return { x: x, y: y };\n };\n\n /**\n * @private\n *\n * Returns selected text as String\n * @returns {string}\n */\n inline.getSelectionText = function getSelectionText(){\n\n var selectedText = \"\";\n\n if (window.getSelection){ // all modern browsers and IE9+\n selectedText = window.getSelection().toString();\n }\n\n return selectedText;\n };\n\n /** Opens buttons block */\n inline.showButtons = function() {\n\n var buttons = codex.nodes.inlineToolbar.buttons;\n buttons.classList.add('opened');\n\n codex.toolbar.inline.buttonsOpened = true;\n\n /** highlight buttons */\n codex.nodes.inlineToolbar.buttons.childNodes.forEach(codex.toolbar.inline.hightlight);\n\n };\n\n /** Makes buttons disappear */\n inline.closeButtons = function() {\n var buttons = codex.nodes.inlineToolbar.buttons;\n buttons.classList.remove('opened');\n\n codex.toolbar.inline.buttonsOpened = false;\n };\n\n /** Open buttons defined action if exist */\n inline.showActions = function() {\n var action = codex.nodes.inlineToolbar.actions;\n action.classList.add('opened');\n\n codex.toolbar.inline.actionsOpened = true;\n };\n\n /** Close actions block */\n inline.closeAction = function() {\n var action = codex.nodes.inlineToolbar.actions;\n action.innerHTML = '';\n action.classList.remove('opened');\n codex.toolbar.inline.actionsOpened = false;\n };\n\n /** Action for link creation or for setting anchor */\n inline.createLinkAction = function(event, type) {\n\n var isActive = this.isLinkActive();\n\n var editable = codex.content.currentNode,\n storedSelection = codex.toolbar.inline.storedSelection;\n\n if (isActive) {\n\n var selection = window.getSelection(),\n anchorNode = selection.anchorNode;\n\n storedSelection = codex.toolbar.inline.saveSelection(editable);\n\n /**\n * Changing stored selection. if we want to remove anchor from word\n * we should remove anchor from whole word, not only selected part.\n * The solution is than we get the length of current link\n * Change start position to - end of selection minus length of anchor\n */\n codex.toolbar.inline.restoreSelection(editable, storedSelection);\n\n codex.toolbar.inline.defaultToolAction('unlink');\n\n } else {\n\n /** Create input and close buttons */\n var action = codex.draw.inputForLink();\n codex.nodes.inlineToolbar.actions.appendChild(action);\n\n codex.toolbar.inline.closeButtons();\n codex.toolbar.inline.showActions();\n\n storedSelection = codex.toolbar.inline.saveSelection(editable);\n\n /**\n * focus to input\n * Solution: https://developer.mozilla.org/ru/docs/Web/API/HTMLElement/focus\n * Prevents event after showing input and when we need to focus an input which is in unexisted form\n */\n action.focus();\n event.preventDefault();\n\n /** Callback to link action */\n action.addEventListener('keydown', function(event){\n\n if (event.keyCode == codex.core.keys.ENTER) {\n\n codex.toolbar.inline.restoreSelection(editable, storedSelection);\n codex.toolbar.inline.setAnchor(action.value);\n\n /**\n * Preventing events that will be able to happen\n */\n event.preventDefault();\n event.stopImmediatePropagation();\n\n codex.toolbar.inline.clearRange();\n }\n\n }, false);\n }\n };\n\n inline.isLinkActive = function() {\n\n var isActive = false;\n\n codex.nodes.inlineToolbar.buttons.childNodes.forEach(function(tool) {\n var dataType = tool.dataset.type;\n\n if (dataType == 'link' && tool.classList.contains('hightlighted')) {\n isActive = true;\n }\n });\n\n return isActive;\n };\n\n /** default action behavior of tool */\n inline.defaultToolAction = function(type) {\n document.execCommand(type, false, null);\n };\n\n /**\n * @private\n *\n * Sets URL\n *\n * @param {String} url - URL\n */\n inline.setAnchor = function(url) {\n\n document.execCommand('createLink', false, url);\n\n /** Close after URL inserting */\n codex.toolbar.inline.closeAction();\n };\n\n /**\n * @private\n *\n * Saves selection\n */\n inline.saveSelection = function(containerEl) {\n\n var range = window.getSelection().getRangeAt(0),\n preSelectionRange = range.cloneRange(),\n start;\n\n preSelectionRange.selectNodeContents(containerEl);\n preSelectionRange.setEnd(range.startContainer, range.startOffset);\n\n start = preSelectionRange.toString().length;\n\n return {\n start: start,\n end: start + range.toString().length\n };\n };\n\n /**\n * @private\n *\n * Sets to previous selection (Range)\n *\n * @param {Element} containerEl - editable element where we restore range\n * @param {Object} savedSel - range basic information to restore\n */\n inline.restoreSelection = function(containerEl, savedSel) {\n\n var range = document.createRange(),\n charIndex = 0;\n\n range.setStart(containerEl, 0);\n range.collapse(true);\n\n var nodeStack = [containerEl],\n node,\n foundStart = false,\n stop = false,\n nextCharIndex;\n\n while (!stop && (node = nodeStack.pop())) {\n\n if (node.nodeType == 3) {\n\n nextCharIndex = charIndex + node.length;\n\n if (!foundStart && savedSel.start >= charIndex && savedSel.start <= nextCharIndex) {\n range.setStart(node, savedSel.start - charIndex);\n foundStart = true;\n }\n if (foundStart && savedSel.end >= charIndex && savedSel.end <= nextCharIndex) {\n range.setEnd(node, savedSel.end - charIndex);\n stop = true;\n }\n charIndex = nextCharIndex;\n } else {\n var i = node.childNodes.length;\n while (i--) {\n nodeStack.push(node.childNodes[i]);\n }\n }\n }\n\n var sel = window.getSelection();\n sel.removeAllRanges();\n sel.addRange(range);\n };\n\n /**\n * @private\n *\n * Removes all ranges from window selection\n */\n inline.clearRange = function() {\n var selection = window.getSelection();\n selection.removeAllRanges();\n };\n\n /**\n * @private\n *\n * sets or removes hightlight\n */\n inline.hightlight = function(tool) {\n var dataType = tool.dataset.type;\n\n if (document.queryCommandState(dataType)) {\n codex.toolbar.inline.setButtonHighlighted(tool);\n } else {\n codex.toolbar.inline.removeButtonsHighLight(tool);\n }\n\n /**\n *\n * hightlight for anchors\n */\n var selection = window.getSelection(),\n tag = selection.anchorNode.parentNode;\n\n if (tag.tagName == 'A' && dataType == 'link') {\n codex.toolbar.inline.setButtonHighlighted(tool);\n }\n };\n\n /**\n * @private\n *\n * Mark button if text is already executed\n */\n inline.setButtonHighlighted = function(button) {\n button.classList.add('hightlighted');\n\n /** At link tool we also change icon */\n if (button.dataset.type == 'link') {\n var icon = button.childNodes[0];\n icon.classList.remove('ce-icon-link');\n icon.classList.add('ce-icon-unlink');\n }\n };\n\n /**\n * @private\n *\n * Removes hightlight\n */\n inline.removeButtonsHighLight = function(button) {\n button.classList.remove('hightlighted');\n\n /** At link tool we also change icon */\n if (button.dataset.type == 'link') {\n var icon = button.childNodes[0];\n icon.classList.remove('ce-icon-unlink');\n icon.classList.add('ce-icon-link');\n }\n };\n\n\n return inline;\n})({});\n\ninline.init();\n\nmodule.exports = inline;\n\n\n/** WEBPACK FOOTER **\n ** ./modules/toolbar/inline.js\n **/","var codex = require('../../editor');\n\nvar toolbox = (function(toolbox) {\n\n toolbox.init = function() {\n require('./toolbar');\n };\n\n toolbox.opened = false;\n\n /** Shows toolbox */\n toolbox.open = function() {\n\n /** Close setting if toolbox is opened */\n if (codex.toolbar.settings.opened) {\n codex.toolbar.settings.close();\n }\n\n /** display toolbox */\n codex.nodes.toolbox.classList.add('opened');\n\n /** Animate plus button */\n codex.nodes.plusButton.classList.add('clicked');\n\n /** toolbox state */\n codex.toolbar.toolbox.opened = true;\n\n };\n\n /** Closes toolbox */\n toolbox.close = function() {\n\n /** Makes toolbox disapear */\n codex.nodes.toolbox.classList.remove('opened');\n\n /** Rotate plus button */\n codex.nodes.plusButton.classList.remove('clicked');\n\n /** toolbox state */\n codex.toolbar.toolbox.opened = false;\n\n };\n\n toolbox.leaf = function(){\n\n var currentTool = codex.toolbar.current,\n tools = Object.keys(codex.tools),\n barButtons = codex.nodes.toolbarButtons,\n nextToolIndex,\n toolToSelect;\n\n if ( !currentTool ) {\n\n /** Get first tool from object*/\n for (toolToSelect in barButtons) break;\n\n } else {\n\n nextToolIndex = tools.indexOf(currentTool) + 1;\n\n if ( nextToolIndex == tools.length) nextToolIndex = 0;\n\n toolToSelect = tools[nextToolIndex];\n\n }\n\n for (var button in barButtons) barButtons[button].classList.remove('selected');\n\n barButtons[toolToSelect].classList.add('selected');\n\n codex.toolbar.current = toolToSelect;\n\n };\n\n /**\n * Transforming selected node type into selected toolbar element type\n * @param {event} event\n */\n toolbox.toolClicked = function() {\n\n /**\n * UNREPLACEBLE_TOOLS this types of tools are forbidden to replace even they are empty\n */\n var UNREPLACEBLE_TOOLS = ['image', 'link', 'list', 'instagram', 'twitter'],\n tool = codex.tools[codex.toolbar.current],\n workingNode = codex.content.currentNode,\n currentInputIndex = codex.caret.inputIndex,\n newBlockContent,\n appendCallback,\n blockData;\n\n /** Make block from plugin */\n newBlockContent = tool.make();\n\n /** information about block */\n blockData = {\n block : newBlockContent,\n type : tool.type,\n stretched : false\n };\n\n if (\n workingNode &&\n UNREPLACEBLE_TOOLS.indexOf(workingNode.dataset.tool) === -1 &&\n workingNode.textContent.trim() === ''\n ){\n /** Replace current block */\n codex.content.switchBlock(workingNode, newBlockContent, tool.type);\n\n } else {\n\n /** Insert new Block from plugin */\n codex.content.insertBlock(blockData);\n\n /** increase input index */\n currentInputIndex++;\n\n }\n\n /** Fire tool append callback */\n appendCallback = tool.appendCallback;\n\n if (appendCallback && typeof appendCallback == 'function') {\n appendCallback.call(event);\n }\n\n setTimeout(function() {\n\n /** Set caret to current block */\n codex.caret.setToBlock(currentInputIndex);\n\n }, 10);\n\n\n /**\n * Changing current Node\n */\n codex.content.workingNodeChanged();\n\n /**\n * Move toolbar when node is changed\n */\n codex.toolbar.move();\n };\n\n return toolbox;\n\n})({});\n\ntoolbox.init();\n\nmodule.exports = toolbox;\n\n\n/** WEBPACK FOOTER **\n ** ./modules/toolbar/toolbox.js\n **/","var codex = require('../editor');\n\nvar tools = (function(tools) {\n\n return tools;\n\n})({});\n\ncodex.tools = tools;\nmodule.exports = tools;\n\n\n\n/** WEBPACK FOOTER **\n ** ./modules/tools.js\n **/","var codex = require('../editor');\n\nvar callbacks = (function(callbacks) {\n\n callbacks.redactorSyncTimeout = null;\n\n callbacks.globalKeydown = function(event){\n switch (event.keyCode){\n case codex.core.keys.TAB : codex.callback.tabKeyPressed(event); break;\n case codex.core.keys.ENTER : codex.callback.enterKeyPressed(event); break;\n case codex.core.keys.ESC : codex.callback.escapeKeyPressed(event); break;\n default : codex.callback.defaultKeyPressed(event); break;\n }\n };\n\n callbacks.globalKeyup = function(event){\n switch (event.keyCode){\n case codex.core.keys.UP :\n case codex.core.keys.LEFT :\n case codex.core.keys.RIGHT :\n case codex.core.keys.DOWN : codex.callback.arrowKeyPressed(event); break;\n }\n };\n\n callbacks.tabKeyPressed = function(event){\n\n if ( !codex.toolbar.opened ) {\n codex.toolbar.open();\n }\n\n if (codex.toolbar.opened && !codex.toolbar.toolbox.opened) {\n codex.toolbar.toolbox.open();\n } else {\n codex.toolbar.toolbox.leaf();\n }\n\n event.preventDefault();\n };\n\n /**\n * ENTER key handler\n * Makes new paragraph block\n */\n callbacks.enterKeyPressed = function(event){\n\n /** Set current node */\n var firstLevelBlocksArea = codex.callback.clickedOnFirstLevelBlockArea();\n\n if (firstLevelBlocksArea) {\n event.preventDefault();\n\n /**\n * it means that we lose input index, saved index before is not correct\n * therefore we need to set caret when we insert new block\n */\n codex.caret.inputIndex = -1;\n\n codex.callback.enterPressedOnBlock();\n return;\n }\n\n if (event.target.contentEditable == 'true') {\n\n /** Update input index */\n codex.caret.saveCurrentInputIndex();\n }\n\n if (!codex.content.currentNode) {\n /**\n * Enter key pressed in first-level block area\n */\n codex.callback.enterPressedOnBlock(event);\n return;\n }\n\n\n var currentInputIndex = codex.caret.getCurrentInputIndex() || 0,\n workingNode = codex.content.currentNode,\n tool = workingNode.dataset.tool,\n isEnterPressedOnToolbar = codex.toolbar.opened &&\n codex.toolbar.current &&\n event.target == codex.state.inputs[currentInputIndex];\n\n /** The list of tools which needs the default browser behaviour */\n var enableLineBreaks = codex.tools[tool].enableLineBreaks;\n\n /** This type of block creates when enter is pressed */\n var NEW_BLOCK_TYPE = 'paragraph';\n\n /**\n * When toolbar is opened, select tool instead of making new paragraph\n */\n if ( isEnterPressedOnToolbar ) {\n\n event.preventDefault();\n\n codex.toolbar.toolbox.toolClicked(event);\n\n codex.toolbar.close();\n\n return;\n\n }\n\n /**\n * Allow making new

in same block by SHIFT+ENTER and forbids to prevent default browser behaviour\n */\n if ( event.shiftKey && !enableLineBreaks) {\n codex.callback.enterPressedOnBlock(codex.content.currentBlock, event);\n event.preventDefault();\n\n } else if ( (event.shiftKey && !enableLineBreaks) || (!event.shiftKey && enableLineBreaks) ){\n /** XOR */\n return;\n }\n\n var isLastTextNode = false,\n currentSelection = window.getSelection(),\n currentSelectedNode = currentSelection.anchorNode,\n caretAtTheEndOfText = codex.caret.position.atTheEnd(),\n isTextNodeHasParentBetweenContenteditable = false;\n\n /**\n * Workaround situation when caret at the Text node that has some wrapper Elements\n * Split block cant handle this.\n * We need to save default behavior\n */\n isTextNodeHasParentBetweenContenteditable = currentSelectedNode && currentSelectedNode.parentNode.contentEditable != \"true\";\n\n /**\n * Split blocks when input has several nodes and caret placed in textNode\n */\n if (\n currentSelectedNode.nodeType == codex.core.nodeTypes.TEXT &&\n !isTextNodeHasParentBetweenContenteditable &&\n !caretAtTheEndOfText\n ){\n\n event.preventDefault();\n\n codex.core.log('Splitting Text node...');\n\n codex.content.splitBlock(currentInputIndex);\n\n /** Show plus button when next input after split is empty*/\n if (!codex.state.inputs[currentInputIndex + 1].textContent.trim()) {\n codex.toolbar.showPlusButton();\n }\n\n } else {\n\n if ( currentSelectedNode && currentSelectedNode.parentNode) {\n\n isLastTextNode = !currentSelectedNode.parentNode.nextSibling;\n\n }\n\n if ( isLastTextNode && caretAtTheEndOfText ) {\n\n event.preventDefault();\n\n codex.core.log('ENTER clicked in last textNode. Create new BLOCK');\n\n codex.content.insertBlock({\n type : NEW_BLOCK_TYPE,\n block : codex.tools[NEW_BLOCK_TYPE].render()\n }, true );\n\n codex.toolbar.move();\n codex.toolbar.open();\n\n /** Show plus button with empty block */\n codex.toolbar.showPlusButton();\n\n } else {\n\n codex.core.log('Default ENTER behavior.');\n\n }\n\n }\n\n /** get all inputs after new appending block */\n codex.ui.saveInputs();\n\n };\n\n callbacks.escapeKeyPressed = function(event){\n\n /** Close all toolbar */\n codex.toolbar.close();\n\n /** Close toolbox */\n codex.toolbar.toolbox.close();\n\n event.preventDefault();\n\n };\n\n callbacks.arrowKeyPressed = function(event){\n\n codex.content.workingNodeChanged();\n\n /* Closing toolbar */\n codex.toolbar.close();\n codex.toolbar.move();\n\n };\n\n callbacks.defaultKeyPressed = function(event) {\n\n codex.toolbar.close();\n\n if (!codex.toolbar.inline.actionsOpened) {\n codex.toolbar.inline.close();\n codex.content.clearMark();\n }\n };\n\n callbacks.redactorClicked = function (event) {\n\n codex.content.workingNodeChanged(event.target);\n\n codex.ui.saveInputs();\n\n var selectedText = codex.toolbar.inline.getSelectionText();\n\n /**\n * If selection range took off, then we hide inline toolbar\n */\n if (selectedText.length === 0) {\n codex.toolbar.inline.close();\n }\n\n /** Update current input index in memory when caret focused into existed input */\n if (event.target.contentEditable == 'true') {\n\n codex.caret.saveCurrentInputIndex();\n\n }\n\n if (codex.content.currentNode === null) {\n\n /**\n * If inputs in redactor does not exits, then we put input index 0 not -1\n */\n var indexOfLastInput = codex.state.inputs.length > 0 ? codex.state.inputs.length - 1 : 0;\n\n /** If we have any inputs */\n if (codex.state.inputs.length) {\n\n /** getting firstlevel parent of input */\n var firstLevelBlock = codex.content.getFirstLevelBlock(codex.state.inputs[indexOfLastInput]);\n }\n\n /** If input is empty, then we set caret to the last input */\n if (codex.state.inputs.length && codex.state.inputs[indexOfLastInput].textContent === '' && firstLevelBlock.dataset.tool == 'paragraph') {\n\n codex.caret.setToBlock(indexOfLastInput);\n\n } else {\n\n /** Create new input when caret clicked in redactors area */\n var NEW_BLOCK_TYPE = 'paragraph';\n\n codex.content.insertBlock({\n type : NEW_BLOCK_TYPE,\n block : codex.tools[NEW_BLOCK_TYPE].render()\n });\n\n /** If there is no inputs except inserted */\n if (codex.state.inputs.length === 1) {\n\n codex.caret.setToBlock(indexOfLastInput);\n\n } else {\n\n /** Set caret to this appended input */\n codex.caret.setToNextBlock(indexOfLastInput);\n }\n }\n\n /**\n * Move toolbar to the right position and open\n */\n codex.toolbar.move();\n\n\n codex.toolbar.open();\n\n } else {\n\n /**\n * Move toolbar to the new position and open\n */\n codex.toolbar.move();\n\n codex.toolbar.open();\n\n /** Close all panels */\n codex.toolbar.settings.close();\n codex.toolbar.toolbox.close();\n }\n\n\n var inputIsEmpty = !codex.content.currentNode.textContent.trim();\n\n if (inputIsEmpty) {\n\n /** Show plus button */\n codex.toolbar.showPlusButton();\n\n } else {\n\n /** Hide plus buttons */\n codex.toolbar.hidePlusButton();\n\n }\n\n var currentNodeType = codex.content.currentNode.dataset.tool;\n\n /** Mark current block*/\n if (currentNodeType != 'paragraph' || !inputIsEmpty) {\n\n codex.content.markBlock();\n\n }\n\n };\n\n /**\n * This method allows to define, is caret in contenteditable element or not.\n * Otherwise, if we get TEXT node from range container, that will means we have input index.\n * In this case we use default browsers behaviour (if plugin allows that) or overwritten action.\n * Therefore, to be sure that we've clicked first-level block area, we should have currentNode, which always\n * specifies to the first-level block. Other cases we just ignore.\n */\n callbacks.clickedOnFirstLevelBlockArea = function() {\n\n var selection = window.getSelection(),\n anchorNode = selection.anchorNode,\n flag = false;\n\n\n if (selection.rangeCount == 0) {\n\n return true;\n\n } else {\n\n if (!codex.core.isDomNode(anchorNode)) {\n anchorNode = anchorNode.parentNode;\n }\n\n /** Already founded, without loop */\n if (anchorNode.contentEditable == 'true') {\n flag = true;\n }\n\n while (anchorNode.contentEditable != 'true') {\n anchorNode = anchorNode.parentNode;\n\n if (anchorNode.contentEditable == 'true') {\n flag = true;\n }\n\n if (anchorNode == document.body) {\n break;\n }\n }\n\n /** If editable element founded, flag is \"TRUE\", Therefore we return \"FALSE\" */\n return flag ? false : true;\n }\n\n };\n\n /**\n * Toolbar button click handler\n * @param this - cursor to the button\n */\n callbacks.toolbarButtonClicked = function (event) {\n\n var button = this;\n\n codex.toolbar.current = button.dataset.type;\n\n codex.toolbar.toolbox.toolClicked(event);\n codex.toolbar.close();\n\n };\n\n callbacks.redactorInputEvent = function (event) {\n\n /**\n * Clear previous sync-timeout\n */\n if (this.redactorSyncTimeout){\n clearTimeout(this.redactorSyncTimeout);\n }\n\n /**\n * Start waiting to input finish and sync redactor\n */\n this.redactorSyncTimeout = setTimeout(function() {\n\n codex.content.sync();\n\n }, 500);\n\n };\n\n /** Show or Hide toolbox when plus button is clicked */\n callbacks.plusButtonClicked = function() {\n\n if (!codex.nodes.toolbox.classList.contains('opened')) {\n\n codex.toolbar.toolbox.open();\n\n } else {\n\n codex.toolbar.toolbox.close();\n\n }\n };\n\n /**\n * Block handlers for KeyDown events\n */\n callbacks.blockKeydown = function(event, block) {\n\n switch (event.keyCode){\n\n case codex.core.keys.DOWN:\n case codex.core.keys.RIGHT:\n codex.callback.blockRightOrDownArrowPressed(block);\n break;\n\n case codex.core.keys.BACKSPACE:\n codex.callback.backspacePressed(block);\n break;\n\n case codex.core.keys.UP:\n case codex.core.keys.LEFT:\n codex.callback.blockLeftOrUpArrowPressed(block);\n break;\n\n }\n };\n\n /**\n * RIGHT or DOWN keydowns on block\n */\n callbacks.blockRightOrDownArrowPressed = function (block) {\n\n var selection = window.getSelection(),\n inputs = codex.state.inputs,\n focusedNode = selection.anchorNode,\n focusedNodeHolder;\n\n /** Check for caret existance */\n if (!focusedNode){\n return false;\n }\n\n /** Looking for closest (parent) contentEditable element of focused node */\n while (focusedNode.contentEditable != 'true') {\n\n focusedNodeHolder = focusedNode.parentNode;\n focusedNode = focusedNodeHolder;\n }\n\n /** Input index in DOM level */\n var editableElementIndex = 0;\n while (focusedNode != inputs[editableElementIndex]) {\n editableElementIndex ++;\n }\n\n /**\n * Founded contentEditable element doesn't have childs\n * Or maybe New created block\n */\n if (!focusedNode.textContent)\n {\n codex.caret.setToNextBlock(editableElementIndex);\n return;\n }\n\n /**\n * Do nothing when caret doesn not reaches the end of last child\n */\n var caretInLastChild = false,\n caretAtTheEndOfText = false;\n\n var lastChild,\n deepestTextnode;\n\n lastChild = focusedNode.childNodes[focusedNode.childNodes.length - 1 ];\n\n if (codex.core.isDomNode(lastChild)) {\n\n deepestTextnode = codex.content.getDeepestTextNodeFromPosition(lastChild, lastChild.childNodes.length);\n\n } else {\n\n deepestTextnode = lastChild;\n\n }\n\n caretInLastChild = selection.anchorNode == deepestTextnode;\n caretAtTheEndOfText = deepestTextnode.length == selection.anchorOffset;\n\n if ( !caretInLastChild || !caretAtTheEndOfText ) {\n codex.core.log('arrow [down|right] : caret does not reached the end');\n return false;\n }\n\n codex.caret.setToNextBlock(editableElementIndex);\n\n };\n\n /**\n * LEFT or UP keydowns on block\n */\n callbacks.blockLeftOrUpArrowPressed = function (block) {\n\n var selection = window.getSelection(),\n inputs = codex.state.inputs,\n focusedNode = selection.anchorNode,\n focusedNodeHolder;\n\n /** Check for caret existance */\n if (!focusedNode){\n return false;\n }\n\n /**\n * LEFT or UP not at the beginning\n */\n if ( selection.anchorOffset !== 0) {\n return false;\n }\n\n /** Looking for parent contentEditable block */\n while (focusedNode.contentEditable != 'true') {\n focusedNodeHolder = focusedNode.parentNode;\n focusedNode = focusedNodeHolder;\n }\n\n /** Input index in DOM level */\n var editableElementIndex = 0;\n while (focusedNode != inputs[editableElementIndex]) {\n editableElementIndex ++;\n }\n\n /**\n * Do nothing if caret is not at the beginning of first child\n */\n var caretInFirstChild = false,\n caretAtTheBeginning = false;\n\n var firstChild,\n deepestTextnode;\n\n /**\n * Founded contentEditable element doesn't have childs\n * Or maybe New created block\n */\n if (!focusedNode.textContent) {\n codex.caret.setToPreviousBlock(editableElementIndex);\n return;\n }\n\n firstChild = focusedNode.childNodes[0];\n\n if (codex.core.isDomNode(firstChild)) {\n\n deepestTextnode = codex.content.getDeepestTextNodeFromPosition(firstChild, 0);\n\n } else {\n\n deepestTextnode = firstChild;\n\n }\n\n caretInFirstChild = selection.anchorNode == deepestTextnode;\n caretAtTheBeginning = selection.anchorOffset === 0;\n\n if ( caretInFirstChild && caretAtTheBeginning ) {\n\n codex.caret.setToPreviousBlock(editableElementIndex);\n\n }\n\n };\n\n /**\n * Callback for enter key pressing in first-level block area\n */\n callbacks.enterPressedOnBlock = function (event) {\n\n var NEW_BLOCK_TYPE = 'paragraph';\n\n codex.content.insertBlock({\n type : NEW_BLOCK_TYPE,\n block : codex.tools[NEW_BLOCK_TYPE].render()\n }, true );\n\n codex.toolbar.move();\n codex.toolbar.open();\n\n };\n\n callbacks.backspacePressed = function (block) {\n\n var currentInputIndex = codex.caret.getCurrentInputIndex(),\n range,\n selectionLength,\n firstLevelBlocksCount;\n\n if (block.textContent.trim()) {\n\n range = codex.content.getRange();\n selectionLength = range.endOffset - range.startOffset;\n\n if (codex.caret.position.atStart() && !selectionLength) {\n\n codex.content.mergeBlocks(currentInputIndex);\n\n } else {\n\n return;\n\n }\n }\n\n if (!selectionLength) {\n block.remove();\n }\n\n\n firstLevelBlocksCount = codex.nodes.redactor.childNodes.length;\n\n /**\n * If all blocks are removed\n */\n if (firstLevelBlocksCount === 0) {\n\n /** update currentNode variable */\n codex.content.currentNode = null;\n\n /** Inserting new empty initial block */\n codex.ui.addInitialBlock();\n\n /** Updating inputs state after deleting last block */\n codex.ui.saveInputs();\n\n /** Set to current appended block */\n setTimeout(function () {\n\n codex.caret.setToPreviousBlock(1);\n\n }, 10);\n\n } else {\n\n if (codex.caret.inputIndex !== 0) {\n\n /** Target block is not first */\n codex.caret.setToPreviousBlock(codex.caret.inputIndex);\n\n } else {\n\n /** If we try to delete first block */\n codex.caret.setToNextBlock(codex.caret.inputIndex);\n\n }\n }\n\n codex.toolbar.move();\n\n if (!codex.toolbar.opened) {\n codex.toolbar.open();\n }\n\n /** Updating inputs state */\n codex.ui.saveInputs();\n\n /** Prevent default browser behaviour */\n event.preventDefault();\n\n };\n\n callbacks.blockPaste = function(event) {\n\n var currentInputIndex = codex.caret.getCurrentInputIndex(),\n node = codex.state.inputs[currentInputIndex];\n\n setTimeout(function() {\n\n codex.content.sanitize(node);\n\n }, 10);\n\n };\n\n callbacks._blockPaste = function(event) {\n\n var currentInputIndex = codex.caret.getCurrentInputIndex();\n\n /**\n * create an observer instance\n */\n var observer = new MutationObserver(codex.callback.handlePasteEvents);\n\n /**\n * configuration of the observer:\n */\n var config = { attributes: true, childList: true, characterData: false };\n\n // pass in the target node, as well as the observer options\n observer.observe(codex.state.inputs[currentInputIndex], config);\n };\n\n /**\n * Sends all mutations to paste handler\n */\n callbacks.handlePasteEvents = function(mutations) {\n mutations.forEach(codex.content.paste);\n };\n\n /**\n * Clicks on block settings button\n */\n callbacks.showSettingsButtonClicked = function(){\n\n /**\n * Get type of current block\n * It uses to append settings from tool.settings property.\n * ...\n * Type is stored in data-type attribute on block\n */\n var currentToolType = codex.content.currentNode.dataset.tool;\n\n codex.toolbar.settings.toggle(currentToolType);\n\n /** Close toolbox when settings button is active */\n codex.toolbar.toolbox.close();\n codex.toolbar.settings.hideRemoveActions();\n\n };\n\n return callbacks;\n\n})({});\n\ncodex.callback = callbacks;\nmodule.exports = callbacks;\n\n\n\n/** WEBPACK FOOTER **\n ** ./modules/callbacks.js\n **/","var codex = require('../editor');\n\nvar draw = (function(draw) {\n\n /**\n * Base editor wrapper\n */\n draw.wrapper = function () {\n\n var wrapper = document.createElement('div');\n\n wrapper.className += 'codex-editor';\n\n return wrapper;\n\n };\n\n /**\n * Content-editable holder\n */\n draw.redactor = function () {\n\n var redactor = document.createElement('div');\n\n redactor.className += 'ce-redactor';\n\n return redactor;\n\n };\n\n draw.ceBlock = function() {\n\n var block = document.createElement('DIV');\n\n block.className += 'ce_block';\n\n return block;\n\n };\n\n /**\n * Empty toolbar with toggler\n */\n draw.toolbar = function () {\n\n var bar = document.createElement('div');\n\n bar.className += 'ce-toolbar';\n\n return bar;\n };\n\n draw.toolbarContent = function() {\n\n var wrapper = document.createElement('DIV');\n wrapper.classList.add('ce-toolbar__content');\n\n return wrapper;\n };\n\n /**\n * Inline toolbar\n */\n draw.inlineToolbar = function() {\n\n var bar = document.createElement('DIV');\n\n bar.className += 'ce-toolbar-inline';\n\n return bar;\n\n };\n\n /**\n * Wrapper for inline toobar buttons\n */\n draw.inlineToolbarButtons = function() {\n\n var wrapper = document.createElement('DIV');\n\n wrapper.className += 'ce-toolbar-inline__buttons';\n\n return wrapper;\n };\n\n /**\n * For some actions\n */\n draw.inlineToolbarActions = function() {\n\n var wrapper = document.createElement('DIV');\n\n wrapper.className += 'ce-toolbar-inline__actions';\n\n return wrapper;\n\n };\n\n draw.inputForLink = function() {\n\n var input = document.createElement('INPUT');\n\n input.type = 'input';\n input.className += 'inputForLink';\n input.placeholder = 'Type URL ...';\n input.setAttribute('form', 'defaultForm');\n\n input.setAttribute('autofocus', 'autofocus');\n\n return input;\n\n };\n\n /**\n * Block with notifications\n */\n draw.alertsHolder = function() {\n\n var block = document.createElement('div');\n\n block.classList.add('ce_notifications-block');\n\n return block;\n\n };\n\n /**\n * @todo Desc\n */\n draw.blockButtons = function() {\n\n var block = document.createElement('div');\n\n block.className += 'ce-toolbar__actions';\n\n return block;\n };\n\n /**\n * Block settings panel\n */\n draw.blockSettings = function () {\n\n var settings = document.createElement('div');\n\n settings.className += 'ce-settings';\n\n return settings;\n };\n\n draw.defaultSettings = function() {\n\n var div = document.createElement('div');\n\n div.classList.add('ce-settings_default');\n\n return div;\n },\n\n draw.pluginsSettings = function() {\n\n var div = document.createElement('div');\n\n div.classList.add('ce-settings_plugin');\n\n return div;\n\n };\n\n draw.plusButton = function() {\n\n var button = document.createElement('span');\n\n button.className = 'ce-toolbar__plus';\n // button.innerHTML = '';\n\n return button;\n };\n\n /**\n * Settings button in toolbar\n */\n draw.settingsButton = function () {\n\n var toggler = document.createElement('span');\n\n toggler.className = 'ce-toolbar__settings-btn';\n\n /** Toggler button*/\n toggler.innerHTML = '';\n\n return toggler;\n };\n\n /**\n * Redactor tools wrapper\n */\n\n draw.toolbox = function() {\n\n var wrapper = document.createElement('div');\n\n wrapper.className = 'ce-toolbar__tools';\n\n return wrapper;\n };\n\n /**\n * @protected\n *\n * Draws tool buttons for toolbox\n *\n * @param {String} type\n * @param {String} classname\n * @returns {Element}\n */\n draw.toolbarButton = function (type, classname) {\n\n var button = document.createElement(\"li\"),\n tool_icon = document.createElement(\"i\"),\n tool_title = document.createElement(\"span\");\n\n button.dataset.type = type;\n button.setAttribute('title', type);\n\n tool_icon.classList.add(classname);\n tool_title.classList.add('ce_toolbar_tools--title');\n\n\n button.appendChild(tool_icon);\n button.appendChild(tool_title);\n\n return button;\n\n };\n\n /**\n * @protected\n *\n * Draws tools for inline toolbar\n *\n * @param {String} type\n * @param {String} classname\n */\n draw.toolbarButtonInline = function(type, classname) {\n var button = document.createElement(\"BUTTON\"),\n tool_icon = document.createElement(\"I\");\n\n button.type = \"button\";\n button.dataset.type = type;\n tool_icon.classList.add(classname);\n\n button.appendChild(tool_icon);\n\n return button;\n };\n\n /**\n * Redactor block\n */\n draw.block = function (tagName, content) {\n\n var node = document.createElement(tagName);\n\n node.innerHTML = content || '';\n\n return node;\n\n };\n\n /**\n * Creates Node with passed tagName and className\n * @param {string} tagName\n * @param {string} className\n * @param {object} properties - allow to assign properties\n */\n draw.node = function( tagName , className , properties ){\n\n var el = document.createElement( tagName );\n\n if ( className ) el.className = className;\n\n if ( properties ) {\n\n for (var name in properties){\n el[name] = properties[name];\n }\n }\n\n return el;\n };\n\n draw.pluginsRender = function(type, content) {\n\n return {\n type : type,\n block : cEditor.tools[type].render({\n text : content\n })\n };\n };\n\n return draw;\n\n})({});\n\ncodex.draw = draw;\n\nmodule.exports = draw;\n\n\n\n\n\n/** WEBPACK FOOTER **\n ** ./modules/draw.js\n **/","var codex = require('../editor');\n\nvar caret = (function(caret) {\n\n /**\n * @var {int} InputIndex - editable element in DOM\n */\n caret.inputIndex = null;\n\n /**\n * @var {int} offset - caret position in a text node.\n */\n caret.offset = null;\n\n /**\n * @var {int} focusedNodeIndex - we get index of child node from first-level block\n */\n caret.focusedNodeIndex = null;\n\n /**\n * Creates Document Range and sets caret to the element.\n * @protected\n * @uses caret.save — if you need to save caret position\n * @param {Element} el - Changed Node.\n */\n caret.set = function( el , index, offset) {\n\n offset = offset || this.offset || 0;\n index = index || this.focusedNodeIndex || 0;\n\n var childs = el.childNodes,\n nodeToSet;\n\n if ( childs.length === 0 ) {\n\n nodeToSet = el;\n\n } else {\n\n nodeToSet = childs[index];\n\n }\n\n /** If Element is INPUT */\n if (el.tagName == 'INPUT') {\n el.focus();\n return;\n }\n\n if (codex.core.isDomNode(nodeToSet)) {\n\n nodeToSet = codex.content.getDeepestTextNodeFromPosition(nodeToSet, nodeToSet.childNodes.length);\n }\n\n var range = document.createRange(),\n selection = window.getSelection();\n\n setTimeout(function() {\n\n range.setStart(nodeToSet, offset);\n range.setEnd(nodeToSet, offset);\n\n selection.removeAllRanges();\n selection.addRange(range);\n\n codex.caret.saveCurrentInputIndex();\n\n }, 20);\n };\n\n /**\n * @protected\n * Updates index of input and saves it in caret object\n */\n caret.saveCurrentInputIndex = function () {\n\n /** Index of Input that we paste sanitized content */\n var selection = window.getSelection(),\n inputs = codex.state.inputs,\n focusedNode = selection.anchorNode,\n focusedNodeHolder;\n\n if (!focusedNode){\n return;\n }\n\n /** Looking for parent contentEditable block */\n while (focusedNode.contentEditable != 'true') {\n focusedNodeHolder = focusedNode.parentNode;\n focusedNode = focusedNodeHolder;\n }\n\n /** Input index in DOM level */\n var editableElementIndex = 0;\n\n while (focusedNode != inputs[editableElementIndex]) {\n editableElementIndex ++;\n }\n\n this.inputIndex = editableElementIndex;\n };\n\n /**\n * Returns current input index (caret object)\n */\n caret.getCurrentInputIndex = function() {\n return this.inputIndex;\n };\n\n /**\n * @param {int} index - index of first-level block after that we set caret into next input\n */\n caret.setToNextBlock = function(index) {\n\n var inputs = codex.state.inputs,\n nextInput = inputs[index + 1];\n\n if (!nextInput) {\n codex.core.log('We are reached the end');\n return;\n }\n\n /**\n * When new Block created or deleted content of input\n * We should add some text node to set caret\n */\n if (!nextInput.childNodes.length) {\n var emptyTextElement = document.createTextNode('');\n nextInput.appendChild(emptyTextElement);\n }\n\n codex.caret.inputIndex = index + 1;\n codex.caret.set(nextInput, 0, 0);\n codex.content.workingNodeChanged(nextInput);\n\n };\n\n /**\n * @param {int} index - index of target input.\n * Sets caret to input with this index\n */\n caret.setToBlock = function(index) {\n\n var inputs = codex.state.inputs,\n targetInput = inputs[index];\n\n console.assert( targetInput , 'caret.setToBlock: target input does not exists');\n\n if ( !targetInput ) {\n return;\n }\n\n /**\n * When new Block created or deleted content of input\n * We should add some text node to set caret\n */\n if (!targetInput.childNodes.length) {\n var emptyTextElement = document.createTextNode('');\n targetInput.appendChild(emptyTextElement);\n }\n\n codex.caret.inputIndex = index;\n codex.caret.set(targetInput, 0, 0);\n codex.content.workingNodeChanged(targetInput);\n\n };\n\n /**\n * @param {int} index - index of input\n */\n caret.setToPreviousBlock = function(index) {\n\n index = index || 0;\n\n var inputs = codex.state.inputs,\n previousInput = inputs[index - 1],\n lastChildNode,\n lengthOfLastChildNode,\n emptyTextElement;\n\n\n if (!previousInput) {\n codex.core.log('We are reached first node');\n return;\n }\n\n lastChildNode = codex.content.getDeepestTextNodeFromPosition(previousInput, previousInput.childNodes.length);\n lengthOfLastChildNode = lastChildNode.length;\n\n /**\n * When new Block created or deleted content of input\n * We should add some text node to set caret\n */\n if (!previousInput.childNodes.length) {\n\n emptyTextElement = document.createTextNode('');\n previousInput.appendChild(emptyTextElement);\n }\n codex.caret.inputIndex = index - 1;\n codex.caret.set(previousInput, previousInput.childNodes.length - 1, lengthOfLastChildNode);\n codex.content.workingNodeChanged(inputs[index - 1]);\n };\n\n caret.position = {\n\n atStart : function() {\n\n var selection = window.getSelection(),\n anchorOffset = selection.anchorOffset,\n anchorNode = selection.anchorNode,\n firstLevelBlock = codex.content.getFirstLevelBlock(anchorNode),\n pluginsRender = firstLevelBlock.childNodes[0];\n\n if (!codex.core.isDomNode(anchorNode)) {\n anchorNode = anchorNode.parentNode;\n }\n\n var isFirstNode = anchorNode === pluginsRender.childNodes[0],\n isOffsetZero = anchorOffset === 0;\n\n return isFirstNode && isOffsetZero;\n\n },\n\n atTheEnd : function() {\n\n var selection = window.getSelection(),\n anchorOffset = selection.anchorOffset,\n anchorNode = selection.anchorNode;\n\n /** Caret is at the end of input */\n return !anchorNode || !anchorNode.length || anchorOffset === anchorNode.length;\n }\n };\n\n return caret;\n\n})({});\n\ncodex.caret = caret;\nmodule.exports = caret;\n\n\n/** WEBPACK FOOTER **\n ** ./modules/caret.js\n **/","var codex = require('../editor');\n\nvar notifications = (function(notifications) {\n\n /**\n * Error notificator. Shows block with message\n * @protected\n */\n notifications.errorThrown = function(errorMsg, event) {\n\n codex.notifications.send('This action is not available currently', event.type, false);\n\n },\n\n /**\n * Appends notification with different types\n * @param message {string} - Error or alert message\n * @param type {string} - Type of message notification. Ex: Error, Warning, Danger ...\n * @param append {boolean} - can be True or False when notification should be inserted after\n */\n notifications.send = function(message, type, append) {\n\n var notification = codex.draw.block('div');\n\n notification.textContent = message;\n notification.classList.add('ce_notification-item', 'ce_notification-' + type, 'flipInX');\n\n if (!append) {\n codex.nodes.notifications.innerHTML = '';\n }\n\n codex.nodes.notifications.appendChild(notification);\n\n setTimeout(function () {\n notification.remove();\n }, 3000);\n\n };\n\n return notifications;\n\n})({});\n\ncodex.notifications = notifications;\nmodule.exports = notifications;\n\n\n/** WEBPACK FOOTER **\n ** ./modules/notifications.js\n **/","var codex = require('../editor');\n\nvar parser = (function(parser) {\n\n parser.init = function() {\n\n };\n\n /**\n * Splits content by `\\n` and returns blocks\n */\n parser.getSeparatedTexttSeparatedTextFromContent = function(content) {\n return content.split('\\n');\n };\n\n /** inserting text */\n parser.insertPastedContent = function(content) {\n\n var blocks = this.getSeparatedTextFromContent(content),\n i,\n inputIndex = cEditor.caret.getCurrentInputIndex(),\n textNode,\n parsedTextContent;\n\n for(i = 0; i < blocks.length; i++) {\n\n blocks[i].trim();\n\n if (blocks[i]) {\n var data = cEditor.draw.pluginsRender('paragraph', blocks[i]);\n cEditor.content.insertBlock(data);\n }\n }\n\n };\n\n /**\n * Asynchronously parses textarea input string to HTML editor blocks\n */\n parser.parseTextareaContent = function () {\n\n var initialContent = cEditor.nodes.textarea.value;\n\n if ( initialContent.trim().length === 0 ) return true;\n\n\n cEditor.parser\n\n /** Get child nodes async-aware */\n .getNodesFromString(initialContent)\n\n /** Then append nodes to the redactor */\n .then(cEditor.parser.appendNodesToRedactor)\n\n /** Write log if something goes wrong */\n .catch(function(error) {\n cEditor.core.log('Error while parsing content: %o', 'warn', error);\n });\n\n };\n\n /**\n * Parses string to nodeList\n * @param string inputString\n * @return Primise -> nodeList\n */\n parser.getNodesFromString = function (inputString) {\n\n return Promise.resolve().then(function() {\n\n var contentHolder = document.createElement('div');\n\n contentHolder.innerHTML = inputString;\n\n /**\n * Returning childNodes will include:\n * - Elements (html-tags),\n * - Texts (empty-spaces or non-wrapped strings )\n * - Comments and other\n */\n return contentHolder.childNodes;\n\n });\n };\n\n /**\n * Appends nodes to the redactor\n * @param nodeList nodes - list for nodes to append\n */\n parser.appendNodesToRedactor = function(nodes) {\n\n /**\n * Sequence of one-by-one nodes appending\n * Uses to save blocks order after async-handler\n */\n var nodeSequence = Promise.resolve();\n\n\n for (var index = 0; index < nodes.length ; index++ ) {\n\n /** Add node to sequence at specified index */\n cEditor.parser.appendNodeAtIndex(nodeSequence, nodes, index);\n\n }\n\n };\n\n /**\n * Append node at specified index\n */\n parser.appendNodeAtIndex = function (nodeSequence, nodes, index) {\n\n /** We need to append node to sequence */\n nodeSequence\n\n /** first, get node async-aware */\n .then(function() {\n\n return cEditor.parser.getNodeAsync(nodes , index);\n\n })\n\n /**\n * second, compose editor-block from node\n * and append it to redactor\n */\n .then(function(node){\n\n var block = cEditor.parser.createBlockByDomNode(node);\n\n if ( cEditor.core.isDomNode(block) ) {\n\n block.contentEditable = \"true\";\n\n /** Mark node as redactor block*/\n block.classList.add('ce-block');\n\n /** Append block to the redactor */\n cEditor.nodes.redactor.appendChild(block);\n\n /** Save block to the cEditor.state array */\n cEditor.state.blocks.push(block);\n\n return block;\n\n }\n return null;\n })\n\n .then(cEditor.ui.addBlockHandlers)\n\n /** Log if something wrong with node */\n .catch(function(error) {\n cEditor.core.log('Node skipped while parsing because %o', 'warn', error);\n });\n\n };\n\n /**\n * Asynchronously returns node from nodeList by index\n * @return Promise to node\n */\n parser.getNodeAsync = function (nodeList, index) {\n\n return Promise.resolve().then(function() {\n\n return nodeList.item(index);\n\n });\n };\n\n /**\n * Creates editor block by DOM node\n *\n * First-level blocks (see cEditor.settings.blockTags) saves as-is,\n * other wrapps with

-tag\n *\n * @param DOMnode node\n * @return First-level node (paragraph)\n */\n parser.createBlockByDomNode = function (node) {\n\n /** First level nodes already appears as blocks */\n if ( cEditor.parser.isFirstLevelBlock(node) ){\n\n /** Save plugin type in data-type */\n node = this.storeBlockType(node);\n\n return node;\n }\n\n /** Other nodes wraps into parent block (paragraph-tag) */\n var parentBlock,\n nodeContent = node.textContent.trim(),\n isPlainTextNode = node.nodeType != cEditor.core.nodeTypes.TAG;\n\n\n /** Skip empty textNodes with space-symbols */\n if (isPlainTextNode && !nodeContent.length) return null;\n\n /** Make

tag */\n parentBlock = cEditor.draw.block('P');\n\n if (isPlainTextNode){\n parentBlock.textContent = nodeContent.replace(/(\\s){2,}/, '$1'); // remove double spaces\n } else {\n parentBlock.appendChild(node);\n }\n\n /** Save plugin type in data-type */\n parentBlock = this.storeBlockType(parentBlock);\n\n return parentBlock;\n\n };\n\n /**\n * It's a crutch\n * - - - - - - -\n * We need block type stored as data-attr\n * Now supports only simple blocks : P, HEADER, QUOTE, CODE\n * Remove it after updating parser module for the block-oriented structure:\n * - each block must have stored type\n * @param {Element} node\n */\n parser.storeBlockType = function (node) {\n\n switch (node.tagName) {\n case 'P' : node.dataset.tool = 'paragraph'; break;\n case 'H1':\n case 'H2':\n case 'H3':\n case 'H4':\n case 'H5':\n case 'H6': node.dataset.tool = 'header'; break;\n case 'BLOCKQUOTE': node.dataset.tool = 'quote'; break;\n case 'CODE': node.dataset.tool = 'code'; break;\n }\n\n return node;\n\n };\n\n /**\n * Check DOM node for display style: separated block or child-view\n */\n parser.isFirstLevelBlock = function (node) {\n\n return node.nodeType == cEditor.core.nodeTypes.TAG &&\n node.classList.contains(cEditor.ui.className.BLOCK_CLASSNAME);\n\n };\n\n return parser;\n\n})({});\n\nparser.init();\n\ncodex.parser = parser;\nmodule.exports = parser;\n\n\n\n/** WEBPACK FOOTER **\n ** ./modules/parser.js\n **/"],"sourceRoot":""} \ No newline at end of file diff --git a/editor.css b/editor.css deleted file mode 100644 index 348322b7..00000000 --- a/editor.css +++ /dev/null @@ -1,267 +0,0 @@ -@font-face { - font-family: 'codex_editor'; - src: url('fonts/codex_editor/codex-editor.eot?20895205'); - src: url('fonts/codex_editor/codex-editor.eot?20895205#iefix') format('embedded-opentype'), - url('fonts/codex_editor/codex-editor.woff?20895205') format('woff'), - url('fonts/codex_editor/codex-editor.ttf?20895205') format('truetype'), - url('fonts/codex_editor/codex-editor.svg?20895205#codex_editor') format('svg'); - font-weight: normal; - font-style: normal; -} -[class^="ce-icon-"]:before, -[class*="ce-icon-"]:before { - font-family: "codex_editor"; - font-style: normal; - font-weight: normal; - speak: none; - - display: inline-block; - text-decoration: inherit; - width: 1em; - margin-right: .2em; - text-align: center; - font-variant: normal; - text-transform: none; - - line-height: 1em; - - /* Animation center compensation - margins should be symmetric */ - margin-left: .2em; - - -moz-osx-font-smoothing: grayscale; -} - -.ce-icon-instagram:before { content: '\e800'; } /* '' */ -.ce-icon-picture:before { content: '\e801'; } /* '' */ -.ce-icon-cog:before { content: '\e802'; } /* '' */ -.ce-icon-link:before { content: '\e803'; } /* '' */ -.ce-icon-unlink:before { content: '\e804'; } /* '' */ -.ce-icon-code:before { content: '\e805'; } /* '' */ -.ce-icon-quote:before { content: '\e806'; } /* '' */ -.ce-icon-trash:before { content: '\e807'; } /* '' */ -.ce-icon-down-big:before { content: '\e808'; } /* '' */ -.ce-icon-up-big:before { content: '\e809'; } /* '' */ -.ce-icon-header:before { content: '\e80a'; } /* '' */ -.ce-icon-paragraph:before { content: '\e80b'; } /* '' */ -.ce-icon-align-left:before { content: '\e80c'; } /* '' */ -.ce-icon-align-center:before { content: '\e80d'; } /* '' */ -.ce-icon-align-right:before { content: '\e80e'; } /* '' */ -.ce-icon-font:before { content: '\e80f'; } /* '' */ -.ce-icon-bold:before { content: '\e810'; } /* '' */ -.ce-icon-medium:before { content: '\e811'; } /* '' */ -.ce-icon-italic:before { content: '\e812'; } /* '' */ -.ce-icon-list-bullet:before { content: '\e813'; } /* '' */ -.ce-icon-list-numbered:before { content: '\e814'; } /* '' */ -.ce-icon-strike:before { content: '\e815'; } /* '' */ -.ce-icon-underline:before { content: '\e816'; } /* '' */ -.ce-icon-table:before { content: '\e817'; } /* '' */ -.ce-icon-ellipsis-vert:before { content: '\e818'; } /* '' */ -.ce-icon-columns:before { content: '\e819'; } /* '' */ -.ce-icon-smile:before { content: '\e81a'; } /* '' */ -.ce-icon-newspaper:before { content: '\e81b'; } /* '' */ -.ce-icon-twitter:before { content: '\e81c'; } /* '' */ -.ce-icon-facebook-squared:before { content: '\e81d'; } /* '' */ -.ce-icon-vkontakte:before { content: '\e81e'; } /* '' */ - - - -/* EDITOR */ - -.ce_wrapper { - position: relative; -} - -.ce_redactor { - position: relative; - outline: none; - padding: 1px 0; -} - -.ce_toolbar{ - position: absolute; - z-index: 2; - - margin-left: -1px; - - background: #414758; - /*background: #fff;*/ - /*border: 1px solid #e3e7ee;*/ - /*box-shadow: 0 2px 11px rgba(27,39,54,.11);*/ - /*color: #2e394b;*/ - border-radius: 3px; - color: #bab9d8; - - display: none; - -} - .ce_toolbar.opened{ - display: block; - - /*animation-name: bounceIn; animation-duration: 200ms; animation-iteration-count: 1;*/ - } - - - .ce_toolbar .toggler{ - /*background: #f8f9fd;*/ - background: #34384a; - /*color: #6485d0;*/ - color: #05ff9b; - cursor: pointer; - border-radius: 3px 0 0 3px - } - .ce_toolbar .toggler, - .ce_toolbar li - { - display: inline-block; - margin: 0 !important; - padding: 12px; - cursor: pointer; - font-size: 14px; - } - .ce_toolbar .selected, - .ce_toolbar .toggler:hover, - .ce_toolbar li:hover - { - background: #36374e; - color: #85aeff; - } - - .ce_toolbar .settings_btn{ - font-size: 1.1em; - } - - -/** Block settings panel */ - -.ce_block_settings{ - position: absolute; - z-index: 2; - padding: 25px 30px; - - background: #32384c !important; - color: #81839e; - - overflow: hidden; - - background: #fff; - border-radius: 0 0 3px 3px; - font-size: 14px; - - display: none; -} - .ce_block_settings.opened{ - display: block; - } - - -/** Typography styles */ - -.ce_redactor p{ - padding: 5px 0; - font-size: 1em; - line-height: 1.7em; - margin: 0; -} -.ce_redactor ul, -.ce_redactor ol{ - list-style-position: inside; -} -.ce_redactor li{ - margin: 5px 0; -} - - - -.ce_redactor .ce_block{ - padding: 10px; - /*margin: -1px;*/ - /*border: 1px dotted #ccc;*/ - background: #fff; - outline: none; -} - .ce_redactor .ce_block:focus{ - background: #fbfbfb; - border-radius: 3px; - } - -/* -} - -@-moz-keyframes bounceIn { - 0% {opacity: 0;-moz-transform: scale(.3);} - 50% {opacity: 1;-moz-transform: scale(1.05);} - 70% {-moz-transform: scale(.9);} - 100% {-moz-transform: scale(1);} -} -@-o-keyframes bounceIn { - 0% {opacity: 0;-o-transform: scale(.3);} - 50% {opacity: 1;-o-transform: scale(1.05);} - 70% {-o-transform: scale(.9);} - 100% {-o-transform: scale(1);} -} -@keyframes bounceIn { - 0% {opacity: 0;transform: scale(.3);} - 50% {opacity: 1;transform: scale(1.07);} - 70% {transform: scale(.9);} - 100% {transform: scale(1);} -} - -.bounceIn { - -moz-animation-name: bounceIn; -moz-animation-duration: 600ms; -moz-animation-iteration-count: 1; - -o-animation-name: bounceIn; -o-animation-duration: 600ms; -o-animation-iteration-count: 1; - animation-name: bounceIn; animation-duration: 600ms; animation-iteration-count: 1; -} -*/ - - -/** Alerts */ -.ce_notifications-block { - position: fixed; - top: 0; - right: 0; - left: 0; -} - .ce_notification-item { - padding: 15px 25px; - font-size: 14px; - text-align: center; - animation-duration: 1s; - animation-iteration-count: 1; - animation-fill-mode: both; - } - - .ce_notification-error { - background: #e5f3ed; - color: #55818c; - } - - @keyframes flipInX { - from { - transform: perspective(400px) rotate3d(1, 0, 0, 90deg); - animation-timing-function: ease-in; - opacity: 0; - } - - 40% { - transform: perspective(400px) rotate3d(1, 0, 0, -20deg); - animation-timing-function: ease-in; - } - - 60% { - transform: perspective(400px) rotate3d(1, 0, 0, 10deg); - opacity: 1; - } - - 80% { - transform: perspective(400px) rotate3d(1, 0, 0, -5deg); - } - - to { - transform: perspective(400px); - } - } - - .flipInX { - backface-visibility: visible !important; - animation-name: flipInX; - } diff --git a/editor.js b/editor.js new file mode 100644 index 00000000..995bff89 --- /dev/null +++ b/editor.js @@ -0,0 +1,129 @@ +var codex = (function(codex){ + + var init = function() { + + require('./modules/core'); + require('./modules/ui'); + require('./modules/transport'); + require('./modules/renderer'); + require('./modules/saver'); + require('./modules/content'); + require('./modules/toolbar/toolbar'); + require('./modules/tools'); + require('./modules/callbacks'); + require('./modules/draw'); + require('./modules/caret'); + require('./modules/notifications'); + require('./modules/parser'); + }; + + /** + * @public + * + * holds initial settings + */ + codex.settings = { + tools : ['paragraph', 'header', 'picture', 'list', 'quote', 'code', 'twitter', 'instagram', 'smile'], + textareaId: 'codex-editor', + uploadImagesUrl: '/editor/transport/', + + // Type of block showing on empty editor + initialBlockPlugin: "paragraph" + }; + + /** + * public + * + * Static nodes + */ + codex.nodes = { + textarea : null, + wrapper : null, + toolbar : null, + inlineToolbar : { + wrapper : null, + buttons : null, + actions : null + }, + toolbox : null, + notifications : null, + plusButton : null, + showSettingsButton: null, + showTrashButton : null, + blockSettings : null, + pluginSettings : null, + defaultSettings : null, + toolbarButtons : {}, // { type : DomEl, ... } + redactor : null + }; + + /** + * @public + * + * Output state + */ + codex.state = { + jsonOutput: [], + blocks : [], + inputs : [] + }; + + /** + * Initialization + * @uses Promise cEditor.core.prepare + * @param {} userSettings are : + * - tools [], + * - textareaId String + * ... + * + * Load user defined tools + * Tools must contain this important objects : + * @param {String} type - this is a type of plugin. It can be used as plugin name + * @param {String} iconClassname - this a icon in toolbar + * @param {Object} make - what should plugin do, when it is clicked + * @param {Object} appendCallback - callback after clicking + * @param {Element} settings - what settings does it have + * @param {Object} render - plugin get JSON, and should return HTML + * @param {Object} save - plugin gets HTML content, returns JSON + * @param {Boolean} displayInToolbox - will be displayed in toolbox. Default value is TRUE + * @param {Boolean} enableLineBreaks - inserts new block or break lines. Default value is FALSE + * + * @example + * - type : 'header', + * - iconClassname : 'ce-icon-header', + * - make : headerTool.make, + * - appendCallback : headerTool.appendCallback, + * - settings : headerTool.makeSettings(), + * - render : headerTool.render, + * - save : headerTool.save, + * - displayInToolbox : true, + * - enableLineBreaks : false + */ + codex.start = function (userSettings) { + + init(); + + this.core.prepare(userSettings) + + // If all ok, make UI, bind events and parse initial-content + .then(this.ui.make) + .then(this.ui.addTools) + .then(this.ui.bindEvents) + .then(this.ui.preparePlugins) + .then(this.transport.prepare) + .then(this.renderer.makeBlocksFromData) + .then(this.ui.saveInputs) + .catch(function (error) { + codex.core.log('Initialization failed with error: %o', 'warn', error); + }); + + }; + + return codex; + +})({}); + +module.exports = codex; + + + diff --git a/example.html b/example.html index 1880c262..91f97dc2 100644 --- a/example.html +++ b/example.html @@ -1,445 +1,27 @@ - + - - CodeX Editor - - - - - + + Title - - -

- -

CodeX Editor

- - -
-
-
- - - -
- -
- - + + - - - + + + - - - - - - - - - - - - - - - - - - - - + + diff --git a/fonts/codex_editor/icon-plus.svg b/fonts/codex_editor/icon-plus.svg new file mode 100644 index 00000000..fdc0776c --- /dev/null +++ b/fonts/codex_editor/icon-plus.svg @@ -0,0 +1,16 @@ + + + + Combined Shape + Created with Sketch. + + + + + + + + + + + \ No newline at end of file diff --git a/icons.css b/icons.css new file mode 100644 index 00000000..b8914486 --- /dev/null +++ b/icons.css @@ -0,0 +1,63 @@ +@font-face { + font-family: 'codex_editor'; + src: url('fonts/codex_editor/codex-editor.eot?20895205'); + src: url('fonts/codex_editor/codex-editor.eot?20895205#iefix') format('embedded-opentype'), + url('fonts/codex_editor/codex-editor.woff?20895205') format('woff'), + url('fonts/codex_editor/codex-editor.ttf?20895205') format('truetype'), + url('fonts/codex_editor/codex-editor.svg?20895205#codex_editor') format('svg'); + font-weight: normal; + font-style: normal; +} +[class^="ce-icon-"]:before, +[class*="ce-icon-"]:before { + font-family: "codex_editor"; + font-style: normal; + font-weight: normal; + speak: none; + + display: inline-block; + text-decoration: inherit; + width: 1em; + margin-right: .2em; + text-align: center; + font-variant: normal; + text-transform: none; + + line-height: 1em; + + /* Animation center compensation - margins should be symmetric */ + margin-left: .2em; + + -moz-osx-font-smoothing: grayscale; +} +.ce-icon-instagram:before { content: '\e800'; } /* '' */ +.ce-icon-picture:before { content: '\e801'; } /* '' */ +.ce-icon-cog:before { content: '\e802'; } /* '' */ +.ce-icon-link:before { content: '\e803'; } /* '' */ +.ce-icon-unlink:before { content: '\e804'; } /* '' */ +.ce-icon-code:before { content: '\e805'; } /* '' */ +.ce-icon-quote:before { content: '\e806'; } /* '' */ +.ce-icon-trash:before { content: '\e807'; } /* '' */ +.ce-icon-down-big:before { content: '\e808'; } /* '' */ +.ce-icon-up-big:before { content: '\e809'; } /* '' */ +.ce-icon-header:before { content: '\e80a'; } /* '' */ +.ce-icon-paragraph:before { content: '\e80b'; } /* '' */ +.ce-icon-align-left:before { content: '\e80c'; } /* '' */ +.ce-icon-align-center:before { content: '\e80d'; } /* '' */ +.ce-icon-align-right:before { content: '\e80e'; } /* '' */ +.ce-icon-font:before { content: '\e80f'; } /* '' */ +.ce-icon-bold:before { content: '\e810'; } /* '' */ +.ce-icon-medium:before { content: '\e811'; } /* '' */ +.ce-icon-italic:before { content: '\e812'; } /* '' */ +.ce-icon-list-bullet:before { content: '\e813'; } /* '' */ +.ce-icon-list-numbered:before { content: '\e814'; } /* '' */ +.ce-icon-strike:before { content: '\e815'; } /* '' */ +.ce-icon-underline:before { content: '\e816'; } /* '' */ +.ce-icon-table:before { content: '\e817'; } /* '' */ +.ce-icon-ellipsis-vert:before { content: '\e818'; } /* '' */ +.ce-icon-columns:before { content: '\e819'; } /* '' */ +.ce-icon-smile:before { content: '\e81a'; } /* '' */ +.ce-icon-newspaper:before { content: '\e81b'; } /* '' */ +.ce-icon-twitter:before { content: '\e81c'; } /* '' */ +.ce-icon-facebook-squared:before { content: '\e81d'; } /* '' */ +.ce-icon-vkontakte:before { content: '\e81e'; } /* '' */ diff --git a/index.js b/index.js new file mode 100644 index 00000000..39bffcb0 --- /dev/null +++ b/index.js @@ -0,0 +1,8 @@ +/** + * + */ + +'use strict'; + +var editor = require('./editor'); +module.exports = editor; diff --git a/modules/callbacks.js b/modules/callbacks.js new file mode 100644 index 00000000..70f9d729 --- /dev/null +++ b/modules/callbacks.js @@ -0,0 +1,758 @@ +var codex = require('../editor'); + +var callbacks = (function(callbacks) { + + callbacks.redactorSyncTimeout = null; + + callbacks.globalKeydown = function(event){ + switch (event.keyCode){ + case codex.core.keys.TAB : codex.callback.tabKeyPressed(event); break; + case codex.core.keys.ENTER : codex.callback.enterKeyPressed(event); break; + case codex.core.keys.ESC : codex.callback.escapeKeyPressed(event); break; + default : codex.callback.defaultKeyPressed(event); break; + } + }; + + callbacks.globalKeyup = function(event){ + switch (event.keyCode){ + case codex.core.keys.UP : + case codex.core.keys.LEFT : + case codex.core.keys.RIGHT : + case codex.core.keys.DOWN : codex.callback.arrowKeyPressed(event); break; + } + }; + + callbacks.tabKeyPressed = function(event){ + + if ( !codex.toolbar.opened ) { + codex.toolbar.open(); + } + + if (codex.toolbar.opened && !codex.toolbar.toolbox.opened) { + codex.toolbar.toolbox.open(); + } else { + codex.toolbar.toolbox.leaf(); + } + + event.preventDefault(); + }; + + /** + * ENTER key handler + * Makes new paragraph block + */ + callbacks.enterKeyPressed = function(event){ + + /** Set current node */ + var firstLevelBlocksArea = codex.callback.clickedOnFirstLevelBlockArea(); + + if (firstLevelBlocksArea) { + event.preventDefault(); + + /** + * it means that we lose input index, saved index before is not correct + * therefore we need to set caret when we insert new block + */ + codex.caret.inputIndex = -1; + + codex.callback.enterPressedOnBlock(); + return; + } + + if (event.target.contentEditable == 'true') { + + /** Update input index */ + codex.caret.saveCurrentInputIndex(); + } + + if (!codex.content.currentNode) { + /** + * Enter key pressed in first-level block area + */ + codex.callback.enterPressedOnBlock(event); + return; + } + + + var currentInputIndex = codex.caret.getCurrentInputIndex() || 0, + workingNode = codex.content.currentNode, + tool = workingNode.dataset.tool, + isEnterPressedOnToolbar = codex.toolbar.opened && + codex.toolbar.current && + event.target == codex.state.inputs[currentInputIndex]; + + /** The list of tools which needs the default browser behaviour */ + var enableLineBreaks = codex.tools[tool].enableLineBreaks; + + /** This type of block creates when enter is pressed */ + var NEW_BLOCK_TYPE = 'paragraph'; + + /** + * When toolbar is opened, select tool instead of making new paragraph + */ + if ( isEnterPressedOnToolbar ) { + + event.preventDefault(); + + codex.toolbar.toolbox.toolClicked(event); + + codex.toolbar.close(); + + return; + + } + + /** + * Allow making new

in same block by SHIFT+ENTER and forbids to prevent default browser behaviour + */ + if ( event.shiftKey && !enableLineBreaks) { + codex.callback.enterPressedOnBlock(codex.content.currentBlock, event); + event.preventDefault(); + + } else if ( (event.shiftKey && !enableLineBreaks) || (!event.shiftKey && enableLineBreaks) ){ + /** XOR */ + return; + } + + var isLastTextNode = false, + currentSelection = window.getSelection(), + currentSelectedNode = currentSelection.anchorNode, + caretAtTheEndOfText = codex.caret.position.atTheEnd(), + isTextNodeHasParentBetweenContenteditable = false; + + /** + * Workaround situation when caret at the Text node that has some wrapper Elements + * Split block cant handle this. + * We need to save default behavior + */ + isTextNodeHasParentBetweenContenteditable = currentSelectedNode && currentSelectedNode.parentNode.contentEditable != "true"; + + /** + * Split blocks when input has several nodes and caret placed in textNode + */ + if ( + currentSelectedNode.nodeType == codex.core.nodeTypes.TEXT && + !isTextNodeHasParentBetweenContenteditable && + !caretAtTheEndOfText + ){ + + event.preventDefault(); + + codex.core.log('Splitting Text node...'); + + codex.content.splitBlock(currentInputIndex); + + /** Show plus button when next input after split is empty*/ + if (!codex.state.inputs[currentInputIndex + 1].textContent.trim()) { + codex.toolbar.showPlusButton(); + } + + } else { + + if ( currentSelectedNode && currentSelectedNode.parentNode) { + + isLastTextNode = !currentSelectedNode.parentNode.nextSibling; + + } + + if ( isLastTextNode && caretAtTheEndOfText ) { + + event.preventDefault(); + + codex.core.log('ENTER clicked in last textNode. Create new BLOCK'); + + codex.content.insertBlock({ + type : NEW_BLOCK_TYPE, + block : codex.tools[NEW_BLOCK_TYPE].render() + }, true ); + + codex.toolbar.move(); + codex.toolbar.open(); + + /** Show plus button with empty block */ + codex.toolbar.showPlusButton(); + + } else { + + codex.core.log('Default ENTER behavior.'); + + } + + } + + /** get all inputs after new appending block */ + codex.ui.saveInputs(); + + }; + + callbacks.escapeKeyPressed = function(event){ + + /** Close all toolbar */ + codex.toolbar.close(); + + /** Close toolbox */ + codex.toolbar.toolbox.close(); + + event.preventDefault(); + + }; + + callbacks.arrowKeyPressed = function(event){ + + codex.content.workingNodeChanged(); + + /* Closing toolbar */ + codex.toolbar.close(); + codex.toolbar.move(); + + }; + + callbacks.defaultKeyPressed = function(event) { + + codex.toolbar.close(); + + if (!codex.toolbar.inline.actionsOpened) { + codex.toolbar.inline.close(); + codex.content.clearMark(); + } + }; + + callbacks.redactorClicked = function (event) { + + codex.content.workingNodeChanged(event.target); + + codex.ui.saveInputs(); + + var selectedText = codex.toolbar.inline.getSelectionText(); + + /** + * If selection range took off, then we hide inline toolbar + */ + if (selectedText.length === 0) { + codex.toolbar.inline.close(); + } + + /** Update current input index in memory when caret focused into existed input */ + if (event.target.contentEditable == 'true') { + + codex.caret.saveCurrentInputIndex(); + + } + + if (codex.content.currentNode === null) { + + /** + * If inputs in redactor does not exits, then we put input index 0 not -1 + */ + var indexOfLastInput = codex.state.inputs.length > 0 ? codex.state.inputs.length - 1 : 0; + + /** If we have any inputs */ + if (codex.state.inputs.length) { + + /** getting firstlevel parent of input */ + var firstLevelBlock = codex.content.getFirstLevelBlock(codex.state.inputs[indexOfLastInput]); + } + + /** If input is empty, then we set caret to the last input */ + if (codex.state.inputs.length && codex.state.inputs[indexOfLastInput].textContent === '' && firstLevelBlock.dataset.tool == 'paragraph') { + + codex.caret.setToBlock(indexOfLastInput); + + } else { + + /** Create new input when caret clicked in redactors area */ + var NEW_BLOCK_TYPE = 'paragraph'; + + codex.content.insertBlock({ + type : NEW_BLOCK_TYPE, + block : codex.tools[NEW_BLOCK_TYPE].render() + }); + + /** If there is no inputs except inserted */ + if (codex.state.inputs.length === 1) { + + codex.caret.setToBlock(indexOfLastInput); + + } else { + + /** Set caret to this appended input */ + codex.caret.setToNextBlock(indexOfLastInput); + } + } + + /** + * Move toolbar to the right position and open + */ + codex.toolbar.move(); + + + codex.toolbar.open(); + + } else { + + /** + * Move toolbar to the new position and open + */ + codex.toolbar.move(); + + codex.toolbar.open(); + + /** Close all panels */ + codex.toolbar.settings.close(); + codex.toolbar.toolbox.close(); + } + + + var inputIsEmpty = !codex.content.currentNode.textContent.trim(); + + if (inputIsEmpty) { + + /** Show plus button */ + codex.toolbar.showPlusButton(); + + } else { + + /** Hide plus buttons */ + codex.toolbar.hidePlusButton(); + + } + + var currentNodeType = codex.content.currentNode.dataset.tool; + + /** Mark current block*/ + if (currentNodeType != 'paragraph' || !inputIsEmpty) { + + codex.content.markBlock(); + + } + + }; + + /** + * This method allows to define, is caret in contenteditable element or not. + * Otherwise, if we get TEXT node from range container, that will means we have input index. + * In this case we use default browsers behaviour (if plugin allows that) or overwritten action. + * Therefore, to be sure that we've clicked first-level block area, we should have currentNode, which always + * specifies to the first-level block. Other cases we just ignore. + */ + callbacks.clickedOnFirstLevelBlockArea = function() { + + var selection = window.getSelection(), + anchorNode = selection.anchorNode, + flag = false; + + + if (selection.rangeCount == 0) { + + return true; + + } else { + + if (!codex.core.isDomNode(anchorNode)) { + anchorNode = anchorNode.parentNode; + } + + /** Already founded, without loop */ + if (anchorNode.contentEditable == 'true') { + flag = true; + } + + while (anchorNode.contentEditable != 'true') { + anchorNode = anchorNode.parentNode; + + if (anchorNode.contentEditable == 'true') { + flag = true; + } + + if (anchorNode == document.body) { + break; + } + } + + /** If editable element founded, flag is "TRUE", Therefore we return "FALSE" */ + return flag ? false : true; + } + + }; + + /** + * Toolbar button click handler + * @param this - cursor to the button + */ + callbacks.toolbarButtonClicked = function (event) { + + var button = this; + + codex.toolbar.current = button.dataset.type; + + codex.toolbar.toolbox.toolClicked(event); + codex.toolbar.close(); + + }; + + callbacks.redactorInputEvent = function (event) { + + /** + * Clear previous sync-timeout + */ + if (this.redactorSyncTimeout){ + clearTimeout(this.redactorSyncTimeout); + } + + /** + * Start waiting to input finish and sync redactor + */ + this.redactorSyncTimeout = setTimeout(function() { + + codex.content.sync(); + + }, 500); + + }; + + /** Show or Hide toolbox when plus button is clicked */ + callbacks.plusButtonClicked = function() { + + if (!codex.nodes.toolbox.classList.contains('opened')) { + + codex.toolbar.toolbox.open(); + + } else { + + codex.toolbar.toolbox.close(); + + } + }; + + /** + * Block handlers for KeyDown events + */ + callbacks.blockKeydown = function(event, block) { + + switch (event.keyCode){ + + case codex.core.keys.DOWN: + case codex.core.keys.RIGHT: + codex.callback.blockRightOrDownArrowPressed(block); + break; + + case codex.core.keys.BACKSPACE: + codex.callback.backspacePressed(block); + break; + + case codex.core.keys.UP: + case codex.core.keys.LEFT: + codex.callback.blockLeftOrUpArrowPressed(block); + break; + + } + }; + + /** + * RIGHT or DOWN keydowns on block + */ + callbacks.blockRightOrDownArrowPressed = function (block) { + + var selection = window.getSelection(), + inputs = codex.state.inputs, + focusedNode = selection.anchorNode, + focusedNodeHolder; + + /** Check for caret existance */ + if (!focusedNode){ + return false; + } + + /** Looking for closest (parent) contentEditable element of focused node */ + while (focusedNode.contentEditable != 'true') { + + focusedNodeHolder = focusedNode.parentNode; + focusedNode = focusedNodeHolder; + } + + /** Input index in DOM level */ + var editableElementIndex = 0; + while (focusedNode != inputs[editableElementIndex]) { + editableElementIndex ++; + } + + /** + * Founded contentEditable element doesn't have childs + * Or maybe New created block + */ + if (!focusedNode.textContent) + { + codex.caret.setToNextBlock(editableElementIndex); + return; + } + + /** + * Do nothing when caret doesn not reaches the end of last child + */ + var caretInLastChild = false, + caretAtTheEndOfText = false; + + var lastChild, + deepestTextnode; + + lastChild = focusedNode.childNodes[focusedNode.childNodes.length - 1 ]; + + if (codex.core.isDomNode(lastChild)) { + + deepestTextnode = codex.content.getDeepestTextNodeFromPosition(lastChild, lastChild.childNodes.length); + + } else { + + deepestTextnode = lastChild; + + } + + caretInLastChild = selection.anchorNode == deepestTextnode; + caretAtTheEndOfText = deepestTextnode.length == selection.anchorOffset; + + if ( !caretInLastChild || !caretAtTheEndOfText ) { + codex.core.log('arrow [down|right] : caret does not reached the end'); + return false; + } + + codex.caret.setToNextBlock(editableElementIndex); + + }; + + /** + * LEFT or UP keydowns on block + */ + callbacks.blockLeftOrUpArrowPressed = function (block) { + + var selection = window.getSelection(), + inputs = codex.state.inputs, + focusedNode = selection.anchorNode, + focusedNodeHolder; + + /** Check for caret existance */ + if (!focusedNode){ + return false; + } + + /** + * LEFT or UP not at the beginning + */ + if ( selection.anchorOffset !== 0) { + return false; + } + + /** Looking for parent contentEditable block */ + while (focusedNode.contentEditable != 'true') { + focusedNodeHolder = focusedNode.parentNode; + focusedNode = focusedNodeHolder; + } + + /** Input index in DOM level */ + var editableElementIndex = 0; + while (focusedNode != inputs[editableElementIndex]) { + editableElementIndex ++; + } + + /** + * Do nothing if caret is not at the beginning of first child + */ + var caretInFirstChild = false, + caretAtTheBeginning = false; + + var firstChild, + deepestTextnode; + + /** + * Founded contentEditable element doesn't have childs + * Or maybe New created block + */ + if (!focusedNode.textContent) { + codex.caret.setToPreviousBlock(editableElementIndex); + return; + } + + firstChild = focusedNode.childNodes[0]; + + if (codex.core.isDomNode(firstChild)) { + + deepestTextnode = codex.content.getDeepestTextNodeFromPosition(firstChild, 0); + + } else { + + deepestTextnode = firstChild; + + } + + caretInFirstChild = selection.anchorNode == deepestTextnode; + caretAtTheBeginning = selection.anchorOffset === 0; + + if ( caretInFirstChild && caretAtTheBeginning ) { + + codex.caret.setToPreviousBlock(editableElementIndex); + + } + + }; + + /** + * Callback for enter key pressing in first-level block area + */ + callbacks.enterPressedOnBlock = function (event) { + + var NEW_BLOCK_TYPE = 'paragraph'; + + codex.content.insertBlock({ + type : NEW_BLOCK_TYPE, + block : codex.tools[NEW_BLOCK_TYPE].render() + }, true ); + + codex.toolbar.move(); + codex.toolbar.open(); + + }; + + callbacks.backspacePressed = function (block) { + + var currentInputIndex = codex.caret.getCurrentInputIndex(), + range, + selectionLength, + firstLevelBlocksCount; + + if (block.textContent.trim()) { + + range = codex.content.getRange(); + selectionLength = range.endOffset - range.startOffset; + + if (codex.caret.position.atStart() && !selectionLength) { + + codex.content.mergeBlocks(currentInputIndex); + + } else { + + return; + + } + } + + if (!selectionLength) { + block.remove(); + } + + + firstLevelBlocksCount = codex.nodes.redactor.childNodes.length; + + /** + * If all blocks are removed + */ + if (firstLevelBlocksCount === 0) { + + /** update currentNode variable */ + codex.content.currentNode = null; + + /** Inserting new empty initial block */ + codex.ui.addInitialBlock(); + + /** Updating inputs state after deleting last block */ + codex.ui.saveInputs(); + + /** Set to current appended block */ + setTimeout(function () { + + codex.caret.setToPreviousBlock(1); + + }, 10); + + } else { + + if (codex.caret.inputIndex !== 0) { + + /** Target block is not first */ + codex.caret.setToPreviousBlock(codex.caret.inputIndex); + + } else { + + /** If we try to delete first block */ + codex.caret.setToNextBlock(codex.caret.inputIndex); + + } + } + + codex.toolbar.move(); + + if (!codex.toolbar.opened) { + codex.toolbar.open(); + } + + /** Updating inputs state */ + codex.ui.saveInputs(); + + /** Prevent default browser behaviour */ + event.preventDefault(); + + }; + + callbacks.blockPaste = function(event) { + + var currentInputIndex = codex.caret.getCurrentInputIndex(), + node = codex.state.inputs[currentInputIndex]; + + setTimeout(function() { + + codex.content.sanitize(node); + + }, 10); + + }; + + callbacks._blockPaste = function(event) { + + var currentInputIndex = codex.caret.getCurrentInputIndex(); + + /** + * create an observer instance + */ + var observer = new MutationObserver(codex.callback.handlePasteEvents); + + /** + * configuration of the observer: + */ + var config = { attributes: true, childList: true, characterData: false }; + + // pass in the target node, as well as the observer options + observer.observe(codex.state.inputs[currentInputIndex], config); + }; + + /** + * Sends all mutations to paste handler + */ + callbacks.handlePasteEvents = function(mutations) { + mutations.forEach(codex.content.paste); + }; + + /** + * Clicks on block settings button + */ + callbacks.showSettingsButtonClicked = function(){ + + /** + * Get type of current block + * It uses to append settings from tool.settings property. + * ... + * Type is stored in data-type attribute on block + */ + var currentToolType = codex.content.currentNode.dataset.tool; + + codex.toolbar.settings.toggle(currentToolType); + + /** Close toolbox when settings button is active */ + codex.toolbar.toolbox.close(); + codex.toolbar.settings.hideRemoveActions(); + + }; + + return callbacks; + +})({}); + +codex.callback = callbacks; +module.exports = callbacks; diff --git a/modules/caret.js b/modules/caret.js new file mode 100644 index 00000000..743f06e1 --- /dev/null +++ b/modules/caret.js @@ -0,0 +1,241 @@ +var codex = require('../editor'); + +var caret = (function(caret) { + + /** + * @var {int} InputIndex - editable element in DOM + */ + caret.inputIndex = null; + + /** + * @var {int} offset - caret position in a text node. + */ + caret.offset = null; + + /** + * @var {int} focusedNodeIndex - we get index of child node from first-level block + */ + caret.focusedNodeIndex = null; + + /** + * Creates Document Range and sets caret to the element. + * @protected + * @uses caret.save — if you need to save caret position + * @param {Element} el - Changed Node. + */ + caret.set = function( el , index, offset) { + + offset = offset || this.offset || 0; + index = index || this.focusedNodeIndex || 0; + + var childs = el.childNodes, + nodeToSet; + + if ( childs.length === 0 ) { + + nodeToSet = el; + + } else { + + nodeToSet = childs[index]; + + } + + /** If Element is INPUT */ + if (el.tagName == 'INPUT') { + el.focus(); + return; + } + + if (codex.core.isDomNode(nodeToSet)) { + + nodeToSet = codex.content.getDeepestTextNodeFromPosition(nodeToSet, nodeToSet.childNodes.length); + } + + var range = document.createRange(), + selection = window.getSelection(); + + setTimeout(function() { + + range.setStart(nodeToSet, offset); + range.setEnd(nodeToSet, offset); + + selection.removeAllRanges(); + selection.addRange(range); + + codex.caret.saveCurrentInputIndex(); + + }, 20); + }; + + /** + * @protected + * Updates index of input and saves it in caret object + */ + caret.saveCurrentInputIndex = function () { + + /** Index of Input that we paste sanitized content */ + var selection = window.getSelection(), + inputs = codex.state.inputs, + focusedNode = selection.anchorNode, + focusedNodeHolder; + + if (!focusedNode){ + return; + } + + /** Looking for parent contentEditable block */ + while (focusedNode.contentEditable != 'true') { + focusedNodeHolder = focusedNode.parentNode; + focusedNode = focusedNodeHolder; + } + + /** Input index in DOM level */ + var editableElementIndex = 0; + + while (focusedNode != inputs[editableElementIndex]) { + editableElementIndex ++; + } + + this.inputIndex = editableElementIndex; + }; + + /** + * Returns current input index (caret object) + */ + caret.getCurrentInputIndex = function() { + return this.inputIndex; + }; + + /** + * @param {int} index - index of first-level block after that we set caret into next input + */ + caret.setToNextBlock = function(index) { + + var inputs = codex.state.inputs, + nextInput = inputs[index + 1]; + + if (!nextInput) { + codex.core.log('We are reached the end'); + return; + } + + /** + * When new Block created or deleted content of input + * We should add some text node to set caret + */ + if (!nextInput.childNodes.length) { + var emptyTextElement = document.createTextNode(''); + nextInput.appendChild(emptyTextElement); + } + + codex.caret.inputIndex = index + 1; + codex.caret.set(nextInput, 0, 0); + codex.content.workingNodeChanged(nextInput); + + }; + + /** + * @param {int} index - index of target input. + * Sets caret to input with this index + */ + caret.setToBlock = function(index) { + + var inputs = codex.state.inputs, + targetInput = inputs[index]; + + console.assert( targetInput , 'caret.setToBlock: target input does not exists'); + + if ( !targetInput ) { + return; + } + + /** + * When new Block created or deleted content of input + * We should add some text node to set caret + */ + if (!targetInput.childNodes.length) { + var emptyTextElement = document.createTextNode(''); + targetInput.appendChild(emptyTextElement); + } + + codex.caret.inputIndex = index; + codex.caret.set(targetInput, 0, 0); + codex.content.workingNodeChanged(targetInput); + + }; + + /** + * @param {int} index - index of input + */ + caret.setToPreviousBlock = function(index) { + + index = index || 0; + + var inputs = codex.state.inputs, + previousInput = inputs[index - 1], + lastChildNode, + lengthOfLastChildNode, + emptyTextElement; + + + if (!previousInput) { + codex.core.log('We are reached first node'); + return; + } + + lastChildNode = codex.content.getDeepestTextNodeFromPosition(previousInput, previousInput.childNodes.length); + lengthOfLastChildNode = lastChildNode.length; + + /** + * When new Block created or deleted content of input + * We should add some text node to set caret + */ + if (!previousInput.childNodes.length) { + + emptyTextElement = document.createTextNode(''); + previousInput.appendChild(emptyTextElement); + } + codex.caret.inputIndex = index - 1; + codex.caret.set(previousInput, previousInput.childNodes.length - 1, lengthOfLastChildNode); + codex.content.workingNodeChanged(inputs[index - 1]); + }; + + caret.position = { + + atStart : function() { + + var selection = window.getSelection(), + anchorOffset = selection.anchorOffset, + anchorNode = selection.anchorNode, + firstLevelBlock = codex.content.getFirstLevelBlock(anchorNode), + pluginsRender = firstLevelBlock.childNodes[0]; + + if (!codex.core.isDomNode(anchorNode)) { + anchorNode = anchorNode.parentNode; + } + + var isFirstNode = anchorNode === pluginsRender.childNodes[0], + isOffsetZero = anchorOffset === 0; + + return isFirstNode && isOffsetZero; + + }, + + atTheEnd : function() { + + var selection = window.getSelection(), + anchorOffset = selection.anchorOffset, + anchorNode = selection.anchorNode; + + /** Caret is at the end of input */ + return !anchorNode || !anchorNode.length || anchorOffset === anchorNode.length; + } + }; + + return caret; + +})({}); + +codex.caret = caret; +module.exports = caret; \ No newline at end of file diff --git a/modules/content.js b/modules/content.js new file mode 100644 index 00000000..99576dc5 --- /dev/null +++ b/modules/content.js @@ -0,0 +1,631 @@ +var codex = require('../editor'); + +var content = (function(content) { + + content.currentNode = null; + + /** + * Synchronizes redactor with original textarea + */ + content.sync = function () { + + codex.core.log('syncing...'); + + /** + * Save redactor content to codex.state + */ + codex.state.html = codex.nodes.redactor.innerHTML; + + }; + + /** + * @deprecated + */ + content.getNodeFocused = function() { + + var selection = window.getSelection(), + focused; + + if (selection.anchorNode === null) { + return null; + } + + if ( selection.anchorNode.nodeType == codex.core.nodeTypes.TAG ) { + focused = selection.anchorNode; + } else { + focused = selection.focusNode.parentElement; + } + + if ( !codex.parser.isFirstLevelBlock(focused) ) { + + /** Iterate with parent nodes to find first-level*/ + var parent = focused.parentNode; + + while (parent && !codex.parser.isFirstLevelBlock(parent)){ + parent = parent.parentNode; + } + + focused = parent; + } + + if (focused != codex.nodes.redactor){ + return focused; + } + + return null; + + }; + + /** + * Appends background to the block + */ + content.markBlock = function() { + + codex.content.currentNode.classList.add(codex.ui.className.BLOCK_HIGHLIGHTED); + }; + + /** + * Clear background + */ + content.clearMark = function() { + + if (codex.content.currentNode) { + codex.content.currentNode.classList.remove(codex.ui.className.BLOCK_HIGHLIGHTED); + } + + }; + + /** + * @private + * + * Finds first-level block + * @param {Element} node - selected or clicked in redactors area node + */ + content.getFirstLevelBlock = function(node) { + + if (!codex.core.isDomNode(node)) { + node = node.parentNode; + } + + if (node === codex.nodes.redactor || node === document.body) { + + return null; + + } else { + + while(!node.classList.contains(codex.ui.className.BLOCK_CLASSNAME)) { + node = node.parentNode; + } + + return node; + } + + }; + + /** + * Trigger this event when working node changed + * @param {Element} targetNode - first-level of this node will be current + * If targetNode is first-level then we set it as current else we look for parents to find first-level + */ + content.workingNodeChanged = function (targetNode) { + + /** Clear background from previous marked block before we change */ + codex.content.clearMark(); + + if (!targetNode) { + return; + } + + this.currentNode = this.getFirstLevelBlock(targetNode); + + }; + + /** + * Replaces one redactor block with another + * @protected + * @param {Element} targetBlock - block to replace. Mostly currentNode. + * @param {Element} newBlock + * @param {string} newBlockType - type of new block; we need to store it to data-attribute + * + * [!] Function does not saves old block content. + * You can get it manually and pass with newBlock.innerHTML + */ + content.replaceBlock = function function_name(targetBlock, newBlock) { + + if (!targetBlock || !newBlock){ + codex.core.log('replaceBlock: missed params'); + return; + } + + /** If target-block is not a frist-level block, then we iterate parents to find it */ + while(!targetBlock.classList.contains(codex.ui.className.BLOCK_CLASSNAME)) { + targetBlock = targetBlock.parentNode; + } + + /** Replacing */ + codex.nodes.redactor.replaceChild(newBlock, targetBlock); + + /** + * Set new node as current + */ + codex.content.workingNodeChanged(newBlock); + + /** + * Add block handlers + */ + codex.ui.addBlockHandlers(newBlock); + + /** + * Save changes + */ + codex.ui.saveInputs(); + + }; + + /** + * @private + * + * Inserts new block to redactor + * Wrapps block into a DIV with BLOCK_CLASSNAME class + * + * @param blockData {object} + * @param blockData.block {Element} element with block content + * @param blockData.type {string} block plugin + * @param needPlaceCaret {bool} pass true to set caret in new block + * + */ + content.insertBlock = function( blockData, needPlaceCaret ) { + + var workingBlock = codex.content.currentNode, + newBlockContent = blockData.block, + blockType = blockData.type, + isStretched = blockData.stretched; + + var newBlock = codex.content.composeNewBlock(newBlockContent, blockType, isStretched); + + if (workingBlock) { + + codex.core.insertAfter(workingBlock, newBlock); + + } else { + /** + * If redactor is empty, append as first child + */ + codex.nodes.redactor.appendChild(newBlock); + + } + + /** + * Block handler + */ + codex.ui.addBlockHandlers(newBlock); + + /** + * Set new node as current + */ + codex.content.workingNodeChanged(newBlock); + + /** + * Save changes + */ + codex.ui.saveInputs(); + + + if ( needPlaceCaret ) { + + /** + * If we don't know input index then we set default value -1 + */ + var currentInputIndex = codex.caret.getCurrentInputIndex() || -1; + + + if (currentInputIndex == -1) { + + + var editableElement = newBlock.querySelector('[contenteditable]'), + emptyText = document.createTextNode(''); + + editableElement.appendChild(emptyText); + codex.caret.set(editableElement, 0, 0); + + codex.toolbar.move(); + codex.toolbar.showPlusButton(); + + + } else { + + /** Timeout for browsers execution */ + setTimeout(function () { + + /** Setting to the new input */ + codex.caret.setToNextBlock(currentInputIndex); + codex.toolbar.move(); + codex.toolbar.open(); + + }, 10); + + } + + } + + }; + + /** + * Replaces blocks with saving content + * @protected + * @param {Element} noteToReplace + * @param {Element} newNode + * @param {Element} blockType + */ + content.switchBlock = function(blockToReplace, newBlock, tool){ + + var newBlockComposed = codex.content.composeNewBlock(newBlock, tool); + + /** Replacing */ + codex.content.replaceBlock(blockToReplace, newBlockComposed); + + /** Save new Inputs when block is changed */ + codex.ui.saveInputs(); + }; + + /** + * Iterates between child noted and looking for #text node on deepest level + * @private + * @param {Element} block - node where find + * @param {int} postiton - starting postion + * Example: childNodex.length to find from the end + * or 0 to find from the start + * @return {Text} block + * @uses DFS + */ + content.getDeepestTextNodeFromPosition = function (block, position) { + + /** + * Clear Block from empty and useless spaces with trim. + * Such nodes we should remove + */ + var blockChilds = block.childNodes, + index, + node, + text; + + for(index = 0; index < blockChilds.length; index++) + { + node = blockChilds[index]; + + if (node.nodeType == codex.core.nodeTypes.TEXT) { + + text = node.textContent.trim(); + + /** Text is empty. We should remove this child from node before we start DFS + * decrease the quantity of childs. + */ + if (text === '') { + + block.removeChild(node); + position--; + } + } + } + + if (block.childNodes.length === 0) { + return document.createTextNode(''); + } + + /** Setting default position when we deleted all empty nodes */ + if ( position < 0 ) + position = 1; + + var looking_from_start = false; + + /** For looking from START */ + if (position === 0) { + looking_from_start = true; + position = 1; + } + + while ( position ) { + + /** initial verticle of node. */ + if ( looking_from_start ) { + block = block.childNodes[0]; + } else { + block = block.childNodes[position - 1]; + } + + if ( block.nodeType == codex.core.nodeTypes.TAG ){ + + position = block.childNodes.length; + + } else if (block.nodeType == codex.core.nodeTypes.TEXT ){ + + position = 0; + } + + } + + return block; + }; + + /** + * @private + */ + content.composeNewBlock = function (block, tool, isStretched) { + + var newBlock = codex.draw.node('DIV', codex.ui.className.BLOCK_CLASSNAME, {}), + blockContent = codex.draw.node('DIV', codex.ui.className.BLOCK_CONTENT, {}); + + blockContent.appendChild(block); + newBlock.appendChild(blockContent); + + if (isStretched) { + blockContent.classList.add(codex.ui.className.BLOCK_STRETCHED); + } + + newBlock.dataset.tool = tool; + return newBlock; + }; + + /** + * Returns Range object of current selection + */ + content.getRange = function() { + + var selection = window.getSelection().getRangeAt(0); + + return selection; + }; + + /** + * Divides block in two blocks (after and before caret) + * @private + * @param {Int} inputIndex - target input index + */ + content.splitBlock = function(inputIndex) { + + var selection = window.getSelection(), + anchorNode = selection.anchorNode, + anchorNodeText = anchorNode.textContent, + caretOffset = selection.anchorOffset, + textBeforeCaret, + textNodeBeforeCaret, + textAfterCaret, + textNodeAfterCaret; + + var currentBlock = codex.content.currentNode.querySelector('[contentEditable]'); + + + textBeforeCaret = anchorNodeText.substring(0, caretOffset); + textAfterCaret = anchorNodeText.substring(caretOffset); + + textNodeBeforeCaret = document.createTextNode(textBeforeCaret); + + if (textAfterCaret) { + textNodeAfterCaret = document.createTextNode(textAfterCaret); + } + + var previousChilds = [], + nextChilds = [], + reachedCurrent = false; + + if (textNodeAfterCaret) { + nextChilds.push(textNodeAfterCaret); + } + + for ( var i = 0, child; !!(child = currentBlock.childNodes[i]); i++) { + + if ( child != anchorNode ) { + if ( !reachedCurrent ){ + previousChilds.push(child); + } else { + nextChilds.push(child); + } + } else { + reachedCurrent = true; + } + + } + + /** Clear current input */ + codex.state.inputs[inputIndex].innerHTML = ''; + + /** + * Append all childs founded before anchorNode + */ + var previousChildsLength = previousChilds.length; + + for(i = 0; i < previousChildsLength; i++) { + codex.state.inputs[inputIndex].appendChild(previousChilds[i]); + } + + codex.state.inputs[inputIndex].appendChild(textNodeBeforeCaret); + + /** + * Append text node which is after caret + */ + var nextChildsLength = nextChilds.length, + newNode = document.createElement('div'); + + for(i = 0; i < nextChildsLength; i++) { + newNode.appendChild(nextChilds[i]); + } + + newNode = newNode.innerHTML; + + /** This type of block creates when enter is pressed */ + var NEW_BLOCK_TYPE = 'paragraph'; + + /** + * Make new paragraph with text after caret + */ + codex.content.insertBlock({ + type : NEW_BLOCK_TYPE, + block : codex.tools[NEW_BLOCK_TYPE].render({ + text : newNode, + }) + }, true ); + + }; + + /** + * Merges two blocks — current and target + * If target index is not exist, then previous will be as target + */ + content.mergeBlocks = function(currentInputIndex, targetInputIndex) { + + /** If current input index is zero, then prevent method execution */ + if (currentInputIndex === 0) { + return; + } + + var targetInput, + currentInputContent = codex.state.inputs[currentInputIndex].innerHTML; + + if (!targetInputIndex) { + + targetInput = codex.state.inputs[currentInputIndex - 1]; + + } else { + + targetInput = codex.state.inputs[targetInputIndex]; + + } + + targetInput.innerHTML += currentInputContent; + }; + + /** + * @private + * + * Callback for HTML Mutations + * @param {Array} mutation - Mutation Record + */ + content.paste = function(mutation) { + + var workingNode = codex.content.currentNode, + tool = workingNode.dataset.tool; + + if (codex.tools[tool].allowedToPaste) { + codex.content.sanitize(mutation.addedNodes); + } else { + codex.content.pasteTextContent(mutation.addedNodes); + } + + }; + + /** + * @private + * + * gets only text/plain content of node + * @param {Element} target - HTML node + */ + content.pasteTextContent = function(nodes) { + + var node = nodes[0], + textNode = document.createTextNode(node.textContent); + + if (codex.core.isDomNode(node)) { + node.parentNode.replaceChild(textNode, node); + } + }; + + /** + * @private + * + * Sanitizes HTML content + * @param {Element} target - inserted element + * @uses DFS function for deep searching + */ + content.sanitize = function(target) { + + if (!target) { + return; + } + + for (var i = 0; i < target.childNodes.length; i++) { + this.dfs(target.childNodes[i]); + } + }; + + /** + * Clears styles + * @param {Element|Text} + */ + content.clearStyles = function(target) { + + var href, + newNode = null, + blockTags = ['P', 'BLOCKQUOTE', 'UL', 'CODE', 'OL', 'LI', 'H1', 'H2', 'H3', 'H4', 'H5', 'H6', 'DIV', 'PRE', 'HEADER', 'SECTION'], + allowedTags = ['P', 'B', 'I', 'A', 'U', 'BR'], + needReplace = !allowedTags.includes(target.tagName), + isDisplayedAsBlock = blockTags.includes(target.tagName); + + if (!codex.core.isDomNode(target)){ + return target; + } + + if (!target.parentNode){ + return target; + } + + if (needReplace) { + + if (isDisplayedAsBlock) { + + newNode = document.createElement('P'); + newNode.innerHTML = target.innerHTML; + target.parentNode.replaceChild(newNode, target); + target = newNode; + + } else { + + newNode = document.createTextNode(` ${target.textContent} `); + newNode.textContent = newNode.textContent.replace(/\s{2,}/g, ' '); + target.parentNode.replaceChild(newNode, target); + + } + } + + /** keep href attributes of tag A */ + if (target.tagName == 'A') { + href = target.getAttribute('href'); + } + + /** Remove all tags */ + while(target.attributes.length > 0) { + target.removeAttribute(target.attributes[0].name); + } + + /** return href */ + if (href) { + target.setAttribute('href', href); + } + + return target; + + }; + + /** + * Depth-first search Algorithm + * returns all childs + * @param {Element} + */ + content.dfs = function(el) { + + if (!codex.core.isDomNode(el)) + return; + + var sanitized = this.clearStyles(el); + + for(var i = 0; i < sanitized.childNodes.length; i++) { + this.dfs(sanitized.childNodes[i]); + } + + }; + + return content; + +})({}); + +codex.content = content; +module.exports = content; \ No newline at end of file diff --git a/modules/core.js b/modules/core.js new file mode 100644 index 00000000..9bbfeecb --- /dev/null +++ b/modules/core.js @@ -0,0 +1,181 @@ +var codex = require('./../editor'); + +var core = (function(core) { + + /** + * @public + * + * Editor preparing method + * @return Promise + */ + core.prepare = function (userSettings) { + + return new Promise(function(resolve, reject) { + + if ( userSettings ){ + + codex.settings.tools = userSettings.tools || codex.settings.tools; + + } + + if (userSettings.data) { + codex.state.blocks = userSettings.data; + } + + codex.nodes.textarea = document.getElementById(userSettings.textareaId || codex.settings.textareaId); + + if (typeof codex.nodes.textarea === undefined || codex.nodes.textarea === null) { + reject(Error("Textarea wasn't found by ID: #" + userSettings.textareaId)); + } else { + resolve(); + } + + }); + + }; + + /** + * Logging method + * @param type = ['log', 'info', 'warn'] + */ + core.log = function (msg, type, arg) { + + type = type || 'log'; + + if (!arg) { + arg = msg || 'undefined'; + msg = '[codex-editor]: %o'; + } else { + msg = '[codex-editor]: ' + msg; + } + + try{ + if ( 'console' in window && console[ type ] ){ + if ( arg ) console[ type ]( msg , arg ); + else console[ type ]( msg ); + } + + }catch(e){} + + }; + + /** + * @protected + * + * Helper for insert one element after another + */ + core.insertAfter = function (target, element) { + target.parentNode.insertBefore(element, target.nextSibling); + }; + + /** + * @const + * + * Readable DOM-node types map + */ + core.nodeTypes = { + TAG : 1, + TEXT : 3, + COMMENT : 8 + }; + + /** + * @const + * Readable keys map + */ + core.keys = { BACKSPACE: 8, TAB: 9, ENTER: 13, SHIFT: 16, CTRL: 17, ALT: 18, ESC: 27, SPACE: 32, LEFT: 37, UP: 38, DOWN: 40, RIGHT: 39, DELETE: 46, META: 91 }; + + /** + * @protected + * + * Check object for DOM node + */ + core.isDomNode = function (el) { + return el && typeof el === 'object' && el.nodeType && el.nodeType == this.nodeTypes.TAG; + }; + + /** + * Native Ajax + */ + core.ajax = function (data) { + + if (!data || !data.url){ + return; + } + + var XMLHTTP = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP"), + success_function = function(){}, + params = '', + obj; + + data.async = true; + data.type = data.type || 'GET'; + data.data = data.data || ''; + data['content-type'] = data['content-type'] || 'application/json; charset=utf-8'; + success_function = data.success || success_function ; + + if (data.type == 'GET' && data.data) { + + data.url = /\?/.test(data.url) ? data.url + '&' + data.data : data.url + '?' + data.data; + + } else { + + for(obj in data.data) { + params += (obj + '=' + encodeURIComponent(data.data[obj]) + '&'); + } + } + + if (data.withCredentials) { + XMLHTTP.withCredentials = true; + } + + if (data.beforeSend && typeof data.beforeSend == 'function') { + data.beforeSend.call(); + } + + XMLHTTP.open( data.type, data.url, data.async ); + XMLHTTP.setRequestHeader("X-Requested-With", "XMLHttpRequest"); + XMLHTTP.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); + + XMLHTTP.onreadystatechange = function() { + if (XMLHTTP.readyState == 4 && XMLHTTP.status == 200) { + success_function(XMLHTTP.responseText); + } + }; + + XMLHTTP.send(params); + }; + + /** Appends script to head of document */ + core.importScript = function(scriptPath, instanceName) { + + /** Script is already loaded */ + if ( !instanceName || (instanceName && document.getElementById('ce-script-' + instanceName)) ) { + codex.core.log("Instance name of script is missed or script is already loaded", "warn"); + return; + } + + + var script = document.createElement('SCRIPT'); + script.type = "text/javascript"; + script.src = scriptPath; + script.async = true; + script.defer = true; + + if (instanceName) { + script.id = "ce-script-" + instanceName; + } + + document.head.appendChild(script); + return script; + }; + + return core; + +})({}); + +codex.core = core; + +module.exports = core; + + diff --git a/modules/draw.js b/modules/draw.js new file mode 100644 index 00000000..83612b07 --- /dev/null +++ b/modules/draw.js @@ -0,0 +1,311 @@ +var codex = require('../editor'); + +var draw = (function(draw) { + + /** + * Base editor wrapper + */ + draw.wrapper = function () { + + var wrapper = document.createElement('div'); + + wrapper.className += 'codex-editor'; + + return wrapper; + + }; + + /** + * Content-editable holder + */ + draw.redactor = function () { + + var redactor = document.createElement('div'); + + redactor.className += 'ce-redactor'; + + return redactor; + + }; + + draw.ceBlock = function() { + + var block = document.createElement('DIV'); + + block.className += 'ce_block'; + + return block; + + }; + + /** + * Empty toolbar with toggler + */ + draw.toolbar = function () { + + var bar = document.createElement('div'); + + bar.className += 'ce-toolbar'; + + return bar; + }; + + draw.toolbarContent = function() { + + var wrapper = document.createElement('DIV'); + wrapper.classList.add('ce-toolbar__content'); + + return wrapper; + }; + + /** + * Inline toolbar + */ + draw.inlineToolbar = function() { + + var bar = document.createElement('DIV'); + + bar.className += 'ce-toolbar-inline'; + + return bar; + + }; + + /** + * Wrapper for inline toobar buttons + */ + draw.inlineToolbarButtons = function() { + + var wrapper = document.createElement('DIV'); + + wrapper.className += 'ce-toolbar-inline__buttons'; + + return wrapper; + }; + + /** + * For some actions + */ + draw.inlineToolbarActions = function() { + + var wrapper = document.createElement('DIV'); + + wrapper.className += 'ce-toolbar-inline__actions'; + + return wrapper; + + }; + + draw.inputForLink = function() { + + var input = document.createElement('INPUT'); + + input.type = 'input'; + input.className += 'inputForLink'; + input.placeholder = 'Type URL ...'; + input.setAttribute('form', 'defaultForm'); + + input.setAttribute('autofocus', 'autofocus'); + + return input; + + }; + + /** + * Block with notifications + */ + draw.alertsHolder = function() { + + var block = document.createElement('div'); + + block.classList.add('ce_notifications-block'); + + return block; + + }; + + /** + * @todo Desc + */ + draw.blockButtons = function() { + + var block = document.createElement('div'); + + block.className += 'ce-toolbar__actions'; + + return block; + }; + + /** + * Block settings panel + */ + draw.blockSettings = function () { + + var settings = document.createElement('div'); + + settings.className += 'ce-settings'; + + return settings; + }; + + draw.defaultSettings = function() { + + var div = document.createElement('div'); + + div.classList.add('ce-settings_default'); + + return div; + }, + + draw.pluginsSettings = function() { + + var div = document.createElement('div'); + + div.classList.add('ce-settings_plugin'); + + return div; + + }; + + draw.plusButton = function() { + + var button = document.createElement('span'); + + button.className = 'ce-toolbar__plus'; + // button.innerHTML = ''; + + return button; + }; + + /** + * Settings button in toolbar + */ + draw.settingsButton = function () { + + var toggler = document.createElement('span'); + + toggler.className = 'ce-toolbar__settings-btn'; + + /** Toggler button*/ + toggler.innerHTML = ''; + + return toggler; + }; + + /** + * Redactor tools wrapper + */ + + draw.toolbox = function() { + + var wrapper = document.createElement('div'); + + wrapper.className = 'ce-toolbar__tools'; + + return wrapper; + }; + + /** + * @protected + * + * Draws tool buttons for toolbox + * + * @param {String} type + * @param {String} classname + * @returns {Element} + */ + draw.toolbarButton = function (type, classname) { + + var button = document.createElement("li"), + tool_icon = document.createElement("i"), + tool_title = document.createElement("span"); + + button.dataset.type = type; + button.setAttribute('title', type); + + tool_icon.classList.add(classname); + tool_title.classList.add('ce_toolbar_tools--title'); + + + button.appendChild(tool_icon); + button.appendChild(tool_title); + + return button; + + }; + + /** + * @protected + * + * Draws tools for inline toolbar + * + * @param {String} type + * @param {String} classname + */ + draw.toolbarButtonInline = function(type, classname) { + var button = document.createElement("BUTTON"), + tool_icon = document.createElement("I"); + + button.type = "button"; + button.dataset.type = type; + tool_icon.classList.add(classname); + + button.appendChild(tool_icon); + + return button; + }; + + /** + * Redactor block + */ + draw.block = function (tagName, content) { + + var node = document.createElement(tagName); + + node.innerHTML = content || ''; + + return node; + + }; + + /** + * Creates Node with passed tagName and className + * @param {string} tagName + * @param {string} className + * @param {object} properties - allow to assign properties + */ + draw.node = function( tagName , className , properties ){ + + var el = document.createElement( tagName ); + + if ( className ) el.className = className; + + if ( properties ) { + + for (var name in properties){ + el[name] = properties[name]; + } + } + + return el; + }; + + draw.pluginsRender = function(type, content) { + + return { + type : type, + block : cEditor.tools[type].render({ + text : content + }) + }; + }; + + return draw; + +})({}); + +codex.draw = draw; + +module.exports = draw; + + diff --git a/modules/notifications.js b/modules/notifications.js new file mode 100644 index 00000000..d860e510 --- /dev/null +++ b/modules/notifications.js @@ -0,0 +1,45 @@ +var codex = require('../editor'); + +var notifications = (function(notifications) { + + /** + * Error notificator. Shows block with message + * @protected + */ + notifications.errorThrown = function(errorMsg, event) { + + codex.notifications.send('This action is not available currently', event.type, false); + + }, + + /** + * Appends notification with different types + * @param message {string} - Error or alert message + * @param type {string} - Type of message notification. Ex: Error, Warning, Danger ... + * @param append {boolean} - can be True or False when notification should be inserted after + */ + notifications.send = function(message, type, append) { + + var notification = codex.draw.block('div'); + + notification.textContent = message; + notification.classList.add('ce_notification-item', 'ce_notification-' + type, 'flipInX'); + + if (!append) { + codex.nodes.notifications.innerHTML = ''; + } + + codex.nodes.notifications.appendChild(notification); + + setTimeout(function () { + notification.remove(); + }, 3000); + + }; + + return notifications; + +})({}); + +codex.notifications = notifications; +module.exports = notifications; \ No newline at end of file diff --git a/modules/parser.js b/modules/parser.js new file mode 100644 index 00000000..fbb3936d --- /dev/null +++ b/modules/parser.js @@ -0,0 +1,261 @@ +var codex = require('../editor'); + +var parser = (function(parser) { + + parser.init = function() { + + }; + + /** + * Splits content by `\n` and returns blocks + */ + parser.getSeparatedTexttSeparatedTextFromContent = function(content) { + return content.split('\n'); + }; + + /** inserting text */ + parser.insertPastedContent = function(content) { + + var blocks = this.getSeparatedTextFromContent(content), + i, + inputIndex = cEditor.caret.getCurrentInputIndex(), + textNode, + parsedTextContent; + + for(i = 0; i < blocks.length; i++) { + + blocks[i].trim(); + + if (blocks[i]) { + var data = cEditor.draw.pluginsRender('paragraph', blocks[i]); + cEditor.content.insertBlock(data); + } + } + + }; + + /** + * Asynchronously parses textarea input string to HTML editor blocks + */ + parser.parseTextareaContent = function () { + + var initialContent = cEditor.nodes.textarea.value; + + if ( initialContent.trim().length === 0 ) return true; + + + cEditor.parser + + /** Get child nodes async-aware */ + .getNodesFromString(initialContent) + + /** Then append nodes to the redactor */ + .then(cEditor.parser.appendNodesToRedactor) + + /** Write log if something goes wrong */ + .catch(function(error) { + cEditor.core.log('Error while parsing content: %o', 'warn', error); + }); + + }; + + /** + * Parses string to nodeList + * @param string inputString + * @return Primise -> nodeList + */ + parser.getNodesFromString = function (inputString) { + + return Promise.resolve().then(function() { + + var contentHolder = document.createElement('div'); + + contentHolder.innerHTML = inputString; + + /** + * Returning childNodes will include: + * - Elements (html-tags), + * - Texts (empty-spaces or non-wrapped strings ) + * - Comments and other + */ + return contentHolder.childNodes; + + }); + }; + + /** + * Appends nodes to the redactor + * @param nodeList nodes - list for nodes to append + */ + parser.appendNodesToRedactor = function(nodes) { + + /** + * Sequence of one-by-one nodes appending + * Uses to save blocks order after async-handler + */ + var nodeSequence = Promise.resolve(); + + + for (var index = 0; index < nodes.length ; index++ ) { + + /** Add node to sequence at specified index */ + cEditor.parser.appendNodeAtIndex(nodeSequence, nodes, index); + + } + + }; + + /** + * Append node at specified index + */ + parser.appendNodeAtIndex = function (nodeSequence, nodes, index) { + + /** We need to append node to sequence */ + nodeSequence + + /** first, get node async-aware */ + .then(function() { + + return cEditor.parser.getNodeAsync(nodes , index); + + }) + + /** + * second, compose editor-block from node + * and append it to redactor + */ + .then(function(node){ + + var block = cEditor.parser.createBlockByDomNode(node); + + if ( cEditor.core.isDomNode(block) ) { + + block.contentEditable = "true"; + + /** Mark node as redactor block*/ + block.classList.add('ce-block'); + + /** Append block to the redactor */ + cEditor.nodes.redactor.appendChild(block); + + /** Save block to the cEditor.state array */ + cEditor.state.blocks.push(block); + + return block; + + } + return null; + }) + + .then(cEditor.ui.addBlockHandlers) + + /** Log if something wrong with node */ + .catch(function(error) { + cEditor.core.log('Node skipped while parsing because %o', 'warn', error); + }); + + }; + + /** + * Asynchronously returns node from nodeList by index + * @return Promise to node + */ + parser.getNodeAsync = function (nodeList, index) { + + return Promise.resolve().then(function() { + + return nodeList.item(index); + + }); + }; + + /** + * Creates editor block by DOM node + * + * First-level blocks (see cEditor.settings.blockTags) saves as-is, + * other wrapps with

-tag + * + * @param DOMnode node + * @return First-level node (paragraph) + */ + parser.createBlockByDomNode = function (node) { + + /** First level nodes already appears as blocks */ + if ( cEditor.parser.isFirstLevelBlock(node) ){ + + /** Save plugin type in data-type */ + node = this.storeBlockType(node); + + return node; + } + + /** Other nodes wraps into parent block (paragraph-tag) */ + var parentBlock, + nodeContent = node.textContent.trim(), + isPlainTextNode = node.nodeType != cEditor.core.nodeTypes.TAG; + + + /** Skip empty textNodes with space-symbols */ + if (isPlainTextNode && !nodeContent.length) return null; + + /** Make

tag */ + parentBlock = cEditor.draw.block('P'); + + if (isPlainTextNode){ + parentBlock.textContent = nodeContent.replace(/(\s){2,}/, '$1'); // remove double spaces + } else { + parentBlock.appendChild(node); + } + + /** Save plugin type in data-type */ + parentBlock = this.storeBlockType(parentBlock); + + return parentBlock; + + }; + + /** + * It's a crutch + * - - - - - - - + * We need block type stored as data-attr + * Now supports only simple blocks : P, HEADER, QUOTE, CODE + * Remove it after updating parser module for the block-oriented structure: + * - each block must have stored type + * @param {Element} node + */ + parser.storeBlockType = function (node) { + + switch (node.tagName) { + case 'P' : node.dataset.tool = 'paragraph'; break; + case 'H1': + case 'H2': + case 'H3': + case 'H4': + case 'H5': + case 'H6': node.dataset.tool = 'header'; break; + case 'BLOCKQUOTE': node.dataset.tool = 'quote'; break; + case 'CODE': node.dataset.tool = 'code'; break; + } + + return node; + + }; + + /** + * Check DOM node for display style: separated block or child-view + */ + parser.isFirstLevelBlock = function (node) { + + return node.nodeType == cEditor.core.nodeTypes.TAG && + node.classList.contains(cEditor.ui.className.BLOCK_CLASSNAME); + + }; + + return parser; + +})({}); + +parser.init(); + +codex.parser = parser; +module.exports = parser; diff --git a/modules/renderer.js b/modules/renderer.js new file mode 100644 index 00000000..acd8f8e0 --- /dev/null +++ b/modules/renderer.js @@ -0,0 +1,171 @@ +var codex = require('../editor'); + +var renderer = (function(renderer) { + + /** + * Asyncronously parses input JSON to redactor blocks + */ + renderer.makeBlocksFromData = function () { + + /** + * If redactor is empty, add first paragraph to start writing + */ + if (!codex.state.blocks.items.length) { + + codex.ui.addInitialBlock(); + return; + + } + + Promise.resolve() + + /** First, get JSON from state */ + .then(function() { + return codex.state.blocks; + }) + + /** Then, start to iterate they */ + .then(codex.renderer.appendBlocks) + + /** Write log if something goes wrong */ + .catch(function(error) { + codex.core.log('Error while parsing JSON: %o', 'error', error); + }); + + }; + + /** + * Parses JSON to blocks + * @param {object} data + * @return Primise -> nodeList + */ + renderer.appendBlocks = function (data) { + + var blocks = data.items; + + /** + * Sequence of one-by-one blocks appending + * Uses to save blocks order after async-handler + */ + var nodeSequence = Promise.resolve(); + + for (var index = 0; index < blocks.length ; index++ ) { + + /** Add node to sequence at specified index */ + codex.renderer.appendNodeAtIndex(nodeSequence, blocks, index); + + } + + }; + + /** + * Append node at specified index + */ + renderer.appendNodeAtIndex = function (nodeSequence, blocks, index) { + + /** We need to append node to sequence */ + nodeSequence + + /** first, get node async-aware */ + .then(function() { + + return codex.renderer.getNodeAsync(blocks , index); + + }) + + /** + * second, compose editor-block from JSON object + */ + .then(codex.renderer.createBlockFromData) + + /** + * now insert block to redactor + */ + .then(function(blockData){ + + /** + * blockData has 'block', 'type' and 'stretched' information + */ + codex.content.insertBlock(blockData); + + /** Pass created block to next step */ + return blockData.block; + + }) + + /** Log if something wrong with node */ + .catch(function(error) { + codex.core.log('Node skipped while parsing because %o', 'error', error); + }); + + }; + + /** + * Asynchronously returns block data from blocksList by index + * @return Promise to node + */ + renderer.getNodeAsync = function (blocksList, index) { + + return Promise.resolve().then(function() { + + return blocksList[index]; + + }); + }; + + /** + * Creates editor block by JSON-data + * + * @uses render method of each plugin + * + * @param {object} blockData looks like + * { header : { + * text: '', + * type: 'H3', ... + * } + * } + * @return {object} with type and Element + */ + renderer.createBlockFromData = function (blockData) { + + /** New parser */ + var pluginName = blockData.type; + + /** Get first key of object that stores plugin name */ + // for (var pluginName in blockData) break; + + /** Check for plugin existance */ + if (!codex.tools[pluginName]) { + throw Error(`Plugin «${pluginName}» not found`); + } + + /** Check for plugin having render method */ + if (typeof codex.tools[pluginName].render != 'function') { + + throw Error(`Plugin «${pluginName}» must have «render» method`); + } + + /** New Parser */ + var block = codex.tools[pluginName].render(blockData.data); + + /** Fire the render method with data */ + // var block = codex.tools[pluginName].render(blockData[pluginName]); + + /** is first-level block stretched */ + var stretched = codex.tools[pluginName].isStretched || false; + + /** Retrun type and block */ + return { + type : pluginName, + block : block, + stretched : stretched + }; + + }; + + return renderer; + +})({}); + +codex.renderer = renderer; +module.exports = renderer; \ No newline at end of file diff --git a/modules/saver.js b/modules/saver.js new file mode 100644 index 00000000..9c28e8bd --- /dev/null +++ b/modules/saver.js @@ -0,0 +1,111 @@ +var codex = require('../editor'); + +var saver = (function(saver) { + + /** + * Saves blocks + * @private + */ + saver.saveBlocks = function () { + + /** Save html content of redactor to memory */ + codex.state.html = codex.nodes.redactor.innerHTML; + + /** Empty jsonOutput state */ + codex.state.jsonOutput = []; + + Promise.resolve() + + .then(function() { + return codex.nodes.redactor.childNodes; + }) + /** Making a sequence from separate blocks */ + .then(codex.saver.makeQueue) + + .then(function() { + // codex.nodes.textarea.innerHTML = codex.state.html; + }) + + .catch( function(error) { + console.log('Something happend'); + }); + + }; + + saver.makeQueue = function(blocks) { + + var queue = Promise.resolve(); + + for(var index = 0; index < blocks.length; index++) { + + /** Add node to sequence at specified index */ + codex.saver.getBlockData(queue, blocks, index); + + } + + }; + + /** Gets every block and makes From Data */ + saver.getBlockData = function(queue, blocks, index) { + + queue.then(function() { + return codex.saver.getNodeAsync(blocks, index); + }) + + .then(codex.saver.makeFormDataFromBlocks); + + }; + + + /** + * Asynchronously returns block data from blocksList by index + * @return Promise to node + */ + saver.getNodeAsync = function (blocksList, index) { + + return Promise.resolve().then(function() { + + return blocksList[index]; + + }); + }; + + saver.makeFormDataFromBlocks = function(block) { + + var pluginName = block.dataset.tool; + + /** Check for plugin existance */ + if (!codex.tools[pluginName]) { + throw Error(`Plugin «${pluginName}» not found`); + } + + /** Check for plugin having render method */ + if (typeof codex.tools[pluginName].save != 'function') { + + throw Error(`Plugin «${pluginName}» must have save method`); + } + + /** Result saver */ + var blockContent = block.childNodes[0], + pluginsContent = blockContent.childNodes[0], + savedData = codex.tools[pluginName].save(pluginsContent), + output; + + + output = { + type: pluginName, + data: savedData + }; + + /** Marks Blocks that will be in main page */ + output.cover = block.classList.contains(codex.ui.className.BLOCK_IN_FEED_MODE); + + codex.state.jsonOutput.push(output); + }; + + return saver; + +})({}); + +codex.saver = saver; +module.exports = saver; \ No newline at end of file diff --git a/modules/toolbar/inline.js b/modules/toolbar/inline.js new file mode 100644 index 00000000..650ac5ea --- /dev/null +++ b/modules/toolbar/inline.js @@ -0,0 +1,485 @@ +var codex = require('../../editor'); + +var inline = (function(inline) { + + inline.init = function() { + + }; + + inline.buttonsOpened = null; + inline.actionsOpened = null; + inline.wrappersOffset = null; + + /** + * saving selection that need for execCommand for styling + * + */ + inline.storedSelection = null, + + /** + * @protected + * + * Open inline toobar + */ + inline.show = function() { + + var selectedText = this.getSelectionText(), + toolbar = codex.nodes.inlineToolbar.wrapper, + buttons = codex.nodes.inlineToolbar.buttons; + + if (selectedText.length > 0) { + + /** Move toolbar and open */ + codex.toolbar.inline.move(); + + /** Open inline toolbar */ + toolbar.classList.add('opened'); + + /** show buttons of inline toolbar */ + codex.toolbar.inline.showButtons(); + } + + }; + + /** + * @protected + * + * Closes inline toolbar + */ + inline.close = function() { + var toolbar = codex.nodes.inlineToolbar.wrapper; + toolbar.classList.remove('opened'); + }; + + /** + * @private + * + * Moving toolbar + */ + inline.move = function() { + + if (!this.wrappersOffset) { + this.wrappersOffset = this.getWrappersOffset(); + } + + var coords = this.getSelectionCoords(), + defaultOffset = 0, + toolbar = codex.nodes.inlineToolbar.wrapper, + newCoordinateX, + newCoordinateY; + + if (toolbar.offsetHeight === 0) { + defaultOffset = 40; + } + + newCoordinateX = coords.x - this.wrappersOffset.left; + newCoordinateY = coords.y + window.scrollY - this.wrappersOffset.top - defaultOffset - toolbar.offsetHeight; + + toolbar.style.transform = `translate3D(${Math.floor(newCoordinateX)}px, ${Math.floor(newCoordinateY)}px, 0)`; + + /** Close everything */ + codex.toolbar.inline.closeButtons(); + codex.toolbar.inline.closeAction(); + + }; + + /** + * @private + * + * Tool Clicked + */ + + inline.toolClicked = function(event, type) { + + /** + * For simple tools we use default browser function + * For more complicated tools, we should write our own behavior + */ + switch (type) { + case 'createLink' : codex.toolbar.inline.createLinkAction(event, type); break; + default : codex.toolbar.inline.defaultToolAction(type); break; + } + + /** + * highlight buttons + * after making some action + */ + codex.nodes.inlineToolbar.buttons.childNodes.forEach(codex.toolbar.inline.hightlight); + }; + + /** + * @private + * + * Saving wrappers offset in DOM + */ + inline.getWrappersOffset = function() { + + var wrapper = codex.nodes.wrapper, + offset = this.getOffset(wrapper); + + this.wrappersOffset = offset; + return offset; + + }; + + /** + * @private + * + * Calculates offset of DOM element + * + * @param el + * @returns {{top: number, left: number}} + */ + inline.getOffset = function ( el ) { + + var _x = 0; + var _y = 0; + + while( el && !isNaN( el.offsetLeft ) && !isNaN( el.offsetTop ) ) { + _x += (el.offsetLeft + el.clientLeft); + _y += (el.offsetTop + el.clientTop); + el = el.offsetParent; + } + return { top: _y, left: _x }; + }; + + /** + * @private + * + * Calculates position of selected text + * @returns {{x: number, y: number}} + */ + inline.getSelectionCoords = function() { + + var sel = document.selection, range; + var x = 0, y = 0; + + if (sel) { + + if (sel.type != "Control") { + range = sel.createRange(); + range.collapse(true); + x = range.boundingLeft; + y = range.boundingTop; + } + + } else if (window.getSelection) { + + sel = window.getSelection(); + + if (sel.rangeCount) { + + range = sel.getRangeAt(0).cloneRange(); + if (range.getClientRects) { + range.collapse(true); + var rect = range.getClientRects()[0]; + x = rect.left; + y = rect.top; + } + + } + } + return { x: x, y: y }; + }; + + /** + * @private + * + * Returns selected text as String + * @returns {string} + */ + inline.getSelectionText = function getSelectionText(){ + + var selectedText = ""; + + if (window.getSelection){ // all modern browsers and IE9+ + selectedText = window.getSelection().toString(); + } + + return selectedText; + }; + + /** Opens buttons block */ + inline.showButtons = function() { + + var buttons = codex.nodes.inlineToolbar.buttons; + buttons.classList.add('opened'); + + codex.toolbar.inline.buttonsOpened = true; + + /** highlight buttons */ + codex.nodes.inlineToolbar.buttons.childNodes.forEach(codex.toolbar.inline.hightlight); + + }; + + /** Makes buttons disappear */ + inline.closeButtons = function() { + var buttons = codex.nodes.inlineToolbar.buttons; + buttons.classList.remove('opened'); + + codex.toolbar.inline.buttonsOpened = false; + }; + + /** Open buttons defined action if exist */ + inline.showActions = function() { + var action = codex.nodes.inlineToolbar.actions; + action.classList.add('opened'); + + codex.toolbar.inline.actionsOpened = true; + }; + + /** Close actions block */ + inline.closeAction = function() { + var action = codex.nodes.inlineToolbar.actions; + action.innerHTML = ''; + action.classList.remove('opened'); + codex.toolbar.inline.actionsOpened = false; + }; + + /** Action for link creation or for setting anchor */ + inline.createLinkAction = function(event, type) { + + var isActive = this.isLinkActive(); + + var editable = codex.content.currentNode, + storedSelection = codex.toolbar.inline.storedSelection; + + if (isActive) { + + var selection = window.getSelection(), + anchorNode = selection.anchorNode; + + storedSelection = codex.toolbar.inline.saveSelection(editable); + + /** + * Changing stored selection. if we want to remove anchor from word + * we should remove anchor from whole word, not only selected part. + * The solution is than we get the length of current link + * Change start position to - end of selection minus length of anchor + */ + codex.toolbar.inline.restoreSelection(editable, storedSelection); + + codex.toolbar.inline.defaultToolAction('unlink'); + + } else { + + /** Create input and close buttons */ + var action = codex.draw.inputForLink(); + codex.nodes.inlineToolbar.actions.appendChild(action); + + codex.toolbar.inline.closeButtons(); + codex.toolbar.inline.showActions(); + + storedSelection = codex.toolbar.inline.saveSelection(editable); + + /** + * focus to input + * Solution: https://developer.mozilla.org/ru/docs/Web/API/HTMLElement/focus + * Prevents event after showing input and when we need to focus an input which is in unexisted form + */ + action.focus(); + event.preventDefault(); + + /** Callback to link action */ + action.addEventListener('keydown', function(event){ + + if (event.keyCode == codex.core.keys.ENTER) { + + codex.toolbar.inline.restoreSelection(editable, storedSelection); + codex.toolbar.inline.setAnchor(action.value); + + /** + * Preventing events that will be able to happen + */ + event.preventDefault(); + event.stopImmediatePropagation(); + + codex.toolbar.inline.clearRange(); + } + + }, false); + } + }; + + inline.isLinkActive = function() { + + var isActive = false; + + codex.nodes.inlineToolbar.buttons.childNodes.forEach(function(tool) { + var dataType = tool.dataset.type; + + if (dataType == 'link' && tool.classList.contains('hightlighted')) { + isActive = true; + } + }); + + return isActive; + }; + + /** default action behavior of tool */ + inline.defaultToolAction = function(type) { + document.execCommand(type, false, null); + }; + + /** + * @private + * + * Sets URL + * + * @param {String} url - URL + */ + inline.setAnchor = function(url) { + + document.execCommand('createLink', false, url); + + /** Close after URL inserting */ + codex.toolbar.inline.closeAction(); + }; + + /** + * @private + * + * Saves selection + */ + inline.saveSelection = function(containerEl) { + + var range = window.getSelection().getRangeAt(0), + preSelectionRange = range.cloneRange(), + start; + + preSelectionRange.selectNodeContents(containerEl); + preSelectionRange.setEnd(range.startContainer, range.startOffset); + + start = preSelectionRange.toString().length; + + return { + start: start, + end: start + range.toString().length + }; + }; + + /** + * @private + * + * Sets to previous selection (Range) + * + * @param {Element} containerEl - editable element where we restore range + * @param {Object} savedSel - range basic information to restore + */ + inline.restoreSelection = function(containerEl, savedSel) { + + var range = document.createRange(), + charIndex = 0; + + range.setStart(containerEl, 0); + range.collapse(true); + + var nodeStack = [containerEl], + node, + foundStart = false, + stop = false, + nextCharIndex; + + while (!stop && (node = nodeStack.pop())) { + + if (node.nodeType == 3) { + + nextCharIndex = charIndex + node.length; + + if (!foundStart && savedSel.start >= charIndex && savedSel.start <= nextCharIndex) { + range.setStart(node, savedSel.start - charIndex); + foundStart = true; + } + if (foundStart && savedSel.end >= charIndex && savedSel.end <= nextCharIndex) { + range.setEnd(node, savedSel.end - charIndex); + stop = true; + } + charIndex = nextCharIndex; + } else { + var i = node.childNodes.length; + while (i--) { + nodeStack.push(node.childNodes[i]); + } + } + } + + var sel = window.getSelection(); + sel.removeAllRanges(); + sel.addRange(range); + }; + + /** + * @private + * + * Removes all ranges from window selection + */ + inline.clearRange = function() { + var selection = window.getSelection(); + selection.removeAllRanges(); + }; + + /** + * @private + * + * sets or removes hightlight + */ + inline.hightlight = function(tool) { + var dataType = tool.dataset.type; + + if (document.queryCommandState(dataType)) { + codex.toolbar.inline.setButtonHighlighted(tool); + } else { + codex.toolbar.inline.removeButtonsHighLight(tool); + } + + /** + * + * hightlight for anchors + */ + var selection = window.getSelection(), + tag = selection.anchorNode.parentNode; + + if (tag.tagName == 'A' && dataType == 'link') { + codex.toolbar.inline.setButtonHighlighted(tool); + } + }; + + /** + * @private + * + * Mark button if text is already executed + */ + inline.setButtonHighlighted = function(button) { + button.classList.add('hightlighted'); + + /** At link tool we also change icon */ + if (button.dataset.type == 'link') { + var icon = button.childNodes[0]; + icon.classList.remove('ce-icon-link'); + icon.classList.add('ce-icon-unlink'); + } + }; + + /** + * @private + * + * Removes hightlight + */ + inline.removeButtonsHighLight = function(button) { + button.classList.remove('hightlighted'); + + /** At link tool we also change icon */ + if (button.dataset.type == 'link') { + var icon = button.childNodes[0]; + icon.classList.remove('ce-icon-unlink'); + icon.classList.add('ce-icon-link'); + } + }; + + + return inline; +})({}); + +inline.init(); + +module.exports = inline; \ No newline at end of file diff --git a/modules/toolbar/settings.js b/modules/toolbar/settings.js new file mode 100644 index 00000000..1fb7d2b6 --- /dev/null +++ b/modules/toolbar/settings.js @@ -0,0 +1,249 @@ +var codex = require('../../editor'); + +var settings = (function(settings) { + + settings.init = function() { + require('../content'); + }; + + settings.opened = false; + + settings.setting = null; + settings.actions = null; + + settings.cover = null; + + /** + * Append and open settings + */ + settings.open = function(toolType){ + + /** + * Append settings content + * It's stored in tool.settings + */ + if (!codex.tools[toolType] || !codex.core.isDomNode(codex.tools[toolType].settings) ) { + + codex.core.log(`Plugin «${toolType}» has no settings`, 'warn'); + // codex.nodes.pluginSettings.innerHTML = `Плагин «${toolType}» не имеет настроек`; + + } else { + + codex.nodes.pluginSettings.appendChild(codex.tools[toolType].settings); + + } + + var currentBlock = codex.content.currentNode; + + /** Open settings block */ + codex.nodes.blockSettings.classList.add('opened'); + codex.toolbar.settings.addDefaultSettings(); + this.opened = true; + }; + + /** + * Close and clear settings + */ + settings.close = function(){ + + codex.nodes.blockSettings.classList.remove('opened'); + codex.nodes.pluginSettings.innerHTML = ''; + + this.opened = false; + + }; + + /** + * @param {string} toolType - plugin type + */ + settings.toggle = function( toolType ){ + + if ( !this.opened ){ + + this.open(toolType); + + } else { + + this.close(); + + } + + }; + + /** + * This function adds default core settings + */ + settings.addDefaultSettings = function() { + + /** list of default settings */ + var feedModeToggler; + + /** Clear block and append initialized settings */ + codex.nodes.defaultSettings.innerHTML = ''; + + + /** Init all default setting buttons */ + feedModeToggler = codex.toolbar.settings.makeFeedModeToggler(); + + /** + * Fill defaultSettings + */ + + /** + * Button that enables/disables Feed-mode + * Feed-mode means that block will be showed in articles-feed like cover + */ + codex.nodes.defaultSettings.appendChild(feedModeToggler); + + }; + + /** + * Cover setting. + * This tune highlights block, so that it may be used for showing target block on main page + * Draw different setting when block is marked for main page + * If TRUE, then we show button that removes this selection + * Also defined setting "Click" events will be listened and have separate callbacks + * + * @return {Element} node/button that we place in default settings block + */ + settings.makeFeedModeToggler = function() { + + var isFeedModeActivated = codex.toolbar.settings.isFeedModeActivated(), + setting, + data; + + if (!isFeedModeActivated) { + + data = { + innerHTML : 'Вывести в ленте' + }; + + } else { + + data = { + innerHTML : 'Не выводить в ленте' + }; + + } + + setting = codex.draw.node('DIV', codex.ui.className.SETTINGS_ITEM, data); + setting.addEventListener('click', codex.toolbar.settings.updateFeedMode, false); + + return setting; + }; + + /** + * Updates Feed-mode + */ + settings.updateFeedMode = function() { + + var currentNode = codex.content.currentNode; + + currentNode.classList.toggle(codex.ui.className.BLOCK_IN_FEED_MODE); + + codex.toolbar.settings.close(); + }; + + settings.isFeedModeActivated = function() { + + var currentBlock = codex.content.currentNode; + + if (currentBlock) { + return currentBlock.classList.contains(codex.ui.className.BLOCK_IN_FEED_MODE); + } else { + return false; + } + }; + + /** + * Here we will draw buttons and add listeners to components + */ + settings.makeRemoveBlockButton = function() { + + var removeBlockWrapper = codex.draw.node('SPAN', 'ce-toolbar__remove-btn', {}), + settingButton = codex.draw.node('SPAN', 'ce-toolbar__remove-setting', { innerHTML : '' }), + actionWrapper = codex.draw.node('DIV', 'ce-toolbar__remove-confirmation', {}), + confirmAction = codex.draw.node('DIV', 'ce-toolbar__remove-confirm', { textContent : 'Удалить блок' }), + cancelAction = codex.draw.node('DIV', 'ce-toolbar__remove-cancel', { textContent : 'Отменить удаление' }); + + settingButton.addEventListener('click', codex.toolbar.settings.removeButtonClicked, false); + + confirmAction.addEventListener('click', codex.toolbar.settings.confirmRemovingRequest, false); + + cancelAction.addEventListener('click', codex.toolbar.settings.cancelRemovingRequest, false); + + actionWrapper.appendChild(confirmAction); + actionWrapper.appendChild(cancelAction); + + removeBlockWrapper.appendChild(settingButton); + removeBlockWrapper.appendChild(actionWrapper); + + /** Save setting */ + codex.toolbar.settings.setting = settingButton; + codex.toolbar.settings.actions = actionWrapper; + + return removeBlockWrapper; + + }; + + settings.removeButtonClicked = function() { + + var action = codex.toolbar.settings.actions; + + if (action.classList.contains('opened')) { + codex.toolbar.settings.hideRemoveActions(); + } else { + codex.toolbar.settings.showRemoveActions(); + } + + codex.toolbar.toolbox.close(); + codex.toolbar.settings.close(); + + }; + + settings.cancelRemovingRequest = function() { + + codex.toolbar.settings.actions.classList.remove('opened'); + }; + + settings.confirmRemovingRequest = function() { + + var currentBlock = codex.content.currentNode, + firstLevelBlocksCount; + + currentBlock.remove(); + + firstLevelBlocksCount = codex.nodes.redactor.childNodes.length; + + /** + * If all blocks are removed + */ + if (firstLevelBlocksCount === 0) { + + /** update currentNode variable */ + codex.content.currentNode = null; + + /** Inserting new empty initial block */ + codex.ui.addInitialBlock(); + } + + codex.ui.saveInputs(); + + codex.toolbar.close(); + }; + + settings.showRemoveActions = function() { + codex.toolbar.settings.actions.classList.add('opened'); + }; + + settings.hideRemoveActions = function() { + codex.toolbar.settings.actions.classList.remove('opened'); + }; + + return settings; + +})({}); + +settings.init(); + +module.exports = settings; \ No newline at end of file diff --git a/modules/toolbar/toolbar.js b/modules/toolbar/toolbar.js new file mode 100644 index 00000000..a897232a --- /dev/null +++ b/modules/toolbar/toolbar.js @@ -0,0 +1,104 @@ +var codex = require('../../editor'); + +var toolbar = (function(toolbar) { + + toolbar.init = function() { + toolbar.settings = require('./settings'); + toolbar.inline = require('./inline'); + toolbar.toolbox = require('./toolbox'); + }; + + /** + * Margin between focused node and toolbar + */ + toolbar.defaultToolbarHeight = 49; + + toolbar.defaultOffset = 34; + + toolbar.opened = false; + + toolbar.current = null; + + /** + * @protected + */ + toolbar.open = function (){ + + codex.nodes.toolbar.classList.add('opened'); + this.opened = true; + + }; + + /** + * @protected + */ + toolbar.close = function(){ + + codex.nodes.toolbar.classList.remove('opened'); + this.opened = false; + + this.current = null; + + for (var button in codex.nodes.toolbarButtons){ + codex.nodes.toolbarButtons[button].classList.remove('selected'); + } + + /** Close toolbox when toolbar is not displayed */ + codex.toolbar.toolbox.close(); + codex.toolbar.settings.close(); + + }; + + toolbar.toggle = function(){ + + if ( !this.opened ){ + + this.open(); + + } else { + + this.close(); + + } + + }; + + toolbar.hidePlusButton = function() { + codex.nodes.plusButton.classList.add('hide'); + }; + + toolbar.showPlusButton = function() { + codex.nodes.plusButton.classList.remove('hide'); + }; + + /** + * Moving toolbar to the specified node + */ + toolbar.move = function() { + + /** Close Toolbox when we move toolbar */ + codex.toolbar.toolbox.close(); + + if (!codex.content.currentNode) { + return; + } + + var toolbarHeight = codex.nodes.toolbar.clientHeight || codex.toolbar.defaultToolbarHeight, + newYCoordinate = codex.content.currentNode.offsetTop - (codex.toolbar.defaultToolbarHeight / 2) + codex.toolbar.defaultOffset; + + codex.nodes.toolbar.style.transform = `translate3D(0, ${Math.floor(newYCoordinate)}px, 0)`; + + /** Close trash actions */ + codex.toolbar.settings.hideRemoveActions(); + + }; + + return toolbar; + +})({}); + +toolbar.init(); + +codex.toolbar = toolbar; +module.exports = toolbar; + diff --git a/modules/toolbar/toolbox.js b/modules/toolbar/toolbox.js new file mode 100644 index 00000000..8dde203f --- /dev/null +++ b/modules/toolbar/toolbox.js @@ -0,0 +1,152 @@ +var codex = require('../../editor'); + +var toolbox = (function(toolbox) { + + toolbox.init = function() { + require('./toolbar'); + }; + + toolbox.opened = false; + + /** Shows toolbox */ + toolbox.open = function() { + + /** Close setting if toolbox is opened */ + if (codex.toolbar.settings.opened) { + codex.toolbar.settings.close(); + } + + /** display toolbox */ + codex.nodes.toolbox.classList.add('opened'); + + /** Animate plus button */ + codex.nodes.plusButton.classList.add('clicked'); + + /** toolbox state */ + codex.toolbar.toolbox.opened = true; + + }; + + /** Closes toolbox */ + toolbox.close = function() { + + /** Makes toolbox disapear */ + codex.nodes.toolbox.classList.remove('opened'); + + /** Rotate plus button */ + codex.nodes.plusButton.classList.remove('clicked'); + + /** toolbox state */ + codex.toolbar.toolbox.opened = false; + + }; + + toolbox.leaf = function(){ + + var currentTool = codex.toolbar.current, + tools = Object.keys(codex.tools), + barButtons = codex.nodes.toolbarButtons, + nextToolIndex, + toolToSelect; + + if ( !currentTool ) { + + /** Get first tool from object*/ + for (toolToSelect in barButtons) break; + + } else { + + nextToolIndex = tools.indexOf(currentTool) + 1; + + if ( nextToolIndex == tools.length) nextToolIndex = 0; + + toolToSelect = tools[nextToolIndex]; + + } + + for (var button in barButtons) barButtons[button].classList.remove('selected'); + + barButtons[toolToSelect].classList.add('selected'); + + codex.toolbar.current = toolToSelect; + + }; + + /** + * Transforming selected node type into selected toolbar element type + * @param {event} event + */ + toolbox.toolClicked = function() { + + /** + * UNREPLACEBLE_TOOLS this types of tools are forbidden to replace even they are empty + */ + var UNREPLACEBLE_TOOLS = ['image', 'link', 'list', 'instagram', 'twitter'], + tool = codex.tools[codex.toolbar.current], + workingNode = codex.content.currentNode, + currentInputIndex = codex.caret.inputIndex, + newBlockContent, + appendCallback, + blockData; + + /** Make block from plugin */ + newBlockContent = tool.make(); + + /** information about block */ + blockData = { + block : newBlockContent, + type : tool.type, + stretched : false + }; + + if ( + workingNode && + UNREPLACEBLE_TOOLS.indexOf(workingNode.dataset.tool) === -1 && + workingNode.textContent.trim() === '' + ){ + /** Replace current block */ + codex.content.switchBlock(workingNode, newBlockContent, tool.type); + + } else { + + /** Insert new Block from plugin */ + codex.content.insertBlock(blockData); + + /** increase input index */ + currentInputIndex++; + + } + + /** Fire tool append callback */ + appendCallback = tool.appendCallback; + + if (appendCallback && typeof appendCallback == 'function') { + appendCallback.call(event); + } + + setTimeout(function() { + + /** Set caret to current block */ + codex.caret.setToBlock(currentInputIndex); + + }, 10); + + + /** + * Changing current Node + */ + codex.content.workingNodeChanged(); + + /** + * Move toolbar when node is changed + */ + codex.toolbar.move(); + }; + + return toolbox; + +})({}); + +toolbox.init(); + +module.exports = toolbox; \ No newline at end of file diff --git a/modules/tools.js b/modules/tools.js new file mode 100644 index 00000000..6f5048ea --- /dev/null +++ b/modules/tools.js @@ -0,0 +1,10 @@ +var codex = require('../editor'); + +var tools = (function(tools) { + + return tools; + +})({}); + +codex.tools = tools; +module.exports = tools; diff --git a/modules/transport.js b/modules/transport.js new file mode 100644 index 00000000..ae016d0f --- /dev/null +++ b/modules/transport.js @@ -0,0 +1,101 @@ +var codex = require('../editor'); + +var transport = (function(transport){ + + transport.input = null; + + /** + * @property {Object} arguments - keep plugin settings and defined callbacks + */ + transport.arguments = null; + + transport.prepare = function(){ + + var input = document.createElement('INPUT'); + + input.type = 'file'; + input.addEventListener('change', codex.transport.fileSelected); + + codex.transport.input = input; + + }; + + /** Clear input when files is uploaded */ + transport.clearInput = function() { + + /** Remove old input */ + this.input = null; + + /** Prepare new one */ + this.prepare(); + }; + + /** + * Callback for file selection + */ + transport.fileSelected = function(event){ + + var input = this, + files = input.files, + filesLength = files.length, + formdData = new FormData(), + file, + i; + + formdData.append('files', files[0], files[0].name); + + codex.transport.ajax({ + data : formdData, + beforeSend : codex.transport.arguments.beforeSend, + success : codex.transport.arguments.success, + error : codex.transport.arguments.error + }); + }; + + /** + * Use plugin callbacks + * @protected + */ + transport.selectAndUpload = function (args) { + + this.arguments = args; + this.input.click(); + + }; + + /** + * Ajax requests module + */ + transport.ajax = function(params){ + + var xhr = new XMLHttpRequest(), + beforeSend = typeof params.beforeSend == 'function' ? params.beforeSend : function(){}, + success = typeof params.success == 'function' ? params.success : function(){}, + error = typeof params.error == 'function' ? params.error : function(){}; + + beforeSend(); + + xhr.open('POST', codex.settings.uploadImagesUrl, true); + + xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest"); + + xhr.onload = function () { + if (xhr.status === 200) { + success(xhr.responseText); + } else { + console.log("request error: %o", xhr); + error(); + } + }; + + xhr.send(params.data); + this.clearInput(); + + }; + + return transport; + +})({}); + +codex.transport = transport; +module.exports = transport; \ No newline at end of file diff --git a/modules/ui.js b/modules/ui.js new file mode 100644 index 00000000..6f899de6 --- /dev/null +++ b/modules/ui.js @@ -0,0 +1,383 @@ +var codex = require('../editor'); + +var ui = (function(ui){ + + /** + * Basic editor classnames + */ + ui.className = { + + /** + * @const {string} BLOCK_CLASSNAME - redactor blocks name + */ + BLOCK_CLASSNAME : 'ce-block', + + /** + * @const {String} wrapper for plugins content + */ + BLOCK_CONTENT : 'ce-block__content', + + /** + * @const {String} BLOCK_STRETCHED - makes block stretched + */ + BLOCK_STRETCHED : 'ce-block--stretched', + + /** + * @const {String} BLOCK_HIGHLIGHTED - adds background + */ + BLOCK_HIGHLIGHTED : 'ce-block--focused', + + /** + * @const {String} - highlights covered blocks + */ + BLOCK_IN_FEED_MODE : 'ce-block--feed-mode', + + /** + * @const {String} - for all default settings + */ + SETTINGS_ITEM : 'ce-settings__item' + + }; + + /** + * @protected + * + * Making main interface + */ + ui.make = function () { + + var wrapper, + toolbar, + toolbarContent, + inlineToolbar, + redactor, + ceBlock, + notifications, + blockButtons, + blockSettings, + showSettingsButton, + showTrashButton, + toolbox, + plusButton; + + /** Make editor wrapper */ + wrapper = codex.draw.wrapper(); + + /** Append editor wrapper after initial textarea */ + codex.core.insertAfter(codex.nodes.textarea, wrapper); + + /** Append block with notifications to the document */ + notifications = codex.draw.alertsHolder(); + codex.nodes.notifications = document.body.appendChild(notifications); + + /** Make toolbar and content-editable redactor */ + toolbar = codex.draw.toolbar(); + toolbarContent = codex.draw.toolbarContent(); + inlineToolbar = codex.draw.inlineToolbar(); + plusButton = codex.draw.plusButton(); + showSettingsButton = codex.draw.settingsButton(); + showTrashButton = codex.toolbar.settings.makeRemoveBlockButton(); + blockSettings = codex.draw.blockSettings(); + blockButtons = codex.draw.blockButtons(); + toolbox = codex.draw.toolbox(); + redactor = codex.draw.redactor(); + + /** settings */ + var defaultSettings = codex.draw.defaultSettings(), + pluginSettings = codex.draw.pluginsSettings(); + + /** Add default and plugins settings */ + blockSettings.appendChild(pluginSettings); + blockSettings.appendChild(defaultSettings); + + /** Make blocks buttons + * This block contains settings button and remove block button + */ + blockButtons.appendChild(showSettingsButton); + blockButtons.appendChild(showTrashButton); + blockButtons.appendChild(blockSettings); + + /** Append plus button */ + toolbarContent.appendChild(plusButton); + + /** Appending toolbar tools */ + toolbarContent.appendChild(toolbox); + + /** Appending first-level block buttons */ + toolbar.appendChild(blockButtons); + + /** Append toolbarContent to toolbar */ + toolbar.appendChild(toolbarContent); + + wrapper.appendChild(toolbar); + + wrapper.appendChild(redactor); + + /** Save created ui-elements to static nodes state */ + codex.nodes.wrapper = wrapper; + codex.nodes.toolbar = toolbar; + codex.nodes.plusButton = plusButton; + codex.nodes.toolbox = toolbox; + codex.nodes.blockSettings = blockSettings; + codex.nodes.pluginSettings = pluginSettings; + codex.nodes.defaultSettings = defaultSettings; + codex.nodes.showSettingsButton = showSettingsButton; + codex.nodes.showTrashButton = showTrashButton; + + codex.nodes.redactor = redactor; + + codex.ui.makeInlineToolbar(inlineToolbar); + + /** fill in default settings */ + codex.toolbar.settings.addDefaultSettings(); + }; + + ui.makeInlineToolbar = function(container) { + + /** Append to redactor new inline block */ + codex.nodes.inlineToolbar.wrapper = container; + + /** Draw toolbar buttons */ + codex.nodes.inlineToolbar.buttons = codex.draw.inlineToolbarButtons(); + + /** Buttons action or settings */ + codex.nodes.inlineToolbar.actions = codex.draw.inlineToolbarActions(); + + /** Append to inline toolbar buttons as part of it */ + codex.nodes.inlineToolbar.wrapper.appendChild(codex.nodes.inlineToolbar.buttons); + codex.nodes.inlineToolbar.wrapper.appendChild(codex.nodes.inlineToolbar.actions); + + codex.nodes.wrapper.appendChild(codex.nodes.inlineToolbar.wrapper); + }; + + /** + * @private + * Append tools passed in codex.tools + */ + ui.addTools = function () { + + var tool, + tool_button; + + for(var name in codex.settings.tools) { + tool = codex.settings.tools[name]; + codex.tools[name] = tool;; + } + + /** Make toolbar buttons */ + for (var name in codex.tools){ + + tool = codex.tools[name]; + + if (tool.displayInToolbox == false) { + continue; + } + + if (!tool.iconClassname) { + codex.core.log('Toolbar icon classname missed. Tool %o skipped', 'warn', name); + continue; + } + + if (typeof tool.make != 'function') { + codex.core.log('make method missed. Tool %o skipped', 'warn', name); + continue; + } + + /** + * if tools is for toolbox + */ + tool_button = codex.draw.toolbarButton(name, tool.iconClassname); + + codex.nodes.toolbox.appendChild(tool_button); + + /** Save tools to static nodes */ + codex.nodes.toolbarButtons[name] = tool_button; + } + + + /** + * Add inline toolbar tools + */ + codex.ui.addInlineToolbarTools(); + + + }; + + ui.addInlineToolbarTools = function() { + + var tools = { + + bold: { + icon : 'ce-icon-bold', + command : 'bold' + }, + + italic: { + icon : 'ce-icon-italic', + command : 'italic' + }, + + underline: { + icon : 'ce-icon-underline', + command : 'underline' + }, + + link: { + icon : 'ce-icon-link', + command : 'createLink', + } + }; + + var toolButton, + tool; + + for(var name in tools) { + + tool = tools[name]; + + toolButton = codex.draw.toolbarButtonInline(name, tool.icon); + + codex.nodes.inlineToolbar.buttons.appendChild(toolButton); + /** + * Add callbacks to this buttons + */ + codex.ui.setInlineToolbarButtonBehaviour(toolButton, tool.command); + } + + }; + + /** + * @private + * Bind editor UI events + */ + ui.bindEvents = function () { + + codex.core.log('ui.bindEvents fired', 'info'); + + window.addEventListener('error', function (errorMsg, url, lineNumber) { + codex.notifications.errorThrown(errorMsg, event); + }, false ); + + /** All keydowns on Document */ + codex.nodes.redactor.addEventListener('keydown', codex.callback.globalKeydown, false ); + + /** All keydowns on Document */ + document.addEventListener('keyup', codex.callback.globalKeyup, false ); + + /** + * Mouse click to radactor + */ + codex.nodes.redactor.addEventListener('click', codex.callback.redactorClicked, false ); + + /** + * Clicks to the Plus button + */ + codex.nodes.plusButton.addEventListener('click', codex.callback.plusButtonClicked, false); + + /** + * Clicks to SETTINGS button in toolbar + */ + codex.nodes.showSettingsButton.addEventListener('click', codex.callback.showSettingsButtonClicked, false ); + /** + * @deprecated ( but now in use for syncronization ); + * Any redactor changes: keyboard input, mouse cut/paste, drag-n-drop text + */ + codex.nodes.redactor.addEventListener('input', codex.callback.redactorInputEvent, false ); + + /** Bind click listeners on toolbar buttons */ + for (var button in codex.nodes.toolbarButtons){ + codex.nodes.toolbarButtons[button].addEventListener('click', codex.callback.toolbarButtonClicked, false); + } + + }; + + /** + * Initialize plugins before using + * Ex. Load scripts or call some internal methods + */ + ui.preparePlugins = function() { + + for(var tool in codex.tools) { + + if (typeof codex.tools[tool].prepare != 'function') + continue; + + codex.tools[tool].prepare(); + } + }, + + ui.addBlockHandlers = function(block) { + + if (!block) return; + + /** + * Block keydowns + */ + block.addEventListener('keydown', function(event) { + codex.callback.blockKeydown(event, block); + }, false); + + /** + * Pasting content from another source + */ + block.addEventListener('paste', function (event) { + codex.callback.blockPaste(event); + }, false); + + block.addEventListener('mouseup', function(){ + codex.toolbar.inline.show(); + }, false); + + }; + + /** getting all contenteditable elements */ + ui.saveInputs = function() { + + var redactor = codex.nodes.redactor, + elements = []; + + /** Save all inputs in global variable state */ + codex.state.inputs = redactor.querySelectorAll('[contenteditable], input'); + }; + + /** + * Adds first initial block on empty redactor + */ + ui.addInitialBlock = function(){ + + var initialBlockType = codex.settings.initialBlockPlugin, + initialBlock; + + if ( !codex.tools[initialBlockType] ){ + codex.core.log('Plugin %o was not implemented and can\'t be used as initial block', 'warn', initialBlockType); + return; + } + + initialBlock = codex.tools[initialBlockType].render(); + + initialBlock.setAttribute('data-placeholder', 'Write your story...'); + + codex.content.insertBlock({ + type : initialBlockType, + block : initialBlock + }); + + codex.content.workingNodeChanged(initialBlock); + + }; + + ui.setInlineToolbarButtonBehaviour = function(button, type) { + + button.addEventListener('mousedown', function(event) { + + codex.toolbar.inline.toolClicked(event, type); + + }, false); + }; + + return ui; + +})({}); + +codex.ui = ui; +module.exports = codex; \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 00000000..0b7b30f5 --- /dev/null +++ b/package.json @@ -0,0 +1,16 @@ +{ + "name": "webpack", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC", + "dependencies": { + "css-loader": "^0.26.1", + "lodash": "^4.17.2", + "style-loader": "^0.13.1" + } +} diff --git a/plugins/code/code.css b/plugins/code/code.css deleted file mode 100644 index cde82227..00000000 --- a/plugins/code/code.css +++ /dev/null @@ -1,7 +0,0 @@ -.tool-code { - display: block; - font-family: 'monospace', 'monaco', 'consolas', 'courier'; - line-height: 1.5em; - background: #f8f8fd !important; - color: #304f77; -} \ No newline at end of file diff --git a/plugins/code/code.js b/plugins/code/code.js deleted file mode 100644 index 13b4af10..00000000 --- a/plugins/code/code.js +++ /dev/null @@ -1,74 +0,0 @@ -/** - * Code Plugin\ - * Creates code tag and adds content to this tag - */ -var codeTool = { - - baseClass : "tool-code", - - /** - * Make initial header block - * @param {object} JSON with block data - * @return {Element} element to append - */ - make : function (data) { - - var tag = document.createElement('code'); - - tag.classList += codeTool.baseClass; - - if (data && data.text) { - tag.innerHTML = data.text; - } - - tag.contentEditable = true; - - return tag; - - }, - - /** - * Method to render HTML block from JSON - */ - render : function (data) { - - return codeTool.make(data); - - }, - - /** - * Method to extract JSON data from HTML block - */ - save : function (blockContent){ - - var block = blockContent[0]; - json = { - type : 'code', - data : { - text : null, - } - }; - - json.data.text = block.innerHTML; - - return json; - - }, - -}; - -/** - * Now plugin is ready. - * Add it to redactor tools - */ -cEditor.tools.code = { - - type : 'code', - iconClassname : 'ce-icon-code', - make : codeTool.make, - appendCallback : null, - settings : null, - render : codeTool.render, - save : codeTool.save - -}; diff --git a/plugins/header/header.css b/plugins/header/header.css deleted file mode 100644 index 4a32f615..00000000 --- a/plugins/header/header.css +++ /dev/null @@ -1,19 +0,0 @@ -/** -* Plugin styles -*/ -/** H e a d e r - settings */ -.ce_plugin_header--settings{ - white-space: nowrap; - /*padding-right: 10px; */ -} -.ce_plugin_header--select_button{ - display: inline-block; - margin-left: 40px; - border-bottom: 1px solid #475588; - color: #6881e6; - cursor: pointer; -} - .ce_plugin_header--select_button:hover{ - border-bottom-color: #687da5; - color: #8da8dc; - } diff --git a/plugins/header/header.js b/plugins/header/header.js deleted file mode 100644 index e1065247..00000000 --- a/plugins/header/header.js +++ /dev/null @@ -1,182 +0,0 @@ -/** -* Example of making plugin -* H e a d e r -*/ -var headerTool = { - - /** - * Make initial header block - * @param {object} JSON with block data - * @return {Element} element to append - */ - make : function (data) { - - var availableTypes = ['H1', 'H2', 'H3', 'H4', 'H5', 'H6'], - tag; - - if (data && data.type && availableTypes.includes(data.type)) { - - tag = document.createElement( data.type ); - - /** - * Save header type in data-attr. - * We need it in save method to extract type from HTML to JSON - */ - tag.dataset.headerData = data.type; - - } else { - - tag = document.createElement( 'H2' ); - - } - - if (data && data.text) { - tag.textContent = data.text; - } - - tag.contentEditable = true; - - return tag; - - }, - - /** - * Method to render HTML block from JSON - */ - render : function (data) { - - return headerTool.make(data); - - }, - - /** - * Method to extract JSON data from HTML block - */ - save : function (blockContent) { - - var block = blockContent[0], - json = { - type : 'header', - data : { - type : null, - text : null, - } - }; - - json.data.type = block.dataset.headerData; - json.data.text = block.textContent; - - return json; - - }, - - /** - * Block appending callback - */ - appendCallback : function (argument) { - - console.log('header appended...'); - - }, - - /** - * Settings panel content - * - - - - - - - - - - - - - - * | настройки H1 H2 H3 | - * - - - - - - - - - - - - - - * @return {Element} element contains all settings - */ - makeSettings : function () { - - var holder = document.createElement('DIV'), - caption = document.createElement('SPAN'), - types = { - H2: 'Заголовок раздела', - H3: 'Подзаголовок', - H4: 'Заголовок 3-его уровня' - }, - selectTypeButton; - - /** Add holder classname */ - holder.className = 'ce_plugin_header--settings'; - - /** Add settings helper caption */ - caption.textContent = 'Настройки заголовка'; - caption.className = 'ce_plugin_header--caption'; - - holder.appendChild(caption); - - /** Now add type selectors */ - for (var type in types){ - - selectTypeButton = document.createElement('SPAN'); - - selectTypeButton.textContent = types[type]; - selectTypeButton.className = 'ce_plugin_header--select_button'; - - this.addSelectTypeClickListener(selectTypeButton, type); - - holder.appendChild(selectTypeButton); - - } - - return holder; - - }, - - /** - * Binds click event to passed button - */ - addSelectTypeClickListener : function (el, type) { - - el.addEventListener('click', function () { - - headerTool.selectTypeClicked(type); - - }, false); - }, - - /** - * Replaces old header with new type - * @params {string} type - new header tagName: H1—H6 - */ - selectTypeClicked : function (type) { - - var old_header, new_header; - - /** Now current header stored as a currentNode */ - old_header = cEditor.content.currentNode; - - /** Making new header */ - new_header = document.createElement(type); - - new_header.innerHTML = old_header.innerHTML; - new_header.contentEditable = true; - - cEditor.content.switchBlock(old_header, new_header, 'header'); - - /** Add listeners for Arrow keys*/ - cEditor.ui.addBlockHandlers(new_header); - - /** Close settings after replacing */ - cEditor.toolbar.settings.close(); - - }, - -}; - -/** -* Now plugin is ready. -* Add it to redactor tools -*/ -cEditor.tools.header = { - - type : 'header', - iconClassname : 'ce-icon-header', - make : headerTool.make, - appendCallback : headerTool.appendCallback, - settings : headerTool.makeSettings(), - render : headerTool.render, - save : headerTool.save - -}; diff --git a/plugins/images/images.css b/plugins/images/images.css deleted file mode 100644 index 57195664..00000000 --- a/plugins/images/images.css +++ /dev/null @@ -1,99 +0,0 @@ -/** -* Image plugin for codex-editor -* @author CodeX Team -* -* @version 0.0.1 -*/ -.ce-plugin-image__holder{ - position: relative; - background: #FEFEFE; - border: 2px dashed #E8EBF5; - border-radius: 55px; - margin: 30px 0; - padding: 30px 110px 30px 40px; -} - .ce-plugin-image__holder input{ - border: 0; - background: transparent; - outline: none; - -webkit-appearance: none; - font-size: 1.2em; - color: #A5ABBC; - } - /* Placeholder color for Chrome */ - .ce-plugin-image__holder input::-webkit-input-placeholder { - color: #A5ABBC; - } - /* Placeholder color for IE 10+ */ - .ce-plugin-image__holder input:-ms-input-placeholder { - color: #A5ABBC; - } - /* Placeholder color for Firefox 19+ */ - .ce-plugin-image__holder input::-moz-placeholder { - color: #A5ABBC; - opacity: 1; - } -.ce-plugin-image__button{ - position: absolute; - z-index: 2; - right: 40px; - cursor: pointer; - font-family: "codex_editor"; - font-size: 1.5em; - color: #8990AA; -} - .ce-plugin-image__button:hover{ - color: #393F52; - } - -.ce-plugin-image__wrapper { - margin : 3em 0; -} -.ce-plugin-image__uploaded--centered { - max-width: 700px; - display:block; - margin: 0 auto; -} - -.ce-plugin-image__uploaded--stretched { - /*width: 939px;*/ -} - .ce-plugin-image--stretch { - margin: 0 !important; - max-width: 100% !important; - } - -.ce-plugin-image__caption { - margin-top: 1em; - text-align: center; - color: #898a8c; -} - - .ce-plugin-image--caption:empty::before { - content : 'Подпись'; - font-weight: normal; - color: #a1a5b3;; - opacity: 1; - transition: opacity 200ms ease; - } - - .ce-plugin-image--caption:focus::before { - opacity: .1; - } - -/** Settings */ -.ce_plugin_image--settings{ - white-space: nowrap; - /*padding-right: 10px; */ -} -.ce_plugin_image--select_button{ - display: inline-block; - margin-left: 40px; - border-bottom: 1px solid #475588; - color: #6881e6; - cursor: pointer; -} - .ce_plugin_image--select_button:hover{ - border-bottom-color: #687da5; - color: #8da8dc; - } diff --git a/plugins/images/images.js b/plugins/images/images.js deleted file mode 100644 index 8243a69c..00000000 --- a/plugins/images/images.js +++ /dev/null @@ -1,353 +0,0 @@ -/** -* Image plugin for codex-editor -* @author CodeX Team -* -* @version 0.0.2 -*/ -var ceImage = { - - elementClasses : { - uploadedImage : { - centered : 'ce-plugin-image__uploaded--centered', - stretched : 'ce-plugin-image__uploaded--stretched', - }, - stretch : 'ce-plugin-image--stretch', - imageCaption : 'ce-plugin-image__caption', - imageWrapper : 'ce-plugin-image__wrapper', - formHolder : 'ce-plugin-image__holder', - uploadButton : 'ce-plugin-image__button', - - }, - - /** Default path to redactors images */ - path : '/upload/redactor_images/', - - make : function ( data ) { - - /** - * If we can't find image or we've got some problems with image path, we show plugin uploader - */ - if (!data || !data.file.url) { - holder = ceImage.ui.formView(); - } else { - - if ( !data.isStretch) { - holder = ceImage.ui.centeredImage(data); - } else { - holder = ceImage.ui.stretchedImage(data); - } - } - - return holder; - }, - - /** - * Settings panel content - * @return {Element} element contains all settings - */ - makeSettings : function () { - - var holder = document.createElement('DIV'), - caption = document.createElement('SPAN'), - types = { - centered : 'По центру', - stretched : 'На всю ширину', - }, - selectTypeButton; - - /** Add holder classname */ - holder.className = 'ce_plugin_image--settings'; - - /** Add settings helper caption */ - caption.textContent = 'Настройки плагина'; - caption.className = 'ce_plugin_image--caption'; - - holder.appendChild(caption); - - /** Now add type selectors */ - for (var type in types){ - - selectTypeButton = document.createElement('SPAN'); - - selectTypeButton.textContent = types[type]; - selectTypeButton.className = 'ce_plugin_image--select_button'; - - this.addSelectTypeClickListener(selectTypeButton, type); - - holder.appendChild(selectTypeButton); - - } - - return holder; - - }, - - addSelectTypeClickListener : function(el, type) { - - el.addEventListener('click', function() { - - ceImage.selectTypeClicked(type); - - }, false); - - }, - - selectTypeClicked : function(type) { - - var current = cEditor.content.currentNode; - - if (type == 'stretched') { - - current.classList.add(ceImage.elementClasses.stretch); - - } else if (type == 'centered') { - - current.classList.remove(ceImage.elementClasses.stretch); - - } - - }, - - render : function( data ) { - - return this.make(data); - - }, - - save : function ( block ) { - - var data = block[0], - image = data.querySelector('.' + ceImage.elementClasses.uploadedImage.centered) || - data.querySelector('.' + ceImage.elementClasses.uploadedImage.stretched), - caption = data.querySelector('.' + ceImage.elementClasses.imageCaption); - - var json = { - type : 'image', - data : { - background : false, - border : false, - isStrech : data.dataset.stretched, - file : { - url : image.src, - bigUrl : null, - width : image.width, - height : image.height, - additionalData :null, - }, - caption : caption.textContent, - cover : null, - } - }; - - return json; - }, - - uploadButtonClicked : function(event) { - - var success = ceImage.photoUploadingCallbacks.success, - error = ceImage.photoUploadingCallbacks.error; - - /** Define callbacks */ - cEditor.transport.selectAndUpload({ - success, - error, - }); - } -}; - -ceImage.ui = { - - holder : function(){ - - var element = document.createElement('DIV'); - - element.classList.add(ceImage.elementClasses.formHolder); - - return element; - }, - - input : function(){ - - var input = document.createElement('INPUT'); - - return input; - - }, - - uploadButton : function(){ - - var button = document.createElement('SPAN'); - - button.classList.add(ceImage.elementClasses.uploadButton); - - button.innerHTML = ''; - - return button; - - }, - - /** - * @param {string} source - file path - * @param {string} style - css class - * @return {object} image - document IMG tag - */ - image : function(source, style) { - - var image = document.createElement('IMG'); - - image.classList.add(style); - - image.src = source; - - return image; - }, - - wrapper : function() { - - var div = document.createElement('div'); - - div.classList.add(ceImage.elementClasses.imageWrapper); - - return div; - }, - - caption : function() { - - var div = document.createElement('div'); - - div.classList.add(ceImage.elementClasses.imageCaption); - - div.contentEditable = true; - - return div; - }, - - /** - * Draws form for image upload - */ - formView : function() { - - var holder = ceImage.ui.holder(), - uploadButton = ceImage.ui.uploadButton(), - input = ceImage.ui.input(); - - input.placeholder = 'Paste image URL or file'; - - holder.appendChild(uploadButton); - holder.appendChild(input); - - uploadButton.addEventListener('click', ceImage.uploadButtonClicked, false ); - - return holder; - }, - - /** - * wraps image and caption - * @param {object} data - image information - * @return wrapped block with image and caption - */ - centeredImage : function(data) { - - var file = data.file.url, - text = data.caption, - type = data.type, - image = ceImage.ui.image(file, ceImage.elementClasses.uploadedImage.centered), - caption = ceImage.ui.caption(), - wrapper = ceImage.ui.wrapper(); - - caption.textContent = text; - - wrapper.dataset.stretched = 'false', - /** Appeding to the wrapper */ - wrapper.appendChild(image); - wrapper.appendChild(caption); - - return wrapper; - }, - - /** - * wraps image and caption - * @param {object} data - image information - * @return stretched image - */ - stretchedImage : function(data) { - - var file = data.file.url, - text = data.caption, - type = data.type, - image = ceImage.ui.image(file, ceImage.elementClasses.uploadedImage.stretched), - caption = ceImage.ui.caption(), - wrapper = ceImage.ui.wrapper(); - - caption.textContent = text; - - wrapper.dataset.stretched = 'true', - /** Appeding to the wrapper */ - wrapper.appendChild(image); - wrapper.appendChild(caption); - - return wrapper; - - } - -}; - -ceImage.photoUploadingCallbacks = { - - /** Photo was uploaded successfully */ - success : function(result) { - - var parsed = JSON.parse(result), - data, - image; - - /** - * Preparing {Object} data to draw an image - * @uses ceImage.make method - */ - data = { - background : false, - border : false, - isStrech : false, - file : { - url : ceImage.path + 'o_' + parsed.filename, - bigUrl : null, - width : null, - height : null, - additionalData : null, - }, - caption : '', - cover : null, - }; - - image = ceImage.make(data); - - /** Replace form to image */ - var form = cEditor.content.currentNode.querySelector('.' + ceImage.elementClasses.formHolder); - - cEditor.content.switchBlock(form, image, 'image'); - - }, - - /** Error callback. Sends notification to user that something happend or plugin doesn't supports method */ - error : function(result) { - console.log('Choosen file is not image or image is corrupted'); - cEditor.notifications.errorThrown(); - }, - -} - - -/** -* Add plugin it to redactor tools -*/ -cEditor.tools.image = { - - type : 'image', - iconClassname : 'ce-icon-picture', - make : ceImage.make, - settings : ceImage.makeSettings(), - render : ceImage.render, - save : ceImage.save - -}; diff --git a/plugins/link/link.css b/plugins/link/link.css deleted file mode 100644 index a846a5a2..00000000 --- a/plugins/link/link.css +++ /dev/null @@ -1,75 +0,0 @@ -.clearfix:after { - visibility: hidden; - display: block; - font-size: 0; - content: " "; - clear: both; - height: 0; -} - -.ceditor-tool-link-input { - outline: none; - border: 0; - width: 100%; - background: transparent; - font-size: 1em; - padding: 8px 25px; - transition: background 200ms; - border-left: 3px solid #65d8b3; -} - -.tool-link-panel { - position: relative; - margin: 5px 0; - background: #f8f7ef; - border: 1px solid transparent; - padding: 25px 30px; -} - -.tool-link-image { - float:right; - width: 75px; - border-radius: 3px; -} - -.tool-link-title { - display: block; - width: 340px; - margin-bottom: 4px; - line-height: 1.2em; - font-size: 20px; - font-weight: 700; - color: #000; -} - -.tool-link-description { - display: block; - margin-top: 10px; - font-size: 14px; - color: #000; -} - -.tool-link-link { - width: 360px; - font-size: 10px; - margin-bottom: 4px; - letter-spacing: 1px; - overflow: hidden; - text-transform: uppercase; - text-decoration: none; - color: rgba(165,156,86,.8); -} - -.tool-link-loader { - background: url("loading.gif") !important; - opacity: 0.1; -} - -.tool-link-error { - background: rgb(255, 241, 241); - color: #bf4747; -} -.tool-link-error .ceditor-tool-link-input { - border-left-color: #d86b6b -} - diff --git a/plugins/link/link.js b/plugins/link/link.js deleted file mode 100644 index 4122fd6e..00000000 --- a/plugins/link/link.js +++ /dev/null @@ -1,321 +0,0 @@ -/** - * Created by nostr on 29.06.16. - */ - -/** - * Link tool plugin - */ -var linkTool = { - - defaultText : 'Insert link here ...', - ENTER_KEY : 13, - - currentBlock : null, - currentInput : null, - elementClasses : { - link : "tool-link-link", - image : "tool-link-image", - title : "tool-link-title", - description : "tool-link-description", - loader : "tool-link-loader", - error : "tool-link-error" - }, - - /** - * Make initial header block - * @param {object} JSON with block data - * @return {Element} element to append - */ - makeNewBlock : function (data) { - - var wrapper = linkTool.ui.mainBlock(), - tag = linkTool.ui.input(); - - linkTool.currentInput = tag; - - wrapper.appendChild(tag); - - /** - * Bind callbacks - **/ - tag.addEventListener('paste', linkTool.blockPasteCallback, false); - tag.addEventListener('keydown', linkTool.blockKeyDownCallback, false); - - return wrapper; - - }, - - /** - * Method to render HTML block from JSON - */ - render : function (json) { - - var block = linkTool.ui.mainBlock(), - tag = linkTool.ui.make(json); - - block.appendChild(tag); - - return block; - - }, - - /** - * Method to extract JSON data from HTML block - */ - save : function (blockContent){ - - var linkElement = linkTool.elementClasses.link; - - var block = blockContent[0], - json = { - type : 'link', - data : { - fullLink : block.querySelector("." + linkElement).href, - shortLink : block.querySelector("." + linkElement).textContent, - image : block.querySelector("." + linkTool.elementClasses.image).src, - title : block.querySelector("." + linkTool.elementClasses.title).textContent, - description : block.querySelector("." + linkTool.elementClasses.description).textContent - } - }; - - return json; - - }, - - blockPasteCallback : function (event) { - - var clipboardData = event.clipboardData || window.clipboardData, - pastedData = clipboardData.getData('Text'), - block = event.target.parentNode; - - linkTool.renderLink(pastedData, block); - - event.stopPropagation(); - - }, - - blockKeyDownCallback : function (event) { - - var inputTag = event.target, - block = inputTag.parentNode, - url; - - if ( block.classList.contains(linkTool.elementClasses.error) ) - { - block.classList.remove(linkTool.elementClasses.error); - } - - if (event.keyCode == linkTool.ENTER_KEY) { - - url = inputTag.value; - - linkTool.renderLink(url, block); - - event.preventDefault(); - - } - - }, - - /** - * @todo move request-url to accepted settings - */ - renderLink : function (url, block) { - - Promise.resolve() - - .then(function () { - return linkTool.urlify(url); - }) - - .then(function (url) { - - /* Show loader gif **/ - block.classList.add(linkTool.elementClasses.loader); - - return fetch('/editor/parseLink?url=' + encodeURI(url)); - }) - - .then(function (response) { - - if (response.status == "200"){ - - return response.json(); - - } else { - - return Error("Invalid response status: %o", response); - - } - - }) - - .then(function (json) { - linkTool.composeLinkPreview(json, block); - }) - - .catch(function(error) { - - /* Hide loader gif **/ - block.classList.remove(linkTool.elementClasses.loader); - - block.classList.add(linkTool.elementClasses.error); - - cEditor.core.log('Error while doing things with link paste: %o', 'error', error); - }); - - }, - - urlify : function (text) { - - var urlRegex = /(https?:\/\/\S+)/g; - - var links = text.match(urlRegex); - - if (links) { - return links[0]; - } - - return Promise.reject(Error("Url is not matched")); - - }, - - composeLinkPreview : function (json, currentBlock) { - - if (json == {}) { - - return; - - } - - var previewBlock = linkTool.ui.make(json); - - linkTool.currentInput.remove(); - - currentBlock.appendChild(previewBlock); - - currentBlock.classList.remove(linkTool.elementClasses.loader); - - } - -}; - -linkTool.ui = { - - make : function (json) { - - var wrapper = this.wrapper(), - siteImage = this.image(json.image, linkTool.elementClasses.image), - siteTitle = this.title(json.title), - siteDescription = this.description(json.description), - siteLink = this.link(json.linkUrl, json.linkText); - - wrapper.appendChild(siteImage); - wrapper.appendChild(siteTitle); - wrapper.appendChild(siteLink); - wrapper.appendChild(siteDescription); - - siteTitle.contentEditable = true; - siteDescription.contentEditable = true; - - return wrapper; - - }, - - mainBlock : function () { - - var wrapper = document.createElement('div'); - - wrapper.classList += "ceditor-tool-link"; - - return wrapper; - - }, - - input : function () { - - var inputTag = document.createElement('input'); - - inputTag.classList += "ceditor-tool-link-input"; - - inputTag.placeholder = linkTool.defaultText; - - inputTag.contentEditable = false; - - return inputTag; - - }, - - wrapper : function () { - - var wrapper = document.createElement('div'); - - wrapper.className += 'tool-link-panel clearfix'; - - return wrapper; - - }, - - image : function (imageSrc, imageClass) { - - var imageTag = document.createElement('img'); - - imageTag.classList += imageClass; - - imageTag.setAttribute('src', imageSrc); - - return imageTag; - - }, - - link : function (linkUrl, linkText) { - - var linkTag = document.createElement('a'); - - linkTag.classList += linkTool.elementClasses.link; - - linkTag.href = linkUrl; - - linkTag.target = "_blank"; - - linkTag.innerText = linkText; - - return linkTag; - - }, - - title : function (titleText) { - - var titleTag = document.createElement('div'); - - titleTag.classList.add("tool-link-content", linkTool.elementClasses.title); - - titleTag.innerHTML = titleText; - - return titleTag; - }, - - description : function (descriptionText) { - - var descriptionTag = document.createElement('div'); - - descriptionTag.classList.add("tool-link-content", linkTool.elementClasses.description); - - descriptionTag.innerHTML = descriptionText; - - return descriptionTag; - }, - -}; - -cEditor.tools.link = { - - type : 'link', - iconClassname : 'ce-icon-link', - make : linkTool.makeNewBlock, - appendCallback : linkTool.appendCallback, - render : linkTool.render, - // settings : linkTool.makeSettings(), - save : linkTool.save - -}; diff --git a/plugins/link/loading.gif b/plugins/link/loading.gif deleted file mode 100644 index 72ea7ccb5321d5384d70437cfaac73011237901e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 329 zcmZ?wbhEHb9b#5NV>2k zBC~b@b~P=nNfWAe-b%_i6tS^-1y(h@EsB~1TqDA_h@fkxG$bHgvj}VxE1JLgr!*!^ ILUxTc0Q$^Q5C8xG diff --git a/plugins/list/list.css b/plugins/list/list.css deleted file mode 100644 index 43e25704..00000000 --- a/plugins/list/list.css +++ /dev/null @@ -1,15 +0,0 @@ -.ce_plugin_list--settings{ - white-space: nowrap; -} - -.ce_plugin_list--select_button{ - display: inline-block; - margin-left: 40px; - border-bottom: 1px solid #475588; - color: #6881e6; - cursor: pointer; -} - .ce_plugin_list--select_button:hover{ - border-bottom-color: #687da5; - color: #8da8dc; - } diff --git a/plugins/list/list.js b/plugins/list/list.js deleted file mode 100644 index 8ebcc55b..00000000 --- a/plugins/list/list.js +++ /dev/null @@ -1,179 +0,0 @@ -/** - * Code Plugin\ - * Creates code tag and adds content to this tag - */ -var listTool = { - - baseClass : "tool-list", - elementClasses : { - li : "tool-list-li" - }, - - /** - * Make initial header block - * @param {object} JSON with block data - * @return {Element} element to append - */ - make : function () { - - var tag = listTool.ui.make(), - li = listTool.ui.block("li", "tool-link-li"); - - var br = document.createElement("br"); - - li.appendChild(br); - tag.appendChild(li); - - return tag; - - }, - - /** - * Method to render HTML block from JSON - */ - render : function (data) { - - var type = data.type == 'ordered' ? 'OL' : 'UL', - tag = listTool.ui.make(type); - - data.items.forEach(function (element, index, array) { - - var newLi = listTool.ui.block("li", listTool.elementClasses.li); - - newLi.innerHTML = element; - - tag.dataset.type = data.type; - tag.appendChild(newLi); - - }); - - return tag; - - }, - - /** - * Method to extract JSON data from HTML block - */ - save : function (blockContent){ - - var block = blockContent[0], - json = { - type : 'list', - data : { - type : null, - items : [], - } - }; - - for(var index = 0; index < block.childNodes.length; index++) - json.data.items[index] = block.childNodes[index].textContent; - - json.data.type = block.dataset.type; - - return json; - - }, - - makeSettings : function(data) { - - var holder = document.createElement('DIV'), - caption = document.createElement('SPAN'), - selectTypeButton; - - /** Add holder classname */ - holder.className = 'ce_plugin_list--settings'; - - /** Add settings helper caption */ - caption.textContent = 'Настройки списков'; - caption.className = 'ce_plugin_list--caption'; - - var orderedButton = listTool.ui.button("ordered"), - unorderedButton = listTool.ui.button("unordered"); - - orderedButton.addEventListener('click', function (event) { - listTool.changeBlockStyle(event, 'ol'); - cEditor.toolbar.settings.close(); - }); - - unorderedButton.addEventListener('click', function (event) { - listTool.changeBlockStyle(event, 'ul'); - cEditor.toolbar.settings.close(); - }); - - holder.appendChild(caption); - holder.appendChild(orderedButton); - holder.appendChild(unorderedButton); - - return holder; - - }, - - changeBlockStyle : function (event, blockType) { - - var currentBlock = cEditor.content.currentNode, - newEditable = listTool.ui.make(blockType), - oldEditable = currentBlock.querySelector("[contenteditable]"); - - newEditable.dataset.type = blockType; - newEditable.innerHTML = oldEditable.innerHTML; - - currentBlock.appendChild(newEditable); - oldEditable.remove(); - - }, - -}; - -listTool.ui = { - - make : function (blockType) { - - var wrapper = this.block(blockType || 'UL', listTool.baseClass); - - wrapper.contentEditable = true; - - return wrapper; - - }, - - block : function (blockType, blockClass) { - - var block = document.createElement(blockType); - - if ( blockClass ) block.classList.add(blockClass); - - return block; - - }, - - button : function (buttonType) { - - var types = { - unordered : 'Обычный список', - ordered : 'Нумерованный список' - }, - button = document.createElement('SPAN'); - - button.textContent = types[buttonType]; - - button.className = 'ce_plugin_list--select_button'; - - return button; - } -}; - -/** - * Now plugin is ready. - * Add it to redactor tools - */ -cEditor.tools.list = { - - type : 'list', - iconClassname : 'ce-icon-list-bullet', - make : listTool.make, - appendCallback : null, - settings : listTool.makeSettings(), - render : listTool.render, - save : listTool.save - -}; diff --git a/plugins/paragraph/paragraph.css b/plugins/paragraph/paragraph.css deleted file mode 100644 index e69de29b..00000000 diff --git a/plugins/paragraph/paragraph.js b/plugins/paragraph/paragraph.js deleted file mode 100644 index 4cb65002..00000000 --- a/plugins/paragraph/paragraph.js +++ /dev/null @@ -1,69 +0,0 @@ -/** -* Paragraph Plugin\ -* Creates P tag and adds content to this tag -*/ -var paragraphTool = { - - /** - * Make initial header block - * @param {object} JSON with block data - * @return {Element} element to append - */ - make : function (data) { - - var tag = document.createElement('DIV'); - - if (data && data.text) { - tag.innerHTML = data.text; - } - - tag.contentEditable = true; - - return tag; - - }, - - /** - * Method to render HTML block from JSON - */ - render : function (data) { - - return paragraphTool.make(data); - - }, - - /** - * Method to extract JSON data from HTML block - */ - save : function (blockContent){ - - var block = blockContent[0], - json = { - type : 'paragraph', - data : { - text : null, - } - }; - - json.data.text = block.innerHTML; - return json; - - }, - -}; - -/** -* Now plugin is ready. -* Add it to redactor tools -*/ -cEditor.tools.paragraph = { - - type : 'paragraph', - iconClassname : 'ce-icon-paragraph', - make : paragraphTool.make, - appendCallback : null, - settings : null, - render : paragraphTool.render, - save : paragraphTool.save - -}; diff --git a/plugins/quote/img/01.jpg b/plugins/quote/img/01.jpg deleted file mode 100755 index b44786f3264057e99b90fd5239b7f0cc316f7b6a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4033 zcmah}c{r497k_3(6CuWuP>it?voM1xyCG__W+~YRV;jcE5~+w(gT_`-k+EgX?v*Ub zP)KO8l#r0*MI?%E^ws;m-*tW0_nqhdZxUT=*9dkJA=PXI7ARRTDH zzh&za05b}4_YDU?00-MF0RUU$5K(U$Ef9}H1_Z0RdQjX*s_qnjWSDCp60M3t0*7?N z0$tsGNi?_{$%`DIjaX=GM!?A)+6X%=5k(9%Bzcn$M^H)D5yx!YBYfSpJP^7%@Iztv zF#kY*63rDJ=I<8}j1SXB{0xp~>)U1|0{+v5=Btg+-)4o|6D{C|6eX~72jCbK8iPc!7fuDOj>qEg7!CL@L9p4V9-eqBBjaCO?435^S5cv%p{k*3 zsuZdh60N1BwH*V4QDJ+i1cwLET*FiXf~9{)Fd_xJQ^|oeG9>`M9nsZ|5<=5PurvL4 z3I2gZ;$M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{Hq7T;0mn5&>8Jp_ zk+iwmkH&W+B#*5)YO&JNuUFpUo26X49qp2Sf{qoF$i08LM=R*FW;LgAbyG;Z+vU6j zfIFpc_XkphouXP$%%rCodKnG*l5Y$NR`@hnB2u=5k>_>^-st8Z`|_g)(;HN_n7tgm z?t^BvcI+ch>%?!^O{2m^E0?IXXALQ#4f87fmPKnsFNZ^zrqU(Yjt4u*ew2!NO7+Yc zQ5Sj6o%Wq3d9s|zVCe7*kHPl+c?A5IYo>WJ;5aj<3T`@I)iNW{JL*nWa?2dVI%qKq zF~N-VV4#X1MM7VD2in;>2v`*U+ND1ldDhAlNL`c^1=edMB~uxC>Oc5;_GM-62ul0W z`)E^6{8im%i?927VRZ2iCc|XIdCjB0V{#JOV&iB%w!|>?J{?oP_MMsiSw~k<=A7B? q$w@8!Qzon_ndIGlp^~Bs2a}SXn8Nv0I!7Ol3^9Rm4gCvBea8d< diff --git a/plugins/quote/img/codex.png b/plugins/quote/img/codex.png deleted file mode 100644 index 68f53217316e3193c2d4248cb2653aa3a7e90110..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12934 zcmbtbQ+Qonv`u5HC$`PTwrw;vPplI(cG8%QZL4A9q_J%~jd{=idLQpy-?#UESr6-B z?J>t3W6VeuC215yd_)Kc2ozZv2{rIH^}h!m68vs7J8Xu4U{{ot5Y_O?J~x07Nt*cF z!maC*iVMS-jS8W)V4#O@30jVfEWOHLrd=*GPNJ9bM3HhZEBx5HnBk>^ zvwvE9J?hV%a-F)!`Te@?w|AKXk{}=;P~AYcjCi|1b}MW=E>St2QOut%%o59&<_;B$ zcSH;&-T)v9cF+NQ+|+6B{_h(kK0RRhU|gJUmIelzlIQ>ajY-_yy^V?*tDt`>m^(qH zZp_aQ>@#*EH>=mdz`&?#YYPbpiHT`yN=~kdi77}-REj5lfrS-R^cls#`Y_eyLvC_n zf>Dxx{t)8h6Jq`V$;o*rp@yn$diZkS$M)}R=arNk##5yvB`r`UAm809PAF8{JG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000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1853 zcmV-D2g3M?P)b~pr;iA)S z_WAR(+lk5Ltl;m^sMdG6-ICAfwdV5K3WN+(0000HbW%=J5I|snkH63V0C1lmP~WdG z@1TYjO#lD}S4l)cRCoc@&uy05APh!f5iGp}5)-=r&Gv7<66^+ybT@F%LtiVR^vDOZ z;J1YN$d9yW`8ByzDq|4Wk~~B7Q3a=y`cQ`uvf6ODR*gJCv@rfVF6sk9Met!#XgkEd zF{N+Y3DMjzt(J8Y$tsc(;;+VO9#z`s9;l~Ga=Tot#0!m8C%PQ!Mg2L3j2#gqGRu-WCSX|hA2X%FCi77s;?jk!AdV6j9~G< zAqnA1|Aa8Y#s7jNtnbH9Zq5TcRv3n&PVdDSWWZoZm_GYoUwSg_%>U0a8gg=Xa4FBi zmPp=^xh3jAHzYA>M&H=HC|$p|WF_(-cps{icCkf$5zoVp$hDY;v9t$obZ={kl3vvJ zXnbLf?rC{fvQ?JL=s)CbJBMW1@0PiL8b#F|ayjO;jRj^9KgUy+h_$%%{Rza(!W=hAPr{Ihlb zAtJt9JUxj&Tkj%A(gp5w*F8(;*3qSkD73UEfYG??#v{UT>~c$8UJE~1lkSa)@Jn)i zsUj*yO90dEgQ@J|e)c9J`zbq`bsx+|vfo#iO36m=y!&DuBD{|U`u%9f<1Js3lgW$cUitl820Rcon5ikT0DMioFL*S8WMn2#I2#mILiq!^O z1Oet