-
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) · 3.51 KB
/
pell.min.js
File metadata and controls
1 lines (1 loc) · 3.51 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)},l=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;return document.execCommand(t,!1,e)},c={bold:{icon:"<b>B</b>",title:"Bold",state:function(){return o("bold")},result:function(){return l("bold")}},italic:{icon:"<i>I</i>",title:"Italic",state:function(){return o("italic")},result:function(){return l("italic")}},underline:{icon:"<u>U</u>",title:"Underline",state:function(){return o("underline")},result:function(){return l("underline")}},strikethrough:{icon:"<strike>S</strike>",title:"Strike-through",state:function(){return o("strikeThrough")},result:function(){return l("strikeThrough")}},heading1:{icon:"<b>H<sub>1</sub></b>",title:"Heading 1",result:function(){return l("formatBlock","<h1>")}},heading2:{icon:"<b>H<sub>2</sub></b>",title:"Heading 2",result:function(){return l("formatBlock","<h2>")}},paragraph:{icon:"¶",title:"Paragraph",result:function(){return l("formatBlock","<p>")}},quote:{icon:"“ ”",title:"Quote",result:function(){return l("formatBlock","<blockquote>")}},olist:{icon:"#",title:"Ordered List",result:function(){return l("insertOrderedList")}},ulist:{icon:"•",title:"Unordered List",result:function(){return l("insertUnorderedList")}},code:{icon:"</>",title:"Code",result:function(){return l("formatBlock","<pre>")}},line:{icon:"―",title:"Horizontal Line",result:function(){return l("insertHorizontalRule")}},link:{icon:"🔗",title:"Link",result:function(){var t=window.prompt("Enter the link URL");t&&l("createLink",t)}},image:{icon:"📷",title:"Image",result:function(){var t=window.prompt("Enter the image URL");t&&l("insertImage",t)}}},a={actionbar:"pell-actionbar",button:"pell-button",content:"pell-content",selected:"pell-button-selected"},s=function(t){var o=t.actions?t.actions.map(function(t){return"string"==typeof t?c[t]:c[t.name]?e({},c[t.name],t):t}):Object.keys(c).map(function(t){return c[t]}),s=e({},a,t.classes),d=t.defaultParagraphSeparator||"div",f=i("div");f.className=s.actionbar,r(t.element,f);var p=t.element.content=i("div");return p.contentEditable=!0,p.className=s.content,t.placeholder&&(p.dataset.placeholder=t.placeholder),p.oninput=function(e){var n=e.target.firstChild;n&&3===n.nodeType?l("formatBlock","<"+d+">"):"<br>"===p.innerHTML&&(p.innerHTML=""),t.onChange(p.innerHTML)},p.onkeydown=function(t){"Tab"===t.key?t.preventDefault():"Enter"===t.key&&"blockquote"===u("formatBlock")&&setTimeout(function(){return l("formatBlock","<"+d+">")},0)},r(t.element,p),o.forEach(function(t){var e=i("button");if(e.className=s.button,e.innerHTML=t.icon,e.title=t.title,e.setAttribute("type","button"),e.onclick=function(){return t.result()&&p.focus()},t.state){var o=function(){return e.classList[t.state()?"add":"remove"](s.selected)};n(p,"keyup",o),n(p,"mouseup",o),n(e,"click",o)}r(f,e)}),t.styleWithCSS&&l("styleWithCSS"),l("defaultParagraphSeparator",d),t.element},d={exec:l,init:s};t.exec=l,t.init=s,t.default=d,Object.defineProperty(t,"__esModule",{value:!0})});