Skip to content

Commit 88b215e

Browse files
committed
Merge pull request yabwe#566 from daviferreira/spellcheck
Add spellcheck options to enable/disable native spellcheck
2 parents 2149645 + 5486a24 commit 88b215e

File tree

7 files changed

+33
-12
lines changed

7 files changed

+33
-12
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ the textarea value to the div HTML content.
8383
* __imageDragging__: Allows image drag and drop into the editor. Default: true
8484
* __placeholder__: Defines the default placeholder for empty contenteditables when __disablePlaceholders__ is not set to true. You can overwrite it by setting a data-placeholder attribute on your elements. Default: 'Type your text'
8585
* __secondHeader__: HTML tag to be used as second header. Default: h4
86+
* __spellcheck__: Enable/disable native contentEditable automatic spellcheck. Default: true
8687
* __standardizeSelectionStart__: Standardizes how the beginning of a range is decided between browsers whenever the selected text is analyzed for updating toolbar buttons status
8788

8889
### Toolbar options

dist/js/medium-editor.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,6 +1112,7 @@ var editorDefaults;
11121112
activeButtonClass: 'medium-editor-button-active',
11131113
firstButtonClass: 'medium-editor-button-first',
11141114
lastButtonClass: 'medium-editor-button-last',
1115+
spellcheck: true,
11151116

11161117
paste: {
11171118
forcePlainText: true,
@@ -1123,6 +1124,7 @@ var editorDefaults;
11231124
};
11241125

11251126
})();
1127+
11261128
var Extension;
11271129
(function(){
11281130

@@ -3448,6 +3450,7 @@ function MediumEditor(elements, options) {
34483450
this.elements[i] = createContentEditable.call(this, i);
34493451
}
34503452
this.elements[i].setAttribute('contentEditable', true);
3453+
this.elements[i].setAttribute('spellcheck', this.options.spellcheck);
34513454
}
34523455
if (!this.elements[i].getAttribute('data-placeholder')) {
34533456
this.elements[i].setAttribute('data-placeholder', this.options.placeholder);
@@ -3681,6 +3684,7 @@ function MediumEditor(elements, options) {
36813684

36823685
for (i = 0; i < this.elements.length; i += 1) {
36833686
this.elements[i].removeAttribute('contentEditable');
3687+
this.elements[i].removeAttribute('spellcheck');
36843688
this.elements[i].removeAttribute('data-medium-element');
36853689
}
36863690

dist/js/medium-editor.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/content.spec.js

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@ describe('Content TestCase', function () {
1717
tearDown(this.el);
1818
});
1919

20+
it('should removing paragraphs when a list is inserted inside of it', function () {
21+
this.el.innerHTML = '<p>lorem ipsum<ul><li>dolor</li></ul></p>';
22+
var editor = new MediumEditor('.editor', {
23+
buttons: ['orderedlist']
24+
}),
25+
target = editor.elements[0].querySelector('p');
26+
selectElementContentsAndFire(target);
27+
fireEvent(editor.toolbar.getToolbarElement().querySelector('[data-action="insertorderedlist"]'), 'click');
28+
expect(this.el.innerHTML).toMatch(/^<ol><li>lorem ipsum(<br>)?<\/li><\/ol><ul><li>dolor<\/li><\/ul>?/);
29+
});
30+
2031
describe('when the tab key is pressed', function () {
2132
it('should indent when within an <li>', function () {
2233
this.el.innerHTML = '<ol><li>lorem</li><li>ipsum</li></ol>';
@@ -200,14 +211,15 @@ describe('Content TestCase', function () {
200211
});
201212
});
202213

203-
it('should removing paragraphs when a list is inserted inside of it', function () {
204-
this.el.innerHTML = '<p>lorem ipsum<ul><li>dolor</li></ul></p>';
205-
var editor = new MediumEditor('.editor', {
206-
buttons: ['orderedlist']
207-
}),
208-
target = editor.elements[0].querySelector('p');
209-
selectElementContentsAndFire(target);
210-
fireEvent(editor.toolbar.getToolbarElement().querySelector('[data-action="insertorderedlist"]'), 'click');
211-
expect(this.el.innerHTML).toMatch(/^<ol><li>lorem ipsum(<br>)?<\/li><\/ol><ul><li>dolor<\/li><\/ul>?/);
214+
describe('spellcheck', function () {
215+
it('should have spellcheck attribute set to true by default', function () {
216+
var editor = new MediumEditor('.editor');
217+
expect(editor.elements[0].getAttribute('spellcheck')).toBe('true');
218+
});
219+
220+
it('should accept spellcheck as an options', function () {
221+
var editor = new MediumEditor('.editor', {spellcheck: false});
222+
expect(editor.elements[0].getAttribute('spellcheck')).toBe('false');
223+
});
212224
});
213225
});

spec/init.spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ describe('Initialization TestCase', function () {
125125
activeButtonClass: 'medium-editor-button-active',
126126
firstButtonClass: 'medium-editor-button-first',
127127
lastButtonClass: 'medium-editor-button-last',
128+
spellcheck: true,
128129
paste: {
129130
forcePlainText: true,
130131
cleanPastedHTML: false,

src/js/core.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ function MediumEditor(elements, options) {
298298
this.elements[i] = createContentEditable.call(this, i);
299299
}
300300
this.elements[i].setAttribute('contentEditable', true);
301+
this.elements[i].setAttribute('spellcheck', this.options.spellcheck);
301302
}
302303
if (!this.elements[i].getAttribute('data-placeholder')) {
303304
this.elements[i].setAttribute('data-placeholder', this.options.placeholder);
@@ -531,6 +532,7 @@ function MediumEditor(elements, options) {
531532

532533
for (i = 0; i < this.elements.length; i += 1) {
533534
this.elements[i].removeAttribute('contentEditable');
535+
this.elements[i].removeAttribute('spellcheck');
534536
this.elements[i].removeAttribute('data-medium-element');
535537
}
536538

src/js/defaults/options.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ var editorDefaults;
3838
activeButtonClass: 'medium-editor-button-active',
3939
firstButtonClass: 'medium-editor-button-first',
4040
lastButtonClass: 'medium-editor-button-last',
41+
spellcheck: true,
4142

4243
paste: {
4344
forcePlainText: true,
@@ -48,4 +49,4 @@ var editorDefaults;
4849

4950
};
5051

51-
})();
52+
})();

0 commit comments

Comments
 (0)