Grammalecte  Check-in [1bb5f94a84]

Overview
Comment:[fx] update API: send GC result as a string (JSON), not an object
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | fx
Files: files | file ages | folders
SHA3-256: 1bb5f94a8467205540a14db4cada6f980182de050853d75c786f451155863519
User & Date: olr on 2020-03-12 22:46:38
Other Links: manifest | tags
Context
2020-03-12
23:53
[fr] ajustements check-in: bdd6bc1361 user: olr tags: fr, trunk
22:46
[fx] update API: send GC result as a string (JSON), not an object check-in: 1bb5f94a84 user: olr tags: fx, trunk
16:56
[fx] update API and handle iframe node via GC Panel check-in: 76d78039bf user: olr tags: fx, trunk
Changes

Modified gc_lang/fr/webext/content_scripts/api.js from [85027b59ad] to [d7c42966b4].

1
2
3
4
5
6
7

8
9
10
11
12
13
14
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15







+







// JavaScript

"use strict";


const oGrammalecteAPI = {
    // functions callable from within pages
    // to be sent to the content-cript via an event GrammalecteCall

    sVersion: "1.0",

    openPanel: function (arg1) {
        let xNode = null;
        if (typeof(arg1) === 'string') {
            if (document.getElementById(arg1)) {

Modified gc_lang/fr/webext/content_scripts/panel_gc.js from [88c95d607e] to [f1590de9e6].

966
967
968
969
970
971
972
973
974



975
976
977
978
979

980
981
982
983
984
985
986

987
988
989
990
991
992
993
966
967
968
969
970
971
972


973
974
975
976
977
978
979

980
981
982
983
984
985
986

987
988
989
990
991
992
993
994







-
-
+
+
+




-
+






-
+







        this.bIframe = (xNode.tagName == "IFRAME");
        if (this.bTextArea) {
            this.xNode.disabled = true;
            this._loadText(this.xNode.value);
        }
        else if (this.bIframe) {
            // iframe
            let sMessage = (this.bResultInEvent) ? "Note : La zone analysée est un cadre contenant une autre page web (“iframe”)." : "Attention : La zone analysée est un cadre contenant une autre page web (“iframe”). Les changements faits ne seront pas répercutés.";
            oGrammalecte.oGCPanel.addMessageToGCPanel(sMessage);
            if (!this.bResultInEvent) {
                oGrammalecte.oGCPanel.addMessageToGCPanel("⛔ La zone analysée est un cadre contenant une autre page web (“iframe”). Les changements faits ne peuvent être pas répercutés dans cette zone.");
            }
            this._loadText(this.xNode.contentWindow.document.body.innerText);
        }
        else {
            // editable node
            oGrammalecte.oGCPanel.addMessageToGCPanel("Attention : La zone de texte analysée est un champ textuel enrichi susceptible de contenir des éléments non textuels qui seront effacés lors de la correction.");
            oGrammalecte.oGCPanel.addMessageToGCPanel(" La zone de texte analysée est un champ textuel enrichi susceptible de contenir des éléments non textuels qui seront effacés lors de la correction.");
            this._loadText(this.xNode.innerText);
        }
    }

    setText (sText) {
        this.clear();
        oGrammalecte.oGCPanel.addMessageToGCPanel("Attention : Aucun champ textuel défini. Les changements ne seront pas répercutés sur la zone d’où le texte a été extrait.");
        oGrammalecte.oGCPanel.addMessageToGCPanel(" Aucun champ textuel défini. Les changements ne seront pas répercutés sur la zone d’où le texte a été extrait.");
        this._loadText(sText);
    }

    _loadText (sText) {
        if (typeof(sText) === "string") {
            this.dParagraph.clear();
            let i = 0;
1028
1029
1030
1031
1032
1033
1034
1035
1036


1037
1038
1039

1040
1041
1042
1043
1044
1045
1046
1029
1030
1031
1032
1033
1034
1035


1036
1037
1038
1039

1040
1041
1042
1043
1044
1045
1046
1047







-
-
+
+


-
+







            this.xNode.removeChild(this.xNode.firstChild);
        }
    }

    write () {
        if (this.xNode !== null) {
            if (this.bResultInEvent) {
                const xEvent = new CustomEvent("GrammalecteNodeContentUpdated", {
                    detail: { text: this.getText() }
                const xEvent = new CustomEvent("GrammalecteResult", {
                    detail: JSON.stringify({ text: this.getText() })
                });
                this.xNode.dispatchEvent(xEvent);
                console.log("Texte renvoyé via un event :", xEvent.detail.text);
                //console.log("Text sent via an event :", xEvent.detail);
            }
            else if (this.bTextArea) {
                this.xNode.value = this.getText();
            }
            else if (this.bIframe) {
                //console.log(this.getText());
            }