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