Skip to content

Commit

Permalink
Add inheritPlaceholder option
Browse files Browse the repository at this point in the history
  • Loading branch information
lqez committed Jul 26, 2019
1 parent cae115a commit 34d1766
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/js/base/Context.js
Expand Up @@ -54,6 +54,11 @@ export default class Context {
}

_initialize() {
// apply original placeholder
if (this.options.inheritPlaceholder && this.$note.attr('placeholder')) {
this.options.placeholder = this.$note.attr('placeholder');
}

// add optional buttons
const buttons = $.extend({}, this.options.buttons);
Object.keys(buttons).forEach((key) => {
Expand Down
2 changes: 2 additions & 0 deletions src/js/base/settings.js
Expand Up @@ -125,6 +125,8 @@ $.summernote = $.extend($.summernote, {
maxTextLength: 0,
blockquoteBreakingLevel: 2,
spellCheck: true,
placeholder: null,
inheritPlaceholder: false,

styleTags: ['p', 'blockquote', 'pre', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6'],

Expand Down
31 changes: 31 additions & 0 deletions test/base/module/Placeholder.spec.js
@@ -0,0 +1,31 @@
/**
* Placeholder.spec.js
* (c) 2015~ Summernote Team
* summernote may be freely distributed under the MIT license./
*/
import chai from 'chai';
import $ from 'jquery';
import Context from '../../../src/js/base/Context';
import '../../../src/js/bs4/settings';

describe('Placeholder', () => {
var assert = chai.assert;

it('should not be initialized by placeholder attribute without inheritPlaceHolder', () => {
var options = $.extend({}, $.summernote.options);
var context = new Context($('<textarea placeholder="custom_placeholder"><p>hello</p></textarea>'), options);
var $editor = context.layoutInfo.editor;

assert.isTrue($editor.find('.note-placeholder').length === 0);
});

it('should be initialized by placeholder attribute with inheritPlaceHolder', () => {
var options = $.extend({}, $.summernote.options);
options.inheritPlaceholder = true;
var context = new Context($('<textarea placeholder="custom_placeholder"><p>hello</p></textarea>'), options);
var $editor = context.layoutInfo.editor;

assert.isTrue($editor.find('.note-placeholder').length === 1);
assert.isTrue($editor.find('.note-placeholder').html() === 'custom_placeholder');
});
});

0 comments on commit 34d1766

Please sign in to comment.