editor.js/codex-editor.js

3 lines
48 KiB
JavaScript
Raw Normal View History

2017-02-16 23:15:23 +01:00
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.1",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.addTools).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;return 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),e.uploadImagesUrl&&(t.settings.uploadImagesUrl=e.uploadImagesUrl),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=window.XMLHttpRequest?new XMLHttpRequest:new ActiveXObject("Microsoft.XMLHTTP"),o=function(){},r="";if(e.async=!0,e.type=e.type||"GET",e.data=e.data||"",e["content-type"]=e["content-type"]||"application/json; charset=utf-8",o=e.success||o,"GET"==e.type&&e.data)e.url=/\?/.test(e.url)?e.url+"&"+e.data:e.url+"?"+e.data;else for(t in e.data)r+=t+"="+encodeURIComponent(e.data[t])+"&";e.withCredentials&&(n.withCredentials=!0),e.beforeSend&&"function"==typeof e.beforeSend&&e.beforeSend.call(),n.open(e.type,e.url,e.async),n.setRequestHeader("X-Requested-With","XMLHttpRequest"),n.setRequestHeader("Content-type","application/x-www-form-urlencoded"),n.onreadystatechange=function(){4==n.readyState&&200==n.status&&o(n.responseText)},n.send(r)}},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)})},e}({})},function(e,t){"use strict";e.exports=function(){function e(){return new
}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,n){var o,r,i,a=t.caret.getCurrentInputIndex();if(e.textContent.trim()){if(o=t.content.getRange(),r=o.endOffset-o.startOffset,!t.caret.position.atStart()||r||!t.state.inputs[a-1])return;t.content.mergeBlocks(a)}r||e.remove(),i=t.nodes.redactor.childNodes.length,0===i?(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(),n.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){e.preventDefault();var n=t.content.getEditableParent(e.target),o=t.content.getFirstLevelBlock(e.target);if(n){var r,i,a=e.clipboardData.getData("text/html")||e.clipboardData.getData("text/plain"),s=t.draw.node("DIV","",{}),c=new t.sanitizer.init(t.sanitizer.Config.BASIC);i=document.createDocumentFragment(),r=c.clean(a),s.innerHTML=r;for(var l,d;l=s.firstChild;)d=i.appendChild(l);if(!t.tools[o.dataset.tool].allowRenderOnPaste||!t.paste.pasted(e)){var u,p;u=window.getSelection(),p=u.getRangeAt(0),p.deleteContents(),p.insertNode(i),d&&(p=p.cloneRange(),p.setStartAfter(d),p.collapse(!0),u.removeAllRanges(),u.addRange(p))}}},e.handleMutationsOnPaste=function(e){var n=this;e.forEach(function(e){t.content.paste.call(n,e)})},e.showSettingsButtonClicked=fun
2017-01-30 18:29:26 +01:00
//# sourceMappingURL=codex-editor.js.map