Grammalecte  Diff

Differences From Artifact [fd4aa2d823]:

To Artifact [484df461e0]:


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
115


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


const oGrammalecte = {

    nWrapper: 1,

    oConjPanel: null,
    oTFPanel: null,
    oLxgPanel: null,
    oGCPanel: null,

    wrapTextareas: function () {
        let lNode = document.getElementsByTagName("textarea");
        for (let xNode of lNode) {
            this._createWrapper(xNode);
        }
    },

    _createWrapper (xTextArea) {
        try {
            let xParentElement = xTextArea.parentElement;
            let xWrapper = document.createElement("div");
            xWrapper.className = "grammalecte_wrapper";
            xWrapper.id = "grammalecte_wrapper" + this.nWrapper;
            this.nWrapper += 1;
            xParentElement.insertBefore(xWrapper, xTextArea);

            xWrapper.appendChild(xTextArea); // move textarea in wrapper
            xWrapper.appendChild(this._createWrapperToolbar(xTextArea));
        }
        catch (e) {
            showError(e);


        }
    },

    _createWrapperToolbar: function (xTextArea) {
        try {
            let xToolbar = createNode("div", {className: "grammalecte_wrapper_toolbar"});
            let xConjButton = createNode("div", {className: "grammalecte_wrapper_button", textContent: "Conjuguer"});
            xConjButton.onclick = function () {





                this.createConjPanel();



                //this.oConjPanel.show();
            }.bind(this);
            let xTFButton = createNode("div", {className: "grammalecte_wrapper_button", textContent: "Formater"});
            xTFButton.onclick = function () {
                this.createTFPanel();
                this.oTFPanel.start(xTextArea);
                this.oTFPanel.show();
            }.bind(this);
            let xLxgButton = createNode("div", {className: "grammalecte_wrapper_button", textContent: "Analyser"});
            xLxgButton.onclick = function () {
                this.createLxgPanel();
                this.oLxgPanel.clear();
                this.oLxgPanel.show();
                this.oLxgPanel.startWaitIcon();
                xPort.postMessage({
                    sCommand: "getListOfTokens",
                    dParam: {sText: xTextArea.value},
                    dInfo: {sTextAreaId: xTextArea.id}
                });
            }.bind(this);
            let xGCButton = createNode("div", {className: "grammalecte_wrapper_button", textContent: "Corriger"});
            xGCButton.onclick = function () {
                this.createGCPanel();
                this.oGCPanel.clear();
                this.oGCPanel.show();
                this.oGCPanel.start(xTextArea);
                this.oGCPanel.startWaitIcon();
                xPort.postMessage({
                    sCommand: "parseAndSpellcheck",
                    dParam: {sText: xTextArea.value, sCountry: "FR", bDebug: false, bContext: false},
                    dInfo: {sTextAreaId: xTextArea.id}
                });
            }.bind(this);
            // 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(document.createTextNode("Grammalecte"));


            xToolbar.appendChild(xConjButton);
            xToolbar.appendChild(xTFButton);
            xToolbar.appendChild(xLxgButton);
            xToolbar.appendChild(xGCButton);
            return xToolbar;
        }
        catch (e) {
            showError(e);
        }

    },



    createConjPanel: function () {




        if (this.oConjPanel === null) {
            this.oConjPanel = new GrammalectePanel("grammalecte_conj_panel", "Conjugueur", 600, 600);

            this.oConjPanel.insertIntoPage();












        }
    },

    createTFPanel: function () {
        if (this.oTFPanel === null) {
            this.oTFPanel = new GrammalecteTextFormatter("grammalecte_tf_panel", "Formateur de texte", 800, 620, false);
            //this.oTFPanel.logInnerHTML();







|

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

|



|
>
>
>
>
>
|
>
>
>
|



|
|
|
|


|
|
|
|





|


|
|
|
|
|





|




|
>
>
|








>
|
>
>
|
|
>
>
>
>
|
|
>
|
>
>
>
>
>
>
>
>
>
>
>
>







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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129


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


class GrammalecteWrapper {

    constructor (nWrapper, xTextArea) {
        this.nWrapper = nWrapper;














        let xParentElement = xTextArea.parentElement;


        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 () {
        return createNode("div", {className: "grammalecte_wrapper_title", textContent: "Grammalecte"});
    }


    _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);
        }
    }

    showConjButtons () {
        document.getElementById("grammalecte_wrapper_conj_section"+this.nWrapper).style.display = "block";
    }

    hideConjButtons () {
        document.getElementById("grammalecte_wrapper_conj_section"+this.nWrapper).style.display = "none";
    }
}


const oGrammalecte = {

    nWrapper: 0,
    lWrapper: [],

    oTFPanel: null,
    oLxgPanel: null,
    oGCPanel: null,

    wrapTextareas: function () {
        let lNode = document.getElementsByTagName("textarea");
        for (let xNode of lNode) {
            this.lWrapper.push(new GrammalecteWrapper(this.nWrapper, xNode));
            this.nWrapper += 1;
        }
    },

    createTFPanel: function () {
        if (this.oTFPanel === null) {
            this.oTFPanel = new GrammalecteTextFormatter("grammalecte_tf_panel", "Formateur de texte", 800, 620, false);
            //this.oTFPanel.logInnerHTML();