Grammalecte  Check-in [2bedf50a10]

Overview
Comment:[fx] Web API: warn the webpage when the API script is loaded
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | fx
Files: files | file ages | folders
SHA3-256: 2bedf50a1007a6f810af0e0b726d4d1a4aa51115ff4852205e364c12de3f251e
User & Date: olr on 2020-03-21 15:13:47
Other Links: manifest | tags
Context
2020-03-21
15:58
[fx] selection analysis: don’t send directly text from background to the GC check-in: 76e08d6ee8 user: olr tags: fx, trunk
15:13
[fx] Web API: warn the webpage when the API script is loaded check-in: 2bedf50a10 user: olr tags: fx, trunk
14:41
[doc] Web API update: add JSON.parse(event.detail) check-in: ce33035715 user: olr tags: doc, trunk
Changes

Modified gc_lang/fr/webext/content_scripts/api.js from [8cd25765a3] to [6ff89127c7].

    83     83               let xEvent = new CustomEvent("GrammalecteCall", { detail: {sCommand: "getSpellSuggestions", sWord: sWord, sDestination: sDestination, sRequestId: sRequestId} });
    84     84               document.dispatchEvent(xEvent);
    85     85           } else {
    86     86               console.log("[Grammalecte API] Error: one or several parameters aren’t string.");
    87     87           }
    88     88       }
    89     89   }
           90  +
           91  +/*
           92  +    Tell to the webpage that the Grammalecte API is ready.
           93  +*/
           94  +document.dispatchEvent(new Event('GrammalecteLoaded'));
           95  +

Modified gc_lang/fr/webext/content_scripts/init.js from [316d25a5ff] to [ae034ec96f].

   516    516   oGrammalecteBackgroundPort.listen()
   517    517   oGrammalecteBackgroundPort.listen2()
   518    518   
   519    519   
   520    520   
   521    521   /*
   522    522       Callable API for the webpage.
   523         -    The API script must be injected this way to be callable by the page
   524         -*/
   525         -let xScriptGrammalecteAPI = document.createElement("script");
   526         -xScriptGrammalecteAPI.src = browser.extension.getURL("content_scripts/api.js");
   527         -document.documentElement.appendChild(xScriptGrammalecteAPI);
   528    523   
          524  +*/
   529    525   document.addEventListener("GrammalecteCall", function (xEvent) {
   530    526       // GrammalecteCall events are dispatched by functions in the API script
          527  +    // The script is loaded below.
   531    528       try {
   532    529           let oCommand = xEvent.detail;
   533    530           switch (oCommand.sCommand) {
   534    531               case "openPanelForNode":
   535    532                   if (oCommand.xNode) {
   536    533                       oGrammalecte.startGCPanel(oCommand.xNode);
   537    534                   }
................................................................................
   563    560                   console.log("[Grammalecte] Event: Unknown command", oCommand.sCommand);
   564    561           }
   565    562       }
   566    563       catch (e) {
   567    564           showError(e);
   568    565       }
   569    566   });
          567  +
          568  +// The API script must be injected this way to be callable by the page
          569  +let xScriptGrammalecteAPI = document.createElement("script");
          570  +xScriptGrammalecteAPI.src = browser.extension.getURL("content_scripts/api.js");
          571  +document.documentElement.appendChild(xScriptGrammalecteAPI);
   570    572   
   571    573   
   572    574   /*
   573    575       Note:
   574    576       Initialization starts when the background is connected.
   575    577       See: oGrammalecteBackgroundPort.listen() -> case "init"
   576    578   */