Grammalecte  Check-in [9a083a0fd5]

Overview
Comment:[fx] Grammalecte API: getSpellSuggestions()
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | fx
Files: files | file ages | folders
SHA3-256: 9a083a0fd5a2b0da44bff4887d1b6ca4ddf95e66fc53ee90b39fc8e6199513d6
User & Date: olr on 2020-03-13 20:04:34
Other Links: manifest | tags
Context
2020-03-17
13:18
[fr] ajustements check-in: d20401e35a user: olr tags: fr, trunk
2020-03-13
20:04
[fx] Grammalecte API: getSpellSuggestions() check-in: 9a083a0fd5 user: olr tags: fx, trunk
19:37
[fx] Grammalecte API: parseNode -> result as JSON check-in: 15fc2e7c11 user: olr tags: fx, trunk
Changes

Modified gc_lang/fr/webext/content_scripts/api.js from [28772a3aac] to [52f71e590a].

    51     51       parseNode: function (xNode) {
    52     52           if (xNode instanceof HTMLElement) {
    53     53               let xEvent = new CustomEvent("GrammalecteCall", { detail: {sCommand: "parseNode", xNode: xNode} });
    54     54               document.dispatchEvent(xEvent);
    55     55           } else {
    56     56               console.log("[Grammalecte API] Error: parameter is not a HTML node.");
    57     57           }
           58  +    },
           59  +
           60  +    getSpellSuggestions: function (sWord, sDestination, sErrorId) {
           61  +        if (typeof(sWord) === "string") {
           62  +            let xEvent = new CustomEvent("GrammalecteCall", { detail: {sCommand: "getSpellSuggestions", sWord: sWord, sDestination: sDestination, sErrorId: sErrorId} });
           63  +            document.dispatchEvent(xEvent);
           64  +        } else {
           65  +            console.log("[Grammalecte API] Error: parameter is not a text.");
           66  +        }
    58     67       }
    59     68   }

Modified gc_lang/fr/webext/content_scripts/init.js from [166fd912ce] to [96d14d059f].

   348    348           this.xConnect.postMessage({
   349    349               sCommand: "getVerb",
   350    350               dParam: { sVerb: sVerb, bPro: bPro, bNeg: bNeg, bTpsCo: bTpsCo, bInt: bInt, bFem: bFem },
   351    351               dInfo: { bStart: bStart }
   352    352           });
   353    353       },
   354    354   
   355         -    getSpellSuggestions: function (sWord, sErrorId) {
   356         -        this.xConnect.postMessage({ sCommand: "getSpellSuggestions", dParam: { sWord: sWord }, dInfo: { sErrorId: sErrorId } });
          355  +    getSpellSuggestions: function (sWord, sDestination, sErrorId) {
          356  +        this.xConnect.postMessage({ sCommand: "getSpellSuggestions", dParam: { sWord: sWord }, dInfo: { sDestination: sDestination, sErrorId: sErrorId } });
   357    357       },
   358    358   
   359    359       openURL: function (sURL) {
   360    360           this.xConnect.postMessage({ sCommand: "openURL", dParam: { "sURL": sURL }, dInfo: null });
   361    361       },
   362    362   
   363    363       openLexiconEditor: function () {
................................................................................
   387    387                               oGrammalecte.oGCPanel.addParagraphResult(result);
   388    388                           } else {
   389    389                               oGrammalecte.oGCPanel.stopWaitIcon();
   390    390                               oGrammalecte.oGCPanel.endTimer();
   391    391                           }
   392    392                       }
   393    393                       else if (dInfo.sDestination  &&  document.getElementById(dInfo.sDestination)) {
   394         -                        const xEvent = new CustomEvent("GrammalecteResult", { detail: JSON.stringify(result) });
          394  +                        const xEvent = new CustomEvent("GrammalecteResult", { detail: JSON.stringify({ result: result, info: dInfo }) });
   395    395                           document.getElementById(dInfo.sDestination).dispatchEvent(xEvent);
   396    396                       }
   397    397                       break;
   398    398                   case "parseAndSpellcheck1":
   399    399                       if (dInfo.sDestination == "__GrammalectePanel__") {
   400    400                           oGrammalecte.oGCPanel.refreshParagraph(dInfo.sParagraphId, result);
   401    401                       }
................................................................................
   408    408                           oGrammalecte.oGCPanel.addListOfTokens(result);
   409    409                       } else {
   410    410                           oGrammalecte.oGCPanel.stopWaitIcon();
   411    411                           oGrammalecte.oGCPanel.endTimer();
   412    412                       }
   413    413                       break;
   414    414                   case "getSpellSuggestions":
   415         -                    oGrammalecte.oGCPanel.oTooltip.setSpellSuggestionsFor(result.sWord, result.aSugg, result.iSuggBlock, dInfo.sErrorId);
          415  +                    if (dInfo.sDestination == "__GrammalectePanel__") {
          416  +                        oGrammalecte.oGCPanel.oTooltip.setSpellSuggestionsFor(result.sWord, result.aSugg, result.iSuggBlock, dInfo.sErrorId);
          417  +                    }
          418  +                    else if (dInfo.sDestination  &&  document.getElementById(dInfo.sDestination)) {
          419  +                        const xEvent = new CustomEvent("GrammalecteResult", { detail: JSON.stringify({ result: result, info: dInfo }) });
          420  +                        document.getElementById(dInfo.sDestination).dispatchEvent(xEvent);
          421  +                    }
   416    422                       break;
   417    423                   case "getVerb":
   418    424                       if (dInfo.bStart) {
   419    425                           oGrammalecte.oGCPanel.conjugateWith(result.oVerb, result.oConjTable);
   420    426                       } else {
   421    427                           oGrammalecte.oGCPanel.displayConj(result.oConjTable);
   422    428                       }
................................................................................
   525    531                       else if (oCommand.xNode.tagName == "IFRAME") {
   526    532                           oGrammalecteBackgroundPort.parseAndSpellcheck(oCommand.xNode.contentWindow.document.body.innerText, oCommand.xNode.id);
   527    533                       }
   528    534                       else {
   529    535                           oGrammalecteBackgroundPort.parseAndSpellcheck(oCommand.xNode.innerText, oCommand.xNode.id);
   530    536                       }
   531    537                   }
          538  +                break;
          539  +            case "getSpellSuggestions":
          540  +                if (oCommand.sWord) {
          541  +                    oGrammalecteBackgroundPort.getSpellSuggestions(sWord, oCommand.sDestination, oCommand.sErrorId);
          542  +                }
   532    543                   break;
   533    544               default:
   534    545                   console.log("[Grammalecte] Event: Unknown command", oCommand.sCommand);
   535    546           }
   536    547       }
   537    548       catch (e) {
   538    549           showError(e);

Modified gc_lang/fr/webext/content_scripts/panel_gc.js from [2e408919b2] to [5905befb4d].

   852    852                       this.xParent.getElementById("grammalecte_tooltip_db_search").style.display = "inline";
   853    853                       this.xParent.getElementById("grammalecte_tooltip_db_search").dataset.url = "https://grammalecte.net/dictionary.php?prj=fr&lemma="+xNodeErr.textContent;
   854    854                   } else {
   855    855                       this.xParent.getElementById("grammalecte_tooltip_db_search").style.display = "none";
   856    856                   }
   857    857                   this.clearSuggestionBlock();
   858    858                   this.xTooltipSuggBlock.textContent = "Recherche de graphies possibles…";
   859         -                oGrammalecteBackgroundPort.getSpellSuggestions(xNodeErr.textContent, xNodeErr.dataset.error_id);
          859  +                oGrammalecteBackgroundPort.getSpellSuggestions(xNodeErr.textContent, "__GrammalectePanel__", xNodeErr.dataset.error_id);
   860    860               }
   861    861               this.xTooltipArrow.style.display = "block";
   862    862               this.xTooltip.style.display = "block";
   863    863           }
   864    864           catch (e) {
   865    865               showError(e);
   866    866           }