Index: gc_lang/fr/webext/content_scripts/panel.css ================================================================== --- gc_lang/fr/webext/content_scripts/panel.css +++ gc_lang/fr/webext/content_scripts/panel.css @@ -104,11 +104,11 @@ margin: 10px; padding: 10px; border-radius: 5px; background-color: hsl(0, 50%, 40%); color: hsl(0, 50%, 96%); - font-size: 20px; + font-size: 16px; } /* Spinner 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 @@ -50,18 +50,22 @@ this.xParagraphList = oGrammalecte.createNode("div", {id: "grammalecte_paragraph_list"}); this.xContentNode.appendChild(this.xParagraphList); this.xPanelContent.addEventListener("click", onGrammalecteGCPanelClick, false); this.oTooltip = new GrammalecteTooltip(this.xContentNode); this.xPanelContent.appendChild(this.xContentNode); - this.oTAC = new GrammalecteTextAreaControl(); + this.oNodeControl = new GrammalecteNodeControl(); } start (xNode=null) { this.oTooltip.hide(); this.clear(); - if (xNode && xNode.tagName == "TEXTAREA") { - this.oTAC.setTextArea(xNode); + if (xNode) { + if (xNode.tagName == "TEXTAREA") { + this.oNodeControl.setNode(xNode); + } else { + this.addMessage("Cette zone de texte n’est pas un champ de formulaire “textarea” mais un node HTML éditable. Les modifications ne seront pas répercutées automatiquement. Une fois votre texte corrigé, vous pouvez utiliser le bouton ‹∑› pour copier le texte dans le presse-papiers."); + } } } clear () { while (this.xParagraphList.firstChild) { @@ -70,11 +74,11 @@ this.aIgnoredErrors.clear(); } hide () { this.xPanel.style.display = "none"; - this.oTAC.clear(); + this.oNodeControl.clear(); } addParagraphResult (oResult) { try { if (oResult && (oResult.sParagraph.trim() !== "" || oResult.aGrammErr.length > 0 || oResult.aSpellErr.length > 0)) { @@ -85,12 +89,12 @@ xActionsBar.appendChild(oGrammalecte.createNode("div", {id: "grammalecte_hide" + oResult.iParaNum, className: "grammalecte_paragraph_button grammalecte_red", textContent: "×", 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.addEventListener("keyup", function (xEvent) { - this.oTAC.setParagraph(parseInt(xEvent.target.dataset.para_num), this.purgeText(xEvent.target.textContent)); - this.oTAC.write(); + this.oNodeControl.setParagraph(parseInt(xEvent.target.dataset.para_num), this.purgeText(xEvent.target.textContent)); + this.oNodeControl.write(); }.bind(this) , true); this._tagParagraph(xParagraph, oResult.sParagraph, oResult.iParaNum, oResult.aGrammErr, oResult.aSpellErr); // creation xNodeDiv.appendChild(xActionsBar); @@ -111,12 +115,12 @@ xGrammalectePort.postMessage({ sCommand: "parseAndSpellcheck1", dParam: {sText: sText, sCountry: "FR", bDebug: false, bContext: false}, dInfo: {sParagraphId: sParagraphId} }); - this.oTAC.setParagraph(iParaNum, sText); - this.oTAC.write(); + this.oNodeControl.setParagraph(iParaNum, sText); + this.oNodeControl.write(); } refreshParagraph (sParagraphId, oResult) { try { let xParagraph = document.getElementById(sParagraphId); @@ -408,58 +412,65 @@ } } } -class GrammalecteTextAreaControl { +class GrammalecteNodeControl { constructor () { - this._xTextArea = null; - this._dParagraph = new Map(); + this.xNode = null; + this.dParagraph = new Map(); + this.bTextArea = null; + this.bWriteEN = false; // write editable node } - setTextArea (xNode) { + setNode (xNode) { this.clear(); - this._xTextArea = xNode; - this._xTextArea.disabled = true; + this.xNode = xNode; + this.bTextArea = (xNode.tagName == "TEXTAREA"); + this.xNode.disabled = true; this._loadText(); } clear () { - if (this._xTextArea !== null) { - this._xTextArea.disabled = false; - this._xTextArea = null; + if (this.xNode !== null) { + this.xNode.disabled = false; + this.xNode = null; } - this._dParagraph.clear(); + this.dParagraph.clear(); } setParagraph (iParagraph, sText) { - if (this._xTextArea !== null) { - this._dParagraph.set(iParagraph, sText); + if (this.xNode !== null) { + this.dParagraph.set(iParagraph, sText); } } _loadText () { - let sText = this._xTextArea.value; + let sText = (this.bTextArea) ? this.xNode.value : this.xNode.innerText; let i = 0; let iStart = 0; let iEnd = 0; sText = sText.replace("\r\n", "\n").replace("\r", "\n"); while ((iEnd = sText.indexOf("\n", iStart)) !== -1) { - this._dParagraph.set(i, sText.slice(iStart, iEnd)); + this.dParagraph.set(i, sText.slice(iStart, iEnd)); i++; iStart = iEnd+1; } - this._dParagraph.set(i, sText.slice(iStart)); + this.dParagraph.set(i, sText.slice(iStart)); //console.log("Paragraphs number: " + (i+1)); } write () { - if (this._xTextArea !== null) { + if (this.xNode !== null && (this.bTextArea || this.bWriteEN)) { let sText = ""; - this._dParagraph.forEach(function (val, key) { + this.dParagraph.forEach(function (val, key) { sText += val + "\n"; }); - this._xTextArea.value = sText.slice(0,-1); + if (this.bTextArea) { + this.xNode.value = sText.slice(0,-1); + } else { + this.xNode.textContent = sText.slice(0,-1); + } } } }