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, drupalSettings, _) {
9 Drupal.quickedit.editors.editor = Drupal.quickedit.EditorView.extend({
12 textFormatHasTransformations: null,
18 initialize: function initialize(options) {
19 Drupal.quickedit.EditorView.prototype.initialize.call(this, options);
21 var metadata = Drupal.quickedit.metadata.get(this.fieldModel.get('fieldID'), 'custom');
22 this.textFormat = drupalSettings.editor.formats[metadata.format];
23 this.textFormatHasTransformations = metadata.formatHasTransformations;
24 this.textEditor = Drupal.editors[this.textFormat.editor];
26 var $fieldItems = this.$el.find('.quickedit-field');
27 if ($fieldItems.length) {
28 this.$textElement = $fieldItems.eq(0);
30 this.$textElement = this.$el;
32 this.model.set('originalValue', this.$textElement.html());
34 getEditedElement: function getEditedElement() {
35 return this.$textElement;
37 stateChange: function stateChange(fieldModel, state) {
38 var editorModel = this.model;
39 var from = fieldModel.previous('state');
46 if (from !== 'inactive' && from !== 'highlighted') {
47 this.textEditor.detach(this.$textElement.get(0), this.textFormat);
50 if (from === 'active' && this.textFormatHasTransformations) {
53 if (from === 'invalid') {
54 this.removeValidationErrors();
62 if (this.textFormatHasTransformations) {
63 var $textElement = this.$textElement;
64 this._getUntransformedText(function (untransformedText) {
65 $textElement.html(untransformedText);
66 fieldModel.set('state', 'active');
70 fieldModel.set('state', 'active');
77 var textElement = this.$textElement.get(0);
78 var toolbarView = fieldModel.toolbarView;
79 this.textEditor.attachInlineEditor(textElement, this.textFormat, toolbarView.getMainWysiwygToolgroupId(), toolbarView.getFloatedWysiwygToolgroupId());
81 this.textEditor.onChange(textElement, function (htmlText) {
82 editorModel.set('currentValue', htmlText);
83 fieldModel.set('state', 'changed');
92 if (from === 'invalid') {
93 this.removeValidationErrors();
102 this.showValidationErrors();
106 getQuickEditUISettings: function getQuickEditUISettings() {
109 unifiedToolbar: true,
110 fullWidthToolbar: true,
114 revert: function revert() {
115 this.$textElement.html(this.model.get('originalValue'));
117 _getUntransformedText: function _getUntransformedText(callback) {
118 var fieldID = this.fieldModel.get('fieldID');
120 var textLoaderAjax = Drupal.ajax({
121 url: Drupal.quickedit.util.buildUrl(fieldID, Drupal.url('editor/!entity_type/!id/!field_name/!langcode/!view_mode')),
122 submit: { nocssjs: true }
125 textLoaderAjax.commands.editorGetUntransformedText = function (ajax, response, status) {
126 callback(response.data);
129 textLoaderAjax.execute();
132 })(jQuery, Drupal, drupalSettings, _);