Grammalecte  Check-in [3126c1b302]

Overview
Comment:[fx] WebExt: context menu: rescan page
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk | fx
Files: files | file ages | folders
SHA3-256: 3126c1b302479cac58734bf9f04555f7fc35f04657a7f385a3da89c917095481
User & Date: olr on 2017-09-16 10:57:01
Other Links: manifest | tags
Context
2017-09-16
11:18
[fx] WebExt: CSS: line-height in suggestion block check-in: 63577f44c9 user: olr tags: trunk, fx
10:57
[fx] WebExt: context menu: rescan page check-in: 3126c1b302 user: olr tags: trunk, fx
2017-09-15
14:58
[fx] WebExt: smaller text formatter check-in: d4a86b753d user: olr tags: trunk, fx
Changes

Modified gc_lang/fr/webext/background.js from [b21f2d7035] to [cd0a23cfe8].

169
170
171
172
173
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
169
170
171
172
173
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232







-
+
















+
+
+
+
+
+
+
+
+
+
+


















+
+
+
+







browser.contextMenus.create({
    id: "parseAndSpellcheck",
    title: "Corriger",
    contexts: ["selection"]
});

browser.contextMenus.create({
    id: "whatever",
    id: "separator1",
    type: "separator",
    contexts: ["selection"]
});

browser.contextMenus.create({
    id: "conjugueur_window",
    title: "Conjugueur [fenêtre]",
    contexts: ["all"]
});

browser.contextMenus.create({
    id: "conjugueur_tab",
    title: "Conjugueur [onglet]",
    contexts: ["all"]
});

browser.contextMenus.create({
    id: "separator2",
    type: "separator",
    contexts: ["editable"]
});

browser.contextMenus.create({
    id: "rescanPage",
    title: "Rechercher à nouveau les zones de texte",
    contexts: ["editable"]
});

browser.contextMenus.onClicked.addListener(function (xInfo, xTab) {
    // xInfo = https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/contextMenus/OnClickData
    // xTab = https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/tabs/Tab
    // confusing: no way to get the node where we click?!
    switch (xInfo.menuItemId) {
        case "parseAndSpellcheck":
            parseAndSpellcheckSelectedText(xTab.id, xInfo.selectionText);
            break;
        case "getListOfTokens": 
            getListOfTokensFromSelectedText(xTab.id, xInfo.selectionText);
            break;
        case "conjugueur_window":
            openConjugueurWindow();
            break;
        case "conjugueur_tab":
            openConjugueurTab();
            break;
        case "rescanPage":
            let xPort = dConnx.get(xTab.id);
            xPort.postMessage({sActionDone: "rescanPage"});
            break;
        default:
            console.log("[Background] Unknown menu id: " + xInfo.menuItemId);
            console.log(xInfo);
            console.log(xTab);
    }    
});

Modified gc_lang/fr/webext/content_scripts/init.js from [7343d224bf] to [52c46fcb6a].

55
56
57
58
59
60
61











62
63
64
65
66
67
68
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







+
+
+
+
+
+
+
+
+
+
+







    createMenus: function () {
        let lNode = document.getElementsByTagName("textarea");
        for (let xNode of lNode) {
            this.lMenu.push(new GrammalecteMenu(this.nMenu, xNode));
            this.nMenu += 1;
        }
    },

    rescanPage: function () {
        if (this.oTFPanel !== null) { this.oTFPanel.hide(); }
        if (this.oLxgPanel !== null) { this.oLxgPanel.hide(); }
        if (this.oGCPanel !== null) { this.oGCPanel.hide(); }
        for (let oMenu of this.lMenu) {
            oMenu.deleteNodes();
        }
        this.lMenu.length = 0; // to clear an array
        this.createMenus();
    },

    createTFPanel: function () {
        if (this.oTFPanel === null) {
            this.oTFPanel = new GrammalecteTextFormatter("grammalecte_tf_panel", "Formateur de texte", 760, 600, false);
            //this.oTFPanel.logInnerHTML();
            this.oTFPanel.insertIntoPage();
            this.oTFPanel.adjustHeight();
124
125
126
127
128
129
130



131
132
133
134
135
136
137
138
139
140
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154







+
+
+










            break;
        case "openLxgPanel":
            oGrammalecte.createLxgPanel();
            oGrammalecte.oLxgPanel.clear();
            oGrammalecte.oLxgPanel.show();
            oGrammalecte.oLxgPanel.startWaitIcon();
            break;
        case "rescanPage":
            oGrammalecte.rescanPage();
            break;
        default:
            console.log("[Content script] Unknown command: " + sActionDone);
    }
});


/*
    Start
*/
oGrammalecte.createMenus();

Modified gc_lang/fr/webext/content_scripts/menu.js from [89ff587940] to [51ff434365].

1
2
3
4
5
6
7
8
9
10
11
12
13
14





15
16
17
18
19
20
21
1
2
3
4
5
6
7
8
9





10
11
12
13
14
15
16
17
18
19
20
21









-
-
-
-
-
+
+
+
+
+







// JavaScript

"use strict";


class GrammalecteMenu {

    constructor (nMenu, xTextArea) {
        this.sMenuId = "grammalecte_menu" + nMenu;
        let xButton = createNode("div", {className: "grammalecte_menu_main_button", textContent: " "});
        xButton.onclick = () => { this.switchMenu(); };
        let xMenu = this._createMenu(xTextArea);
        this._insertAfter(xButton, xTextArea);
        this._insertAfter(xMenu, xTextArea);
        this.xButton = createNode("div", {className: "grammalecte_menu_main_button", textContent: " "});
        this.xButton.onclick = () => { this.switchMenu(); };
        this.xMenu = this._createMenu(xTextArea);
        this._insertAfter(this.xButton, xTextArea);
        this._insertAfter(this.xMenu, xTextArea);
    }

    _insertAfter (xNewNode, xReferenceNode) {
        xReferenceNode.parentNode.insertBefore(xNewNode, xReferenceNode.nextSibling);
    }

    _createMenu (xTextArea) {
82
83
84
85
86
87
88





89
90
91
92
93
94
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99







+
+
+
+
+






            xMenu.appendChild(createNode("div", {className: "grammalecte_menu_footer"}));
            return xMenu;
        }
        catch (e) {
            showError(e);
        }
    }

    deleteNodes () {
        this.xMenu.parentNode.removeChild(this.xMenu);
        this.xButton.parentNode.removeChild(this.xButton);
    }

    switchMenu () {
    	let xMenu = document.getElementById(this.sMenuId);
        xMenu.style.display = (xMenu.style.display == "block") ? "none" : "block";
    }
}