locale.js with no jquery

master
jfh 2020-09-23 10:05:36 +02:00
parent 2488a3a438
commit e4e7d68aba
1 changed files with 5 additions and 8 deletions

View File

@ -1,4 +1,3 @@
/* globals jQuery */
/** /**
* Localizing script for SVG-edit UI. * Localizing script for SVG-edit UI.
* @module locale * @module locale
@ -24,8 +23,6 @@
* @typedef {PlainObject<string, string>} module:locale.LocaleSelectorValue * @typedef {PlainObject<string, string>} module:locale.LocaleSelectorValue
*/ */
const $ = jQuery;
let langParam; let langParam;
/** /**
@ -50,7 +47,7 @@ let langParam;
*/ */
export const setStrings = function (type, obj, ids) { export const setStrings = function (type, obj, ids) {
// Root element to look for element from // Root element to look for element from
const parent = $('#svg_editor').parent(); const parent = document.getElementById('svg_editor').parentNode;
Object.entries(obj).forEach(([sel, val]) => { Object.entries(obj).forEach(([sel, val]) => {
if (!val) { if (!val) {
console.log(sel); // eslint-disable-line no-console console.log(sel); // eslint-disable-line no-console
@ -58,16 +55,16 @@ export const setStrings = function (type, obj, ids) {
} }
if (ids) { sel = '#' + sel; } if (ids) { sel = '#' + sel; }
const $elem = parent.find(sel); const elems = parent.querySelectorAll(sel);
if ($elem.length) { if (elems.length) {
const elem = $elem[0]; const elem = elems[0];
switch (type) { switch (type) {
case 'aria-label': case 'aria-label':
elem.setAttribute('aria-label', val); elem.setAttribute('aria-label', val);
break; break;
case 'content': case 'content':
[...elem.childNodes].some((node) => { [...elems].some((node) => {
if (node.nodeType === 3 /* Node.TEXT_NODE */ && if (node.nodeType === 3 /* Node.TEXT_NODE */ &&
node.textContent.trim() node.textContent.trim()
) { ) {