Feature #1545
Feature #1544: RCP: X.X, edition annotation
RCP: X.X, edition annotation V1
Status: | New | Start date: | 10/01/2015 | |
---|---|---|---|---|
Priority: | Normal | Due date: | ||
Assignee: | - | % Done: | 0% |
|
Category: | Commands | Spent time: | - | |
Target version: | TXM Annotation 2.0 | Estimated time: | 3.00 hours |
Description
Soit le retour de la sélection rend compte des limites de mots : pas du tout
Le résultat de la sélection correspond à une séquence d'occurences de mots projetée sur une propriété : word - qui correspond à la surface sélectionnée modulo recalage.
Corriger l'appel de la Concordance.
note: works only if anchor node preceeds focus node
SH: Could use Node.compareDocumentPosition() to decide how to move in the DOM ('next|previous'Sibling). See https://groupes.renater.fr/wiki/txm-info/documentation_web.
JS code to get selection content (FF, IE11+, Safari)
var all = "" var sel = window.getSelection(); var node = sel.anchorNode.parentNode; while (node != sel.focusNode.parentNode) { all += node.textContent node = node.nextSibling; } all += sel.focusNode.parentNode.textContent alert(all);
JS code to retrive id from selected span
function getID(node) { if (node.nodeType == 1) { for (i = 0; i < node.attributes.length; i++) { if (node.attributes[i].name == "id") { return node.attributes[i].value; } } } return "" } function myFunction() { var all = [] var sel = window.getSelection(); var node = sel.anchorNode.parentNode; while (node != sel.focusNode.parentNode) { all.push(getID(node)) node = node.nextSibling; } all += getID(sel.focusNode.parentNode) alert(all); }
Solution¶
Previous solutions don't manage word half selected.
The solution is to use the first Range (https://developer.mozilla.org/en-US/docs/Web/API/Range) of the Selection (https://developer.mozilla.org/en-US/docs/Web/API/Selection) to get the id of the first word span and the id of the last word span. Then resolve the CQP "word" properties of positions between pos(START_SPAN_WORD_ID) and pos(END_SPAN_WORD_ID)
function findSpans(c, a) { for (var i = 0 ; i < c.length ; i++) { if (c.item(i).tagName == "SPAN") { var id = c.item(i).getAttribute("id") if (id.indexOf("w_") == 0) a.push(id) } else if (c.item(i).nodeType == 1) { findSpans(c.item(i).children, a) } } } function getWordIDFromSelection() { var all = []; var sel = window.getSelection(); if (sel.rangeCount == 0){ return all; } var range = sel.getRangeAt(0); var frag = range.cloneContents(); findSpans(frag.children, all); return all }
History
#1 Updated by Matthieu Decorde about 8 years ago
- Estimated time set to 3.00
#2 Updated by Matthieu Decorde about 8 years ago
- Description updated (diff)
#3 Updated by Matthieu Decorde about 8 years ago
- Description updated (diff)
#4 Updated by Matthieu Decorde about 8 years ago
- Description updated (diff)
#5 Updated by Serge Heiden about 8 years ago
- Description updated (diff)
#6 Updated by Matthieu Decorde about 8 years ago
- Description updated (diff)
#7 Updated by Matthieu Decorde almost 8 years ago
- Target version changed from TXM Annotation 1.0 to TXM Annotation 2.0