Grammalecte  Diff

Differences From Artifact [8ddc3692fd]:

To Artifact [236732302d]:


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
9
10
11
12
13
14
15




16
17
18
19
20
21
22







-
-
-
-







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

    setTextArea (xTextArea) {
        this.xTextArea = xTextArea;
    }

    _createTextFormatter () {
        let xTFNode = document.createElement("div");
        try {
            // Options
            let xOptions = createNode("div", {id: "grammalecte_tf_options"});
            let xColumn1 = createNode("div", {className: "grammalecte_tf_column"});
            let xSSP = this._createFieldset("group_ssp", true, "Espaces surnuméraires");
74
75
76
77
78
79
80
81

82
83
84
85
86
87
88
70
71
72
73
74
75
76

77
78
79
80
81
82
83
84







-
+







            xOptions.appendChild(xColumn1);
            xOptions.appendChild(xColumn2);
            // Actions
            let xActions = createNode("div", {id: "grammalecte_tf_actions"});
            let xDefaultButton = createNode("div", {id: "grammalecte_tf_reset", textContent: "Par défaut", className: "grammalecte_button", style: "background-color: hsl(210, 50%, 50%)"});
            xDefaultButton.addEventListener("click", () => { this.reset(); });
            let xApplyButton = createNode("div", {id: "grammalecte_tf_apply", textContent: "Appliquer", className: "grammalecte_button", style: "background-color: hsl(180, 50%, 50%)"});
            xApplyButton.addEventListener("click", () => { this.apply(); });
            xApplyButton.addEventListener("click", () => { this.saveOptions(); this.apply(); });
            xActions.appendChild(xDefaultButton);
            xActions.appendChild(createNode("progress", {id: "grammalecte_tf_progressbar"}));
            xActions.appendChild(createNode("span", {id: "grammalecte_tf_time_res", textContent: "…"}));
            xActions.appendChild(xApplyButton);
            //xActions.appendChild(createNode("div", {id: "grammalecte_infomsg", textContent: "blabla"}));
            // create result
            xTFNode.appendChild(xOptions);
177
178
179
180
181
182
183






184
185
186
187
188
189
190
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192







+
+
+
+
+
+







        return xInlineBlock;
    }


    /*
        Actions
    */
    start (xTextArea) {
        this.xTextArea = xTextArea;
        let xPromise = browser.storage.local.get("tf_options");
        xPromise.then(this.setOptions.bind(this), this.reset.bind(this));
    }

    switchGroup (sOptName) {
        if (document.getElementById(sOptName).checked) {
            document.getElementById(sOptName.slice(2)).style.opacity = 1;
        } else {
            document.getElementById(sOptName.slice(2)).style.opacity = 0.3;
        }
        this.resetProgressBar();
202
203
204
205
206
207
208
209

210
211
212

213
214
215
216
217
218









219
220
221
222
223
224
225
226

227
228

229
230
231
232
233
234
235
204
205
206
207
208
209
210

211



212






213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231

232
233
234
235
236
237
238
239







-
+
-
-
-
+
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+








+

-
+








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

    setOptions (oOptions) {
        for (let sOptName in oOptions) {
        if (oOptions.hasOwnProperty("tf_options")) {
            //console.log(sOptName + ":" + oOptions[sOptName]);
            if (document.getElementById(sOptName) !== null) {
                document.getElementById(sOptName).checked = oOptions[sOptName];
            oOptions = oOptions.tf_options;
                if (sOptName.startsWith("o_group_")) {
                    switchGroup(sOptName);
                } 
                if (document.getElementById("res_"+sOptName) !== null) {
                    document.getElementById("res_"+sOptName).textContent = "";
                }
        }
        for (let xNode of document.getElementsByClassName("option")) {
            //console.log(xNode.id + " > " + oOptions.hasOwnProperty(xNode.id) + ": " + oOptions[xNode.id] + " [" + xNode.dataset.default + "]");
            xNode.checked = (oOptions.hasOwnProperty(xNode.id)) ? oOptions[xNode.id] : (xNode.dataset.default === "true");
            if (document.getElementById("res_"+xNode.id) !== null) {
                document.getElementById("res_"+xNode.id).textContent = "";
            }
            if (xNode.id.startsWith("o_group_")) {
                this.switchGroup(xNode.id);
            }
        }
    }

    saveOptions () {
        let oOptions = {};
        for (let xNode of document.getElementsByClassName("option")) {
            oOptions[xNode.id] = xNode.checked;
            console.log(xNode.id + ": " + xNode.checked);
        }
        self.port.emit("saveOptions", JSON.stringify(oOptions));
        browser.storage.local.set({"tf_options": oOptions});
    }

    apply () {
        try {
            const t0 = Date.now();
            //window.setCursor("wait"); // change pointer
            this.resetProgressBar();