forked from jaredreich/pell
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathspell.min.js
1 lines (1 loc) · 1.62 KB
/
spell.min.js
1
function spell(){let e=(e,t=null)=>document.execCommand(e,!1,t),t=e=>/^https?:\//.test(e)?e:`http://${e}`,o=(e,t,o=[],n=document.createElement(e))=>o.map(e=>e&&n.appendChild(e))&&Object.assign(n,t),n=e=>o("input",{type:"color"}),s=e=>o("select",{},e.map(e=>o("option",{textContent:e}))),a={},i=e=>{for(let e in a)a[e].classList.toggle("selected",document.queryCommandState(e))},l=[[["bold"],["italic"],["underline"],["strikeThrough"],["subscript"],["superscript"]],[["justifyLeft"],["justifyCenter"],["justifyRight"],["justifyFull"],["indent"],["outdent"]],[["fontName",s(["serif","sans-serif","monospace","cursive","fantasy"])],["fontSize",s([...Array(33)].map((e,t)=>8+2*t))],["forecolor",n()],["hilitecolor",n()]].map(([t,o])=>[t,0,Object.assign(o,{onchange:n=>e(t,o.value)})]),[...[1,2,3,4].map(e=>["heading"+e,`<h${e}>`]),["paragraph","<p>"],["quote","<blockquote>"],["code","<pre>"]].map(([t,o])=>[t,t=>e("formatBlock",o)]),[["insertOrderedList"],["insertUnorderedList"],["insertHorizontalRule"]],[["removeFormat"],["unlink"]],[["createLink","link",t],["insertImage","image",t],["insertHTML","video",e=>`<video controls src="${t(e)}">`]].map(([t,o,n])=>[o,s=>(s=prompt(`Enter the ${o} URL`))&&e(t,n(s))]),[["copy"],["cut"],["paste"]],[["undo"],["redo"]]];return o("div",{className:"spell"},[o("div",{className:"spell-bar"},l.map(t=>o("div",{className:"spell-zone"},t.map(([t,n=(o=>e(t)),s])=>a[t]=o("button",{className:"spell-icon",title:t.replace(/([^a-z])/g," $1").toLowerCase(),onclick:n},[o("i",{className:"icon-"+t.toLowerCase()}),s]))))),o("div",{className:"spell-content",contentEditable:!0,onkeydown:e=>9!==e.which,onkeyup:i,onmouseup:i})])}