Index: gc_lang/fr/webext/content_scripts/init.js
==================================================================
--- gc_lang/fr/webext/content_scripts/init.js
+++ gc_lang/fr/webext/content_scripts/init.js
@@ -54,10 +54,18 @@
this.lMenu.push(new GrammalecteMenu(this.nMenu, xNode));
this.nMenu += 1;
}
}
},
+
+ createMenus2 () {
+ let lNode = document.querySelectorAll("[contenteditable]");
+ for (let xNode of lNode) {
+ this.lMenu.push(new GrammalecteMenu(this.nMenu, xNode));
+ this.nMenu += 1;
+ }
+ },
rescanPage: function () {
if (this.oTFPanel !== null) { this.oTFPanel.hide(); }
if (this.oLxgPanel !== null) { this.oLxgPanel.hide(); }
if (this.oGCPanel !== null) { this.oGCPanel.hide(); }
@@ -104,10 +112,20 @@
showError(e);
}
}
}
+
+/*
+ Node where a right click is done
+ Bug report: https://bugzilla.mozilla.org/show_bug.cgi?id=1325814
+*/
+let xRightClickedNode = null;
+document.addEventListener('contextmenu', function (xEvent) {
+ xRightClickedNode = xEvent.target;
+}, true);
+
/*
Connexion to the background
*/
let xGrammalectePort = browser.runtime.connect({name: "content-script port"});
@@ -161,5 +179,6 @@
/*
Start
*/
oGrammalecte.createMenus();
+oGrammalecte.createMenus2();
Index: gc_lang/fr/webext/content_scripts/menu.css
==================================================================
--- gc_lang/fr/webext/content_scripts/menu.css
+++ gc_lang/fr/webext/content_scripts/menu.css
@@ -18,11 +18,11 @@
border-radius: 50%;
text-align: center;
cursor: pointer;
box-shadow: 0 0 0 0 hsla(210, 50%, 50%, .5);
z-index: 2147483640; /* maximum is 2147483647: https://stackoverflow.com/questions/491052/minimum-and-maximum-value-of-z-index */
- animation: grammalecte-spin 2s ease 3;
+ animation: grammalecte-spin 2s ease 1;
}
.grammalecte_menu_main_button:hover {
border: 4px solid hsla(210, 80%, 35%, .5);
background-color: hsla(210, 80%, 55%, .5);
animation: grammalecte-spin .5s linear infinite;
Index: gc_lang/fr/webext/content_scripts/menu.js
==================================================================
--- gc_lang/fr/webext/content_scripts/menu.js
+++ gc_lang/fr/webext/content_scripts/menu.js
@@ -3,81 +3,83 @@
"use strict";
class GrammalecteMenu {
- constructor (nMenu, xTextArea) {
+ 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.xMenu = this._createMenu(xTextArea);
- this._insertAfter(this.xButton, xTextArea);
- this._insertAfter(this.xMenu, xTextArea);
+ this.xMenu = this._createMenu(xNode);
+ this._insertAfter(this.xButton, xNode);
+ this._insertAfter(this.xMenu, xNode);
}
_insertAfter (xNewNode, xReferenceNode) {
xReferenceNode.parentNode.insertBefore(xNewNode, xReferenceNode.nextSibling);
}
- _createMenu (xTextArea) {
+ _createMenu (xNode) {
try {
+ let sText = (xNode.tagName == "TEXTAREA") ? xNode.value : xNode.textContent;
let xMenu = oGrammalecte.createNode("div", {id: this.sMenuId, className: "grammalecte_menu"});
+ xMenu.appendChild(oGrammalecte.createNode("div", {className: "grammalecte_menu_header", textContent: "GRAMMALECTE"}));
// Text formatter
- let xTFButton = oGrammalecte.createNode("div", {className: "grammalecte_menu_item", textContent: "Formateur de texte"});
- xTFButton.onclick = () => {
- this.switchMenu();
- oGrammalecte.createTFPanel();
- oGrammalecte.oTFPanel.start(xTextArea);
- oGrammalecte.oTFPanel.show();
- };
+ 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();
+ this.switchMenu();
oGrammalecte.createLxgPanel();
oGrammalecte.oLxgPanel.clear();
oGrammalecte.oLxgPanel.show();
oGrammalecte.oLxgPanel.startWaitIcon();
xGrammalectePort.postMessage({
sCommand: "getListOfTokens",
- dParam: {sText: xTextArea.value},
- dInfo: {sTextAreaId: xTextArea.id}
+ 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();
+ this.switchMenu();
oGrammalecte.createGCPanel();
- oGrammalecte.oGCPanel.start(xTextArea);
+ oGrammalecte.oGCPanel.start(xNode);
oGrammalecte.oGCPanel.show();
oGrammalecte.oGCPanel.startWaitIcon();
xGrammalectePort.postMessage({
sCommand: "parseAndSpellcheck",
- dParam: {sText: xTextArea.value, sCountry: "FR", bDebug: false, bContext: false},
- dInfo: {sTextAreaId: xTextArea.id}
+ 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 = () => {
- this.switchMenu();
- xGrammalectePort.postMessage({sCommand: "openConjugueurTab", dParam: null, dInfo: null});
+ this.switchMenu();
+ xGrammalectePort.postMessage({sCommand: "openConjugueurTab", dParam: null, dInfo: null});
};
let xConjButtonWin = oGrammalecte.createNode("div", {className: "grammalecte_menu_button", textContent: "Fenêtre"});
xConjButtonWin.onclick = () => {
- this.switchMenu();
- xGrammalectePort.postMessage({sCommand: "openConjugueurWindow", dParam: null, dInfo: null});
+ this.switchMenu();
+ xGrammalectePort.postMessage({sCommand: "openConjugueurWindow", dParam: null, dInfo: null});
};
xConjButton.appendChild(xConjButtonTab);
xConjButton.appendChild(xConjButtonWin);
- // Create
- xMenu.appendChild(oGrammalecte.createNode("div", {className: "grammalecte_menu_header", textContent: "GRAMMALECTE"}));
- xMenu.appendChild(xTFButton);
- xMenu.appendChild(xLxgButton);
- xMenu.appendChild(xGCButton);
xMenu.appendChild(xConjButton);
//xMenu.appendChild(oGrammalecte.createNode("img", {scr: browser.extension.getURL("img/logo-16.png")}));
// can’t work, due to content-script policy: https://bugzilla.mozilla.org/show_bug.cgi?id=1267027
xMenu.appendChild(oGrammalecte.createNode("div", {className: "grammalecte_menu_footer"}));
return xMenu;
@@ -91,9 +93,9 @@
this.xMenu.parentNode.removeChild(this.xMenu);
this.xButton.parentNode.removeChild(this.xButton);
}
switchMenu () {
- let xMenu = document.getElementById(this.sMenuId);
+ let xMenu = document.getElementById(this.sMenuId);
xMenu.style.display = (xMenu.style.display == "block") ? "none" : "block";
}
}
Index: gc_lang/fr/webext/content_scripts/panel_gc.js
==================================================================
--- gc_lang/fr/webext/content_scripts/panel_gc.js
+++ gc_lang/fr/webext/content_scripts/panel_gc.js
@@ -53,15 +53,15 @@
this.oTooltip = new GrammalecteTooltip(this.xContentNode);
this.xPanelContent.appendChild(this.xContentNode);
this.oTAC = new GrammalecteTextAreaControl();
}
- start (xTextArea=null) {
+ start (xNode=null) {
this.oTooltip.hide();
this.clear();
- if (xTextArea) {
- this.oTAC.setTextArea(xTextArea);
+ if (xNode && xNode.tagName == "TEXTAREA") {
+ this.oTAC.setTextArea(xNode);
}
}
clear () {
while (this.xParagraphList.firstChild) {
@@ -448,11 +448,11 @@
this._dParagraph.set(i, sText.slice(iStart, iEnd));
i++;
iStart = iEnd+1;
}
this._dParagraph.set(i, sText.slice(iStart));
- console.log("Paragraphs number: " + (i+1));
+ //console.log("Paragraphs number: " + (i+1));
}
write () {
if (this._xTextArea !== null) {
let sText = "";
Index: gc_lang/fr/webext/panel/main.html
==================================================================
--- gc_lang/fr/webext/panel/main.html
+++ gc_lang/fr/webext/panel/main.html
@@ -15,13 +15,13 @@
Grammalecte affiche un bouton d’accès au menu en bas à gauche des zones de texte usuelles pour accéder aux fonctionnalités existantes.
Pour les autres zones de texte (HTML éditable), il faut sélectionner le texte et utiliser le menu contextuel.