Commit b08d1ed1 authored by dindigala's avatar dindigala
Browse files

refactor: minor method add according to the data changes

parent 00736ca3
Pipeline #221813 passed with stages
in 4 minutes and 5 seconds
...@@ -231,6 +231,17 @@ export default { ...@@ -231,6 +231,17 @@ export default {
addIcon(element, annotation) { addIcon(element, annotation) {
const contentType = annotation.body['x-content-type']; const contentType = annotation.body['x-content-type'];
let foundSvg = false;
[...element.children].forEach((el) => {
if (el.nodeName === 'svg' && el.getAttribute('data-annotation-icon')) {
foundSvg = true;
}
});
if (foundSvg) {
return;
}
try { try {
const svg = this.createSVG(this.getIconName(contentType)); const svg = this.createSVG(this.getIconName(contentType));
svg.setAttribute( svg.setAttribute(
......
...@@ -138,7 +138,7 @@ export default { ...@@ -138,7 +138,7 @@ export default {
let dom = parser.parseFromString(data, 'text/html'); let dom = parser.parseFromString(data, 'text/html');
if (!annotationPanelHidden) { if (!annotationPanelHidden) {
const spans = [ const spans = [
...dom.querySelectorAll('span[data-target]:not([value=""])'), ...dom.querySelectorAll('[data-target]:not([value=""])'),
]; ];
const spanIds = [ const spanIds = [
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
--> -->
<script id="tido-config" type="application/json"> <script id="tido-config" type="application/json">
{ {
"entrypoint": "https://subugoe.pages.gwdg.de/emo/backend/sampledata/collection.json", "entrypoint": "https://ahikar-dev.sub.uni-goettingen.de/api/textapi/ahikar/syriac/collection.json",
"annotations": { "annotations": {
"show": true, "show": true,
"types": [ "types": [
......
...@@ -3,17 +3,23 @@ export default { ...@@ -3,17 +3,23 @@ export default {
getAllElementsFromSelector(selector, arr = []) { getAllElementsFromSelector(selector, arr = []) {
const el = document.getElementById(selector); const el = document.getElementById(selector);
if (el) { if (el) {
arr.push(el); // https://www.geeksforgeeks.org/queue-data-structure/
const queue = [];
[...el.children].forEach((child) => { queue.push(el);
arr.push(child);
}); while (queue.length) {
const popped = queue.pop();
arr.push(popped);
[...popped.children].forEach((child) => {
queue.push(child);
});
}
return arr; return arr;
} }
return [...document.querySelectorAll(`.${selector}`)]; return [...document.querySelectorAll(`.${selector}`)];
}, },
getElementById(id) { getElementById(id) {
if (!id) { if (!id) {
return null; return null;
...@@ -81,8 +87,8 @@ export default { ...@@ -81,8 +87,8 @@ export default {
}, },
replaceSelectorWithSpan(selector, root) { replaceSelectorWithSpan(selector, root) {
const start = root.querySelector(`span[data-target="${selector}_start"]`); const start = root.querySelector(`[data-target="${selector}_start"]`);
const end = root.querySelector(`span[data-target="${selector}_end"]`); const end = root.querySelector(`[data-target="${selector}_end"]`);
let started = false; let started = false;
let ended = false; let ended = false;
...@@ -184,8 +190,9 @@ export default { ...@@ -184,8 +190,9 @@ export default {
stripSelector(annotation) { stripSelector(annotation) {
return `.${annotation.target.selector.startSelector.value return `.${annotation.target.selector.startSelector.value
.replace("span[data-target='", '') .replace("span[data-target='", '')
.replace("_start']", '') .replace("'", '')
.replace("_end']", '')}`; .replace('_start]', '')
.replace('_end]', '')}`;
}, },
stripTargetId(annotation, removeDot = true) { stripTargetId(annotation, removeDot = true) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment