1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
// JavaScript
"use strict";
class GrammalecteMenu {
constructor (nMenu, xNode) {
this.sMenuId = "grammalecte_menu" + nMenu;
this.xButton = oGrammalecte.createNode("div", {className: "grammalecte_menu_main_button", textContent: " "});
this.xButton.onclick = () => { this.switchMenu(); };
this.xButton.style.zIndex = (xNode.style.zIndex.search(/^[0-9]+$/) !== -1) ? (parseInt(xNode.style.zIndex) + 1).toString() : xNode.style.zIndex;
this.xMenu = this._createMenu(xNode);
this._insertAfter(this.xButton, xNode);
this._insertAfter(this.xMenu, xNode);
this._createListenersOnReferenceNode(xNode);
}
_insertAfter (xNewNode, xReferenceNode) {
xReferenceNode.parentNode.insertBefore(xNewNode, xReferenceNode.nextSibling);
}
_createListenersOnReferenceNode (xNode) {
xNode.addEventListener('focus', (e) => {
this.xButton.style.display = "block";
});
xNode.addEventListener('blur', (e) => {
window.setTimeout(() => {this.xButton.style.display = "none";}, 300);
});
}
_createMenu (xNode) {
try {
let xMenu = oGrammalecte.createNode("div", {id: this.sMenuId, className: "grammalecte_menu"});
let xCloseButton = oGrammalecte.createNode("div", {className: "grammalecte_menu_close_button", textContent: "×"} );
xCloseButton.onclick = () => { this.switchMenu(); }
xMenu.appendChild(xCloseButton);
xMenu.appendChild(oGrammalecte.createNode("div", {className: "grammalecte_menu_header", textContent: "GRAMMALECTE"}));
// Text formatter
if (xNode.tagName == "TEXTAREA") {
let xTFButton = oGrammalecte.createNode("div", {className: "grammalecte_menu_item", textContent: "Formateur de texte"});
xTFButton.onclick = () => {
this.switchMenu();
oGrammalecte.createTFPanel();
oGrammalecte.oTFPanel.start(xNode);
oGrammalecte.oTFPanel.show();
};
xMenu.appendChild(xTFButton);
}
// lexicographe
let xLxgButton = oGrammalecte.createNode("div", {className: "grammalecte_menu_item", textContent: "Lexicographe"});
xLxgButton.onclick = () => {
this.switchMenu();
let sText = (xNode.tagName == "TEXTAREA") ? xNode.value : xNode.innerText;
oGrammalecte.startLxgPanel();
xGrammalectePort.postMessage({
sCommand: "getListOfTokens",
dParam: {sText: sText},
dInfo: {sTextAreaId: xNode.id}
});
};
xMenu.appendChild(xLxgButton);
// Grammar checker
let xGCButton = oGrammalecte.createNode("div", {className: "grammalecte_menu_item", textContent: "Correction grammaticale"});
xGCButton.onclick = () => {
this.switchMenu();
let sText = (xNode.tagName == "TEXTAREA") ? xNode.value : xNode.innerText;
oGrammalecte.startGCPanel(xNode);
xGrammalectePort.postMessage({
sCommand: "parseAndSpellcheck",
dParam: {sText: sText, sCountry: "FR", bDebug: false, bContext: false},
dInfo: {sTextAreaId: xNode.id}
});
};
xMenu.appendChild(xGCButton);
// Conjugation tool
let xConjButton = oGrammalecte.createNode("div", {className: "grammalecte_menu_item_block", textContent: "Conjugueur"});
let xConjButtonTab = oGrammalecte.createNode("div", {className: "grammalecte_menu_button", textContent: "Onglet"});
xConjButtonTab.onclick = () => {
|
>
|
>
>
>
>
>
>
>
>
>
|
|
|
|
>
|
|
|
|
>
>
>
>
|
|
>
>
>
|
|
<
|
|
<
|
|
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
// JavaScript
"use strict";
class GrammalecteMenu {
constructor (nMenu, xNode) {
this.xNode = xNode;
this.sMenuId = "grammalecte_menu" + nMenu;
this.xButton = oGrammalecte.createNode("div", {className: "grammalecte_menu_main_button", textContent: " "});
this.xButton.onclick = () => { this.switchMenu(); };
this.xButton.style.zIndex = (xNode.style.zIndex.search(/^[0-9]+$/) !== -1) ? (parseInt(xNode.style.zIndex) + 1).toString() : xNode.style.zIndex;
this.xMenu = this._createMenu();
let xStyle = window.getComputedStyle(this.xNode);
let nMarginTop = -1 * (8 + parseInt(xStyle.marginBottom.replace('px', ''), 10));
let xNodeInsertAfter = this.xNode;
if (document.location.host == "twitter.com" && this.xNode.classList.contains('rich-editor')) {
xNodeInsertAfter = this.xNode.parentNode;
}
this._insertAfter(this.xButton, xNodeInsertAfter, nMarginTop);
this._insertAfter(this.xMenu, xNodeInsertAfter, nMarginTop + 8);
this._createListeners();
}
_insertAfter (xNewNode, xReferenceNode, nMarginTop) {
xReferenceNode.parentNode.insertBefore(xNewNode, xReferenceNode.nextSibling);
xNewNode.style.marginTop = nMarginTop + "px";
}
_createListeners () {
this.xNode.addEventListener('focus', (e) => {
this.xButton.style.display = "block";
});
/*this.xNode.addEventListener('blur', (e) => {
window.setTimeout(() => {this.xButton.style.display = "none";}, 300);
});*/
}
_getText () {
return (this.xNode.tagName == "TEXTAREA") ? this.xNode.value.normalize("NFC") : this.xNode.innerText.normalize("NFC");
}
_createMenu () {
try {
let xMenu = oGrammalecte.createNode("div", {id: this.sMenuId, className: "grammalecte_menu"});
let xCloseButton = oGrammalecte.createNode("div", {className: "grammalecte_menu_close_button", textContent: "×"} );
xCloseButton.onclick = () => {
this.xButton.style.display = "none";
this.switchMenu();
}
xMenu.appendChild(xCloseButton);
xMenu.appendChild(oGrammalecte.createNode("div", {className: "grammalecte_menu_header", textContent: "GRAMMALECTE"}));
// Text formatter
if (this.xNode.tagName == "TEXTAREA") {
let xTFButton = oGrammalecte.createNode("div", {className: "grammalecte_menu_item", textContent: "Formateur de texte"});
xTFButton.onclick = () => {
this.switchMenu();
oGrammalecte.createTFPanel();
oGrammalecte.oTFPanel.start(this.xNode);
oGrammalecte.oTFPanel.show();
};
xMenu.appendChild(xTFButton);
}
// lexicographe
let xLxgButton = oGrammalecte.createNode("div", {className: "grammalecte_menu_item", textContent: "Lexicographe"});
xLxgButton.onclick = () => {
this.switchMenu();
oGrammalecte.startLxgPanel();
xGrammalectePort.postMessage({
sCommand: "getListOfTokens",
dParam: {sText: this._getText()},
dInfo: {sTextAreaId: this.xNode.id}
});
};
xMenu.appendChild(xLxgButton);
// Grammar checker
let xGCButton = oGrammalecte.createNode("div", {className: "grammalecte_menu_item", textContent: "Correction grammaticale"});
xGCButton.onclick = () => {
this.switchMenu();
oGrammalecte.startGCPanel(this.xNode);
xGrammalectePort.postMessage({
sCommand: "parseAndSpellcheck",
dParam: {sText: this._getText(), sCountry: "FR", bDebug: false, bContext: false},
dInfo: {sTextAreaId: this.xNode.id}
});
};
xMenu.appendChild(xGCButton);
// Conjugation tool
let xConjButton = oGrammalecte.createNode("div", {className: "grammalecte_menu_item_block", textContent: "Conjugueur"});
let xConjButtonTab = oGrammalecte.createNode("div", {className: "grammalecte_menu_button", textContent: "Onglet"});
xConjButtonTab.onclick = () => {
|