274
275
276
277
278
279
280
281
282
283
284
285
286
287
|
}
}
class GrammalecteTooltip {
constructor (xContentNode) {
this.xTooltip = createNode("div", {id: "grammalecte_tooltip"});
this.xTooltipArrow = createNode("img", {
id: "grammalecte_tooltip_arrow",
src: " data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAYAAADED76LAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAOwAAADsABataJCQAAABl0RVh0U29mdHdhcmUAcGFpbnQubmV0IDQuMC4xNzNun2MAAAAnSURBVChTY/j//z8cq/kW/wdhZDEMSXRFWCVhGKwAmwQyHngFxf8B5fOGYfeFpYoAAAAASUVORK5CYII=",
alt: "^",
});
this.xTooltipSuggBlock = createNode("div", {id: "grammalecte_tooltip_sugg_block"});
|
>
|
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
|
}
}
class GrammalecteTooltip {
constructor (xContentNode) {
this.sErrorId = null;
this.xTooltip = createNode("div", {id: "grammalecte_tooltip"});
this.xTooltipArrow = createNode("img", {
id: "grammalecte_tooltip_arrow",
src: " data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAYAAADED76LAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAOwAAADsABataJCQAAABl0RVh0U29mdHdhcmUAcGFpbnQubmV0IDQuMC4xNzNun2MAAAAnSURBVChTY/j//z8cq/kW/wdhZDEMSXRFWCVhGKwAmwQyHngFxf8B5fOGYfeFpYoAAAAASUVORK5CYII=",
alt: "^",
});
this.xTooltipSuggBlock = createNode("div", {id: "grammalecte_tooltip_sugg_block"});
|
298
299
300
301
302
303
304
305
306
307
308
309
310
311
|
xContentNode.appendChild(this.xTooltip);
xContentNode.appendChild(this.xTooltipArrow);
}
show (sNodeErrorId) { // err
try {
let xNodeErr = document.getElementById(sNodeErrorId);
let nLimit = 500 - 330; // paragraph width - tooltip width
this.xTooltipArrow.style.top = (xNodeErr.offsetTop + 16) + "px";
this.xTooltipArrow.style.left = (xNodeErr.offsetLeft + Math.floor((xNodeErr.offsetWidth / 2))-4) + "px"; // 4 is half the width of the arrow.
this.xTooltip.style.top = (xNodeErr.offsetTop + 20) + "px";
this.xTooltip.style.left = (xNodeErr.offsetLeft > nLimit) ? nLimit + "px" : xNodeErr.offsetLeft + "px";
if (xNodeErr.dataset.error_type === "grammar") {
// grammar error
|
>
|
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
|
xContentNode.appendChild(this.xTooltip);
xContentNode.appendChild(this.xTooltipArrow);
}
show (sNodeErrorId) { // err
try {
let xNodeErr = document.getElementById(sNodeErrorId);
this.sErrorId = xNodeErr.dataset.error_id; // we store error_id here to know if spell_suggestions are given to the right word.
let nLimit = 500 - 330; // paragraph width - tooltip width
this.xTooltipArrow.style.top = (xNodeErr.offsetTop + 16) + "px";
this.xTooltipArrow.style.left = (xNodeErr.offsetLeft + Math.floor((xNodeErr.offsetWidth / 2))-4) + "px"; // 4 is half the width of the arrow.
this.xTooltip.style.top = (xNodeErr.offsetTop + 20) + "px";
this.xTooltip.style.left = (xNodeErr.offsetLeft > nLimit) ? nLimit + "px" : xNodeErr.offsetLeft + "px";
if (xNodeErr.dataset.error_type === "grammar") {
// grammar error
|
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
|
document.getElementById("grammalecte_tooltip_url").style.display = "inline";
} else {
document.getElementById("grammalecte_tooltip_url").dataset.url = "";
document.getElementById("grammalecte_tooltip_url").style.display = "none";
}
document.getElementById("grammalecte_tooltip_ignore").dataset.error_id = xNodeErr.dataset.error_id;
let iSugg = 0;
let xGCSugg = document.getElementById("grammalecte_tooltip_sugg_block");
xGCSugg.textContent = "";
if (xNodeErr.dataset.suggestions.length > 0) {
for (let sSugg of xNodeErr.dataset.suggestions.split("|")) {
xGCSugg.appendChild(this._createSuggestion(xNodeErr.dataset.error_id, iSugg, sSugg));
xGCSugg.appendChild(document.createTextNode(" "));
iSugg += 1;
}
} else {
xGCSugg.textContent = "Aucune.";
}
}
this.xTooltipArrow.style.display = "block";
this.xTooltip.style.display = "block";
if (xNodeErr.dataset.error_type === "spelling") {
// spelling mistake
document.getElementById("grammalecte_tooltip_message").textContent = "Mot inconnu du dictionnaire.";
document.getElementById("grammalecte_tooltip_ignore").dataset.error_id = xNodeErr.dataset.error_id;
while (this.xTooltipSuggBlock.firstChild) {
this.xTooltipSuggBlock.removeChild(this.xTooltipSuggBlock.firstChild);
}
//console.log("getSuggFor: " + xNodeErr.textContent.trim() + " // error_id: " + xNodeErr.dataset.error_id);
//self.port.emit("getSuggestionsForTo", xNodeErr.textContent.trim(), xNodeErr.dataset.error_id);
this.setSpellSuggestionsFor(xNodeErr.textContent.trim(), "", xNodeErr.dataset.error_id);
}
}
catch (e) {
showError(e);
}
}
setTooltipColor () {
// todo
}
hide () {
this.xTooltipArrow.style.display = "none";
this.xTooltip.style.display = "none";
}
_createSuggestion (sErrId, iSugg, sSugg) {
let xNodeSugg = document.createElement("div");
xNodeSugg.id = "grammalecte_sugg" + sErrId + "--" + iSugg.toString();
xNodeSugg.className = "grammalecte_tooltip_sugg";
xNodeSugg.dataset.error_id = sErrId;
xNodeSugg.textContent = sSugg;
return xNodeSugg;
}
setSpellSuggestionsFor (sWord, sSuggestions, sErrId) {
// spell checking suggestions
try {
// console.log("setSuggestionsFor: " + sWord + " > " + sSuggestions + " // " + sErrId);
let xSuggBlock = document.getElementById("grammalecte_tooltip_sugg_block");
xSuggBlock.textContent = "";
if (sSuggestions === "") {
xSuggBlock.appendChild(document.createTextNode("Aucune."));
} else if (sSuggestions.startsWith("#")) {
xSuggBlock.appendChild(document.createTextNode(sSuggestions));
} else {
let lSugg = sSuggestions.split("|");
let iSugg = 0;
for (let sSugg of lSugg) {
xSuggBlock.appendChild(this._createSuggestion(sErrId, iSugg, sSugg));
xSuggBlock.appendChild(document.createTextNode(" "));
iSugg += 1;
}
}
}
catch (e) {
showError(e);
}
}
}
class GrammalecteTextAreaControl {
|
<
|
|
|
|
<
<
|
|
<
>
|
|
|
>
>
>
>
>
>
>
>
>
|
|
|
|
|
|
|
|
|
<
<
|
<
|
|
|
|
|
>
>
|
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
|
document.getElementById("grammalecte_tooltip_url").style.display = "inline";
} else {
document.getElementById("grammalecte_tooltip_url").dataset.url = "";
document.getElementById("grammalecte_tooltip_url").style.display = "none";
}
document.getElementById("grammalecte_tooltip_ignore").dataset.error_id = xNodeErr.dataset.error_id;
let iSugg = 0;
this.clearSuggestionBlock();
if (xNodeErr.dataset.suggestions.length > 0) {
for (let sSugg of xNodeErr.dataset.suggestions.split("|")) {
this.xTooltipSuggBlock.appendChild(this._createSuggestion(xNodeErr.dataset.error_id, iSugg, sSugg));
this.xTooltipSuggBlock.appendChild(document.createTextNode(" "));
iSugg += 1;
}
} else {
this.xTooltipSuggBlock.textContent = "Aucune.";
}
}
if (xNodeErr.dataset.error_type === "spelling") {
// spelling mistake
document.getElementById("grammalecte_tooltip_message").textContent = "Mot inconnu du dictionnaire.";
document.getElementById("grammalecte_tooltip_ignore").dataset.error_id = xNodeErr.dataset.error_id;
this.clearSuggestionBlock();
this.xTooltipSuggBlock.textContent = "Recherche de graphies possibles…";
xGrammalectePort.postMessage({
sCommand: "getSpellSuggestions",
dParam: {sWord: xNodeErr.textContent},
dInfo: {sErrorId: xNodeErr.dataset.error_id}
});
}
this.xTooltipArrow.style.display = "block";
this.xTooltip.style.display = "block";
}
catch (e) {
showError(e);
}
}
clearSuggestionBlock () {
while (this.xTooltipSuggBlock.firstChild) {
this.xTooltipSuggBlock.removeChild(this.xTooltipSuggBlock.firstChild);
}
}
setTooltipColor () {
// todo
}
hide () {
this.xTooltipArrow.style.display = "none";
this.xTooltip.style.display = "none";
}
_createSuggestion (sErrorId, iSugg, sSugg) {
let xNodeSugg = document.createElement("div");
xNodeSugg.id = "grammalecte_sugg" + sErrorId + "--" + iSugg.toString();
xNodeSugg.className = "grammalecte_tooltip_sugg";
xNodeSugg.dataset.error_id = sErrorId;
xNodeSugg.textContent = sSugg;
return xNodeSugg;
}
setSpellSuggestionsFor (sWord, aSugg, sErrorId) {
// spell checking suggestions
try {
if (sErrorId === this.sErrorId) {
let xSuggBlock = document.getElementById("grammalecte_tooltip_sugg_block");
xSuggBlock.textContent = "";
if (!aSugg || aSugg.length == 0) {
xSuggBlock.appendChild(document.createTextNode("Aucune."));
} else {
let iSugg = 0;
for (let sSugg of aSugg) {
xSuggBlock.appendChild(this._createSuggestion(sErrorId, iSugg, sSugg));
xSuggBlock.appendChild(document.createTextNode(" "));
iSugg += 1;
}
}
}
}
catch (e) {
xSuggBlock.appendChild(document.createTextNode("# Oups. Le mécanisme de suggestion orthographique a rencontré un bug… (Ce module est encore en phase β.)"));
showError(e);
}
}
}
class GrammalecteTextAreaControl {
|