diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 168f4532d53c36ae4b8e8653f1fe69112056267a..d94b3bf18a920c38e7282bb5eda56eb34b6e055f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -26,6 +26,8 @@ composer-lint: allow_failure: false cspell: allow_failure: false +eslint: + allow_failure: false phpcs: allow_failure: false phpstan: diff --git a/assets/js/json_field.js b/assets/js/json_field.js index 7f65dded1f40b682f12f7bb8ceca75631d5c95c7..30b743eb92b5bad230209d0ba47e5a3b4b50e9f1 100644 --- a/assets/js/json_field.js +++ b/assets/js/json_field.js @@ -4,15 +4,14 @@ */ (function ($, Drupal, drupalSettings, once) { - 'use strict'; - - var options = $.extend(drupalSettings.json_field, + const options = $.extend( + drupalSettings.json_field, // Merge strings on top of drupalSettings so that they are not mutable. { strings: { - quickEdit: Drupal.t('Quick edit') - } - } + quickEdit: Drupal.t('Quick edit'), + }, + }, ); /** @@ -21,12 +20,11 @@ * @type {Drupal~behavior} */ Drupal.behaviors.json_field = { - attach: function (context) { + attach(context) { // Initialize the Quick Edit app once per page load. $(once('json-field-init', 'pre.json-field', context)).each(function () { $(this).parent().JSONView($(this).parent().find('pre code').text()); }); - } + }, }; - })(jQuery, Drupal, drupalSettings, once); diff --git a/modules/json_field_widget/assets/js/json_widget.js b/modules/json_field_widget/assets/js/json_widget.js index fa245834c233a83092c7efd9da9dcaffc7672238..352f6239f20944006fb3ce26a778ed2d319fd13a 100644 --- a/modules/json_field_widget/assets/js/json_widget.js +++ b/modules/json_field_widget/assets/js/json_widget.js @@ -4,13 +4,10 @@ */ (function ($, Drupal, drupalSettings) { - 'use strict'; - function parseJson(string) { try { return JSON.parse(string); - } - catch (e) { + } catch (e) { return null; } } @@ -22,44 +19,51 @@ */ Drupal.behaviors.json_widget = { attach(context) { - $(once('json-editor', '[data-json-editor]', context)) - .each(function (index, element) { - var $textarea = $(element); - var hash = $textarea.attr('data-json-editor'); - var options = drupalSettings.json_field[hash]; - var data = $textarea.val(); - var json = parseJson(data); + $(once('json-editor', '[data-json-editor]', context)).each( + function (index, element) { + const $textarea = $(element); + const hash = $textarea.attr('data-json-editor'); + const options = drupalSettings.json_field[hash]; + const data = $textarea.value; + const json = parseJson(data); if (options || data) { - var $editor = $(Drupal.theme('jsonEditorWrapper', 'json-editor-' + $textarea.attr('name'))); + const $editor = $( + Drupal.theme( + 'jsonEditorWrapper', + `json-editor-${$textarea.attr('name')}`, + ), + ); $textarea.addClass('js-hide'); $textarea.after($editor); - var instanceOptions = { + const instanceOptions = { // Copy the data as-is in the textarea regardless of the // validity of the JSON. - onChange: function () { + onChange() { $textarea.text(jsonEditor.getText()); - } + }, }; if (options.schema) { instanceOptions.schema = parseJson(options.schema); } - var jsonEditor = new JSONEditor($editor[0], Object.assign({}, options, instanceOptions)); + const jsonEditor = new JSONEditor($editor[0], { + ...options, + ...instanceOptions, + }); if (json) { jsonEditor.set(json); - } - else { + } else { jsonEditor.setText(data); } } - }); - } + }, + ); + }, }; Drupal.theme.jsonEditorWrapper = function (id) { - return '<div style="width:100%;height:500px" id="' + id + '"></div>'; - } - + return `<div style="width:100%;height:500px" id="${id}"></div>`; + }; })(jQuery, Drupal, drupalSettings);