Skip to content
Snippets Groups Projects
Commit feb79c8e 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 7d0f2859 e9f50f94
No related branches found
No related tags found
No related merge requests found
Pipeline #312631 failed
......@@ -26,6 +26,8 @@ composer-lint:
allow_failure: false
cspell:
allow_failure: false
eslint:
allow_failure: false
phpcs:
allow_failure: false
phpstan:
......@@ -41,6 +43,5 @@ stylelint:
# following is just an example.
################
variables:
SKIP_ESLINT: 1
OPT_IN_TEST_NEXT_MAJOR: 1
OPT_IN_TEST_PREVIOUS_MINOR: 1
......@@ -15,6 +15,7 @@ JSON Field 8.x-1.x-dev, 2024-xx-xx
#3453691 by ankitv18, DamienMcKenna, ptmkenny: Enable Drupal 11 tests, fix
regressions.
#3463449 by acbramley, DamienMcKenna: Fix diff 2.x integration.
#3450116 by damienmckenna, ptmkenny, acbramley, nicxvan: Fix eslint tests.
JSON Field 8.x-1.3, 2023-08-09
......
......@@ -4,15 +4,17 @@
*/
(function ($, Drupal, drupalSettings, once) {
'use strict';
var options = $.extend(drupalSettings.json_field,
/**
* Default settings for this item.
*/
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 +23,13 @@
* @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());
$(this)
.parent()
.JSONView($(this).parent().find('pre code').textContent);
});
}
},
};
})(jQuery, Drupal, drupalSettings, once);
......@@ -3,15 +3,17 @@
* Custom JS for the JSON field WYSIWYG-style widget.
*/
(function ($, Drupal, drupalSettings) {
'use strict';
/* global jsonEditor, JSONEditor */
(function ($, Drupal, drupalSettings) {
/**
* Parse the string, convert it to JSON.
*/
function parseJson(string) {
try {
return JSON.parse(string);
}
catch (e) {
return NULL;
} catch (e) {
return null;
}
}
......@@ -22,44 +24,48 @@
*/
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 = {
// Copy the data as-is in the textarea regardless of the
// validity of the JSON.
onChange: function () {
$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,
// Copy the data as-is in the textarea regardless of the validity
// of the JSON.
onChange: () => {
$textarea.textContent = jsonEditor.getText();
},
schema: options.schema ? parseJson(options.schema) : null,
});
if (json) {
jsonEditor.set(json);
}
else {
} else {
jsonEditor.setText(data);
}
}
});
}
},
);
},
};
/**
* Wrap the requested ID with a specific wrapper HTML.
*/
Drupal.theme.jsonEditorWrapper = function (id) {
return '<div style="width:100%;height:500px" id="' + id + '"></div>';
}
})(jQuery, Drupal, drupalSettings);
return `<div style="width:100%;height:500px" id="${id}"></div>`;
};
})(jQuery, Drupal, drupalSettings, jsonEditor, JSONEditor);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment