213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
|
xActionsBar.appendChild(oGrammalecte.createNode("div", {id: "grammalecte_check" + oResult.iParaNum, className: "grammalecte_paragraph_button grammalecte_green", textContent: "↻", title: "Réanalyser…"}, {para_num: oResult.iParaNum}));
xActionsBar.appendChild(oGrammalecte.createNode("div", {id: "grammalecte_hide" + oResult.iParaNum, className: "grammalecte_paragraph_button grammalecte_red", textContent: "×", title: "Cacher", style: "font-weight: bold;"}));
// paragraph
let xParagraph = oGrammalecte.createNode("p", {id: "grammalecte_paragraph"+oResult.iParaNum, className: "grammalecte_paragraph", lang: "fr", contentEditable: "true"}, {para_num: oResult.iParaNum});
xParagraph.setAttribute("spellcheck", "false"); // doesn’t seem possible to use “spellcheck” as a common attribute.
xParagraph.dataset.timer_id = "0";
xParagraph.addEventListener("input", function (xEvent) {
window.clearTimeout(parseInt(xParagraph.dataset.timer_id));
xParagraph.dataset.timer_id = window.setTimeout(this.recheckParagraph.bind(this), 3000, oResult.iParaNum);
let [nStart, nEnd] = oGrammalecte.getCaretPosition(xParagraph);
xParagraph.dataset.caret_position_start = nStart;
xParagraph.dataset.caret_position_end = nEnd;
this.oTextControl.setParagraph(parseInt(xEvent.target.dataset.para_num), this.purgeText(xEvent.target.textContent));
this.oTextControl.write();
}.bind(this)
, true);
this._tagParagraph(xParagraph, oResult.sParagraph, oResult.iParaNum, oResult.aGrammErr, oResult.aSpellErr);
// creation
xNodeDiv.appendChild(xActionsBar);
xNodeDiv.appendChild(xParagraph);
this.xParagraphList.appendChild(xNodeDiv);
}
|
>
>
>
>
>
>
>
>
>
>
>
>
>
|
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
|
xActionsBar.appendChild(oGrammalecte.createNode("div", {id: "grammalecte_check" + oResult.iParaNum, className: "grammalecte_paragraph_button grammalecte_green", textContent: "↻", title: "Réanalyser…"}, {para_num: oResult.iParaNum}));
xActionsBar.appendChild(oGrammalecte.createNode("div", {id: "grammalecte_hide" + oResult.iParaNum, className: "grammalecte_paragraph_button grammalecte_red", textContent: "×", title: "Cacher", style: "font-weight: bold;"}));
// paragraph
let xParagraph = oGrammalecte.createNode("p", {id: "grammalecte_paragraph"+oResult.iParaNum, className: "grammalecte_paragraph", lang: "fr", contentEditable: "true"}, {para_num: oResult.iParaNum});
xParagraph.setAttribute("spellcheck", "false"); // doesn’t seem possible to use “spellcheck” as a common attribute.
xParagraph.dataset.timer_id = "0";
xParagraph.addEventListener("input", function (xEvent) {
// timer for refreshing analysis
window.clearTimeout(parseInt(xParagraph.dataset.timer_id));
xParagraph.dataset.timer_id = window.setTimeout(this.recheckParagraph.bind(this), 3000, oResult.iParaNum);
// save caret position
let [nStart, nEnd] = oGrammalecte.getCaretPosition(xParagraph);
xParagraph.dataset.caret_position_start = nStart;
xParagraph.dataset.caret_position_end = nEnd;
// write text
this.oTextControl.setParagraph(parseInt(xEvent.target.dataset.para_num), this.purgeText(xEvent.target.textContent));
this.oTextControl.write();
}.bind(this)
, true);
xParagraph.addEventListener("blur", function (xEvent) {
// remove timer for refreshing analysis
window.clearTimeout(parseInt(xParagraph.dataset.timer_id));
// unset caret position
xParagraph.dataset.caret_position_start = "-1";
xParagraph.dataset.caret_position_end = "-1";
// recheck
this.recheckParagraph(oResult.iParaNum);
}.bind(this)
, true);
this._tagParagraph(xParagraph, oResult.sParagraph, oResult.iParaNum, oResult.aGrammErr, oResult.aSpellErr);
// creation
xNodeDiv.appendChild(xActionsBar);
xNodeDiv.appendChild(xParagraph);
this.xParagraphList.appendChild(xNodeDiv);
}
|
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
|
this.xParent.getElementById("grammalecte_check"+xParagraph.dataset.para_num).style.backgroundColor = "hsl(0, 50%, 50%)";
this.xParent.getElementById("grammalecte_check"+xParagraph.dataset.para_num).style.boxShadow = "0 0 0 3px hsla(0, 0%, 50%, .2)";
this.xParent.getElementById("grammalecte_check"+xParagraph.dataset.para_num).style.animation = "grammalecte-pulse 1s linear infinite";
}
freeParagraph (xParagraph) {
xParagraph.contentEditable = "true";
let nStart = parseInt(xParagraph.dataset.caret_position_start);
let nEnd = parseInt(xParagraph.dataset.caret_position_end);
oGrammalecte.setCaretPosition(xParagraph, nStart, nEnd);
this.xParent.getElementById("grammalecte_check"+xParagraph.dataset.para_num).textContent = "↻";
this.xParent.getElementById("grammalecte_check"+xParagraph.dataset.para_num).style.backgroundColor = "";
this.xParent.getElementById("grammalecte_check"+xParagraph.dataset.para_num).style.animation = "";
setTimeout(() => { this.xParent.getElementById("grammalecte_check"+xParagraph.dataset.para_num).style.boxShadow = ""; }, 500);
}
applySuggestion (sNodeSuggId) { // sugg
|
>
|
|
|
>
|
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
|
this.xParent.getElementById("grammalecte_check"+xParagraph.dataset.para_num).style.backgroundColor = "hsl(0, 50%, 50%)";
this.xParent.getElementById("grammalecte_check"+xParagraph.dataset.para_num).style.boxShadow = "0 0 0 3px hsla(0, 0%, 50%, .2)";
this.xParent.getElementById("grammalecte_check"+xParagraph.dataset.para_num).style.animation = "grammalecte-pulse 1s linear infinite";
}
freeParagraph (xParagraph) {
xParagraph.contentEditable = "true";
if (xParagraph.dataset.caret_position_start !== "-1") {
let nStart = parseInt(xParagraph.dataset.caret_position_start);
let nEnd = parseInt(xParagraph.dataset.caret_position_end);
oGrammalecte.setCaretPosition(xParagraph, nStart, nEnd);
}
this.xParent.getElementById("grammalecte_check"+xParagraph.dataset.para_num).textContent = "↻";
this.xParent.getElementById("grammalecte_check"+xParagraph.dataset.para_num).style.backgroundColor = "";
this.xParent.getElementById("grammalecte_check"+xParagraph.dataset.para_num).style.animation = "";
setTimeout(() => { this.xParent.getElementById("grammalecte_check"+xParagraph.dataset.para_num).style.boxShadow = ""; }, 500);
}
applySuggestion (sNodeSuggId) { // sugg
|
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
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
|
let xNode = oGrammalecte.createNode("div", {className: "grammalecte_panel_flow_message", textContent: sMessage});
this.xParagraphList.appendChild(xNode);
}
copyTextToClipboard () {
this.startWaitIcon();
try {
let sText = "";
// Dans un shadow, <this.xParent.getElementsByClassName> n’existe pas.
let xElem = this.xParent.getElementById("grammalecte_gc_panel");
for (let xNode of xElem.getElementsByClassName("grammalecte_paragraph")) {
sText += xNode.textContent + "\n";
}
this._sendTextToClipboard(sText);
}
catch (e) {
showError(e);
}
this.stopWaitIcon();
}
_sendTextToClipboard (sText) {
let xClipboardButton = this.xParent.getElementById("grammalecte_clipboard_button");
xClipboardButton.textContent = "⇒ presse-papiers";
// Firefox 63+, Chrome 66+
// Working draft: https://developer.mozilla.org/en-US/docs/Web/API/Clipboard
navigator.clipboard.writeText(sText)
.then(
(res) => { window.setTimeout(() => { xClipboardButton.textContent = "📋"; }, 2000); }
)
.catch(
(e) => { console.error(e); this._sendTextToClipboard(sText, xClipboardButton); }
);
}
_sendTextToClipboardFallback (sText, xClipboardButton) {
try {
// Copy to clipboard fallback
// recipe from https://github.com/mdn/webextensions-examples/blob/master/context-menu-copy-link-with-types/clipboard-helper.js
function setClipboardData (xEvent) {
document.removeEventListener("copy", setClipboardData, true);
xEvent.stopImmediatePropagation();
xEvent.preventDefault();
xEvent.clipboardData.setData("text/plain", sText);
}
document.addEventListener("copy", setClipboardData, true);
document.execCommand("copy");
window.setTimeout(() => { xClipboardButton.textContent = "📋"; }, 2000);
}
catch (e) {
console.error(e);
}
}
// Lexicographer
|
<
<
<
|
>
|
|
|
|
|
|
|
>
>
|
|
>
|
|
|
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
|
let xNode = oGrammalecte.createNode("div", {className: "grammalecte_panel_flow_message", textContent: sMessage});
this.xParagraphList.appendChild(xNode);
}
copyTextToClipboard () {
this.startWaitIcon();
try {
let sText = "";
// Dans un shadow, <this.xParent.getElementsByClassName> n’existe pas.
let xElem = this.xParent.getElementById("grammalecte_gc_panel");
for (let xNode of xElem.getElementsByClassName("grammalecte_paragraph")) {
sText += xNode.textContent + "\n";
}
this._sendTextToClipboard(sText);
}
catch (e) {
showError(e);
}
this.stopWaitIcon();
}
_sendTextToClipboard (sText) {
this.xClipboardButton.textContent = "⇒ presse-papiers";
// Firefox 63+, Chrome 66+
// Working draft: https://developer.mozilla.org/en-US/docs/Web/API/Clipboard
if (navigator.clipboard && navigator.clipboard.writeText) {
navigator.clipboard.writeText(sText)
.then(
(res) => { window.setTimeout(() => { this.xClipboardButton.textContent = "📋"; }, 2000); }
)
.catch(
(e) => { console.error(e); this._sendTextToClipboard(sText); }
);
} else {
this._sendTextToClipboardFallback(sText);
}
}
_sendTextToClipboardFallback (sText) {
try {
// Copy to clipboard fallback
// recipe from https://github.com/mdn/webextensions-examples/blob/master/context-menu-copy-link-with-types/clipboard-helper.js
function setClipboardData (xEvent) {
document.removeEventListener("copy", setClipboardData, true);
xEvent.stopImmediatePropagation();
xEvent.preventDefault();
xEvent.clipboardData.setData("text/plain", sText);
}
document.addEventListener("copy", setClipboardData, true);
document.execCommand("copy");
window.setTimeout(() => { this.xClipboardButton.textContent = "📋"; }, 2000);
}
catch (e) {
console.error(e);
}
}
// Lexicographer
|