Feature #1545
Feature #1544: RCP: X.X, edition annotation
RCP: X.X, edition annotation V1
| Statut: | New | Début: | 01/10/2015 | |
|---|---|---|---|---|
| Priorité: | Normal | Echéance: | ||
| Assigné à: | - | % réalisé: | 0% |
|
| Catégorie: | Commands | Temps passé: | - | |
| Version cible: | TXM Annotation X.X | Temps estimé: | 3.00 heures |
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
}
Historique
#1 Mis à jour par Matthieu Decorde il y a environ 10 ans
- Temps estimé mis à 3.00
#2 Mis à jour par Matthieu Decorde il y a environ 10 ans
- Description mis à jour (diff)
#3 Mis à jour par Matthieu Decorde il y a environ 10 ans
- Description mis à jour (diff)
#4 Mis à jour par Matthieu Decorde il y a environ 10 ans
- Description mis à jour (diff)
#5 Mis à jour par Serge Heiden il y a environ 10 ans
- Description mis à jour (diff)
#6 Mis à jour par Matthieu Decorde il y a environ 10 ans
- Description mis à jour (diff)
#7 Mis à jour par Matthieu Decorde il y a presque 10 ans
- Version cible changé de TXM Annotation 1.0 à 41
#8 Mis à jour par Matthieu Decorde il y a plus d'un an
- Version cible changé de 41 à TXM Annotation X.X