Grammalecte  Check-in [f02079aa95]

Overview
Comment:[fx] open conjugueur with wrapper buttons + code revamping
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | fx | webext2
Files: files | file ages | folders
SHA3-256: f02079aa957e34b628f2cdd176967a0e139fd01acbc039544583d1bb9d619109
User & Date: olr on 2017-08-30 12:55:39
Other Links: branch diff | manifest | tags
Context
2017-08-30
13:15
[fx] wrapper code in separate files check-in: 684d94c839 user: olr tags: fx, webext2
12:55
[fx] open conjugueur with wrapper buttons + code revamping check-in: f02079aa95 user: olr tags: fx, webext2
10:31
[fx] openURL in main panel check-in: 327355a98f user: olr tags: fx, webext2
Changes

Modified gc_lang/fr/webext/background.js from [326c22ae1a] to [9d2c8ffd1c].

131
132
133
134
135
136
137






138
139
140
141
142
143
144
            case "getListOfTokens":
                oRequest.dInfo.iReturnPort = iPortId; // we pass the id of the return port to receive answer
                xGCEWorker.postMessage(oRequest);
                break;
            case "openURL":
                browser.tabs.create({url: dParam.sURL});
                break;






            default:
                console.log("[background] Unknown command: " + sCommand);
                console.log(oRequest);
        }
    });
    xPort.postMessage({sActionDone: "newId", result: iPortId});
}







>
>
>
>
>
>







131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
            case "getListOfTokens":
                oRequest.dInfo.iReturnPort = iPortId; // we pass the id of the return port to receive answer
                xGCEWorker.postMessage(oRequest);
                break;
            case "openURL":
                browser.tabs.create({url: dParam.sURL});
                break;
            case "openConjugueurTab":
                openConjugueurTab();
                break;
            case "openConjugueurWindow":
                openConjugueurWindow();
                break;
            default:
                console.log("[background] Unknown command: " + sCommand);
                console.log(oRequest);
        }
    });
    xPort.postMessage({sActionDone: "newId", result: iPortId});
}

Modified gc_lang/fr/webext/content_scripts/content_modifier.js from [fd4aa2d823] to [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();

Modified gc_lang/fr/webext/content_scripts/panels_content.css from [2efcd78668] to [076476015d].

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
    border-radius: 3px;
    background-color: hsl(210, 40%, 96%);
    border: 1px solid hsl(210, 40%, 92%);
    box-shadow: 0 0 2px hsla(210, 40%, 0%, .5);
    font-family: "Trebuchet MS", "Liberation Sans", sans-serif;
    color: hsl(210, 40%, 50%);
}














.grammalecte_wrapper_button {
    display: inline-block;
    padding: 0 5px;
    margin-left: 5px;
    background-color: hsl(210, 60%, 80%);
    border-radius: 2px;
    border: 1px solid hsl(210, 60%, 70%);

    color: hsl(210, 40%, 40%);
    cursor: pointer;
}
.grammalecte_wrapper_button:hover {
    background-color: hsl(210, 80%, 70%);
    border: 1px solid hsl(210, 80%, 60%);
    box-shadow: 0 0 1px 1px hsl(210, 80%, 80%);
    color: hsl(210, 80%, 30%);
}

.grammalecte_wrapper_toolbar {
    display: flex;
    justify-content: flex-end;
    margin-top: 5px;




    padding: 5px 10px;













}

/*
    Panels
*/
.grammalecte_panel {
    padding: 0;







>
>
>
>
>
>
>
>
>
>
>
>
>








>







|

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







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
    border-radius: 3px;
    background-color: hsl(210, 40%, 96%);
    border: 1px solid hsl(210, 40%, 92%);
    box-shadow: 0 0 2px hsla(210, 40%, 0%, .5);
    font-family: "Trebuchet MS", "Liberation Sans", sans-serif;
    color: hsl(210, 40%, 50%);
}

.grammalecte_wrapper_title {
    padding: 5px 0;
    font-size: 12px;
    font-variant: small-caps;
}

.grammalecte_wrapper_toolbar {
    display: flex;
    justify-content: flex-end;
    margin-top: 5px;
    padding: 5px 10px;
}

.grammalecte_wrapper_button {
    display: inline-block;
    padding: 0 5px;
    margin-left: 5px;
    background-color: hsl(210, 60%, 80%);
    border-radius: 2px;
    border: 1px solid hsl(210, 60%, 70%);
    font-size: 14px;
    color: hsl(210, 40%, 40%);
    cursor: pointer;
}
.grammalecte_wrapper_button:hover {
    background-color: hsl(210, 80%, 70%);
    border: 1px solid hsl(210, 80%, 60%);
    box-shadow: 0 0 1px 1px hsl(210, 80%, 80%);
    color: hsl(210, 80%, 98%);
}

.grammalecte_wrapper_conj_section {
    display: none;


}

.grammalecte_wrapper_button2 {
    display: inline-block;
    padding: 0 5px;
    margin-left: 5px;
    background-color: hsl(180, 60%, 80%);
    border-radius: 2px;
    border: 1px solid hsl(180, 60%, 70%);
    font-size: 14px;
    color: hsl(180, 40%, 40%);
    cursor: pointer;
}
.grammalecte_wrapper_button2:hover {
    background-color: hsl(180, 80%, 70%);
    border: 1px solid hsl(180, 80%, 60%);
    box-shadow: 0 0 1px 1px hsl(180, 80%, 80%);
    color: hsl(180, 80%, 98%);
}

/*
    Panels
*/
.grammalecte_panel {
    padding: 0;