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 @@ -75,38 +75,54 @@ this.xRightClickedNode = null; }, createButtons: function () { if (bChrome) { - browser.storage.local.get("ui_options", this._createButtons.bind(this)); + browser.storage.local.get("ui_options", this._prepareButtons.bind(this)); return; } - browser.storage.local.get("ui_options").then(this._createButtons.bind(this), showError); + browser.storage.local.get("ui_options").then(this._prepareButtons.bind(this), showError); }, - _createButtons: function (oOptions) { + _prepareButtons: function (oOptions) { if (oOptions.hasOwnProperty("ui_options")) { this.oOptions = oOptions.ui_options; - if (this.oOptions.textarea) { - for (let xNode of document.getElementsByTagName("textarea")) { - if (xNode.style.display !== "none" && xNode.style.visibility !== "hidden" && xNode.getAttribute("spellcheck") !== "false") { - this.lButton.push(new GrammalecteButton(this.nButton, xNode)); - this.nButton += 1; - } + // textarea + for (let xNode of document.getElementsByTagName("textarea")) { + if (xNode.dataset.grammalecte_callbutton && document.getElementById(xNode.dataset.grammalecte_callbutton)) { + let xButton = document.getElementById(xNode.dataset.grammalecte_callbutton) + xButton.onclick = () => { + oGrammalecte.startGCPanel(xNode, true, true); + }; + this.lButton.push(xButton); + this.nButton += 1; + } + else if (this.oOptions.textarea && xNode.style.display !== "none" && xNode.style.visibility !== "hidden" && xNode.getAttribute("spellcheck") !== "false") { + this.lButton.push(new GrammalecteButton(this.nButton, xNode)); + this.nButton += 1; } } - if (this.oOptions.editablenode) { - for (let xNode of document.querySelectorAll("[contenteditable]")) { + // editable nodes + for (let xNode of document.querySelectorAll("[contenteditable]")) { + if (xNode.dataset.grammalecte_callbutton && document.getElementById(xNode.dataset.grammalecte_callbutton)) { + let xButton = document.getElementById(xNode.dataset.grammalecte_callbutton) + xButton.onclick = () => { + oGrammalecte.startGCPanel(xNode, true, true); + }; + this.lButton.push(xButton); + this.nButton += 1; + } + else if (this.oOptions.editablenode && xNode.style.display !== "none" && xNode.style.visibility !== "hidden") { this.lButton.push(new GrammalecteButton(this.nButton, xNode)); this.nButton += 1; } } } }, observePage: function () { - // When a textarea is added via jascript we add the menu + // When a textarea is added via jascript we add the buttons let that = this; this.xObserver = new MutationObserver(function (mutations) { mutations.forEach(function (mutation) { for (let i = 0; i < mutation.addedNodes.length; i++){ if (mutation.addedNodes[i].tagName == "TEXTAREA") { @@ -158,16 +174,16 @@ this.oMessageBox = new GrammalecteMessageBox("grammalecte_message_box", "Grammalecte"); this.oMessageBox.insertIntoPage(); } }, - startGCPanel: function (what, bCheckText=true) { + startGCPanel: function (what, bCheckText=true, bResultInEvent=false) { this.createGCPanel(); this.oGCPanel.clear(); this.oGCPanel.show(); this.oGCPanel.showEditor(); - this.oGCPanel.start(what); + this.oGCPanel.start(what, bResultInEvent); this.oGCPanel.startWaitIcon(); if (what && bCheckText) { let sText = this.oGCPanel.oTextControl.getText(); xGrammalectePort.postMessage({ sCommand: "parseAndSpellcheck", 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 @@ -137,13 +137,14 @@ this.xMenu.appendChild(this.xLxgButton) this.xMenu.appendChild(this.xConjButton) this.xPanelBar.appendChild(this.xMenu); } - start (what) { + start (what, bResultInEvent=false) { this.oTooltip.hide(); this.bWorking = false; + this.oTextControl.bResultInEvent = bResultInEvent; this.clear(); this.hideMessage(); this.resetTimer(); if (typeof(what) === "string") { // text @@ -952,10 +953,11 @@ constructor () { this.xNode = null; this.dParagraph = new Map(); this.bTextArea = null; + this.bResultInEvent = false; // if true, the node content is not modified, but an event is dispatched on the node with the modified text } setNode (xNode) { this.clear(); this.xNode = xNode; @@ -1017,21 +1019,25 @@ } } write () { if (this.xNode !== null) { - if (this.bTextArea) { + if (this.bResultInEvent) { + const xEvent = new CustomEvent("GrammalecteNodeContentUpdated", { + detail: { text: [...this.dParagraph.values()].join("\n").normalize("NFC") } + }); + this.xNode.dispatchEvent(xEvent); + console.log("event", xEvent.detail.text); + } + else if (this.bTextArea) { this.xNode.value = this.getText(); - } else { + } + else { this.eraseNodeContent(); this.dParagraph.forEach((val, key) => { this.xNode.appendChild(document.createTextNode(val.normalize("NFC"))); this.xNode.appendChild(document.createElement("br")); }); - const xEvent = new CustomEvent("grammalecteNodeContentUpdated", { - detail: { text: [...this.dParagraph.values()].join("\n").normalize("NFC") } - }); - this.xNode.dispatchEvent(xEvent); } } } }