Grammalecte  Diff

Differences From Artifact [484df461e0]:

To Artifact [473b1e492b]:


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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97






98





99
100



101
102

103
104
105



106
107

108
109
110
111
112
113
114
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
38


39



40
41
42
43

44
45
46
47
48
49
50
51







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

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

-
+







"use strict";


function showError (e) {
    console.error(e.fileName + "\n" + e.name + "\nline: " + e.lineNumber + "\n" + e.message);
}


function createNode (sType, oAttr, oDataset=null) {
class GrammalecteWrapper {

    try {
    constructor (nWrapper, xTextArea) {
        this.nWrapper = nWrapper;
        let xParentElement = xTextArea.parentElement;
        let xNode = document.createElement(sType);
        let xWrapper = createNode("div", {id: "grammalecte_wrapper" + nWrapper, className: "grammalecte_wrapper"});
        xParentElement.insertBefore(xWrapper, xTextArea);
        xWrapper.appendChild(this._createTitle());
        xWrapper.appendChild(xTextArea); // move textarea in wrapper
        xWrapper.appendChild(this._createWrapperToolbar(xTextArea));
    }

    _createTitle () {
        Object.assign(xNode, oAttr);
        if (oDataset) {
        return createNode("div", {className: "grammalecte_wrapper_title", textContent: "Grammalecte"});
    }
            Object.assign(xNode.dataset, oDataset);
        }

    _createWrapperToolbar (xTextArea) {
        try {
            let xToolbar = createNode("div", {className: "grammalecte_wrapper_toolbar"});
            let xConjButton = createNode("div", {className: "grammalecte_wrapper_button", textContent: "Conjuguer"});
            xConjButton.onclick = () => { this.showConjButtons(); };
            let xConjSection = createNode("div", {id: "grammalecte_wrapper_conj_section"+this.nWrapper, className: "grammalecte_wrapper_conj_section"});
            let xConjButtonTab = createNode("div", {className: "grammalecte_wrapper_button2", textContent: ">Onglet"});
            xConjButtonTab.onclick = function () {
                xPort.postMessage({sCommand: "openConjugueurTab", dParam: null, dInfo: null});
                this.hideConjButtons();
            }.bind(this);
            let xConjButtonWin = createNode("div", {className: "grammalecte_wrapper_button2", textContent: ">Fenêtre"});
            xConjButtonWin.onclick = function () {
                xPort.postMessage({sCommand: "openConjugueurWindow", dParam: null, dInfo: null});
                this.hideConjButtons();
            }.bind(this);
            let xTFButton = createNode("div", {className: "grammalecte_wrapper_button", textContent: "Formater"});
            xTFButton.onclick = function () {
                oGrammalecte.createTFPanel();
                oGrammalecte.oTFPanel.start(xTextArea);
                oGrammalecte.oTFPanel.show();
            };
            let xLxgButton = createNode("div", {className: "grammalecte_wrapper_button", textContent: "Analyser"});
            xLxgButton.onclick = function () {
                oGrammalecte.createLxgPanel();
                oGrammalecte.oLxgPanel.clear();
                oGrammalecte.oLxgPanel.show();
                oGrammalecte.oLxgPanel.startWaitIcon();
                xPort.postMessage({
                    sCommand: "getListOfTokens",
                    dParam: {sText: xTextArea.value},
                    dInfo: {sTextAreaId: xTextArea.id}
                });
            };
            let xGCButton = createNode("div", {className: "grammalecte_wrapper_button", textContent: "Corriger"});
            xGCButton.onclick = function () {
                oGrammalecte.createGCPanel();
                oGrammalecte.oGCPanel.clear();
                oGrammalecte.oGCPanel.show();
                oGrammalecte.oGCPanel.start(xTextArea);
                oGrammalecte.oGCPanel.startWaitIcon();
                xPort.postMessage({
                    sCommand: "parseAndSpellcheck",
                    dParam: {sText: xTextArea.value, sCountry: "FR", bDebug: false, bContext: false},
                    dInfo: {sTextAreaId: xTextArea.id}
                });
            };
            // Create
            //xToolbar.appendChild(createNode("img", {scr: browser.extension.getURL("img/logo-16.png")}));
            // can’t work, due to content-script policy: https://bugzilla.mozilla.org/show_bug.cgi?id=1267027
            //xToolbar.appendChild(createLogo());
            xToolbar.appendChild(xConjButton);
            xConjSection.appendChild(xConjButtonTab);
            xConjSection.appendChild(xConjButtonWin);
            xToolbar.appendChild(xConjSection);
            xToolbar.appendChild(xTFButton);
            xToolbar.appendChild(xLxgButton);
            xToolbar.appendChild(xGCButton);
            return xToolbar;
        }
        catch (e) {
            showError(e);
        }
    }
        return xNode;
    }
    catch (e) {
        showError(e);
    }
}

/*
function loadImage (sContainerClass, sImagePath) {
    let xRequest = new XMLHttpRequest();
    xRequest.open('GET', browser.extension.getURL("")+sImagePath, false);
    xRequest.responseType = "arraybuffer";
    showConjButtons () {
        document.getElementById("grammalecte_wrapper_conj_section"+this.nWrapper).style.display = "block";
    xRequest.send();
    let blobTxt = new Blob([xRequest.response], {type: 'image/png'});
    let img = document.createElement('img');
    }

    img.src = (URL || webkitURL).createObjectURL(blobTxt); // webkitURL is obsolete: https://bugs.webkit.org/show_bug.cgi?id=167518
    hideConjButtons () {
        document.getElementById("grammalecte_wrapper_conj_section"+this.nWrapper).style.display = "none";
    }
    Array.filter(document.getElementsByClassName(sContainerClass), function (oElem) {
        oElem.appendChild(img);
    });
}

*/

const oGrammalecte = {

    nWrapper: 0,
    lWrapper: [],

    oTFPanel: null,