Grammalecte  Diff

Differences From Artifact [61b25ed2ef]:

To Artifact [c562cfe40e]:


127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142

143

144
145
146
147

148
149
150
151
152
153
154
155
        this.xMenu.appendChild(this.xTFButton)
        this.xMenu.appendChild(this.xEditorButton)
        this.xMenu.appendChild(this.xLxgButton)
        this.xMenu.appendChild(this.xConjButton)
        this.xPanelBar.appendChild(this.xMenu);
    }

    start (what) {
        this.oTooltip.hide();
        this.bWorking = false;
        this.clear();
        this.hideMessage();
        this.resetTimer();
        if (typeof(what) === "string") {
            // text
            this.xNode = null;

            this.oTextControl.setText(what);

        } else if (what.nodeType && what.nodeType === 1) { // 1 = Node.ELEMENT_NODE
            // node
            this.xNode = what;
            this.oTextControl.setNode(this.xNode);

        } else {
            // error
            oGrammalecte.oMessageBox.showMessage("[BUG] Analyse d’un élément inconnu…");
            console.log("[Grammalecte] Unknown element:", what);
        }
    }

    setAutoRefreshButton () {







|








>

>
|



>
|







127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
        this.xMenu.appendChild(this.xTFButton)
        this.xMenu.appendChild(this.xEditorButton)
        this.xMenu.appendChild(this.xLxgButton)
        this.xMenu.appendChild(this.xConjButton)
        this.xPanelBar.appendChild(this.xMenu);
    }

    start (what, xResultNode=null) {
        this.oTooltip.hide();
        this.bWorking = false;
        this.clear();
        this.hideMessage();
        this.resetTimer();
        if (typeof(what) === "string") {
            // text
            this.xNode = null;
            this.oTextControl.setResultNode(xResultNode);
            this.oTextControl.setText(what);
        }
        else if (what.nodeType && what.nodeType === 1) { // 1 = Node.ELEMENT_NODE
            // node
            this.xNode = what;
            this.oTextControl.setNode(this.xNode);
        }
        else {
            // error
            oGrammalecte.oMessageBox.showMessage("[BUG] Analyse d’un élément inconnu…");
            console.log("[Grammalecte] Unknown element:", what);
        }
    }

    setAutoRefreshButton () {
928
929
930
931
932
933
934

935
936
937
938
939
940
941

    constructor () {
        this.xNode = null;
        this.dParagraph = new Map();
        this.bTextArea = false;
        this.bIframe = false;
        this.bResultInEvent = false; // if true, the node content is not modified, but an event is dispatched on the node with the modified text

    }

    setNode (xNode) {
        this.clear();
        this.xNode = xNode;
        this.bResultInEvent = Boolean(xNode.dataset.grammalecte_result_via_event && xNode.dataset.grammalecte_result_via_event == "true");
        this.bTextArea = (xNode.tagName == "TEXTAREA" || xNode.tagName == "INPUT");







>







931
932
933
934
935
936
937
938
939
940
941
942
943
944
945

    constructor () {
        this.xNode = null;
        this.dParagraph = new Map();
        this.bTextArea = false;
        this.bIframe = false;
        this.bResultInEvent = false; // if true, the node content is not modified, but an event is dispatched on the node with the modified text
        this.xResultNode = null; // only useful if for text analysed without node
    }

    setNode (xNode) {
        this.clear();
        this.xNode = xNode;
        this.bResultInEvent = Boolean(xNode.dataset.grammalecte_result_via_event && xNode.dataset.grammalecte_result_via_event == "true");
        this.bTextArea = (xNode.tagName == "TEXTAREA" || xNode.tagName == "INPUT");
953
954
955
956
957
958
959







960
961
962

963

964
965
966
967
968
969
970
        }
        else {
            // editable node
            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("⛔ 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) {
        // function also used by the text formatter
        if (typeof(sText) === "string") {
            this.dParagraph.clear();







>
>
>
>
>
>
>



>
|
>







957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
        }
        else {
            // editable node
            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);
        }
    }

    setResultNode (xNode) {
        if (xNode instanceof HTMLElement) {
            this.xResultNode = xNode;
            this.bResultInEvent = true;
        }
    }

    setText (sText) {
        this.clear();
        if (!this.xResultNode) {
            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) {
        // function also used by the text formatter
        if (typeof(sText) === "string") {
            this.dParagraph.clear();
985
986
987
988
989
990
991

992
993
994
995
996
997
998
    clear () {
        if (this.xNode !== null) {
            this.xNode.disabled = false;
            this.bTextArea = false;
            this.bIframe = false;
            this.bResultInEvent = false;
            this.xNode = null;

        }
        this.dParagraph.clear();
    }

    getText () {
        return [...this.dParagraph.values()].join("\n").normalize("NFC");
    }







>







998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
    clear () {
        if (this.xNode !== null) {
            this.xNode.disabled = false;
            this.bTextArea = false;
            this.bIframe = false;
            this.bResultInEvent = false;
            this.xNode = null;
            this.xResultNode = null;
        }
        this.dParagraph.clear();
    }

    getText () {
        return [...this.dParagraph.values()].join("\n").normalize("NFC");
    }
1007
1008
1009
1010
1011
1012
1013

1014




1015
1016
1017
1018
1019
1020
1021
        }
    }

    write () {
        if (this.xNode !== null) {
            if (this.bResultInEvent) {
                const xEvent = new CustomEvent("GrammalecteResult", { detail: JSON.stringify({ sType: "text", sText: this.getText() }) });

                this.xNode.dispatchEvent(xEvent);




                //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());







>
|
>
>
>
>







1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
        }
    }

    write () {
        if (this.xNode !== null) {
            if (this.bResultInEvent) {
                const xEvent = new CustomEvent("GrammalecteResult", { detail: JSON.stringify({ sType: "text", sText: this.getText() }) });
                if (this.xNode) {
                    this.xNode.dispatchEvent(xEvent);
                }
                else if (this.xResultNode) {
                    this.xResultNode.dispatchEvent(xEvent);
                }
                //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());