Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / web / core / modules / quickedit / js / editors / plainTextEditor.js
1 /**
2 * DO NOT EDIT THIS FILE.
3 * See the following change record for more information,
4 * https://www.drupal.org/node/2815083
5 * @preserve
6 **/
7
8 (function ($, _, Drupal) {
9   Drupal.quickedit.editors.plain_text = Drupal.quickedit.EditorView.extend({
10     $textElement: null,
11
12     initialize: function initialize(options) {
13       Drupal.quickedit.EditorView.prototype.initialize.call(this, options);
14
15       var editorModel = this.model;
16       var fieldModel = this.fieldModel;
17
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()));
22
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');
30         }
31       });
32     },
33     getEditedElement: function getEditedElement() {
34       return this.$textElement;
35     },
36     stateChange: function stateChange(fieldModel, state, options) {
37       var from = fieldModel.previous('state');
38       var to = state;
39       switch (to) {
40         case 'inactive':
41           break;
42
43         case 'candidate':
44           if (from !== 'inactive') {
45             this.$textElement.removeAttr('contenteditable');
46           }
47           if (from === 'invalid') {
48             this.removeValidationErrors();
49           }
50           break;
51
52         case 'highlighted':
53           break;
54
55         case 'activating':
56           _.defer(function () {
57             fieldModel.set('state', 'active');
58           });
59           break;
60
61         case 'active':
62           this.$textElement.attr('contenteditable', 'true');
63           break;
64
65         case 'changed':
66           break;
67
68         case 'saving':
69           if (from === 'invalid') {
70             this.removeValidationErrors();
71           }
72           this.save(options);
73           break;
74
75         case 'saved':
76           break;
77
78         case 'invalid':
79           this.showValidationErrors();
80           break;
81       }
82     },
83     getQuickEditUISettings: function getQuickEditUISettings() {
84       return {
85         padding: true,
86         unifiedToolbar: false,
87         fullWidthToolbar: false,
88         popup: false
89       };
90     },
91     revert: function revert() {
92       this.$textElement.html(this.model.get('originalValue'));
93     }
94   });
95 })(jQuery, _, Drupal);