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