diff --git a/README.md b/README.md index 6545088..73b87fd 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ Live demo: [https://jaredreich.com/pell](https://jaredreich.com/pell) | library | size (min+gzip) | size (min) | jquery | bootstrap | |---------------|-----------------|------------|--------|-----------| -| pell | 1.11kB | 2.86kB | | | +| pell | 1.11kB | 2.85kB | | | | medium-editor | 27kB | 105kB | | | | quill | 43kB | 205kB | | | | ckeditor | 163kB | 551kB | | | @@ -100,7 +100,7 @@ npm install --save pell // ES6 import pell from 'pell' // or -import { execute, init } from 'pell' +import { exec, init } from 'pell' ``` ```js @@ -153,7 +153,7 @@ pell.init({ // Execute a document command, see reference: // https://developer.mozilla.org/en/docs/Web/API/Document/execCommand // this is just `document.execCommand(command, false, value)` -pell.execute(command, value) +pell.exec(command, value) ``` #### List of overwriteable action names @@ -197,7 +197,7 @@ const editor = pell.init({ 'underline', { name: 'italic', - result: () => window.pell.execute('italic') + result: () => window.pell.exec('italic') }, { name: 'custom', @@ -209,14 +209,14 @@ const editor = pell.init({ name: 'image', result: () => { const url = window.prompt('Enter the image URL') - if (url) window.pell.execute('insertImage', ensureHTTP(url)) + if (url) window.pell.exec('insertImage', ensureHTTP(url)) } }, { name: 'link', result: () => { const url = window.prompt('Enter the link URL') - if (url) window.pell.execute('createLink', ensureHTTP(url)) + if (url) window.pell.exec('createLink', ensureHTTP(url)) } } ], diff --git a/demo.html b/demo.html index 0e7687e..47c2310 100644 --- a/demo.html +++ b/demo.html @@ -59,20 +59,20 @@

HTML output:

name: 'zitalic', icon: 'Z', title: 'Zitalic', - result: () => window.pell.execute('italic') + result: () => window.pell.exec('italic') }, { name: 'image', result: () => { const url = window.prompt('Enter the image URL') - if (url) window.pell.execute('insertImage', ensureHTTP(url)) + if (url) window.pell.exec('insertImage', ensureHTTP(url)) } }, { name: 'link', result: () => { const url = window.prompt('Enter the link URL') - if (url) window.pell.execute('createLink', ensureHTTP(url)) + if (url) window.pell.exec('createLink', ensureHTTP(url)) } } ], diff --git a/dist/pell.js b/dist/pell.js index a86640c..2768106 100644 --- a/dist/pell.js +++ b/dist/pell.js @@ -11,84 +11,84 @@ var actions = { icon: 'B', title: 'Bold', result: function result() { - return execute('bold'); + return exec('bold'); } }, italic: { icon: 'I', title: 'Italic', result: function result() { - return execute('italic'); + return exec('italic'); } }, underline: { icon: 'U', title: 'Underline', result: function result() { - return execute('underline'); + return exec('underline'); } }, strikethrough: { icon: 'S', title: 'Strike-through', result: function result() { - return execute('strikeThrough'); + return exec('strikeThrough'); } }, heading1: { icon: 'H1', title: 'Heading 1', result: function result() { - return execute('formatBlock', '

'); + return exec('formatBlock', '

'); } }, heading2: { icon: 'H2', title: 'Heading 2', result: function result() { - return execute('formatBlock', '

'); + return exec('formatBlock', '

'); } }, paragraph: { icon: '¶', title: 'Paragraph', result: function result() { - return execute('formatBlock', '

'); + return exec('formatBlock', '

'); } }, quote: { icon: '“ ”', title: 'Quote', result: function result() { - return execute('formatBlock', '

'); + return exec('formatBlock', '
'); } }, olist: { icon: '#', title: 'Ordered List', result: function result() { - return execute('insertOrderedList'); + return exec('insertOrderedList'); } }, ulist: { icon: '•', title: 'Unordered List', result: function result() { - return execute('insertUnorderedList'); + return exec('insertUnorderedList'); } }, code: { icon: '</>', title: 'Code', result: function result() { - return execute('formatBlock', '
');
+      return exec('formatBlock', '
');
     }
   },
   line: {
     icon: '―',
     title: 'Horizontal Line',
     result: function result() {
-      return execute('insertHorizontalRule');
+      return exec('insertHorizontalRule');
     }
   },
   link: {
@@ -96,7 +96,7 @@ var actions = {
     title: 'Link',
     result: function result() {
       var url = window.prompt('Enter the link URL');
-      if (url) execute('createLink', url);
+      if (url) exec('createLink', url);
     }
   },
   image: {
@@ -104,7 +104,7 @@ var actions = {
     title: 'Image',
     result: function result() {
       var url = window.prompt('Enter the image URL');
-      if (url) execute('insertImage', url);
+      if (url) exec('insertImage', url);
     }
   }
 };
@@ -115,7 +115,7 @@ var classes = {
   content: 'pell-content'
 };
 
-var execute = function execute(command) {
+var exec = function exec(command) {
   var value = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
 
   document.execCommand(command, false, value);
@@ -157,14 +157,14 @@ var init = function init(settings) {
     actionbar.appendChild(button);
   });
 
-  if (settings.styleWithCSS) execute('styleWithCSS');
+  if (settings.styleWithCSS) exec('styleWithCSS');
 
   return settings.element;
 };
 
-var pell = { execute: execute, init: init };
+var pell = { exec: exec, init: init };
 
-exports.execute = execute;
+exports.exec = exec;
 exports.init = init;
 exports['default'] = pell;
 
diff --git a/dist/pell.min.js b/dist/pell.min.js
index 6b0f09c..124f7ed 100644
--- a/dist/pell.min.js
+++ b/dist/pell.min.js
@@ -1 +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;eB",title:"Bold",result:function(){return o("bold")}},italic:{icon:"I",title:"Italic",result:function(){return o("italic")}},underline:{icon:"U",title:"Underline",result:function(){return o("underline")}},strikethrough:{icon:"S",title:"Strike-through",result:function(){return o("strikeThrough")}},heading1:{icon:"H1",title:"Heading 1",result:function(){return o("formatBlock","

")}},heading2:{icon:"H2",title:"Heading 2",result:function(){return o("formatBlock","

")}},paragraph:{icon:"¶",title:"Paragraph",result:function(){return o("formatBlock","

")}},quote:{icon:"“ ”",title:"Quote",result:function(){return o("formatBlock","

")}},olist:{icon:"#",title:"Ordered List",result:function(){return o("insertOrderedList")}},ulist:{icon:"•",title:"Unordered List",result:function(){return o("insertUnorderedList")}},code:{icon:"</>",title:"Code",result:function(){return o("formatBlock","
")}},line:{icon:"―",title:"Horizontal Line",result:function(){return o("insertHorizontalRule")}},link:{icon:"🔗",title:"Link",result:function(){var t=window.prompt("Enter the link URL");t&&o("createLink",t)}},image:{icon:"📷",title:"Image",result:function(){var t=window.prompt("Enter the image URL");t&&o("insertImage",t)}}},i={actionbar:"pell-actionbar",button:"pell-button",content:"pell-content"},o=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;document.execCommand(t,!1,e)},r=function(t){9===t.which&&t.preventDefault()},l=function(t){t.actions=t.actions?t.actions.map(function(t){return"string"==typeof t?n[t]:n[t.name]?e({},n[t.name],t):t}):Object.keys(n).map(function(t){return n[t]}),t.classes=e({},i,t.classes);var l=document.createElement("div");return l.className=t.classes.actionbar,t.element.appendChild(l),t.element.content=document.createElement("div"),t.element.content.contentEditable=!0,t.element.content.className=t.classes.content,t.element.content.oninput=function(e){return t.onChange(e.target.innerHTML)},t.element.content.onkeydown=r,t.element.appendChild(t.element.content),t.actions.forEach(function(e){var n=document.createElement("button");n.className=t.classes.button,n.innerHTML=e.icon,n.title=e.title,n.onclick=e.result,l.appendChild(n)}),t.styleWithCSS&&o("styleWithCSS"),t.element},c={execute:o,init:l};t.execute=o,t.init=l,t.default=c,Object.defineProperty(t,"__esModule",{value:!0})});
+!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;eB",title:"Bold",result:function(){return o("bold")}},italic:{icon:"I",title:"Italic",result:function(){return o("italic")}},underline:{icon:"U",title:"Underline",result:function(){return o("underline")}},strikethrough:{icon:"S",title:"Strike-through",result:function(){return o("strikeThrough")}},heading1:{icon:"H1",title:"Heading 1",result:function(){return o("formatBlock","

")}},heading2:{icon:"H2",title:"Heading 2",result:function(){return o("formatBlock","

")}},paragraph:{icon:"¶",title:"Paragraph",result:function(){return o("formatBlock","

")}},quote:{icon:"“ ”",title:"Quote",result:function(){return o("formatBlock","

")}},olist:{icon:"#",title:"Ordered List",result:function(){return o("insertOrderedList")}},ulist:{icon:"•",title:"Unordered List",result:function(){return o("insertUnorderedList")}},code:{icon:"</>",title:"Code",result:function(){return o("formatBlock","
")}},line:{icon:"―",title:"Horizontal Line",result:function(){return o("insertHorizontalRule")}},link:{icon:"🔗",title:"Link",result:function(){var t=window.prompt("Enter the link URL");t&&o("createLink",t)}},image:{icon:"📷",title:"Image",result:function(){var t=window.prompt("Enter the image URL");t&&o("insertImage",t)}}},i={actionbar:"pell-actionbar",button:"pell-button",content:"pell-content"},o=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;document.execCommand(t,!1,e)},r=function(t){9===t.which&&t.preventDefault()},l=function(t){t.actions=t.actions?t.actions.map(function(t){return"string"==typeof t?n[t]:n[t.name]?e({},n[t.name],t):t}):Object.keys(n).map(function(t){return n[t]}),t.classes=e({},i,t.classes);var l=document.createElement("div");return l.className=t.classes.actionbar,t.element.appendChild(l),t.element.content=document.createElement("div"),t.element.content.contentEditable=!0,t.element.content.className=t.classes.content,t.element.content.oninput=function(e){return t.onChange(e.target.innerHTML)},t.element.content.onkeydown=r,t.element.appendChild(t.element.content),t.actions.forEach(function(e){var n=document.createElement("button");n.className=t.classes.button,n.innerHTML=e.icon,n.title=e.title,n.onclick=e.result,l.appendChild(n)}),t.styleWithCSS&&o("styleWithCSS"),t.element},c={exec:o,init:l};t.exec=o,t.init=l,t.default=c,Object.defineProperty(t,"__esModule",{value:!0})});
diff --git a/package.json b/package.json
index fc54872..ef97e6e 100644
--- a/package.json
+++ b/package.json
@@ -2,7 +2,7 @@
   "name": "pell",
   "description": "pell - the simplest and smallest WYSIWYG text editor for web, with no dependencies",
   "author": "Jared Reich",
-  "version": "0.6.0",
+  "version": "0.7.0",
   "main": "./dist/pell.min.js",
   "scripts": {
     "dev": "gulp",
diff --git a/src/pell.js b/src/pell.js
index 1a0b29e..d826c2e 100644
--- a/src/pell.js
+++ b/src/pell.js
@@ -2,69 +2,69 @@ const actions = {
   bold: {
     icon: 'B',
     title: 'Bold',
-    result: () => execute('bold')
+    result: () => exec('bold')
   },
   italic: {
     icon: 'I',
     title: 'Italic',
-    result: () => execute('italic')
+    result: () => exec('italic')
   },
   underline: {
     icon: 'U',
     title: 'Underline',
-    result: () => execute('underline')
+    result: () => exec('underline')
   },
   strikethrough: {
     icon: 'S',
     title: 'Strike-through',
-    result: () => execute('strikeThrough')
+    result: () => exec('strikeThrough')
   },
   heading1: {
     icon: 'H1',
     title: 'Heading 1',
-    result: () => execute('formatBlock', '

') + result: () => exec('formatBlock', '

') }, heading2: { icon: 'H2', title: 'Heading 2', - result: () => execute('formatBlock', '

') + result: () => exec('formatBlock', '

') }, paragraph: { icon: '¶', title: 'Paragraph', - result: () => execute('formatBlock', '

') + result: () => exec('formatBlock', '

') }, quote: { icon: '“ ”', title: 'Quote', - result: () => execute('formatBlock', '

') + result: () => exec('formatBlock', '
') }, olist: { icon: '#', title: 'Ordered List', - result: () => execute('insertOrderedList') + result: () => exec('insertOrderedList') }, ulist: { icon: '•', title: 'Unordered List', - result: () => execute('insertUnorderedList') + result: () => exec('insertUnorderedList') }, code: { icon: '</>', title: 'Code', - result: () => execute('formatBlock', '
')
+    result: () => exec('formatBlock', '
')
   },
   line: {
     icon: '―',
     title: 'Horizontal Line',
-    result: () => execute('insertHorizontalRule')
+    result: () => exec('insertHorizontalRule')
   },
   link: {
     icon: '🔗',
     title: 'Link',
     result: () => {
       const url = window.prompt('Enter the link URL')
-      if (url) execute('createLink', url)
+      if (url) exec('createLink', url)
     }
   },
   image: {
@@ -72,7 +72,7 @@ const actions = {
     title: 'Image',
     result: () => {
       const url = window.prompt('Enter the image URL')
-      if (url) execute('insertImage', url)
+      if (url) exec('insertImage', url)
     }
   }
 }
@@ -83,7 +83,7 @@ const classes = {
   content: 'pell-content'
 }
 
-export const execute = (command, value = null) => {
+export const exec = (command, value = null) => {
   document.execCommand(command, false, value)
 }
 
@@ -122,9 +122,9 @@ export const init = settings => {
     actionbar.appendChild(button)
   })
 
-  if (settings.styleWithCSS) execute('styleWithCSS')
+  if (settings.styleWithCSS) exec('styleWithCSS')
 
   return settings.element
 }
 
-export default { execute, init }
+export default { exec, init }