Skip to content
Snippets Groups Projects
Commit b5e188d2 authored by Patrick Kenny's avatar Patrick Kenny
Browse files

Merge branch 'eslint' into '8.x-1.x'

fix eslint test

See merge request !29
parents c4adef48 0bb98b67
No related branches found
No related tags found
No related merge requests found
Pipeline #183455 failed
......@@ -26,6 +26,8 @@ composer-lint:
allow_failure: false
cspell:
allow_failure: false
eslint:
allow_failure: false
phpcs:
allow_failure: false
phpstan:
......
......@@ -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);
......@@ -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);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment