Index: doc/API_web.md ================================================================== --- doc/API_web.md +++ doc/API_web.md @@ -67,12 +67,12 @@ If you have disabled the spinning button, you can launch the Grammalecte panel with your custom button. oGrammalecteAPI.openPanelForNode("node_id") oGrammalecteAPI.openPanelForNode(node) -The node can be a textarea, an editable node or an iframe. -If the node is an iframe, the content won’t be modified by Grammalecte. +The node can be a textarea, an editable node or an iframe. **The node must have an identifier**. +If the node is an iframe, the content won’t be modified by Grammalecte, but events with results may be received (see below). ### Prevent Grammalecte to modify the node content If you don’t want Grammalecte to modify directly the node content, add the property: `data-grammalecte_result_via_event="true"`. @@ -93,19 +93,19 @@ oGrammalecteAPI.openPanelForText("your text") oGrammalecteAPI.openPanelForText("your text", "node_id") oGrammalecteAPI.openPanelForText("your text", node) -With the second parameter, Grammalecte will send an event to the node each times the text is modified within the panel. +With the second parameter, Grammalecte will send an event to the node each times the text is modified within the panel. **The node must have an identifier**. ### Parse a node and get errors oGrammalecteAPI.parseNode("node_id") oGrammalecteAPI.parseNode(node) -The node can be a textarea, an editable node or an iframe. The node must have an identifier. +The node can be a textarea, an editable node or an iframe. **The node must have an identifier**. Results (for each paragraph) will be sent in a succession of events at the node. node.addEventListener("GrammalecteResult", function (event) { const detail = (typeof(event.detail) === 'string') && JSON.parse(event.detail); if (detail.sType && detail.sType == "proofreading") { @@ -120,12 +120,12 @@ ### Parse text and get errors oGrammalecteAPI.parseText("your text", "node_id") oGrammalecteAPI.parseText("your text", node) -The node must have an identifier. Like with `oGrammalecteAPI.parseNode()`, results (for each paragraph) will be sent in a succession of events at the node. +**The node must have an identifier**. ### Get spelling suggestions Index: gc_lang/fr/webext/content_scripts/api.js ================================================================== --- gc_lang/fr/webext/content_scripts/api.js +++ gc_lang/fr/webext/content_scripts/api.js @@ -32,10 +32,13 @@ sNodeId = vNode.id; } else if (typeof(vNode) === "string" && document.getElementById(vNode)) { sNodeId = vNode; } + else { + console.log("[Grammalecte API] No node identifier. No event, no result will be sent.") + } let xEvent = new CustomEvent("GrammalecteCall", { detail: JSON.stringify({sCommand: "openPanelForText", sText: sText, sNodeId: sNodeId}) }); document.dispatchEvent(xEvent); } else { console.log("[Grammalecte API] Error: parameter is not a text."); }