Index: gc_lang/fr/webext/background.js ================================================================== --- gc_lang/fr/webext/background.js +++ gc_lang/fr/webext/background.js @@ -133,10 +133,16 @@ xGCEWorker.postMessage(oRequest); break; case "openURL": browser.tabs.create({url: dParam.sURL}); break; + case "openConjugueurTab": + openConjugueurTab(); + break; + case "openConjugueurWindow": + openConjugueurWindow(); + break; default: console.log("[background] Unknown command: " + sCommand); console.log(oRequest); } }); Index: gc_lang/fr/webext/content_scripts/content_modifier.js ================================================================== --- gc_lang/fr/webext/content_scripts/content_modifier.js +++ gc_lang/fr/webext/content_scripts/content_modifier.js @@ -13,101 +13,115 @@ function showError (e) { console.error(e.fileName + "\n" + e.name + "\nline: " + e.lineNumber + "\n" + e.message); } -const oGrammalecte = { - - nWrapper: 1, - - oConjPanel: null, - oTFPanel: null, - oLxgPanel: null, - oGCPanel: null, - - wrapTextareas: function () { - let lNode = document.getElementsByTagName("textarea"); - for (let xNode of lNode) { - this._createWrapper(xNode); - } - }, - - _createWrapper (xTextArea) { - try { - let xParentElement = xTextArea.parentElement; - let xWrapper = document.createElement("div"); - xWrapper.className = "grammalecte_wrapper"; - xWrapper.id = "grammalecte_wrapper" + this.nWrapper; - this.nWrapper += 1; - xParentElement.insertBefore(xWrapper, xTextArea); - xWrapper.appendChild(xTextArea); // move textarea in wrapper - xWrapper.appendChild(this._createWrapperToolbar(xTextArea)); - } - catch (e) { - showError(e); - } - }, - - _createWrapperToolbar: function (xTextArea) { +class GrammalecteWrapper { + + constructor (nWrapper, xTextArea) { + this.nWrapper = nWrapper; + let xParentElement = xTextArea.parentElement; + let xWrapper = createNode("div", {id: "grammalecte_wrapper" + nWrapper, className: "grammalecte_wrapper"}); + xParentElement.insertBefore(xWrapper, xTextArea); + xWrapper.appendChild(this._createTitle()); + xWrapper.appendChild(xTextArea); // move textarea in wrapper + xWrapper.appendChild(this._createWrapperToolbar(xTextArea)); + } + + _createTitle () { + return createNode("div", {className: "grammalecte_wrapper_title", textContent: "Grammalecte"}); + } + + _createWrapperToolbar (xTextArea) { try { let xToolbar = createNode("div", {className: "grammalecte_wrapper_toolbar"}); let xConjButton = createNode("div", {className: "grammalecte_wrapper_button", textContent: "Conjuguer"}); - xConjButton.onclick = function () { - this.createConjPanel(); - //this.oConjPanel.show(); + xConjButton.onclick = () => { this.showConjButtons(); }; + let xConjSection = createNode("div", {id: "grammalecte_wrapper_conj_section"+this.nWrapper, className: "grammalecte_wrapper_conj_section"}); + let xConjButtonTab = createNode("div", {className: "grammalecte_wrapper_button2", textContent: ">Onglet"}); + xConjButtonTab.onclick = function () { + xPort.postMessage({sCommand: "openConjugueurTab", dParam: null, dInfo: null}); + this.hideConjButtons(); + }.bind(this); + let xConjButtonWin = createNode("div", {className: "grammalecte_wrapper_button2", textContent: ">Fenêtre"}); + xConjButtonWin.onclick = function () { + xPort.postMessage({sCommand: "openConjugueurWindow", dParam: null, dInfo: null}); + this.hideConjButtons(); }.bind(this); let xTFButton = createNode("div", {className: "grammalecte_wrapper_button", textContent: "Formater"}); xTFButton.onclick = function () { - this.createTFPanel(); - this.oTFPanel.start(xTextArea); - this.oTFPanel.show(); - }.bind(this); + oGrammalecte.createTFPanel(); + oGrammalecte.oTFPanel.start(xTextArea); + oGrammalecte.oTFPanel.show(); + }; let xLxgButton = createNode("div", {className: "grammalecte_wrapper_button", textContent: "Analyser"}); xLxgButton.onclick = function () { - this.createLxgPanel(); - this.oLxgPanel.clear(); - this.oLxgPanel.show(); - this.oLxgPanel.startWaitIcon(); + oGrammalecte.createLxgPanel(); + oGrammalecte.oLxgPanel.clear(); + oGrammalecte.oLxgPanel.show(); + oGrammalecte.oLxgPanel.startWaitIcon(); xPort.postMessage({ sCommand: "getListOfTokens", dParam: {sText: xTextArea.value}, dInfo: {sTextAreaId: xTextArea.id} }); - }.bind(this); + }; let xGCButton = createNode("div", {className: "grammalecte_wrapper_button", textContent: "Corriger"}); xGCButton.onclick = function () { - this.createGCPanel(); - this.oGCPanel.clear(); - this.oGCPanel.show(); - this.oGCPanel.start(xTextArea); - this.oGCPanel.startWaitIcon(); + oGrammalecte.createGCPanel(); + oGrammalecte.oGCPanel.clear(); + oGrammalecte.oGCPanel.show(); + oGrammalecte.oGCPanel.start(xTextArea); + oGrammalecte.oGCPanel.startWaitIcon(); xPort.postMessage({ sCommand: "parseAndSpellcheck", dParam: {sText: xTextArea.value, sCountry: "FR", bDebug: false, bContext: false}, dInfo: {sTextAreaId: xTextArea.id} }); - }.bind(this); + }; // Create //xToolbar.appendChild(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 //xToolbar.appendChild(createLogo()); - xToolbar.appendChild(document.createTextNode("Grammalecte")); xToolbar.appendChild(xConjButton); + xConjSection.appendChild(xConjButtonTab); + xConjSection.appendChild(xConjButtonWin); + xToolbar.appendChild(xConjSection); xToolbar.appendChild(xTFButton); xToolbar.appendChild(xLxgButton); xToolbar.appendChild(xGCButton); return xToolbar; } catch (e) { showError(e); } - }, + } + + showConjButtons () { + document.getElementById("grammalecte_wrapper_conj_section"+this.nWrapper).style.display = "block"; + } + + hideConjButtons () { + document.getElementById("grammalecte_wrapper_conj_section"+this.nWrapper).style.display = "none"; + } +} + + +const oGrammalecte = { + + nWrapper: 0, + lWrapper: [], + + oTFPanel: null, + oLxgPanel: null, + oGCPanel: null, - createConjPanel: function () { - if (this.oConjPanel === null) { - this.oConjPanel = new GrammalectePanel("grammalecte_conj_panel", "Conjugueur", 600, 600); - this.oConjPanel.insertIntoPage(); + wrapTextareas: function () { + let lNode = document.getElementsByTagName("textarea"); + for (let xNode of lNode) { + this.lWrapper.push(new GrammalecteWrapper(this.nWrapper, xNode)); + this.nWrapper += 1; } }, createTFPanel: function () { if (this.oTFPanel === null) { Index: gc_lang/fr/webext/content_scripts/panels_content.css ================================================================== --- gc_lang/fr/webext/content_scripts/panels_content.css +++ gc_lang/fr/webext/content_scripts/panels_content.css @@ -15,32 +15,62 @@ border: 1px solid hsl(210, 40%, 92%); box-shadow: 0 0 2px hsla(210, 40%, 0%, .5); font-family: "Trebuchet MS", "Liberation Sans", sans-serif; color: hsl(210, 40%, 50%); } + +.grammalecte_wrapper_title { + padding: 5px 0; + font-size: 12px; + font-variant: small-caps; +} + +.grammalecte_wrapper_toolbar { + display: flex; + justify-content: flex-end; + margin-top: 5px; + padding: 5px 10px; +} .grammalecte_wrapper_button { display: inline-block; padding: 0 5px; margin-left: 5px; background-color: hsl(210, 60%, 80%); border-radius: 2px; border: 1px solid hsl(210, 60%, 70%); + font-size: 14px; color: hsl(210, 40%, 40%); cursor: pointer; } .grammalecte_wrapper_button:hover { background-color: hsl(210, 80%, 70%); border: 1px solid hsl(210, 80%, 60%); box-shadow: 0 0 1px 1px hsl(210, 80%, 80%); - color: hsl(210, 80%, 30%); + color: hsl(210, 80%, 98%); +} + +.grammalecte_wrapper_conj_section { + display: none; +} + +.grammalecte_wrapper_button2 { + display: inline-block; + padding: 0 5px; + margin-left: 5px; + background-color: hsl(180, 60%, 80%); + border-radius: 2px; + border: 1px solid hsl(180, 60%, 70%); + font-size: 14px; + color: hsl(180, 40%, 40%); + cursor: pointer; } -.grammalecte_wrapper_toolbar { - display: flex; - justify-content: flex-end; - margin-top: 5px; - padding: 5px 10px; +.grammalecte_wrapper_button2:hover { + background-color: hsl(180, 80%, 70%); + border: 1px solid hsl(180, 80%, 60%); + box-shadow: 0 0 1px 1px hsl(180, 80%, 80%); + color: hsl(180, 80%, 98%); } /* Panels */