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');
76 var textElement = this.$textElement.get(0);
77 var toolbarView = fieldModel.toolbarView;
78 this.textEditor.attachInlineEditor(textElement, this.textFormat, toolbarView.getMainWysiwygToolgroupId(), toolbarView.getFloatedWysiwygToolgroupId());
80 this.textEditor.onChange(textElement, function (htmlText) {
81 editorModel.set('currentValue', htmlText);
82 fieldModel.set('state', 'changed');
90 if (from === 'invalid') {
91 this.removeValidationErrors();
100 this.showValidationErrors();
104 getQuickEditUISettings: function getQuickEditUISettings() {
105 return { padding: true, unifiedToolbar: true, fullWidthToolbar: true, popup: false };
107 revert: function revert() {
108 this.$textElement.html(this.model.get('originalValue'));
110 _getUntransformedText: function _getUntransformedText(callback) {
111 var fieldID = this.fieldModel.get('fieldID');
113 var textLoaderAjax = Drupal.ajax({
114 url: Drupal.quickedit.util.buildUrl(fieldID, Drupal.url('editor/!entity_type/!id/!field_name/!langcode/!view_mode')),
115 submit: { nocssjs: true }
118 textLoaderAjax.commands.editorGetUntransformedText = function (ajax, response, status) {
119 callback(response.data);
122 textLoaderAjax.execute();
125 })(jQuery, Drupal, drupalSettings, _);