editor.js/codex-editor.js
khaydarov ff101ac642 transport module refactored (#168)
* transport module refactored

* transport upgraded

* increase versions

* code improved after review

* upd

* new description

* JSDoc description
2017-02-27 18:41:56 +03:00

3 lines
49 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

var codex=codex||{};codex.editor=function(e){function t(o){if(n[o])return n[o].exports;var r=n[o]={exports:{},id:o,loaded:!1};return e[o].call(r.exports,r,r.exports,t),r.loaded=!0,r.exports}var n={};return t.m=e,t.c=n,t.p="",t(0)}([function(e,t,n){"use strict";e.exports=function(e){e.version="1.5.4",e.scriptPrefix="cdx-script-";var t=function(){e.core=n(1),e.tools=n(2),e.ui=n(3),e.transport=n(4),e.renderer=n(5),e.saver=n(6),e.content=n(7),e.toolbar=n(8),e.callback=n(12),e.draw=n(13),e.caret=n(14),e.notifications=n(15),e.parser=n(16),e.sanitizer=n(17),e.anchors=n(19),e.listeners=n(20),e.destroyer=n(21),e.paste=n(22)};return e.settings={tools:["paragraph","header","picture","list","quote","code","twitter","instagram","smile"],textareaId:"codex-editor",uploadImagesUrl:"/editor/transport/",initialBlockPlugin:"paragraph"},e.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:{},redactor:null},e.state={jsonOutput:[],blocks:[],inputs:[]},e.tools={},e.start=function(n){t(),e.core.prepare(n).then(e.ui.make).then(e.ui.bindEvents).then(e.tools.prepare).then(e.paste.prepare).then(e.transport.prepare).then(e.renderer.makeBlocksFromData).then(e.ui.saveInputs).catch(function(t){e.core.log("Initialization failed with error: %o","warn",t)})},e}({})},function(e,t){"use strict";var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};e.exports=function(e){var t=codex.editor;e.prepare=function(e){return new Promise(function(o,r){e&&(t.settings.tools=e.tools||t.settings.tools),e.data&&(t.state.blocks=e.data),e.initialBlockPlugin&&(t.settings.initialBlockPlugin=e.initialBlockPlugin),t.hideToolbar=e.hideToolbar,t.nodes.textarea=document.getElementById(e.textareaId||t.settings.textareaId),void 0===n(t.nodes.textarea)||null===t.nodes.textarea?r(Error("Textarea wasn't found by ID: #"+e.textareaId)):o()})},e.log=function(e,t,n){t=t||"log",n?e="[codex-editor]: "+e:(n=e||"undefined",e="[codex-editor]: %o");try{"console"in window&&window.console[t]&&(n?window.console[t](e,n):window.console[t](e))}catch(e){}},e.insertAfter=function(e,t){e.parentNode.insertBefore(t,e.nextSibling)},e.nodeTypes={TAG:1,TEXT:3,COMMENT:8},e.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},e.isDomNode=function(e){return e&&"object"===("undefined"==typeof e?"undefined":n(e))&&e.nodeType&&e.nodeType==this.nodeTypes.TAG},e.isEmpty=function(e){return 0===Object.keys(e).length},e.ajax=function(e){if(e&&e.url){var t,n,r,i=window.XMLHttpRequest?new XMLHttpRequest:new ActiveXObject("Microsoft.XMLHTTP"),a=function(){};if(e.async=!0,e.type=e.type||"GET",e.data=e.data||"",e["content-type"]=e["content-type"]||"application/json; charset=utf-8",a=e.success||a,"GET"==e.type&&e.data)e.url=/\?/.test(e.url)?e.url+"&"+e.data:e.url+"?"+e.data;else{t="";for(r in e.data)t+=r+"="+encodeURIComponent(e.data[r])+"&"}e.withCredentials&&(i.withCredentials=!0),e.beforeSend&&"function"==typeof e.beforeSend&&e.beforeSend.call(),i.open(e.type,e.url,e.async),n=o(e.data),n||("POST"!=e.type?i.setRequestHeader("Content-type",e["content-type"]):i.setRequestHeader("Content-type","application/x-www-form-urlencoded")),i.setRequestHeader("X-Requested-With","XMLHttpRequest"),i.onreadystatechange=function(){4==i.readyState&&200==i.status&&a(i.responseText)},n?i.send(e.data):i.send(t)}},e.importScript=function(e,n){return new Promise(function(o,r){var i=void 0;n?document.getElementById(t.scriptPrefix+n)&&o(e):r("Instance name is missed"),i=document.createElement("SCRIPT"),i.async=!0,i.defer=!0,i.id=t.scriptPrefix+n,i.onload=function(){o(e)},i.onerror=function(){r(e)},i.src=e,document.head.appendChild(i)})};var o=function(e){return e instanceof FormData};return e}({})},function(e,t){"use strict";e.exports=function(){function e(){return new Promise(function(e,o){Promise.resolve().then(function(){var t=[],o=n.tools;for(var r in o){var i=o[r];i.prepare&&"function"!=typeof i.prepare||!i.prepare||t.push(i)}return t.length||e(),t}).then(t).then(function(){n.core.log("Plugins loaded","info"),e()}).catch(function(e){o(e)})})}function t(e){return new Promise(function(t){e.reduce(function(r,i,a){return r.then(function(){return new Promise(function(r){o(i).then(r).then(function(){i.available=!0}).catch(function(e){n.core.log("Plugin «"+i.type+"» was not loaded. Preparation failed because %o","warn",e),i.available=!1,i.loadingMessage=e,r()}).then(function(){a==e.length-1&&t()})})})},Promise.resolve())})}var n=codex.editor,o=function(e){return e.prepare(e.config||{})};return{prepare:e}}()},function(e,t){"use strict";e.exports=function(e){var t=codex.editor;e.className={BLOCK_CLASSNAME:"ce-block",BLOCK_CONTENT:"ce-block__content",BLOCK_STRETCHED:"ce-block--stretched",BLOCK_HIGHLIGHTED:"ce-block--focused",BLOCK_IN_FEED_MODE:"ce-block--feed-mode",BLOCK_WITH_ANCHOR:"ce-block--anchor",SETTINGS_ITEM:"ce-settings__item"},e.make=function(){return new Promise(function(e){var n=t.draw.wrapper(),r=t.draw.redactor(),i=o();n.appendChild(i),n.appendChild(r),t.nodes.wrapper=n,t.nodes.redactor=r,t.core.insertAfter(t.nodes.textarea,n),e()}).then(s).then(n).then(c).then(a).then(t.toolbar.settings.addDefaultSettings).catch(function(){t.core.log("Can't draw editor interface")})};var n=function(){var e=t.draw.inlineToolbar();t.nodes.inlineToolbar.wrapper=e,t.nodes.inlineToolbar.buttons=t.draw.inlineToolbarButtons(),t.nodes.inlineToolbar.actions=t.draw.inlineToolbarActions(),t.nodes.inlineToolbar.wrapper.appendChild(t.nodes.inlineToolbar.buttons),t.nodes.inlineToolbar.wrapper.appendChild(t.nodes.inlineToolbar.actions),t.nodes.wrapper.appendChild(t.nodes.inlineToolbar.wrapper)},o=function(){var e=t.draw.toolbar(),n=i(),o=r();return e.appendChild(n),e.appendChild(o),t.nodes.toolbar=e,e},r=function(){var e=t.draw.toolbarContent(),n=t.draw.toolbox(),o=t.draw.plusButton();return e.appendChild(o),e.appendChild(n),t.nodes.toolbox=n,t.nodes.plusButton=o,e},i=function(){var e=t.draw.blockSettings(),n=t.draw.blockButtons(),o=t.draw.defaultSettings(),r=t.draw.settingsButton(),i=t.toolbar.settings.makeRemoveBlockButton(),a=t.draw.pluginsSettings();return e.appendChild(a),e.appendChild(o),n.appendChild(r),n.appendChild(i),n.appendChild(e),t.nodes.blockSettings=e,t.nodes.pluginSettings=a,t.nodes.defaultSettings=o,t.nodes.showSettingsButton=r,t.nodes.showTrashButton=i,n},a=function(){t.nodes.notifications=t.notifications.createHolder()},s=function(){var e,n,o;for(n in t.settings.tools)e=t.settings.tools[n],t.tools[n]=e,e.iconClassname||!e.displayInToolbox?"function"==typeof e.render?e.displayInToolbox&&(o=t.draw.toolbarButton(n,e.iconClassname),t.nodes.toolbox.appendChild(o),t.nodes.toolbarButtons[n]=o):t.core.log("render method missed. Tool %o skipped","warn",n):t.core.log("Toolbar icon classname missed. Tool %o skipped","warn",n)},c=function(){var e,n,o={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"}};for(var r in o)n=o[r],e=t.draw.toolbarButtonInline(r,n.icon),t.nodes.inlineToolbar.buttons.appendChild(e),t.ui.setInlineToolbarButtonBehaviour(e,n.command)};return e.bindEvents=function(){t.core.log("ui.bindEvents fired","info"),t.listeners.add(document,"keydown",t.callback.globalKeydown,!1),t.listeners.add(t.nodes.redactor,"keydown",t.callback.redactorKeyDown,!1),t.listeners.add(document,"keyup",t.callback.globalKeyup,!1),t.listeners.add(t.nodes.redactor,"click",t.callback.redactorClicked,!1),t.listeners.add(t.nodes.plusButton,"click",t.callback.plusButtonClicked,!1),t.listeners.add(t.nodes.showSettingsButton,"click",t.callback.showSettingsButtonClicked,!1);for(var e in t.nodes.toolbarButtons)t.listeners.add(t.nodes.toolbarButtons[e],"click",t.callback.toolbarButtonClicked,!1)},e.addBlockHandlers=function(e){e&&(t.listeners.add(e,"keydown",t.callback.blockKeydown,!1),t.listeners.add(e,"paste",t.callback.blockPasteCallback,!1),t.listeners.add(e,"mouseup",t.toolbar.inline.show,!1))},e.saveInputs=function(){var e=t.nodes.redactor;t.state.inputs=[];var n=e.querySelectorAll("[contenteditable], input, textarea");Array.prototype.map.call(n,function(e){e.type&&"text"!=e.type&&"textarea"!=e.type||t.state.inputs.push(e)})},e.addInitialBlock=function(){var e,n=t.settings.initialBlockPlugin;return t.tools[n]?(e=t.tools[n].render(),e.setAttribute("data-placeholder","Расскажите свою историю..."),t.content.insertBlock({type:n,block:e}),void t.content.workingNodeChanged(e)):void t.core.log("Plugin %o was not implemented and can't be used as initial block","warn",n)},e.setInlineToolbarButtonBehaviour=function(e,n){t.listeners.add(e,"mousedown",function(e){t.toolbar.inline.toolClicked(e,n)},!1)},e}({})},function(e,t){"use strict";e.exports=function(e){var t=codex.editor;return e.input=null,e.arguments=null,e.prepare=function(){var e=t.draw.node("INPUT","",{type:"file"});t.listeners.add(e,"change",t.transport.fileSelected),t.transport.input=e},e.clearInput=function(){e.input=null,e.prepare()},e.fileSelected=function(){var n,o=this,r=o.files,i=new FormData;if(t.transport.arguments.multiple===!1)i.append("files",r[0],r[0].name);else for(n=0;n<r.length;n++)i.append("files[]",r[n],r[n].name);t.core.ajax({type:"POST",data:i,url:t.transport.arguments.url,beforeSend:t.transport.arguments.beforeSend,success:t.transport.arguments.success,error:t.transport.arguments.error}),e.clearInput()},e.selectAndUpload=function(t){e.arguments=t,t.multiple===!0&&e.input.setAttribute("multiple","multiple"),t.accept&&e.input.setAttribute("accept",t.accept),e.input.click()},e}({})},function(e,t){"use strict";e.exports=function(e){var t=codex.editor;return e.makeBlocksFromData=function(){return t.core.isEmpty(t.state.blocks)||!t.state.blocks.items.length?void t.ui.addInitialBlock():void Promise.resolve().then(function(){return t.state.blocks}).then(t.renderer.appendBlocks).catch(function(e){t.core.log("Error while parsing JSON: %o","error",e)})},e.appendBlocks=function(e){for(var n=e.items,o=Promise.resolve(),r=0;r<n.length;r++)t.renderer.appendNodeAtIndex(o,n,r)},e.appendNodeAtIndex=function(e,n,o){e.then(function(){return t.renderer.getNodeAsync(n,o)}).then(t.renderer.createBlockFromData).then(function(e){return t.content.insertBlock(e),e.block}).catch(function(e){t.core.log("Node skipped while parsing because %o","error",e)})},e.getNodeAsync=function(e,t){return Promise.resolve().then(function(){return{tool:e[t],position:t}})},e.createBlockFromData=function(e){var n,o=e.tool,r=o.type,i=o.anchor,a=o.cover;if(!t.tools[r])throw Error("Plugin «"+r+"» not found");if("function"!=typeof t.tools[r].render)throw Error("Plugin «"+r+"» must have «render» method");t.tools[r].available===!1?(n=t.draw.unavailableBlock(),n.innerHTML=t.tools[r].loadingMessage,n.dataset.inputPosition=e.position):n=t.tools[r].render(o.data);var s=t.tools[r].isStretched||!1;return{type:r,block:n,stretched:s,cover:a,anchor:i}},e}({})},function(e,t){"use strict";e.exports=function(e){var t=codex.editor;return e.saveBlocks=function(){t.state.html=t.nodes.redactor.innerHTML,t.state.jsonOutput=[],Promise.resolve().then(function(){return t.nodes.redactor.childNodes}).then(t.saver.makeQueue).then(function(){}).catch(function(e){t.core.log(e)})},e.makeQueue=function(e){for(var n=Promise.resolve(),o=0;o<e.length;o++)t.saver.getBlockData(n,e,o)},e.getBlockData=function(e,n,o){e.then(function(){return t.saver.getNodeAsync(n,o)}).then(t.saver.makeFormDataFromBlocks)},e.getNodeAsync=function(e,t){return Promise.resolve().then(function(){return e[t]})},e.makeFormDataFromBlocks=function(e){var n=e.dataset.tool,o=e.dataset.anchor;if(!t.tools[n])throw Error("Plugin «"+n+"» not found");if("function"!=typeof t.tools[n].save)throw Error("Plugin «"+n+"» must have save method");var r,i,a,s=e.childNodes[0],c=s.childNodes[0],l=!1;if(t.tools[n].available===!1)i=c.dataset.inputPosition,r=codex.editor.state.blocks.items[i].data,l=codex.editor.state.blocks.items[i].cover,o=codex.editor.state.blocks.items[i].anchor;else if(r=t.tools[n].save(c),l=e.classList.contains(t.ui.className.BLOCK_IN_FEED_MODE),t.tools[n].validate){var d=t.tools[n].validate(r);if(!d)return}a={type:n,anchor:o,data:r},a.cover=l,t.state.jsonOutput.push(a)},e}({})},function(e,t){"use strict";e.exports=function(e){var t=codex.editor;e.currentNode=null,e.editorAreaHightlighted=null,e.sync=function(){t.core.log("syncing..."),t.state.html=t.nodes.redactor.innerHTML},e.getNodeFocused=function(){var e,n=window.getSelection();if(null===n.anchorNode)return null;if(e=n.anchorNode.nodeType==t.core.nodeTypes.TAG?n.anchorNode:n.focusNode.parentElement,!t.parser.isFirstLevelBlock(e)){for(var o=e.parentNode;o&&!t.parser.isFirstLevelBlock(o);)o=o.parentNode;e=o}return e!=t.nodes.redactor?e:null},e.markBlock=function(){t.content.currentNode.classList.add(t.ui.className.BLOCK_HIGHLIGHTED)},e.clearMark=function(){t.content.currentNode&&t.content.currentNode.classList.remove(t.ui.className.BLOCK_HIGHLIGHTED)},e.getFirstLevelBlock=function(e){if(t.core.isDomNode(e)||(e=e.parentNode),e===t.nodes.redactor||e===document.body)return null;for(;!e.classList.contains(t.ui.className.BLOCK_CLASSNAME);)e=e.parentNode;return e},e.workingNodeChanged=function(e){t.content.clearMark(),e&&(this.currentNode=this.getFirstLevelBlock(e))},e.replaceBlock=function(e,n){if(!e||!n)return void t.core.log("replaceBlock: missed params");for(;!e.classList.contains(t.ui.className.BLOCK_CLASSNAME);)e=e.parentNode;e.classList.contains(t.ui.className.BLOCK_IN_FEED_MODE)&&n.classList.add(t.ui.className.BLOCK_IN_FEED_MODE),e.classList.contains(t.ui.className.BLOCK_WITH_ANCHOR)&&n.classList.add(t.ui.className.BLOCK_WITH_ANCHOR),n.dataset.anchor=e.dataset.anchor,t.nodes.redactor.replaceChild(n,e),t.content.workingNodeChanged(n),t.ui.addBlockHandlers(n),t.ui.saveInputs()},e.insertBlock=function(n,o){var r=t.content.currentNode,i=n.block,a=n.type,s=n.cover,c=n.anchor,l=n.stretched,d=t.content.composeNewBlock(i,a,l,c);if(s===!0&&d.classList.add(t.ui.className.BLOCK_IN_FEED_MODE),c&&d.classList.add(t.ui.className.BLOCK_WITH_ANCHOR),r?t.core.insertAfter(r,d):t.nodes.redactor.appendChild(d),t.ui.addBlockHandlers(d),t.content.workingNodeChanged(d),t.ui.saveInputs(),o){var u=t.caret.getCurrentInputIndex()||-1;if(u==-1){var p=d.querySelector("[contenteditable]"),f=document.createTextNode("");p.appendChild(f),t.caret.set(p,0,0),t.toolbar.move(),t.toolbar.showPlusButton()}else{if(u===t.state.inputs.length-1)return;window.setTimeout(function(){t.caret.setToNextBlock(u),t.toolbar.move(),t.toolbar.open()},10)}}e.editorAreaHightlighted=!1},e.switchBlock=function(e,n,o){o=o||t.content.currentNode.dataset.tool;var r=t.content.composeNewBlock(n,o);t.content.replaceBlock(e,r),t.ui.saveInputs()},e.getDeepestTextNodeFromPosition=function(e,n){var o,r,i,a=e.childNodes;for(o=0;o<a.length;o++)r=a[o],r.nodeType==t.core.nodeTypes.TEXT&&(i=r.textContent.trim(),""===i&&(e.removeChild(r),n--));if(0===e.childNodes.length)return document.createTextNode("");n<0&&(n=1);var s=!1;for(0===n&&(s=!0,n=1);n;)e=s?e.childNodes[0]:e.childNodes[n-1],e.nodeType==t.core.nodeTypes.TAG?n=e.childNodes.length:e.nodeType==t.core.nodeTypes.TEXT&&(n=0);return e},e.composeNewBlock=function(e,n,o,r){var i=t.draw.node("DIV",t.ui.className.BLOCK_CLASSNAME,{}),a=t.draw.node("DIV",t.ui.className.BLOCK_CONTENT,{});return a.appendChild(e),i.appendChild(a),o&&a.classList.add(t.ui.className.BLOCK_STRETCHED),i.dataset.tool=n,i.dataset.anchor=r||"",i},e.getRange=function(){var e=window.getSelection().getRangeAt(0);return e},e.splitBlock=function(e){var n,o,r,i,a=window.getSelection(),s=a.anchorNode,c=s.textContent,l=a.anchorOffset,d=t.content.currentNode.querySelector("[contentEditable]");n=c.substring(0,l),r=c.substring(l),o=document.createTextNode(n),r&&(i=document.createTextNode(r));var u=[],p=[],f=!1;i&&p.push(i);for(var h,g=0;h=d.childNodes[g];g++)h!=s?f?p.push(h):u.push(h):f=!0;t.state.inputs[e].innerHTML="";var v=u.length;for(g=0;g<v;g++)t.state.inputs[e].appendChild(u[g]);t.state.inputs[e].appendChild(o);var m=p.length,b=document.createElement("div");for(g=0;g<m;g++)b.appendChild(p[g]);b=b.innerHTML;var k=t.settings.initialBlockPlugin;t.content.insertBlock({type:k,block:t.tools[k].render({text:b})},!0)},e.mergeBlocks=function(e,n){if(0!==e){var o,r=t.state.inputs[e].innerHTML;o=n?t.state.inputs[n]:t.state.inputs[e-1],o.innerHTML+=r}},e.paste=function(e){var n=t.content.currentNode,o=n.dataset.tool;t.tools[o].allowedToPaste?t.content.sanitize.call(this,e.target):t.content.pasteTextContent(e.addedNodes)},e.pasteTextContent=function(e){var n,o=e[0];o&&(n=o.nodeType==t.core.nodeTypes.TEXT?document.createTextNode(o):document.createTextNode(o.textContent),t.core.isDomNode(o)&&o.parentNode.replaceChild(n,o))},e.sanitize=function(e){if(e){var n=e[0];if(n&&(this.disconnect(),n.nodeType!=t.core.nodeTypes.TEXT)){var o=t.sanitizer.init(t.satinizer.Config.BASIC),r=o.clean(e.outerHTML),i=t.draw.node("DIV",[],{innerHTML:r});n.replaceWith(i.childNodes[0])}}},e.isLastNode=function(e){for(var o=!1;!o;){if(!n(e))return!1;e=e.parentNode,e.classList.contains(t.ui.className.BLOCK_CONTENT)&&(o=!0)}return!0};var n=function(e){for(var t=e.nextSibling;t;){if(t.textContent.length)return!1;t=t.nextSibling}return!0};return e.wrapTextWithParagraphs=function(e){var t,n,o,r,i=document.createElement("DIV"),a=document.createElement("DIV"),s=["DIV","P"];for(i.innerHTML=e,n=document.createElement("P"),t=0;t<i.childNodes.length;t++)r=i.childNodes[t],o=s.indexOf(r.tagName)!=-1,o?(n.childNodes.length&&(a.appendChild(n.cloneNode(!0)),n=null,n=document.createElement("P")),a.appendChild(r.cloneNode(!0))):(n.appendChild(r.cloneNode(!0)),t==i.childNodes.length-1&&a.appendChild(n.cloneNode(!0)));return a.innerHTML},e.getEditableParent=function(e){for(;e&&"true"!=e.contentEditable;)e=e.parentNode;return e},e}({})},function(e,t,n){"use strict";e.exports=function(e){var t=codex.editor;return e.settings=n(9),e.inline=n(10),e.toolbox=n(11),e.defaultToolbarHeight=49,e.defaultOffset=34,e.opened=!1,e.current=null,e.open=function(){t.hideToolbar||(t.nodes.toolbar.classList.add("opened"),this.opened=!0)},e.close=function(){t.nodes.toolbar.classList.remove("opened"),e.opened=!1,e.current=null;for(var n in t.nodes.toolbarButtons)t.nodes.toolbarButtons[n].classList.remove("selected");t.toolbar.toolbox.close(),t.toolbar.settings.close()},e.toggle=function(){this.opened?this.close():this.open()},e.hidePlusButton=function(){t.nodes.plusButton.classList.add("hide")},e.showPlusButton=function(){t.nodes.plusButton.classList.remove("hide")},e.move=function(){if(t.toolbar.toolbox.close(),t.content.currentNode){var e=t.content.currentNode.offsetTop-t.toolbar.defaultToolbarHeight/2+t.toolbar.defaultOffset;t.nodes.toolbar.style.transform="translate3D(0, "+Math.floor(e)+"px, 0)",t.toolbar.settings.hideRemoveActions()}},e}({})},function(e,t){"use strict";e.exports=function(e){var t=codex.editor;return e.opened=!1,e.setting=null,e.actions=null,e.cover=null,e.open=function(e){if(t.tools[e]&&t.tools[e].makeSettings){var n=t.tools[e].makeSettings();t.nodes.pluginSettings.appendChild(n)}else t.core.log("Plugin «"+e+"» has no settings","warn");t.nodes.blockSettings.classList.add("opened"),t.toolbar.settings.addDefaultSettings(),this.opened=!0},e.close=function(){t.nodes.blockSettings.classList.remove("opened"),t.nodes.pluginSettings.innerHTML="",this.opened=!1},e.toggle=function(e){this.opened?this.close():(this.open(e),t.anchors.settingsOpened(t.content.currentNode))},e.addDefaultSettings=function(){var e,n;t.nodes.defaultSettings.innerHTML="",e=t.toolbar.settings.makeFeedModeToggler(),n=t.toolbar.settings.makeAnchorInput(),t.nodes.defaultSettings.appendChild(n),t.nodes.defaultSettings.appendChild(e)},e.makeFeedModeToggler=function(){var e,n,o=t.toolbar.settings.isFeedModeActivated();return n=o?{innerHTML:'<i class="ce-icon-newspaper"></i>Не выводить в ленте'}:{innerHTML:'<i class="ce-icon-newspaper"></i>Вывести в ленте'},e=t.draw.node("DIV",t.ui.className.SETTINGS_ITEM,n),t.listeners.add(e,"click",t.toolbar.settings.updateFeedMode,!1),e},e.updateFeedMode=function(){var e=t.content.currentNode;e.classList.toggle(t.ui.className.BLOCK_IN_FEED_MODE),t.toolbar.settings.close()},e.isFeedModeActivated=function(){var e=t.content.currentNode;return!!e&&e.classList.contains(t.ui.className.BLOCK_IN_FEED_MODE)},e.makeAnchorInput=function(){var e=t.draw.node("div","ce-settings__anchor-wrapper ce-settings__item",{}),n=t.draw.node("i","ce-settings__anchor-hash",{}),o=t.draw.node("input","ce-settings__anchor-input",{placeholder:"Якорь"});return t.listeners.add(o,"keydown",t.anchors.keyDownOnAnchorInput),t.listeners.add(o,"keyup",t.anchors.keyUpOnAnchorInput),t.listeners.add(o,"input",t.anchors.anchorChanged),t.listeners.add(o,"blur",t.anchors.anchorChanged),e.appendChild(n),e.appendChild(o),t.anchors.input=o,e},e.makeRemoveBlockButton=function(){var e=t.draw.node("SPAN","ce-toolbar__remove-btn",{}),n=t.draw.node("SPAN","ce-toolbar__remove-setting",{innerHTML:'<i class="ce-icon-trash"></i>'}),o=t.draw.node("DIV","ce-toolbar__remove-confirmation",{}),r=t.draw.node("DIV","ce-toolbar__remove-confirm",{textContent:"Удалить блок"}),i=t.draw.node("DIV","ce-toolbar__remove-cancel",{textContent:"Отмена"});return t.listeners.add(n,"click",t.toolbar.settings.removeButtonClicked,!1),t.listeners.add(r,"click",t.toolbar.settings.confirmRemovingRequest,!1),t.listeners.add(i,"click",t.toolbar.settings.cancelRemovingRequest,!1),o.appendChild(r),o.appendChild(i),e.appendChild(n),e.appendChild(o),t.toolbar.settings.setting=n,t.toolbar.settings.actions=o,e},e.removeButtonClicked=function(){var e=t.toolbar.settings.actions;e.classList.contains("opened")?t.toolbar.settings.hideRemoveActions():t.toolbar.settings.showRemoveActions(),t.toolbar.toolbox.close(),t.toolbar.settings.close()},e.cancelRemovingRequest=function(){t.toolbar.settings.actions.classList.remove("opened")},e.confirmRemovingRequest=function(){var e,n=t.content.currentNode;n.remove(),e=t.nodes.redactor.childNodes.length,0===e&&(t.content.currentNode=null,t.ui.addInitialBlock()),t.ui.saveInputs(),t.toolbar.close()},e.showRemoveActions=function(){t.toolbar.settings.actions.classList.add("opened")},e.hideRemoveActions=function(){t.toolbar.settings.actions.classList.remove("opened")},e}({})},function(e,t){"use strict";e.exports=function(e){var t=codex.editor;e.buttonsOpened=null,e.actionsOpened=null,e.wrappersOffset=null,e.storedSelection=null,e.show=function(){var n,o=t.content.currentNode,r=o.dataset.tool;if(n=t.tools[r],n.showInlineToolbar){var i=e.getSelectionText(),a=t.nodes.inlineToolbar.wrapper;i.length>0&&(t.toolbar.inline.move(),a.classList.add("opened"),t.toolbar.inline.showButtons())}},e.close=function(){var e=t.nodes.inlineToolbar.wrapper;e.classList.remove("opened")},e.move=function(){this.wrappersOffset||(this.wrappersOffset=this.getWrappersOffset());var e,n,o=this.getSelectionCoords(),r=0,i=t.nodes.inlineToolbar.wrapper;0===i.offsetHeight&&(r=40),e=o.x-this.wrappersOffset.left,n=o.y+window.scrollY-this.wrappersOffset.top-r-i.offsetHeight,i.style.transform="translate3D("+Math.floor(e)+"px, "+Math.floor(n)+"px, 0)",t.toolbar.inline.closeButtons(),t.toolbar.inline.closeAction()},e.toolClicked=function(e,n){switch(n){case"createLink":t.toolbar.inline.createLinkAction(e,n);break;default:t.toolbar.inline.defaultToolAction(n)}t.nodes.inlineToolbar.buttons.childNodes.forEach(t.toolbar.inline.hightlight)},e.getWrappersOffset=function(){var e=t.nodes.wrapper,n=this.getOffset(e);return this.wrappersOffset=n,n},e.getOffset=function(e){for(var t=0,n=0;e&&!isNaN(e.offsetLeft)&&!isNaN(e.offsetTop);)t+=e.offsetLeft+e.clientLeft,n+=e.offsetTop+e.clientTop,e=e.offsetParent;return{top:n,left:t}},e.getSelectionCoords=function(){var e,t=document.selection,n=0,o=0;if(t)"Control"!=t.type&&(e=t.createRange(),e.collapse(!0),n=e.boundingLeft,o=e.boundingTop);else if(window.getSelection&&(t=window.getSelection(),t.rangeCount&&(e=t.getRangeAt(0).cloneRange(),e.getClientRects))){e.collapse(!0);var r=e.getClientRects()[0];if(!r)return;n=r.left,o=r.top}return{x:n,y:o}},e.getSelectionText=function(){var e="";return window.getSelection&&(e=window.getSelection().toString()),e},e.showButtons=function(){var e=t.nodes.inlineToolbar.buttons;e.classList.add("opened"),t.toolbar.inline.buttonsOpened=!0,t.nodes.inlineToolbar.buttons.childNodes.forEach(t.toolbar.inline.hightlight)},e.closeButtons=function(){var e=t.nodes.inlineToolbar.buttons;e.classList.remove("opened"),t.toolbar.inline.buttonsOpened=!1},e.showActions=function(){var e=t.nodes.inlineToolbar.actions;e.classList.add("opened"),t.toolbar.inline.actionsOpened=!0},e.closeAction=function(){var e=t.nodes.inlineToolbar.actions;e.innerHTML="",e.classList.remove("opened"),t.toolbar.inline.actionsOpened=!1};var n=function(e){if(e.keyCode==t.core.keys.ENTER){var n=t.content.currentNode,o=t.toolbar.inline.storedSelection;t.toolbar.inline.restoreSelection(n,o),t.toolbar.inline.setAnchor(this.value),e.preventDefault(),e.stopImmediatePropagation(),t.toolbar.inline.clearRange()}};return e.createLinkAction=function(e){var o=this.isLinkActive(),r=t.content.currentNode,i=t.toolbar.inline.saveSelection(r);if(t.toolbar.inline.storedSelection=i,o)t.toolbar.inline.restoreSelection(r,i),t.toolbar.inline.defaultToolAction("unlink");else{var a=t.draw.inputForLink();t.nodes.inlineToolbar.actions.appendChild(a),t.toolbar.inline.closeButtons(),t.toolbar.inline.showActions(),a.focus(),e.preventDefault(),t.listeners.add(a,"keydown",n,!1)}},e.isLinkActive=function(){var e=!1;return t.nodes.inlineToolbar.buttons.childNodes.forEach(function(t){var n=t.dataset.type;"link"==n&&t.classList.contains("hightlighted")&&(e=!0)}),e},e.defaultToolAction=function(e){document.execCommand(e,!1,null)},e.setAnchor=function(e){document.execCommand("createLink",!1,e),t.toolbar.inline.closeAction()},e.saveSelection=function(e){var t,n=window.getSelection().getRangeAt(0),o=n.cloneRange();return o.selectNodeContents(e),o.setEnd(n.startContainer,n.startOffset),t=o.toString().length,{start:t,end:t+n.toString().length}},e.restoreSelection=function(e,t){var n=document.createRange(),o=0;n.setStart(e,0),n.collapse(!0);for(var r,i,a=[e],s=!1,c=!1;!c&&(r=a.pop());)if(3==r.nodeType)i=o+r.length,!s&&t.start>=o&&t.start<=i&&(n.setStart(r,t.start-o),s=!0),s&&t.end>=o&&t.end<=i&&(n.setEnd(r,t.end-o),c=!0),o=i;else for(var l=r.childNodes.length;l--;)a.push(r.childNodes[l]);var d=window.getSelection();d.removeAllRanges(),d.addRange(n)},e.clearRange=function(){var e=window.getSelection();e.removeAllRanges()},e.hightlight=function(e){var n=e.dataset.type;document.queryCommandState(n)?t.toolbar.inline.setButtonHighlighted(e):t.toolbar.inline.removeButtonsHighLight(e);var o=window.getSelection(),r=o.anchorNode.parentNode;"A"==r.tagName&&"link"==n&&t.toolbar.inline.setButtonHighlighted(e)},e.setButtonHighlighted=function(e){if(e.classList.add("hightlighted"),"link"==e.dataset.type){var t=e.childNodes[0];t.classList.remove("ce-icon-link"),t.classList.add("ce-icon-unlink")}},e.removeButtonsHighLight=function(e){if(e.classList.remove("hightlighted"),"link"==e.dataset.type){var t=e.childNodes[0];t.classList.remove("ce-icon-unlink"),t.classList.add("ce-icon-link")}},e}({})},function(e,t){"use strict";e.exports=function(e){var t=codex.editor;return e.opened=!1,e.open=function(){t.toolbar.settings.opened&&t.toolbar.settings.close(),t.nodes.toolbox.classList.add("opened"),t.nodes.plusButton.classList.add("clicked"),t.toolbar.toolbox.opened=!0},e.close=function(){t.nodes.toolbox.classList.remove("opened"),t.nodes.plusButton.classList.remove("clicked"),t.toolbar.toolbox.opened=!1,t.toolbar.current=null},e.leaf=function(){var e=t.toolbar.current,n=Object.keys(t.tools),o=t.nodes.toolbarButtons,r=0,i=void 0,a=void 0,s=void 0;if(e)for(r=(n.indexOf(e)+1)%n.length,a=n[r];!t.tools[a].displayInToolbox;)r=(r+1)%n.length,a=n[r];else for(s in t.tools){if(t.tools[s].displayInToolbox)break;r++}i=n[r];for(var c in o)o[c].classList.remove("selected");o[i].classList.add("selected"),t.toolbar.current=i},e.toolClicked=function(e){var n,o,r,i=["image","link","list","instagram","twitter","embed"],a=t.tools[t.toolbar.current],s=t.content.currentNode,c=t.caret.inputIndex;n=a.render(),r={block:n,type:a.type,stretched:!1},s&&i.indexOf(s.dataset.tool)===-1&&""===s.textContent.trim()?t.content.switchBlock(s,n,a.type):(t.content.insertBlock(r),c++),o=a.appendCallback,o&&"function"==typeof o&&o.call(e),window.setTimeout(function(){t.caret.setToBlock(c)},10),t.content.workingNodeChanged(),t.toolbar.move()},e}({})},function(e,t){"use strict";e.exports=function(e){var t=codex.editor;e.globalKeydown=function(e){switch(e.keyCode){case t.core.keys.ENTER:t.callback.enterKeyPressed(e)}},e.redactorKeyDown=function(e){switch(e.keyCode){case t.core.keys.TAB:t.callback.tabKeyPressed(e);break;case t.core.keys.ENTER:t.callback.enterKeyPressedOnRedactorZone(e);break;case t.core.keys.ESC:t.callback.escapeKeyPressed(e);break;default:t.callback.defaultKeyPressed(e)}},e.globalKeyup=function(e){switch(e.keyCode){case t.core.keys.UP:case t.core.keys.LEFT:case t.core.keys.RIGHT:case t.core.keys.DOWN:t.callback.arrowKeyPressed(e)}},e.tabKeyPressed=function(e){var n=t.content.currentNode.querySelectorAll("textarea, input"),o=!0,r=!t.content.currentNode.textContent.trim();Array.prototype.map.call(n,function(e){"textarea"!=e.type&&"text"!=e.type||(o=o&&!e.value.trim())});var i=r&&o;i&&(t.toolbar.opened||t.toolbar.open(),t.toolbar.opened&&!t.toolbar.toolbox.opened?t.toolbar.toolbox.open():t.toolbar.toolbox.leaf(),e.preventDefault())},e.enterKeyPressed=function(){t.content.editorAreaHightlighted&&(t.caret.inputIndex=-1,t.callback.enterPressedOnBlock())},e.enterKeyPressedOnRedactorZone=function(e){"true"==e.target.contentEditable&&t.caret.saveCurrentInputIndex();var n=t.caret.getCurrentInputIndex()||0,o=t.content.currentNode,r=o.dataset.tool,i=t.toolbar.opened&&t.toolbar.current&&e.target==t.state.inputs[n],a=t.tools[r].enableLineBreaks,s=t.settings.initialBlockPlugin;if(i)return e.preventDefault(),t.toolbar.toolbox.toolClicked(e),t.toolbar.close(),e.stopPropagation(),void e.stopImmediatePropagation();if(e.shiftKey||a)return e.stopPropagation(),void e.stopImmediatePropagation();var c=window.getSelection(),l=c.anchorNode,d=t.caret.position.atTheEnd(),u=!1;if(e.shiftKey&&!a)return t.callback.enterPressedOnBlock(t.content.currentBlock,e),void e.preventDefault();if(u=l&&"true"!=l.parentNode.contentEditable,l.nodeType!=t.core.nodeTypes.TEXT||u||d){var p=t.content.isLastNode(l);p&&d&&(e.preventDefault(),e.stopPropagation(),e.stopImmediatePropagation(),t.core.log("ENTER clicked in last textNode. Create new BLOCK"),t.content.insertBlock({type:s,block:t.tools[s].render()},!0),t.toolbar.move(),t.toolbar.open(),t.toolbar.showPlusButton())}else e.preventDefault(),t.core.log("Splitting Text node..."),t.content.splitBlock(n),t.state.inputs[n+1].textContent.trim()||t.toolbar.showPlusButton();t.ui.saveInputs()},e.escapeKeyPressed=function(e){t.toolbar.close(),t.toolbar.toolbox.close(),e.preventDefault()},e.arrowKeyPressed=function(){t.content.workingNodeChanged(),t.toolbar.close(),t.toolbar.move()},e.defaultKeyPressed=function(){t.toolbar.close(),t.toolbar.inline.actionsOpened||(t.toolbar.inline.close(),t.content.clearMark())},e.redactorClicked=function(n){e.detectWhenClickedOnFirstLevelBlockArea(),t.content.workingNodeChanged(n.target),t.ui.saveInputs();var o,r=t.toolbar.inline.getSelectionText();if(0===r.length&&t.toolbar.inline.close(),"true"==n.target.contentEditable&&t.caret.saveCurrentInputIndex(),null===t.content.currentNode){var i=t.state.inputs.length>0?t.state.inputs.length-1:0;
if(t.state.inputs.length&&(o=t.content.getFirstLevelBlock(t.state.inputs[i])),t.state.inputs.length&&""===t.state.inputs[i].textContent&&o.dataset.tool==t.settings.initialBlockPlugin)t.caret.setToBlock(i);else{var a=t.settings.initialBlockPlugin;t.content.insertBlock({type:a,block:t.tools[a].render()}),1===t.state.inputs.length?t.caret.setToBlock(i):t.caret.setToNextBlock(i)}t.toolbar.move(),t.toolbar.open()}else t.toolbar.move(),t.toolbar.open(),t.toolbar.settings.close(),t.toolbar.toolbox.close();var s=!t.content.currentNode.textContent.trim(),c=t.content.currentNode.dataset.tool,l=c==t.settings.initialBlockPlugin;t.toolbar.hidePlusButton(),s||t.content.markBlock(),l&&s&&t.toolbar.showPlusButton()},e.detectWhenClickedOnFirstLevelBlockArea=function(){var e=window.getSelection(),n=e.anchorNode,o=!1;if(0===e.rangeCount)t.content.editorAreaHightlighted=!0;else{for(t.core.isDomNode(n)||(n=n.parentNode),"true"==n.contentEditable&&(o=!0);"true"!=n.contentEditable&&(n=n.parentNode,"true"==n.contentEditable&&(o=!0),n!=document.body););t.content.editorAreaHightlighted=!o}},e.toolbarButtonClicked=function(e){var n=this;t.toolbar.current=n.dataset.type,t.toolbar.toolbox.toolClicked(e),t.toolbar.close()},e.plusButtonClicked=function(){t.nodes.toolbox.classList.contains("opened")?t.toolbar.toolbox.close():t.toolbar.toolbox.open()},e.blockKeydown=function(e){var n=this;switch(e.keyCode){case t.core.keys.DOWN:case t.core.keys.RIGHT:t.callback.blockRightOrDownArrowPressed();break;case t.core.keys.BACKSPACE:t.callback.backspacePressed(n,e);break;case t.core.keys.UP:case t.core.keys.LEFT:t.callback.blockLeftOrUpArrowPressed()}},e.blockRightOrDownArrowPressed=function(){var e,n=window.getSelection(),o=t.state.inputs,r=n.anchorNode;if(!r)return!1;for(;"true"!=r.contentEditable;)e=r.parentNode,r=e;for(var i=0;r!=o[i];)i++;if(!r.textContent)return void t.caret.setToNextBlock(i);var a,s,c=!1,l=!1;return a=r.childNodes[r.childNodes.length-1],s=t.core.isDomNode(a)?t.content.getDeepestTextNodeFromPosition(a,a.childNodes.length):a,c=n.anchorNode==s,l=s.length==n.anchorOffset,c&&l?void t.caret.setToNextBlock(i):(t.core.log("arrow [down|right] : caret does not reached the end"),!1)},e.blockLeftOrUpArrowPressed=function(){var e,n=window.getSelection(),o=t.state.inputs,r=n.anchorNode;if(!r)return!1;if(0!==n.anchorOffset)return!1;for(;"true"!=r.contentEditable;)e=r.parentNode,r=e;for(var i=0;r!=o[i];)i++;var a,s,c=!1,l=!1;return r.textContent?(a=r.childNodes[0],s=t.core.isDomNode(a)?t.content.getDeepestTextNodeFromPosition(a,0):a,c=n.anchorNode==s,l=0===n.anchorOffset,void(c&&l&&t.caret.setToPreviousBlock(i))):void t.caret.setToPreviousBlock(i)},e.enterPressedOnBlock=function(){var e=t.settings.initialBlockPlugin;t.content.insertBlock({type:e,block:t.tools[e].render()},!0),t.toolbar.move(),t.toolbar.open()},e.backspacePressed=function(e,o){var r,i,a,s=t.caret.getCurrentInputIndex();if(n(o.target)){if(""!=o.target.value.trim())return;e.remove()}if(e.textContent.trim()){if(r=t.content.getRange(),i=r.endOffset-r.startOffset,!t.caret.position.atStart()||i||!t.state.inputs[s-1])return;t.content.mergeBlocks(s)}i||e.remove(),a=t.nodes.redactor.childNodes.length,0===a?(t.content.currentNode=null,t.ui.addInitialBlock(),t.ui.saveInputs(),window.setTimeout(function(){t.caret.setToPreviousBlock(1)},10)):0!==t.caret.inputIndex?t.caret.setToPreviousBlock(t.caret.inputIndex):t.caret.setToNextBlock(t.caret.inputIndex),t.toolbar.move(),t.toolbar.opened||t.toolbar.open(),t.ui.saveInputs(),o.preventDefault()},e._blockPasteCallback=function(){var e=t.caret.getCurrentInputIndex(),n=new MutationObserver(t.callback.handleMutationsOnPaste),o={attributes:!0,childList:!1,characterData:!1,subtree:!0};n.observe(t.state.inputs[e],o)},e.blockPasteCallback=function(e){if(!n(e.target)){e.preventDefault();var o=t.content.getEditableParent(e.target),r=t.content.currentNode;if(o){var i,a,s=e.clipboardData.getData("text/html"),c=e.clipboardData.getData("text/plain"),l=t.draw.node("DIV","",{}),d=new t.sanitizer.init(t.sanitizer.Config.BASIC);a=document.createDocumentFragment(),""!=s.trim()?(i=d.clean(s),l.innerHTML=i):l.innerText=c.toString();for(var u,p;u=l.firstChild;)p=a.appendChild(u);if(!t.tools[r.dataset.tool].allowRenderOnPaste||!t.paste.pasted(e)){var f,h;f=window.getSelection(),h=f.getRangeAt(0),h.deleteContents(),h.insertNode(a),p&&(h=h.cloneRange(),h.setStartAfter(p),h.collapse(!0),f.removeAllRanges(),f.addRange(h))}}}},e.handleMutationsOnPaste=function(e){var n=this;e.forEach(function(e){t.content.paste.call(n,e)})},e.showSettingsButtonClicked=function(){var e=t.content.currentNode.dataset.tool;t.toolbar.settings.toggle(e),t.toolbar.toolbox.close(),t.toolbar.settings.hideRemoveActions()};var n=function(e){var t=["INPUT","TEXTAREA"];return t.indexOf(e.tagName)!=-1};return e}({})},function(e,t){"use strict";e.exports=function(e){return e.wrapper=function(){var e=document.createElement("div");return e.className+="codex-editor",e},e.redactor=function(){var e=document.createElement("div");return e.className+="ce-redactor",e},e.ceBlock=function(){var e=document.createElement("DIV");return e.className+="ce_block",e},e.toolbar=function(){var e=document.createElement("div");return e.className+="ce-toolbar",e},e.toolbarContent=function(){var e=document.createElement("DIV");return e.classList.add("ce-toolbar__content"),e},e.inlineToolbar=function(){var e=document.createElement("DIV");return e.className+="ce-toolbar-inline",e},e.inlineToolbarButtons=function(){var e=document.createElement("DIV");return e.className+="ce-toolbar-inline__buttons",e},e.inlineToolbarActions=function(){var e=document.createElement("DIV");return e.className+="ce-toolbar-inline__actions",e},e.inputForLink=function(){var e=document.createElement("INPUT");return e.type="input",e.className+="inputForLink",e.placeholder="Вставьте ссылку ...",e.setAttribute("form","defaultForm"),e.setAttribute("autofocus","autofocus"),e},e.blockButtons=function(){var e=document.createElement("div");return e.className+="ce-toolbar__actions",e},e.blockSettings=function(){var e=document.createElement("div");return e.className+="ce-settings",e},e.defaultSettings=function(){var e=document.createElement("div");return e.classList.add("ce-settings_default"),e},e.pluginsSettings=function(){var e=document.createElement("div");return e.classList.add("ce-settings_plugin"),e},e.plusButton=function(){var e=document.createElement("span");return e.className="ce-toolbar__plus",e},e.settingsButton=function(){var e=document.createElement("span");return e.className="ce-toolbar__settings-btn",e.innerHTML='<i class="ce-icon-cog"></i>',e},e.toolbox=function(){var e=document.createElement("div");return e.className="ce-toolbar__tools",e},e.toolbarButton=function(e,t){var n=document.createElement("li"),o=document.createElement("i"),r=document.createElement("span");return n.dataset.type=e,n.setAttribute("title",e),o.classList.add(t),r.classList.add("ce_toolbar_tools--title"),n.appendChild(o),n.appendChild(r),n},e.toolbarButtonInline=function(e,t){var n=document.createElement("BUTTON"),o=document.createElement("I");return n.type="button",n.dataset.type=e,o.classList.add(t),n.appendChild(o),n},e.block=function(e,t){var n=document.createElement(e);return n.innerHTML=t||"",n},e.node=function(e,t,n){var o=document.createElement(e);if(t&&(o.className=t),n)for(var r in n)o[r]=n[r];return o},e.unavailableBlock=function(){var e=document.createElement("DIV");return e.classList.add("cdx-unavailable-block"),e},e}({})},function(e,t){"use strict";e.exports=function(e){var t=codex.editor;return e.inputIndex=null,e.offset=null,e.focusedNodeIndex=null,e.set=function(n,o,r){r=r||e.offset||0,o=o||e.focusedNodeIndex||0;var i,a=n.childNodes;if(i=0===a.length?n:a[o],"true"!=n.contentEditable)return void n.focus();t.core.isDomNode(i)&&(i=t.content.getDeepestTextNodeFromPosition(i,i.childNodes.length));var s=document.createRange(),c=window.getSelection();window.setTimeout(function(){s.setStart(i,r),s.setEnd(i,r),c.removeAllRanges(),c.addRange(s),t.caret.saveCurrentInputIndex()},20)},e.saveCurrentInputIndex=function(){var n,o=window.getSelection(),r=t.state.inputs,i=o.anchorNode;if(i){for(;"true"!=i.contentEditable;)n=i.parentNode,i=n;for(var a=0;i!=r[a];)a++;e.inputIndex=a}},e.getCurrentInputIndex=function(){return e.inputIndex},e.setToNextBlock=function(e){var n=t.state.inputs,o=n[e+1];if(!o)return void t.core.log("We are reached the end");if(!o.childNodes.length){var r=document.createTextNode("");o.appendChild(r)}t.caret.inputIndex=e+1,t.caret.set(o,0,0),t.content.workingNodeChanged(o)},e.setToBlock=function(e){var n=t.state.inputs,o=n[e];if(o){if(!o.childNodes.length){var r=document.createTextNode("");o.appendChild(r)}t.caret.inputIndex=e,t.caret.set(o,0,0),t.content.workingNodeChanged(o)}},e.setToPreviousBlock=function(e){e=e||0;var n,o,r,i=t.state.inputs,a=i[e-1];return a?(n=t.content.getDeepestTextNodeFromPosition(a,a.childNodes.length),o=n.length,a.childNodes.length||(r=document.createTextNode(""),a.appendChild(r)),t.caret.inputIndex=e-1,t.caret.set(a,a.childNodes.length-1,o),void t.content.workingNodeChanged(i[e-1])):void t.core.log("We are reached first node")},e.position={atStart:function(){var e=window.getSelection(),n=e.anchorOffset,o=e.anchorNode,r=t.content.getFirstLevelBlock(o),i=r.childNodes[0];t.core.isDomNode(o)||(o=o.parentNode);var a=o===i.childNodes[0],s=0===n;return a&&s},atTheEnd:function(){var e=window.getSelection(),t=e.anchorOffset,n=e.anchorNode;return!n||!n.length||t===n.length}},e}({})},function(e,t){"use strict";e.exports=function(e){var t=codex.editor,n=[],o=function(e){n.push(e);for(var t=0;t<n.length&&n.length>5;)"confirm"!=n[t].type&&"prompt"!=n[t].type?(n[t].close(),n.splice(t,1)):t++};return e.createHolder=function(){var e=t.draw.node("DIV","cdx-notifications-block");return t.nodes.notifications=document.body.appendChild(e),e},e.errorThrown=function(e,n){t.notifications.notification({message:"This action is not available currently",type:n.type})},e.notification=function(e){function n(e){if(!e||!e.message)return void t.core.log("Can't create notification. Message is missed");e.type=e.type||"alert",e.time=1e3*e.time||1e4;var n=t.draw.node("DIV","cdx-notification"),o=t.draw.node("DIV","cdx-notification__message"),r=t.draw.node("INPUT","cdx-notification__input"),f=t.draw.node("SPAN","cdx-notification__ok-btn"),h=t.draw.node("SPAN","cdx-notification__cancel-btn");o.textContent=e.message,f.textContent=e.okMsg||"ОК",h.textContent=e.cancelMsg||"Отмена",t.listeners.add(f,"click",u),t.listeners.add(h,"click",p),n.appendChild(o),"prompt"==e.type&&n.appendChild(r),n.appendChild(f),"prompt"!=e.type&&"confirm"!=e.type||n.appendChild(h),n.classList.add("cdx-notification-"+e.type),n.dataset.type=e.type,a=n,c=e.type,l=e.confirm,s=e.cancel,d=r,"prompt"!=e.type&&"confirm"!=e.type&&window.setTimeout(i,e.time)}function r(){t.nodes.notifications.appendChild(a),d.focus(),t.nodes.notifications.classList.add("cdx-notification__notification-appending"),window.setTimeout(function(){t.nodes.notifications.classList.remove("cdx-notification__notification-appending")},100),o({type:c,close:i})}function i(){a.remove()}var a=null,s=null,c=null,l=null,d=null,u=function(){if(i(),"function"==typeof l)return"prompt"==c?void l(d.value):void l()},p=function(){i(),"function"==typeof s&&s()};return e&&(n(e),r()),{create:n,send:r,close:i}},e.clear=function(){t.nodes.notifications.innerHTML="",n=[]},e}({})},function(e,t){"use strict";e.exports=function(e){var t=codex.editor;return e.insertPastedContent=function(e,n){t.content.insertBlock({type:e.type,block:e.render({text:n.innerHTML})})},e.isFirstLevelBlock=function(e){return e.nodeType==t.core.nodeTypes.TAG&&e.classList.contains(t.ui.className.BLOCK_CLASSNAME)},e}({})},function(e,t,n){"use strict";e.exports=function(e){var t=n(18),o={BASIC:{tags:{p:{},a:{href:!0,target:"_blank",rel:"nofollow"},i:{},b:{},strong:{},em:{},span:{}}}};return e.Config=o,e.init=t,e}({})},function(e,t,n){var o,r;!function(i,a){o=a,r="function"==typeof o?o.call(t,n,t,e):o,!(void 0!==r&&(e.exports=r))}(this,function(){function e(e){var t=e.tags,n=Object.keys(t),o=n.map(function(e){return typeof t[e]}).every(function(e){return"object"===e||"boolean"===e||"function"===e});if(!o)throw new Error("The configuration was invalid");this.config=e}function t(e){return s.indexOf(e.nodeName)!==-1}function n(e){return c.indexOf(e.nodeName)!==-1}function o(e){return document.createTreeWalker(e,NodeFilter.SHOW_TEXT|NodeFilter.SHOW_ELEMENT|NodeFilter.SHOW_COMMENT,null,!1)}function r(e,t,n){return"function"==typeof e.tags[t]?e.tags[t](n):e.tags[t]}function i(e,t){return"undefined"==typeof t||"boolean"==typeof t&&!t}function a(e,t,n){var o=e.name.toLowerCase();return t!==!0&&("function"==typeof t[o]?!t[o](e.value,n):"undefined"==typeof t[o]||(t[o]===!1||"string"==typeof t[o]&&t[o]!==e.value))}var s=["P","LI","TD","TH","DIV","H1","H2","H3","H4","H5","H6","PRE"],c=["A","B","STRONG","I","EM","SUB","SUP","U","STRIKE"];return e.prototype.clean=function(e){var t=document.createElement("div");return t.innerHTML=e,this._sanitize(t),t.innerHTML},e.prototype._sanitize=function(e){var s=o(e),c=s.firstChild();if(c)do if(!c._sanitized)if(c.nodeType!==Node.TEXT_NODE){if(c.nodeType===Node.COMMENT_NODE){e.removeChild(c),this._sanitize(e);break}var l,d=n(c);d&&(l=Array.prototype.some.call(c.childNodes,t));var u=!!e.parentNode,p=t(e)&&t(c)&&u,f=c.nodeName.toLowerCase(),h=r(this.config,f,c),g=d&&l;if(g||i(c,h)||!this.config.keepNestedBlockElements&&p){if("SCRIPT"!==c.nodeName&&"STYLE"!==c.nodeName)for(;c.childNodes.length>0;)e.insertBefore(c.childNodes[0],c);e.removeChild(c),this._sanitize(e);break}for(var v=0;v<c.attributes.length;v+=1){var m=c.attributes[v];a(m,h,c)&&(c.removeAttribute(m.name),v-=1)}this._sanitize(c),c._sanitized=!0}else if(""===c.data.trim()&&(c.previousElementSibling&&t(c.previousElementSibling)||c.nextElementSibling&&t(c.nextElementSibling))){e.removeChild(c),this._sanitize(e);break}while(c=s.nextSibling())},e})},function(e,t){"use strict";e.exports=function(e){var t=codex.editor;return e.input=null,e.currentNode=null,e.settingsOpened=function(t){e.currentNode=t,e.input.value=e.currentNode.dataset.anchor||""},e.anchorChanged=function(n){var o=n.target.value=e.rusToTranslit(n.target.value);e.currentNode.dataset.anchor=o,""!==o.trim()?e.currentNode.classList.add(t.ui.className.BLOCK_WITH_ANCHOR):e.currentNode.classList.remove(t.ui.className.BLOCK_WITH_ANCHOR)},e.keyDownOnAnchorInput=function(e){e.keyCode==t.core.keys.ENTER&&(e.preventDefault(),e.stopPropagation(),e.target.blur(),t.toolbar.settings.close())},e.keyUpOnAnchorInput=function(e){e.keyCode>=t.core.keys.LEFT&&e.keyCode<=t.core.keys.DOWN&&e.stopPropagation()},e.rusToTranslit=function(e){for(var t=["А","Б","В","Г","Д","Е","Ё","Ж","З","И","Й","К","Л","М","Н","О","П","Р","С","Т","У","Ф","Х","Ц","Ч","Ш","Щ","Ь","Ы","Ь","Э","Ю","Я"],n=["A","B","V","G","D","E","E","Zh","Z","I","Y","K","L","M","N","O","P","R","S","T","U","F","H","C","Ch","Sh","Sch","","Y","","E","Yu","Ya"],o=0;o<t.length;o++)e=e.split(t[o]).join(n[o]),e=e.split(t[o].toLowerCase()).join(n[o].toLowerCase());return e=e.replace(/[^0-9a-zA-Z_]+/g,"-")},e}({})},function(e,t){"use strict";e.exports=function(e){var t=[];return e.search=function(){var e=function(e,n){var o=[];n=n||t;for(var r=0;r<n.length;r++){var i=n[r];i.element===e&&o.push(i)}return o},n=function(e,n){var o=[];n=n||t;for(var r=0;r<n.length;r++){var i=n[r];i.type===e&&o.push(i)}return o},o=function(e,n){var o=[];n=n||t;for(var r=0;r<n.length;r++){var i=n[r];i.handler===e&&o.push(i)}return o},r=function(r,i,a){var s=t;return r&&(s=e(r,s)),i&&(s=n(i,s)),a&&(s=o(a,s)),s[0]},i=function(r,i,a){var s=t;return r&&(s=e(r,s)),i&&(s=n(i,s)),a&&(s=o(a,s)),s};return{byElement:e,byType:n,byHandler:o,one:r,all:i}}(),e.add=function(n,o,r,i){n.addEventListener(o,r,i);var a={element:n,type:o,handler:r},s=e.search.one(n,o,r);s||t.push(a)},e.remove=function(n,o,r){n.removeEventListener(o,r);for(var i=e.search.all(n,o,r),a=0;a<i.length;a++){var s=t.indexOf(i[a]);s>0&&t.splice(s,1)}},e.removeAll=function(){t.map(function(t){e.remove(t.element,t.type,t.handler)})},e.get=function(t,n,o){return e.search.all(t,n,o)},e}({})},function(e,t){"use strict";var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e};e.exports=function(e){var t=codex.editor;return e.removeNodes=function(){t.nodes.wrapper.remove(),t.nodes.notifications.remove()},e.destroyPlugins=function(){for(var e in t.tools)"function"==typeof t.tools[e].destroy&&t.tools[e].destroy()},e.destroyScripts=function(){for(var e=document.getElementsByTagName("SCRIPT"),n=0;n<e.length;n++)e[n].id.indexOf(t.scriptPrefix)+1&&(e[n].remove(),n--)},e.destroy=function(o){o&&"object"===("undefined"==typeof o?"undefined":n(o))&&(o.ui&&(e.removeNodes(),t.listeners.removeAll()),o.scripts&&e.destroyScripts(),o.plugins&&e.destroyPlugins(),o.ui&&o.scripts&&o.core&&delete codex.editor)},e}({})},function(e,t){"use strict";e.exports=function(e){var t=codex.editor,n=[];e.prepare=function(){var e=t.tools;for(var o in e)e[o].renderOnPastePatterns&&Array.isArray(e[o].renderOnPastePatterns)&&e[o].renderOnPastePatterns.map(function(e){n.push(e)});return Promise.resolve()},e.pasted=function(e){var t=e.clipboardData||window.clipboardData,n=t.getData("Text"),r=o(n);return r&&(e.preventDefault(),e.stopImmediatePropagation()),r};var o=function(e){var o=!1,i=t.content.currentNode,a=i.dataset.tool;return n.map(function(n){var s=n.regex.exec(e),c=s&&s[0];c&&c===e.trim()&&(i.textContent.trim()&&a==t.settings.initialBlockPlugin&&r(),n.callback(e,n),o=!0)}),o},r=function(){t.content.insertBlock({type:t.settings.initialBlockPlugin,block:t.tools[t.settings.initialBlockPlugin].render({text:""})},!1)};return e}({})}]);
//# sourceMappingURL=codex-editor.js.map