Grammalecte  Diff

Differences From Artifact [6794ec1e36]:

To Artifact [c58813ca49]:


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37

class GrammalecteTextFormatter extends GrammalectePanel {

    constructor (...args) {
        super(...args);
        this.xTFNode = this._createTextFormatter();
        this.xPanelContent.appendChild(this.xTFNode);
        this.xTextNode = null;
        this.xPanel.style.zIndex = 2147483647; /* maximum is 2147483647: https://stackoverflow.com/questions/491052/minimum-and-maximum-value-of-z-index */
        this.bTextChanged = false;

        this.TextFormatter = new TextFormatter();
        this.formatText = this.TextFormatter.formatTextRuleCount;
        this.removeHyphenAtEndOfParagraphs = this.TextFormatter.removeHyphenAtEndOfParagraphsCount;
        this.mergeContiguousParagraphs = this.TextFormatter.mergeContiguousParagraphsCount;
        this.getParagraph = this.TextFormatter.getParagraph;

        this.xCloseButton.onclick = () => {
            this.hide();
            if (this.bTextChanged) {
                this.xGCPanel.recheckAll();
                this.bTextChanged = false;
            }
        };
    }

    _createTextFormatter () {
        let xTFNode = document.createElement("div");







<



|
|
|
|
|




|







10
11
12
13
14
15
16

17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

class GrammalecteTextFormatter extends GrammalectePanel {

    constructor (...args) {
        super(...args);
        this.xTFNode = this._createTextFormatter();
        this.xPanelContent.appendChild(this.xTFNode);

        this.xPanel.style.zIndex = 2147483647; /* maximum is 2147483647: https://stackoverflow.com/questions/491052/minimum-and-maximum-value-of-z-index */
        this.bTextChanged = false;

        this.oTextFormatter = new TextFormatter();
        this.formatText = this.oTextFormatter.formatTextRuleCount;
        this.removeHyphenAtEndOfParagraphs = this.oTextFormatter.removeHyphenAtEndOfParagraphsCount;
        this.mergeContiguousParagraphs = this.oTextFormatter.mergeContiguousParagraphsCount;
        this.getParagraph = this.oTextFormatter.getParagraph;

        this.xCloseButton.onclick = () => {
            this.hide();
            if (this.bTextChanged) {
                oGrammalecte.oGCPanel.recheckAll();
                this.bTextChanged = false;
            }
        };
    }

    _createTextFormatter () {
        let xTFNode = document.createElement("div");
175
176
177
178
179
180
181
182

183
184
185
186
187
188
189
190
191
192
193
194
195
196
197



198
199
200






201


202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
    _createOrdinalOptions () {
        let xLine = oGrammalecte.createNode("div", {className: "grammalecte_tf_blockopt grammalecte_tf_underline"});
        xLine.appendChild(this._createOption("o_ordinals_no_exponant", true, "Ordinaux (15e, XXIe…)"));
        xLine.appendChild(this._createOption("o_ordinals_exponant", true, "e → ᵉ"));
        xLine.appendChild(oGrammalecte.createNode("div", {id: "res_"+"o_ordinals_no_exponant", className: "grammalecte_tf_result", textContent: "·"}));
        return xLine;
    }


    /*
        Actions
    */
    start (xGCPanel) {
        if (xGCPanel.xNode !== null && (xGCPanel.xNode.tagName == "TEXTAREA" || xGCPanel.xNode.tagName == "INPUT" || xGCPanel.xNode.isContentEditable)) {
            this.xTextNode = xGCPanel.xNode;
            this.xGCPanel = xGCPanel;
            if (bChrome) {
                browser.storage.local.get("tf_options", this.setOptions.bind(this));
            } else {
                let xPromise = browser.storage.local.get("tf_options");
                xPromise.then(this.setOptions.bind(this), this.reset.bind(this));
            }
        }
    }




    getNodeText () {
        return (this.xTextNode.tagName == "TEXTAREA" || this.xTextNode.tagName == "INPUT") ? this.xTextNode.value.normalize("NFC") : this.xTextNode.innerText.normalize("NFC");






    }



    setNodeText (sText) {
        if (this.xTextNode.tagName == "TEXTAREA" || this.xTextNode.tagName == "INPUT") {
            this.xTextNode.value = sText;
        } else {
            this.xTextNode.textContent = sText;
        }
        this.bTextChanged = true;
    }

    switchGroup (sOptName) {
        if (this.xParent.getElementById(sOptName).dataset.selected == "true") {
            this.xParent.getElementById(sOptName.slice(2)).style.opacity = 1;
        } else {
            this.xParent.getElementById(sOptName.slice(2)).style.opacity = 0.3;








>



|
<
<
<
|
|
|
|
|
|
|
|
>
>
>
|
<
|
>
>
>
>
>
>
|
>
>
|
<
<
<
<
<

<







174
175
176
177
178
179
180
181
182
183
184
185
186



187
188
189
190
191
192
193
194
195
196
197
198

199
200
201
202
203
204
205
206
207
208
209





210

211
212
213
214
215
216
217
    _createOrdinalOptions () {
        let xLine = oGrammalecte.createNode("div", {className: "grammalecte_tf_blockopt grammalecte_tf_underline"});
        xLine.appendChild(this._createOption("o_ordinals_no_exponant", true, "Ordinaux (15e, XXIe…)"));
        xLine.appendChild(this._createOption("o_ordinals_exponant", true, "e → ᵉ"));
        xLine.appendChild(oGrammalecte.createNode("div", {id: "res_"+"o_ordinals_no_exponant", className: "grammalecte_tf_result", textContent: "·"}));
        return xLine;
    }


    /*
        Actions
    */
    start () {



        if (bChrome) {
            browser.storage.local.get("tf_options", this.setOptions.bind(this));
        } else {
            let xPromise = browser.storage.local.get("tf_options");
            xPromise.then(this.setOptions.bind(this), this.reset.bind(this));
        }
    }

    setOptions (oOptions) {
        if (oOptions.hasOwnProperty("tf_options")) {
            oOptions = oOptions.tf_options;
        }

        let elmOpt = this.xParent.getElementById('grammalecte_tf_options');
        for (let xOption of elmOpt.getElementsByClassName("grammalecte_tf_option")) {
            //console.log(xOption.id + " > " + oOptions.hasOwnProperty(xOption.id) + ": " + oOptions[xOption.id] + " [" + xOption.dataset.default + "]");
            xOption.dataset.selected = (oOptions.hasOwnProperty(xOption.id)) ? oOptions[xOption.id] : xOption.dataset.default;
            xOption.className = (xOption.dataset.selected == "true") ? xOption.className.replace("_off", "_on") : xOption.className.replace("_on", "_off");
            if (this.xParent.getElementById("res_"+xOption.id) !== null) {
                this.xParent.getElementById("res_"+xOption.id).textContent = "";
            }
            if (xOption.id.startsWith("o_group_")) {
                this.switchGroup(xOption.id);
            }





        }

    }

    switchGroup (sOptName) {
        if (this.xParent.getElementById(sOptName).dataset.selected == "true") {
            this.xParent.getElementById(sOptName.slice(2)).style.opacity = 1;
        } else {
            this.xParent.getElementById(sOptName.slice(2)).style.opacity = 0.3;
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
    }

    resetProgressBar () {
        this.xParent.getElementById('grammalecte_tf_progressbar').value = 0;
        this.xParent.getElementById('grammalecte_tf_time_res').textContent = "";
    }

    setOptions (oOptions) {
        if (oOptions.hasOwnProperty("tf_options")) {
            oOptions = oOptions.tf_options;
        }
        let elmOpt = this.xParent.getElementById('grammalecte_tf_options');
        for (let xOption of elmOpt.getElementsByClassName("grammalecte_tf_option")) {
            //console.log(xOption.id + " > " + oOptions.hasOwnProperty(xOption.id) + ": " + oOptions[xOption.id] + " [" + xOption.dataset.default + "]");
            xOption.dataset.selected = (oOptions.hasOwnProperty(xOption.id)) ? oOptions[xOption.id] : xOption.dataset.default;
            xOption.className = (xOption.dataset.selected == "true") ? xOption.className.replace("_off", "_on") : xOption.className.replace("_on", "_off");
            if (this.xParent.getElementById("res_"+xOption.id) !== null) {
                this.xParent.getElementById("res_"+xOption.id).textContent = "";
            }
            if (xOption.id.startsWith("o_group_")) {
                this.switchGroup(xOption.id);
            }
        }
    }

    saveOptions () {
        let oOptions = {};
        let elmOpt = this.xParent.getElementById('grammalecte_tf_options');
        for (let xOption of elmOpt.getElementsByClassName("grammalecte_tf_option")) {
            oOptions[xOption.id] = (xOption.dataset.selected == "true");
            //console.log(xOption.id + ": " + xOption.checked);
        }







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







252
253
254
255
256
257
258


















259
260
261
262
263
264
265
    }

    resetProgressBar () {
        this.xParent.getElementById('grammalecte_tf_progressbar').value = 0;
        this.xParent.getElementById('grammalecte_tf_time_res').textContent = "";
    }



















    saveOptions () {
        let oOptions = {};
        let elmOpt = this.xParent.getElementById('grammalecte_tf_options');
        for (let xOption of elmOpt.getElementsByClassName("grammalecte_tf_option")) {
            oOptions[xOption.id] = (xOption.dataset.selected == "true");
            //console.log(xOption.id + ": " + xOption.checked);
        }
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
    }

    apply () {
        try {
            const t0 = Date.now();
            //window.setCursor("wait"); // change pointer
            this.resetProgressBar();
            let sText = this.getNodeText();
            this.xParent.getElementById('grammalecte_tf_progressbar').max = 7;
            let n1 = 0, n2 = 0, n3 = 0, n4 = 0, n5 = 0, n6 = 0, n7 = 0;

            // Restructuration
            if (this.isSelected("o_group_struct")) {
                if (this.isSelected("o_remove_hyphens_at_end_of_paragraphs")) {
                    [sText, n1] = this.removeHyphenAtEndOfParagraphs(sText);







|







274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
    }

    apply () {
        try {
            const t0 = Date.now();
            //window.setCursor("wait"); // change pointer
            this.resetProgressBar();
            let sText = oGrammalecte.oGCPanel.oTextControl.getText();
            this.xParent.getElementById('grammalecte_tf_progressbar').max = 7;
            let n1 = 0, n2 = 0, n3 = 0, n4 = 0, n5 = 0, n6 = 0, n7 = 0;

            // Restructuration
            if (this.isSelected("o_group_struct")) {
                if (this.isSelected("o_remove_hyphens_at_end_of_paragraphs")) {
                    [sText, n1] = this.removeHyphenAtEndOfParagraphs(sText);
537
538
539
540
541
542
543
544


545
546
547
548
549
550
551
            this.xParent.getElementById('grammalecte_tf_progressbar').value = this.xParent.getElementById('grammalecte_tf_progressbar').max;
            // end of processing

            //window.setCursor("auto"); // restore pointer

            const t1 = Date.now();
            this.xParent.getElementById('grammalecte_tf_time_res').textContent = this.getTimeRes((t1-t0)/1000);
            this.setNodeText(sText);


        }
        catch (e) {
            showError(e);
        }
    }

    getTimeRes (n) {







|
>
>







520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
            this.xParent.getElementById('grammalecte_tf_progressbar').value = this.xParent.getElementById('grammalecte_tf_progressbar').max;
            // end of processing

            //window.setCursor("auto"); // restore pointer

            const t1 = Date.now();
            this.xParent.getElementById('grammalecte_tf_time_res').textContent = this.getTimeRes((t1-t0)/1000);
            oGrammalecte.oGCPanel.oTextControl.loadText(sText);
            oGrammalecte.oGCPanel.oTextControl.write();
            this.bTextChanged = true;
        }
        catch (e) {
            showError(e);
        }
    }

    getTimeRes (n) {