-
Notifications
You must be signed in to change notification settings - Fork 547
Expand file tree
/
Copy pathpell.min.js
More file actions
1 lines (1 loc) · 4.05 KB
/
pell.min.js
File metadata and controls
1 lines (1 loc) · 4.05 KB
1
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e(t.pell={})}(this,function(t){"use strict";var e=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},n=function(t,e,n){return t.addEventListener(e,n)},r=function(t,e){return t.appendChild(e)},i=function(t){return document.createElement(t)},o=function(t){return document.queryCommandState(t)},u=function(t){return document.queryCommandValue(t)},c=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;return document.execCommand(t,!1,e)},a={bold:{icon:"<b>B</b>",title:"Bold",state:function(){return o("bold")},result:function(){return c("bold")}},italic:{icon:"<i>I</i>",title:"Italic",state:function(){return o("italic")},result:function(){return c("italic")}},underline:{icon:"<u>U</u>",title:"Underline",state:function(){return o("underline")},result:function(){return c("underline")}},strikethrough:{icon:"<strike>S</strike>",title:"Strike-through",state:function(){return o("strikeThrough")},result:function(){return c("strikeThrough")}},heading1:{icon:"<b>H<sub>1</sub></b>",title:"Heading 1",result:function(){return c("formatBlock","<h1>")}},heading2:{icon:"<b>H<sub>2</sub></b>",title:"Heading 2",result:function(){return c("formatBlock","<h2>")}},paragraph:{icon:"¶",title:"Paragraph",result:function(){return c("formatBlock","<p>")}},quote:{icon:"“ ”",title:"Quote",result:function(){return c("formatBlock","<blockquote>")}},olist:{icon:"#",title:"Ordered List",result:function(){return c("insertOrderedList")}},ulist:{icon:"•",title:"Unordered List",result:function(){return c("insertUnorderedList")}},code:{icon:"</>",title:"Code",result:function(){return c("formatBlock","<pre>")}},line:{icon:"―",title:"Horizontal Line",result:function(){return c("insertHorizontalRule")}},link:{icon:"🔗",title:"Link",result:function(){var t=window.prompt("Enter the link URL");t&&c("createLink",t)}},image:{icon:"📷",title:"Image",result:function(){l()}}},l=function(){var t=document.querySelector('.pell input[type="file"]');if(t)t.click();else{var e=window.prompt("Enter the image URL");e&&c("insertImage",e)}},s=function(t,e,n){var r=t.api,i=t.data;window.fetch&&window.fetch(r,{method:"POST",body:i}).then(function(t){return t.json()}).then(function(t){t.success&&e(t.url)},function(t){return n(t)})},f=function(t){var e=t.upload&&t.upload.api;if(e){var o=i("input");o.type="file",o.hidden=!0,n(o,"change",function(t){var n=t.target.files[0],r=new window.FormData;r.append("pell-upload-image",n),s({api:e,data:r},function(t){return c("insertImage",t)},function(t){return window.alert(t)})}),r(t.element,o)}},d={actionbar:"pell-actionbar",button:"pell-button",content:"pell-content",selected:"pell-button-selected"},p=function(t){var o=t.actions?t.actions.map(function(t){return"string"==typeof t?a[t]:a[t.name]?e({},a[t.name],t):t}):Object.keys(a).map(function(t){return a[t]}),l=e({},d,t.classes),s=t.defaultParagraphSeparator||"div",p=i("div");p.className=l.actionbar,r(t.element,p);var m=t.element.content=i("div");return m.contentEditable=!0,m.className=l.content,m.oninput=function(e){var n=e.target.firstChild;n&&3===n.nodeType?c("formatBlock","<"+s+">"):"<br>"===m.innerHTML&&(m.innerHTML=""),t.onChange(m.innerHTML)},m.onkeydown=function(t){"Tab"===t.key?t.preventDefault():"Enter"===t.key&&"blockquote"===u("formatBlock")&&setTimeout(function(){return c("formatBlock","<"+s+">")},0)},r(t.element,m),o.forEach(function(t){var e=i("button");if(e.className=l.button,e.innerHTML=t.icon,e.title=t.title,e.setAttribute("type","button"),e.onclick=function(){return t.result()&&m.focus()},t.state){var o=function(){return e.classList[t.state()?"add":"remove"](l.selected)};n(m,"keyup",o),n(m,"mouseup",o),n(e,"click",o)}r(p,e)}),t.styleWithCSS&&c("styleWithCSS"),c("defaultParagraphSeparator",s),f(t),t.element},m={exec:c,init:p};t.exec=c,t.init=p,t.default=m,Object.defineProperty(t,"__esModule",{value:!0})});