123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- "use strict";
- var oGrammalecteAPI = {
-
-
-
- sVersion: "1.0",
- generateNodeId: function (xNode) {
- xNode.id = "grammalecte_generated_id_" + Date.now().toString(36) + "_" + (Math.floor(Math.random() * (1000000))).toString(36);
- console.log("[Grammalecte API] generated id:", xNode.id);
- return xNode.id;
- },
- openPanelForNode: function (vNode) {
-
- if (vNode instanceof HTMLElement) {
- let sNodeId = vNode.id || this.generateNodeId(vNode);
- let xEvent = new CustomEvent("GrammalecteCall", { detail: JSON.stringify({sCommand: "openPanelForNode", sNodeId: sNodeId}) });
- document.dispatchEvent(xEvent);
- }
- else if (typeof(vNode) === "string" && document.getElementById(vNode)) {
- let xEvent = new CustomEvent("GrammalecteCall", { detail: JSON.stringify({sCommand: "openPanelForNode", sNodeId: vNode}) });
- document.dispatchEvent(xEvent);
- }
- else {
- console.log("[Grammalecte API] Error: parameter is not a HTML node with an identifier.");
- }
- },
- openPanelForText: function (sText, vNode=null) {
-
- if (typeof(sText) === "string") {
- let sNodeId = "";
- if (vNode instanceof HTMLElement) {
- sNodeId = vNode.id || this.generateNodeId(vNode);
- }
- 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.");
- }
- },
- parseNode: function (vNode) {
-
- if (vNode instanceof HTMLElement) {
- let sNodeId = vNode.id || this.generateNodeId(vNode);
- let xEvent = new CustomEvent("GrammalecteCall", { detail: JSON.stringify({sCommand: "parseNode", sNodeId: sNodeId}) });
- document.dispatchEvent(xEvent);
- }
- else if (typeof(vNode) === "string" && document.getElementById(vNode)) {
- let xEvent = new CustomEvent("GrammalecteCall", { detail: JSON.stringify({sCommand: "parseNode", sNodeId: vNode}) });
- document.dispatchEvent(xEvent);
- }
- else {
- console.log("[Grammalecte API] Error: parameter is not a HTML node with an identifier.");
- }
- },
- parseText: function (sText, vNode) {
-
- if (typeof(sText) === "string") {
- if (vNode instanceof HTMLElement) {
- let sNodeId = vNode.id || this.generateNodeId(vNode);
- let xEvent = new CustomEvent("GrammalecteCall", { detail: JSON.stringify({sCommand: "parseText", sText: sText, sNodeId: sNodeId}) });
- document.dispatchEvent(xEvent);
- }
- else if (typeof(vNode) === "string" && document.getElementById(vNode)) {
- let xEvent = new CustomEvent("GrammalecteCall", { detail: JSON.stringify({sCommand: "parseText", sText: sText, sNodeId: vNode}) });
- document.dispatchEvent(xEvent);
- }
- else {
- console.log("[Grammalecte API] Error: parameter is not a HTML node with an identifier.");
- }
- } else {
- console.log("[Grammalecte API] Error: parameter is not a text.");
- }
- },
- getSpellSuggestions: function (sWord, sDestination, sRequestId="") {
-
- if (typeof(sWord) === "string" && typeof(sDestination) === "string" && typeof(sRequestId) === "string") {
- let xEvent = new CustomEvent("GrammalecteCall", { detail: JSON.stringify({sCommand: "getSpellSuggestions", sWord: sWord, sDestination: sDestination, sRequestId: sRequestId}) });
- document.dispatchEvent(xEvent);
- } else {
- console.log("[Grammalecte API] Error: one or several parameters aren’t string.");
- }
- }
- }
- document.dispatchEvent(new Event('GrammalecteLoaded'));
|