Skip to content

Commit c1db3b3

Browse files
committed
Build for 1.0.0 release.
1 parent 1742bf9 commit c1db3b3

File tree

7 files changed

+59
-28
lines changed

7 files changed

+59
-28
lines changed

README.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Live demo: [https://jaredreich.com/pell](https://jaredreich.com/pell)
1313

1414
| library | size (min+gzip) | size (min) | jquery | bootstrap | link |
1515
|---------------|-----------------|------------|--------|-----------|------|
16-
| pell | 1.11kB | 2.85kB | | | https://github.com/jaredreich/pell |
16+
| pell | 1.29kB | 3.48kB | | | https://github.com/jaredreich/pell |
1717
| squire | 16kB | 49kB | | | https://github.com/neilj/Squire |
1818
| medium-editor | 27kB | 105kB | | | https://github.com/yabwe/medium-editor |
1919
| quill | 43kB | 205kB | | | https://github.com/quilljs/quill |
@@ -29,7 +29,7 @@ Live demo: [https://jaredreich.com/pell](https://jaredreich.com/pell)
2929
* Pure JavaScript, no dependencies, written in ES6
3030
* Easily customizable with the sass file (pell.scss) or overwrite the CSS
3131

32-
Current actions:
32+
Included actions:
3333
- Bold
3434
- Italic
3535
- Underline
@@ -45,7 +45,7 @@ Current actions:
4545
- Link
4646
- Image
4747

48-
Other possible future actions:
48+
Other available actions (listed at https://developer.mozilla.org/en-US/docs/Web/API/Document/execCommand):
4949
- Justify Center
5050
- Justify Full
5151
- Justify Left
@@ -60,6 +60,8 @@ Other possible future actions:
6060
- Undo
6161
- Redo
6262

63+
Or create any custom action!
64+
6365
## Browser Support
6466

6567
* IE 9+
@@ -116,7 +118,7 @@ window.pell
116118

117119
```js
118120
// Initialize pell on an HTMLElement
119-
pell.init({
121+
init({
120122
// <HTMLElement>, required
121123
element: document.getElementById('some-id'),
122124

@@ -193,7 +195,7 @@ pell.exec(command<string>, value<string>)
193195
```
194196

195197
```js
196-
const editor = pell.init({
198+
const editor = init({
197199
element: document.getElementById('pell'),
198200
onChange: html => {
199201
document.getElementById('text-output').innerHTML = html
@@ -206,7 +208,7 @@ const editor = pell.init({
206208
'underline',
207209
{
208210
name: 'italic',
209-
result: () => window.pell.exec('italic')
211+
result: () => exec('italic')
210212
},
211213
{
212214
name: 'custom',
@@ -218,14 +220,14 @@ const editor = pell.init({
218220
name: 'image',
219221
result: () => {
220222
const url = window.prompt('Enter the image URL')
221-
if (url) window.pell.exec('insertImage', ensureHTTP(url))
223+
if (url) exec('insertImage', ensureHTTP(url))
222224
}
223225
},
224226
{
225227
name: 'link',
226228
result: () => {
227229
const url = window.prompt('Enter the link URL')
228-
if (url) window.pell.exec('createLink', ensureHTTP(url))
230+
if (url) exec('createLink', ensureHTTP(url))
229231
}
230232
}
231233
],

demo.gif

584 KB
Loading

dist/pell.css

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,26 @@
11
.pell {
2-
border-radius: 5px;
3-
box-shadow: 0 2px 3px rgba(10, 10, 10, 0.1), 0 0 0 1px rgba(10, 10, 10, 0.1);
4-
box-sizing: border-box;
5-
width: 100%; }
2+
border: 1px solid rgba(10, 10, 10, 0.1);
3+
box-sizing: border-box; }
64

75
.pell-content {
86
box-sizing: border-box;
97
height: 300px;
108
outline: 0;
119
overflow-y: auto;
12-
padding: 10px;
13-
width: 100%; }
10+
padding: 10px; }
1411

1512
.pell-actionbar {
1613
background-color: #FFF;
17-
border-bottom: 1px solid rgba(10, 10, 10, 0.1);
18-
border-top-left-radius: 5px;
19-
border-top-right-radius: 5px;
20-
width: 100%; }
14+
border-bottom: 1px solid rgba(10, 10, 10, 0.1); }
2115

2216
.pell-button {
2317
background-color: transparent;
2418
border: none;
2519
cursor: pointer;
2620
height: 30px;
2721
outline: 0;
28-
width: 30px; }
22+
width: 30px;
23+
vertical-align: bottom; }
24+
25+
.pell-button-selected {
26+
background-color: #F0F0F0; }

dist/pell.js

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,39 @@ var actions = {
1010
bold: {
1111
icon: '<b>B</b>',
1212
title: 'Bold',
13+
state: function state() {
14+
return queryCommandState('bold');
15+
},
1316
result: function result() {
1417
return exec('bold');
1518
}
1619
},
1720
italic: {
1821
icon: '<i>I</i>',
1922
title: 'Italic',
23+
state: function state() {
24+
return queryCommandState('italic');
25+
},
2026
result: function result() {
2127
return exec('italic');
2228
}
2329
},
2430
underline: {
2531
icon: '<u>U</u>',
2632
title: 'Underline',
33+
state: function state() {
34+
return queryCommandState('underline');
35+
},
2736
result: function result() {
2837
return exec('underline');
2938
}
3039
},
3140
strikethrough: {
3241
icon: '<strike>S</strike>',
3342
title: 'Strike-through',
43+
state: function state() {
44+
return queryCommandState('strikeThrough');
45+
},
3446
result: function result() {
3547
return exec('strikeThrough');
3648
}
@@ -112,19 +124,24 @@ var actions = {
112124
var classes = {
113125
actionbar: 'pell-actionbar',
114126
button: 'pell-button',
115-
content: 'pell-content'
127+
content: 'pell-content',
128+
selected: 'pell-button-selected'
116129
};
117130

118-
var exec = function exec(command) {
119-
var value = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
120-
121-
document.execCommand(command, false, value);
131+
var queryCommandState = function queryCommandState(command) {
132+
return document.queryCommandState(command);
122133
};
123134

124135
var preventTab = function preventTab(event) {
125136
if (event.which === 9) event.preventDefault();
126137
};
127138

139+
var exec = function exec(command) {
140+
var value = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
141+
142+
document.execCommand(command, false, value);
143+
};
144+
128145
var init = function init(settings) {
129146
settings.actions = settings.actions ? settings.actions.map(function (action) {
130147
if (typeof action === 'string') return actions[action];else if (actions[action.name]) return _extends({}, actions[action.name], action);
@@ -153,10 +170,24 @@ var init = function init(settings) {
153170
button.className = settings.classes.button;
154171
button.innerHTML = action.icon;
155172
button.title = action.title;
156-
button.onclick = action.result;
173+
button.setAttribute('type', 'button');
174+
button.onclick = function () {
175+
return action.result() || settings.element.content.focus();
176+
};
177+
178+
if (action.state) {
179+
var handler = function handler() {
180+
return button.classList[action.state() ? 'add' : 'remove'](settings.classes.selected);
181+
};
182+
settings.element.content.addEventListener('keyup', handler);
183+
settings.element.content.addEventListener('mouseup', handler);
184+
button.addEventListener('click', handler);
185+
}
186+
157187
actionbar.appendChild(button);
158188
});
159189

190+
if (settings.defaultParagraphSeparator) exec('defaultParagraphSeparator', settings.defaultParagraphSeparator);
160191
if (settings.styleWithCSS) exec('styleWithCSS');
161192

162193
return settings.element;

dist/pell.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/pell.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "pell",
33
"description": "pell - the simplest and smallest WYSIWYG text editor for web, with no dependencies",
44
"author": "Jared Reich",
5-
"version": "0.7.0",
5+
"version": "1.0.0",
66
"main": "./dist/pell.min.js",
77
"scripts": {
88
"dev": "gulp",

0 commit comments

Comments
 (0)