Grammalecte  Check-in [5cf14b861c]

Overview
Comment:[fx] tabs -> spaces
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | fx | kill_innerHTML
Files: files | file ages | folders
SHA3-256: 5cf14b861c026a052b30feef756aa822aa6ed0a4ef7d27f082aa1d4d2d134240
User & Date: olr on 2017-07-15 05:14:16
Original Comment: [fr] tabs -> spaces
Other Links: branch diff | manifest | tags
Context
2017-07-15
05:38
[fx] gc_panel: paragraphs editable by default check-in: 417e143855 user: olr tags: fx, kill_innerHTML
05:14
[fx] tabs -> spaces check-in: 5cf14b861c user: olr tags: fx, kill_innerHTML
2017-07-14
20:00
[fx] gc_panel: tooltips reworked, no innerHTML, new CSS check-in: d6ca610c80 user: olr tags: fx, kill_innerHTML
Changes

Modified gc_lang/fr/xpi/data/gc_panel.js from [ffd9b6bc23] to [2b7b6123e9].

1
2
3
4
5
6
7

8
9
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
115

116
117
118
119

120
121
122
123
124


125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
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
233
234
235
236
237
238
239
240
241
242
243
244


















245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262















263
264
265
266
267
268
269
270
271
272
273
274
275










276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316






































317
318
319
320
321
322
323
324
325
326
327








328
329
330
331
332
333
334
335
336
337
338
339
340










341
342
343
344
345
346
347




348
349
350
351
352


353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377






















378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
















397
398
399
400
401
402
403
404





405
406
407
408
409
410
411
412





413
414
415
416
417
418
419
420
421
422
423








424
1
2
3
4
5
6

7
8
9
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
115

116
117
118
119

120
121
122
123


124
125
126
127
128
129
130
131
132
133
134
135




































136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248















249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266










267
268
269
270
271
272
273
274
275
276
277
278
279






































280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320








321
322
323
324
325
326
327
328
329
330
331










332
333
334
335
336
337
338
339
340
341
342
343
344




345
346
347
348
349
350
351


352
353
354
355
356






















357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
















382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400





401
402
403
404
405
406
407
408





409
410
411
412
413
414
415
416








417
418
419
420
421
422
423
424
425






-
+






-
-
+
+



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



-
+



-
+



-
+







-
+



-
+



-
-
-
+
+
+



-
+
+



-
+



-
-
+
+



-
+




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




-
+



-
+



-
-
+
+










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



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



-
-
+
+












-
+







-
+








-
+

-
-
-
-
+
+
+
+



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



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



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



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



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



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



-
-
-
-
+
+
+
+



-
-
+
+



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



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



-
-
-
-
-
+
+
+
+
+



-
-
-
-
-
+
+
+
+
+



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

// JavaScript

let nPanelWidth = 0;  // must be set at launch
let bExpanded = true;

/*
	Events
    Events
*/

showSpecialMessage();


document.getElementById('close').addEventListener("click", function (event) {
	bExpanded = true; // size is reset in ui.js
	self.port.emit('closePanel');
    bExpanded = true; // size is reset in ui.js
    self.port.emit('closePanel');
});

document.getElementById('expand_reduce').addEventListener("click", function (event) {
	if (bExpanded) {
		self.port.emit("resize", "reduce", 10); // the number has no meaning here
		bExpanded = false;
	} else {
		self.port.emit("resize", "expand", 10); // the number has no meaning here
		bExpanded = true;
	}
    if (bExpanded) {
        self.port.emit("resize", "reduce", 10); // the number has no meaning here
        bExpanded = false;
    } else {
        self.port.emit("resize", "expand", 10); // the number has no meaning here
        bExpanded = true;
    }
});

document.getElementById('copy_to_clipboard').addEventListener("click", function (event) {
	copyToClipboard();
    copyToClipboard();
});

document.getElementById('closemsg').addEventListener("click", function (event) {
	closeMessageBox();
    closeMessageBox();
});

self.port.on("setPanelWidth", function (n) {
	nPanelWidth = n;
    nPanelWidth = n;
});

self.port.on("addMessage", function (sClass, sText) {
    addMessage(sClass, sText);
});

self.port.on("addParagraph", function (sText, iParagraph, sJSON) {
	addParagraph(sText, iParagraph, sJSON);
    addParagraph(sText, iParagraph, sJSON);
});

self.port.on("refreshParagraph", function (sText, sIdParagr, sJSON) {
	refreshParagraph(sText, sIdParagr, sJSON);
    refreshParagraph(sText, sIdParagr, sJSON);
});

self.port.on("showMessage", function (sText) {
	document.getElementById("message").textContent = sText;
	document.getElementById("messagebox").style.display = "block";
	window.setTimeout(closeMessageBox, 20000);
    document.getElementById("message").textContent = sText;
    document.getElementById("messagebox").style.display = "block";
    window.setTimeout(closeMessageBox, 20000);
});

self.port.on("clearErrors", function (sHtml) {
	document.getElementById("errorlist").textContent = "";
    document.getElementById("errorlist").textContent = "";
    hideAllTooltips();
});

self.port.on("start", function() {
	startWaitIcon();
    startWaitIcon();
});

self.port.on("end", function() {
	stopWaitIcon();
	document.getElementById("copy_to_clipboard").style.display = "block";
    stopWaitIcon();
    document.getElementById("copy_to_clipboard").style.display = "block";
});

self.port.on("suggestionsFor", function (sWord, sSuggestions, sErrId) {
	setSpellSuggestionsFor(sWord, sSuggestions, sErrId);
    setSpellSuggestionsFor(sWord, sSuggestions, sErrId);
});


window.addEventListener(
	"click",
	function (xEvent) {
		try {
			let xElem = xEvent.target;
			if (xElem.id) {
				if (xElem.id.startsWith("sugg")) {
					applySuggestion(xElem.id);
				} else if (xElem.id.endsWith("_ignore")) {
					ignoreError(xElem.id);
				} else if (xElem.id.startsWith("check")) {
					sendBackAndCheck(xElem.id);
				} else if (xElem.id.startsWith("edit")) {
					switchEdition(xElem.id);
				} else if (xElem.id.startsWith("end")) {
					document.getElementById(xElem.id).parentNode.parentNode.style.display = "none";
				} else if (xElem.tagName === "U" && xElem.id.startsWith("err")
						   && xElem.className !== "corrected" && xElem.className !== "ignored") {
					showTooltip(xElem.id);
				} else if (xElem.id.startsWith("resize")) {
					self.port.emit("resize", xElem.id, 10);
				} else {
					hideAllTooltips();
				}
			} else if (xElem.tagName === "A") {
				self.port.emit("openURL", xElem.getAttribute("href"));
			} else {
				hideAllTooltips();
			}
		}
		catch (e) {
			showError(e);
		}
	},
	false
    "click",
    function (xEvent) {
        try {
            let xElem = xEvent.target;
            if (xElem.id) {
                if (xElem.id.startsWith("sugg")) {
                    applySuggestion(xElem.id);
                } else if (xElem.id.endsWith("_ignore")) {
                    ignoreError(xElem.id);
                } else if (xElem.id.startsWith("check")) {
                    sendBackAndCheck(xElem.id);
                } else if (xElem.id.startsWith("edit")) {
                    switchEdition(xElem.id);
                } else if (xElem.id.startsWith("end")) {
                    document.getElementById(xElem.id).parentNode.parentNode.style.display = "none";
                } else if (xElem.tagName === "U" && xElem.id.startsWith("err")
                           && xElem.className !== "corrected" && xElem.className !== "ignored") {
                    showTooltip(xElem.id);
                } else if (xElem.id.startsWith("resize")) {
                    self.port.emit("resize", xElem.id, 10);
                } else {
                    hideAllTooltips();
                }
            } else if (xElem.tagName === "A") {
                self.port.emit("openURL", xElem.getAttribute("href"));
            } else {
                hideAllTooltips();
            }
        }
        catch (e) {
            showError(e);
        }
    },
    false
);


/*
	Actions
    Actions
*/

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

function closeMessageBox () {
	document.getElementById("messagebox").style.display = "none";
	document.getElementById("message").textContent = "";
    document.getElementById("messagebox").style.display = "none";
    document.getElementById("message").textContent = "";
}

function addMessage (sClass, sText) {
    let xNode = document.createElement("p");
    xNode.className = sClass;
    xNode.textContent = sText;
    document.getElementById("errorlist").appendChild(xNode);
}

function addParagraph (sText, iParagraph, sJSON) {
	try {
		let xNodeDiv = document.createElement("div");
		xNodeDiv.className = "paragraph_block";
		// paragraph
		let xParagraph = document.createElement("p");
		xParagraph.id = "paragr" + iParagraph.toString();
		xParagraph.lang = "fr";
		xParagraph.setAttribute("spellcheck", false);
		let oErrors = JSON.parse(sJSON);
		xParagraph.className = (oErrors.aGrammErr.length || oErrors.aSpellErr.length) ? "paragraph softred" : "paragraph";
		_tagParagraph(sText, xParagraph, iParagraph, oErrors.aGrammErr, oErrors.aSpellErr);
		xNodeDiv.appendChild(xParagraph);
		// actions
		let xDivActions = document.createElement("div");
		xDivActions.className = "actions";
		let xDivClose = document.createElement("div");
		xDivClose.id = "end" + iParagraph.toString();
		xDivClose.className = "button red";
		xDivClose.textContent = "×";
		let xDivEdit = document.createElement("div");
		xDivEdit.id = "edit" + iParagraph.toString();
		xDivEdit.className = "button";
		xDivEdit.textContent = "Éditer";
		let xDivCheck = document.createElement("div");
		xDivCheck.id = "check" + iParagraph.toString();
		xDivCheck.className = "button green";
		xDivCheck.textContent = "Réanalyser";
		xDivActions.appendChild(xDivClose);
		xDivActions.appendChild(xDivEdit);
		xDivActions.appendChild(xDivCheck);
		xNodeDiv.appendChild(xDivActions);
		document.getElementById("errorlist").appendChild(xNodeDiv);
	}
	catch (e) {
		showError(e);
	}
    try {
        let xNodeDiv = document.createElement("div");
        xNodeDiv.className = "paragraph_block";
        // paragraph
        let xParagraph = document.createElement("p");
        xParagraph.id = "paragr" + iParagraph.toString();
        xParagraph.lang = "fr";
        xParagraph.setAttribute("spellcheck", false);
        let oErrors = JSON.parse(sJSON);
        xParagraph.className = (oErrors.aGrammErr.length || oErrors.aSpellErr.length) ? "paragraph softred" : "paragraph";
        _tagParagraph(sText, xParagraph, iParagraph, oErrors.aGrammErr, oErrors.aSpellErr);
        xNodeDiv.appendChild(xParagraph);
        // actions
        let xDivActions = document.createElement("div");
        xDivActions.className = "actions";
        let xDivClose = document.createElement("div");
        xDivClose.id = "end" + iParagraph.toString();
        xDivClose.className = "button red";
        xDivClose.textContent = "×";
        let xDivEdit = document.createElement("div");
        xDivEdit.id = "edit" + iParagraph.toString();
        xDivEdit.className = "button";
        xDivEdit.textContent = "Éditer";
        let xDivCheck = document.createElement("div");
        xDivCheck.id = "check" + iParagraph.toString();
        xDivCheck.className = "button green";
        xDivCheck.textContent = "Réanalyser";
        xDivActions.appendChild(xDivClose);
        xDivActions.appendChild(xDivEdit);
        xDivActions.appendChild(xDivCheck);
        xNodeDiv.appendChild(xDivActions);
        document.getElementById("errorlist").appendChild(xNodeDiv);
    }
    catch (e) {
        showError(e);
    }
}

function refreshParagraph (sText, sIdParagr, sJSON) {
	try {
		let xParagraph = document.getElementById("paragr"+sIdParagr);
		let oErrors = JSON.parse(sJSON);
		xParagraph.className = (oErrors.aGrammErr.length || oErrors.aSpellErr.length) ? "paragraph softred" : "paragraph softgreen";
		xParagraph.textContent = "";
		_tagParagraph(sText, xParagraph, sIdParagr, oErrors.aGrammErr, oErrors.aSpellErr);
	}
	catch (e) {
		showError(e);
	}
    try {
        let xParagraph = document.getElementById("paragr"+sIdParagr);
        let oErrors = JSON.parse(sJSON);
        xParagraph.className = (oErrors.aGrammErr.length || oErrors.aSpellErr.length) ? "paragraph softred" : "paragraph softgreen";
        xParagraph.textContent = "";
        _tagParagraph(sText, xParagraph, sIdParagr, oErrors.aGrammErr, oErrors.aSpellErr);
    }
    catch (e) {
        showError(e);
    }
}

function _tagParagraph (sParagraph, xParagraph, iParagraph, aSpellErr, aGrammErr) {
	try {
		if (aGrammErr.length === 0  &&  aSpellErr.length === 0) {
    try {
        if (aGrammErr.length === 0  &&  aSpellErr.length === 0) {
            xParagraph.textContent = sParagraph;
            return
        }
        aGrammErr.push(...aSpellErr);
        aGrammErr.sort(function (a, b) {
            if (a["nStart"] < b["nStart"])
                return -1;
            if (a["nStart"] > b["nStart"])
                return 1;
            return 0;
        });

		let nErr = 0; // we count errors to give them an identifier
        let nErr = 0; // we count errors to give them an identifier
        let nEndLastErr = 0;
        for (let oErr of aGrammErr) {
            let nStart = oErr["nStart"];
            let nEnd = oErr["nEnd"];
            if (nStart >= nEndLastErr) {
                oErr["sId"] = iParagraph.toString() + "_" + nErr.toString(); // error identifier
                if (nEndLastErr < nStart) {
                	xParagraph.appendChild(document.createTextNode(sParagraph.slice(nEndLastErr, nStart)));
                    xParagraph.appendChild(document.createTextNode(sParagraph.slice(nEndLastErr, nStart)));
                }
                xParagraph.appendChild(_createError(sParagraph.slice(nStart, nEnd), oErr));
                xParagraph.insertAdjacentHTML("beforeend", "<!-- err_end -->");
                nEndLastErr = nEnd;
            }
            nErr += 1;
        }
        if (nEndLastErr <= sParagraph.length) {
        	xParagraph.appendChild(document.createTextNode(sParagraph.slice(nEndLastErr)));
            xParagraph.appendChild(document.createTextNode(sParagraph.slice(nEndLastErr)));
        }
	}
	catch (e) {
		showError(e);
	}
    }
    catch (e) {
        showError(e);
    }
}

function _createError (sUnderlined, oErr) {
	let xNodeErr = document.createElement("u");
	xNodeErr.id = "err" + oErr['sId'];
	xNodeErr.className = "error " + oErr['sType'];
	xNodeErr.textContent = sUnderlined;
	xNodeErr.dataset.error_id = oErr['sId'];
	xNodeErr.dataset.error_type = (oErr['sType'] === "WORD") ? "spelling" : "grammar";
	xNodeErr.setAttribute("href", "#");
	xNodeErr.setAttribute("onclick", "return false;");
	if (xNodeErr.dataset.error_type === "grammar") {
		xNodeErr.dataset.gc_message = oErr['sMessage'];
		xNodeErr.dataset.gc_url = oErr['URL'];
		if (xNodeErr.dataset.gc_message.includes(" #")) {
			xNodeErr.dataset.line_id = oErr['sLineId'];
			xNodeErr.dataset.rule_id = oErr['sRuleId'];
		}
		xNodeErr.dataset.suggestions = oErr["aSuggestions"].join("|");
	}
	return xNodeErr;
    let xNodeErr = document.createElement("u");
    xNodeErr.id = "err" + oErr['sId'];
    xNodeErr.className = "error " + oErr['sType'];
    xNodeErr.textContent = sUnderlined;
    xNodeErr.dataset.error_id = oErr['sId'];
    xNodeErr.dataset.error_type = (oErr['sType'] === "WORD") ? "spelling" : "grammar";
    xNodeErr.setAttribute("href", "#");
    xNodeErr.setAttribute("onclick", "return false;");
    if (xNodeErr.dataset.error_type === "grammar") {
        xNodeErr.dataset.gc_message = oErr['sMessage'];
        xNodeErr.dataset.gc_url = oErr['URL'];
        if (xNodeErr.dataset.gc_message.includes(" #")) {
            xNodeErr.dataset.line_id = oErr['sLineId'];
            xNodeErr.dataset.rule_id = oErr['sRuleId'];
        }
        xNodeErr.dataset.suggestions = oErr["aSuggestions"].join("|");
    }
    return xNodeErr;
}

function applySuggestion (sSuggId) { // sugg
	try {
		let sErrorId = document.getElementById(sSuggId).dataset.error_id;
		let sIdParagr = sErrorId.slice(0, sErrorId.indexOf("_"));
		startWaitIcon("paragr"+sIdParagr);
		let xNodeErr = document.getElementById("err" + sErrorId);
		xNodeErr.textContent = document.getElementById(sSuggId).textContent;
		xNodeErr.className = "corrected";
		xNodeErr.removeAttribute("style");
		self.port.emit("correction", sIdParagr, document.getElementById("paragr"+sIdParagr).textContent);
		hideAllTooltips();
		stopWaitIcon("paragr"+sIdParagr);
	}
	catch (e) {
		showError(e);
	}
    try {
        let sErrorId = document.getElementById(sSuggId).dataset.error_id;
        let sIdParagr = sErrorId.slice(0, sErrorId.indexOf("_"));
        startWaitIcon("paragr"+sIdParagr);
        let xNodeErr = document.getElementById("err" + sErrorId);
        xNodeErr.textContent = document.getElementById(sSuggId).textContent;
        xNodeErr.className = "corrected";
        xNodeErr.removeAttribute("style");
        self.port.emit("correction", sIdParagr, document.getElementById("paragr"+sIdParagr).textContent);
        hideAllTooltips();
        stopWaitIcon("paragr"+sIdParagr);
    }
    catch (e) {
        showError(e);
    }
}

function ignoreError (sIgnoreButtonId) {  // ignore
	try {
		console.log("ignore button: " + sIgnoreButtonId + " // error id: " + document.getElementById(sIgnoreButtonId).dataset.error_id);
		let xNodeErr = document.getElementById("err"+document.getElementById(sIgnoreButtonId).dataset.error_id);
		xNodeErr.className = "ignored";
		xNodeErr.removeAttribute("style");
		hideAllTooltips();
	}
	catch (e) {
		showError(e);
	}
    try {
        console.log("ignore button: " + sIgnoreButtonId + " // error id: " + document.getElementById(sIgnoreButtonId).dataset.error_id);
        let xNodeErr = document.getElementById("err"+document.getElementById(sIgnoreButtonId).dataset.error_id);
        xNodeErr.className = "ignored";
        xNodeErr.removeAttribute("style");
        hideAllTooltips();
    }
    catch (e) {
        showError(e);
    }
}

function showTooltip (sNodeErrorId) {  // err
	try {
		hideAllTooltips();
		let xNodeError = document.getElementById(sNodeErrorId);
		let sTooltipId = (xNodeError.dataset.error_type === "grammar") ? "gc_tooltip" : "sc_tooltip";
		let xNodeTooltip = document.getElementById(sTooltipId);
		let nLimit = nPanelWidth - 320; // paragraph width - tooltip width
		xNodeTooltip.style.top = (xNodeError.offsetTop + 16) + "px";
		xNodeTooltip.style.left = (xNodeError.offsetLeft > nLimit) ? nLimit + "px" : xNodeError.offsetLeft + "px";
		if (xNodeError.dataset.error_type === "grammar") {
			// grammar error
			document.getElementById("gc_message").textContent = xNodeError.dataset.gc_message;
			if (xNodeError.dataset.gc_url != "") {
				document.getElementById("gc_url").style.display = "inline";
				document.getElementById("gc_url").setAttribute("href", xNodeError.dataset.gc_url);
			} else {
				document.getElementById("gc_url").style.display = "none";
			}
			document.getElementById("gc_ignore").dataset.error_id = xNodeError.dataset.error_id;
			let iSugg = 0;
			let xGCSugg = document.getElementById("gc_sugg_block");
			xGCSugg.textContent = "";
	        for (let sSugg of xNodeError.dataset.suggestions.split("|")) {
	        	xGCSugg.appendChild(_createSuggestion(xNodeError.dataset.error_id, iSugg, sSugg));
	            xGCSugg.appendChild(document.createTextNode(" "));
	            iSugg += 1;
	        }
		}
		xNodeTooltip.style.display = "block";
		if (xNodeError.dataset.error_type === "spelling") {
			// spelling mistake
			document.getElementById("sc_ignore").dataset.error_id = xNodeError.dataset.error_id;
			//console.log("getSuggFor: " + xNodeError.textContent.trim() + " // error_id: " + xNodeError.dataset.error_id);
			self.port.emit("getSuggestionsForTo", xNodeError.textContent.trim(), xNodeError.dataset.error_id);
		}
	}
	catch (e) {
		showError(e);
	}
    try {
        hideAllTooltips();
        let xNodeError = document.getElementById(sNodeErrorId);
        let sTooltipId = (xNodeError.dataset.error_type === "grammar") ? "gc_tooltip" : "sc_tooltip";
        let xNodeTooltip = document.getElementById(sTooltipId);
        let nLimit = nPanelWidth - 330; // paragraph width - tooltip width
        xNodeTooltip.style.top = (xNodeError.offsetTop + 16) + "px";
        xNodeTooltip.style.left = (xNodeError.offsetLeft > nLimit) ? nLimit + "px" : xNodeError.offsetLeft + "px";
        if (xNodeError.dataset.error_type === "grammar") {
            // grammar error
            document.getElementById("gc_message").textContent = xNodeError.dataset.gc_message;
            if (xNodeError.dataset.gc_url != "") {
                document.getElementById("gc_url").style.display = "inline";
                document.getElementById("gc_url").setAttribute("href", xNodeError.dataset.gc_url);
            } else {
                document.getElementById("gc_url").style.display = "none";
            }
            document.getElementById("gc_ignore").dataset.error_id = xNodeError.dataset.error_id;
            let iSugg = 0;
            let xGCSugg = document.getElementById("gc_sugg_block");
            xGCSugg.textContent = "";
            for (let sSugg of xNodeError.dataset.suggestions.split("|")) {
                xGCSugg.appendChild(_createSuggestion(xNodeError.dataset.error_id, iSugg, sSugg));
                xGCSugg.appendChild(document.createTextNode(" "));
                iSugg += 1;
            }
        }
        xNodeTooltip.style.display = "block";
        if (xNodeError.dataset.error_type === "spelling") {
            // spelling mistake
            document.getElementById("sc_ignore").dataset.error_id = xNodeError.dataset.error_id;
            //console.log("getSuggFor: " + xNodeError.textContent.trim() + " // error_id: " + xNodeError.dataset.error_id);
            self.port.emit("getSuggestionsForTo", xNodeError.textContent.trim(), xNodeError.dataset.error_id);
        }
    }
    catch (e) {
        showError(e);
    }
}

function _createSuggestion (sErrId, iSugg, sSugg) {
	let xNodeSugg = document.createElement("a");
	xNodeSugg.id = "sugg" + sErrId + "-" + iSugg.toString();
	xNodeSugg.className = "sugg";
	xNodeSugg.setAttribute("href", "#");
	xNodeSugg.setAttribute("onclick", "return false;");
	xNodeSugg.dataset.error_id = sErrId;
	xNodeSugg.textContent = sSugg;
	return xNodeSugg;
    let xNodeSugg = document.createElement("a");
    xNodeSugg.id = "sugg" + sErrId + "-" + iSugg.toString();
    xNodeSugg.className = "sugg";
    xNodeSugg.setAttribute("href", "#");
    xNodeSugg.setAttribute("onclick", "return false;");
    xNodeSugg.dataset.error_id = sErrId;
    xNodeSugg.textContent = sSugg;
    return xNodeSugg;
}

function switchEdition (sEditButtonId) {  // edit
	let xParagraph = document.getElementById("paragr" + sEditButtonId.slice(4));
	if (xParagraph.hasAttribute("contenteditable") === false
		|| xParagraph.getAttribute("contenteditable") === "false") {
		xParagraph.setAttribute("contenteditable", true);
		document.getElementById(sEditButtonId).className = "button orange";
		xParagraph.focus();
	} else {
		xParagraph.setAttribute("contenteditable", false);
		document.getElementById(sEditButtonId).className = "button";
	}
    let xParagraph = document.getElementById("paragr" + sEditButtonId.slice(4));
    if (xParagraph.hasAttribute("contenteditable") === false
        || xParagraph.getAttribute("contenteditable") === "false") {
        xParagraph.setAttribute("contenteditable", true);
        document.getElementById(sEditButtonId).className = "button orange";
        xParagraph.focus();
    } else {
        xParagraph.setAttribute("contenteditable", false);
        document.getElementById(sEditButtonId).className = "button";
    }
}

function sendBackAndCheck (sCheckButtonId) {  // check
	startWaitIcon();
	let sIdParagr = sCheckButtonId.slice(5);
	self.port.emit("modifyAndCheck", sIdParagr, document.getElementById("paragr"+sIdParagr).textContent);
	stopWaitIcon();
    startWaitIcon();
    let sIdParagr = sCheckButtonId.slice(5);
    self.port.emit("modifyAndCheck", sIdParagr, document.getElementById("paragr"+sIdParagr).textContent);
    stopWaitIcon();
}

function hideAllTooltips () {
	document.getElementById("gc_tooltip").style.display = "none";
	document.getElementById("sc_tooltip").style.display = "none";
    document.getElementById("gc_tooltip").style.display = "none";
    document.getElementById("sc_tooltip").style.display = "none";
}

function setSpellSuggestionsFor (sWord, sSuggestions, sErrId) {
	// spell checking suggestions
	try {
		// console.log("setSuggestionsFor: " + sWord + " > " + sSuggestions + " // " + sErrId);
		let xSuggBlock = document.getElementById("sc_sugg_block");
		xSuggBlock.textContent = "";
		if (sSuggestions === "") {
			xSuggBlock.appendChild(document.createTextNode("Aucune."));
		} else if (sSuggestions.startsWith("#")) {
			xSuggBlock.appendChild(document.createTextNode(sSuggestions));
		} else {
			let lSugg = sSuggestions.split("|");
			let iSugg = 0;
			for (let sSugg of lSugg) {
				xSuggBlock.appendChild(_createSuggestion(sErrId, iSugg, sSugg));
				xSuggBlock.appendChild(document.createTextNode(" "));
				iSugg += 1;
			}
		}
	}
	catch (e) {
		showError(e);
	}
    // spell checking suggestions
    try {
        // console.log("setSuggestionsFor: " + sWord + " > " + sSuggestions + " // " + sErrId);
        let xSuggBlock = document.getElementById("sc_sugg_block");
        xSuggBlock.textContent = "";
        if (sSuggestions === "") {
            xSuggBlock.appendChild(document.createTextNode("Aucune."));
        } else if (sSuggestions.startsWith("#")) {
            xSuggBlock.appendChild(document.createTextNode(sSuggestions));
        } else {
            let lSugg = sSuggestions.split("|");
            let iSugg = 0;
            for (let sSugg of lSugg) {
                xSuggBlock.appendChild(_createSuggestion(sErrId, iSugg, sSugg));
                xSuggBlock.appendChild(document.createTextNode(" "));
                iSugg += 1;
            }
        }
    }
    catch (e) {
        showError(e);
    }
}

function copyToClipboard () {
	startWaitIcon();
	try {
		let xClipboardButton = document.getElementById("clipboard_msg");
		xClipboardButton.textContent = "copie en cours…";
		let sText = "";
		for (let xNode of document.getElementById("errorlist").getElementsByClassName("paragraph")) {
			sText += xNode.textContent + "\n";
		}
		self.port.emit('copyToClipboard', sText);
		xClipboardButton.textContent = "-> presse-papiers";
		window.setTimeout(function() { xClipboardButton.textContent = "∑"; } , 3000);
	}
	catch (e) {
		console.log(e.lineNumber + ": " +e.message);
	}
	stopWaitIcon();
    startWaitIcon();
    try {
        let xClipboardButton = document.getElementById("clipboard_msg");
        xClipboardButton.textContent = "copie en cours…";
        let sText = "";
        for (let xNode of document.getElementById("errorlist").getElementsByClassName("paragraph")) {
            sText += xNode.textContent + "\n";
        }
        self.port.emit('copyToClipboard', sText);
        xClipboardButton.textContent = "-> presse-papiers";
        window.setTimeout(function() { xClipboardButton.textContent = "∑"; } , 3000);
    }
    catch (e) {
        console.log(e.lineNumber + ": " +e.message);
    }
    stopWaitIcon();
}

function startWaitIcon (sIdParagr=null) {
	if (sIdParagr) {
		document.getElementById(sIdParagr).disabled = true;
		document.getElementById(sIdParagr).style.opacity = .3;
	}
	document.getElementById("waiticon").hidden = false;
    if (sIdParagr) {
        document.getElementById(sIdParagr).disabled = true;
        document.getElementById(sIdParagr).style.opacity = .3;
    }
    document.getElementById("waiticon").hidden = false;
}

function stopWaitIcon (sIdParagr=null) {
	if (sIdParagr) {
		document.getElementById(sIdParagr).disabled = false;
		document.getElementById(sIdParagr).style.opacity = 1;
	}
	document.getElementById("waiticon").hidden = true;
    if (sIdParagr) {
        document.getElementById(sIdParagr).disabled = false;
        document.getElementById(sIdParagr).style.opacity = 1;
    }
    document.getElementById("waiticon").hidden = true;
}

function showSpecialMessage () {
	if (Date.now() < Date.UTC(2017, 6, 12)) {
		try {
			document.getElementById('special_message').style.display = "block";
			document.getElementById('errorlist').style.padding = "20px 20px 30px 20px";
		} catch (e) {
			showError(e);
		}
	}
    if (Date.now() < Date.UTC(2017, 6, 12)) {
        try {
            document.getElementById('special_message').style.display = "block";
            document.getElementById('errorlist').style.padding = "20px 20px 30px 20px";
        } catch (e) {
            showError(e);
        }
    }
}