2 * DO NOT EDIT THIS FILE.
3 * See the following change record for more information,
4 * https://www.drupal.org/node/2815083
8 (function ($, _, Drupal) {
9 Drupal.quickedit.editors.plain_text = Drupal.quickedit.EditorView.extend({
12 initialize: function initialize(options) {
13 Drupal.quickedit.EditorView.prototype.initialize.call(this, options);
15 var editorModel = this.model;
16 var fieldModel = this.fieldModel;
18 var $fieldItems = this.$el.find('.quickedit-field');
19 var $textElement = $fieldItems.length ? $fieldItems.eq(0) : this.$el;
20 this.$textElement = $textElement;
21 editorModel.set('originalValue', $.trim(this.$textElement.text()));
23 var previousText = editorModel.get('originalValue');
24 $textElement.on('keyup paste', function (event) {
25 var currentText = $.trim($textElement.text());
26 if (previousText !== currentText) {
27 previousText = currentText;
28 editorModel.set('currentValue', currentText);
29 fieldModel.set('state', 'changed');
33 getEditedElement: function getEditedElement() {
34 return this.$textElement;
36 stateChange: function stateChange(fieldModel, state, options) {
37 var from = fieldModel.previous('state');
44 if (from !== 'inactive') {
45 this.$textElement.removeAttr('contenteditable');
47 if (from === 'invalid') {
48 this.removeValidationErrors();
57 fieldModel.set('state', 'active');
62 this.$textElement.attr('contenteditable', 'true');
69 if (from === 'invalid') {
70 this.removeValidationErrors();
79 this.showValidationErrors();
83 getQuickEditUISettings: function getQuickEditUISettings() {
86 unifiedToolbar: false,
87 fullWidthToolbar: false,
91 revert: function revert() {
92 this.$textElement.html(this.model.get('originalValue'));
95 })(jQuery, _, Drupal);