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
|
addParagraphResult: function (oResult) {
try {
if (oResult) {
let xNodeDiv = createNode("div", {className: "grammalecte_paragraph_block"});
// actions
let xActionsBar = createNode("div", {className: "grammalecte_paragraph_actions"});
xActionsBar.appendChild(createNode("div", {id: "grammalecte_check" + oResult.sParaNum, className: "button green", textContent: "Réanalyser"}));
xActionsBar.appendChild(createNode("div", {id: "grammalecte_hide" + oResult.sParaNum, className: "button red bold", textContent: "×"}));
// paragraph
let xParagraph = createNode("p", {id: "grammalecte_paragraph"+oResult.sParaNum, lang: "fr", contentEditable: "true"});
xParagraph.setAttribute("spellcheck", "false"); // doesn’t seem possible to use “spellcheck” as a common attribute.
xParagraph.className = (oResult.aGrammErr.length || oResult.aSpellErr.length) ? "grammalecte_paragraph softred" : "grammalecte_paragraph";
this._tagParagraph(xParagraph, oResult.sParagraph, oResult.sParaNum, oResult.aGrammErr, oResult.aSpellErr);
// creation
xNodeDiv.appendChild(xActionsBar);
xNodeDiv.appendChild(xParagraph);
this.xParagraphList.appendChild(xNodeDiv);
}
}
catch (e) {
showError(e);
}
},
recheckParagraph: function (sParagraphNum) {
let sParagraphId = "grammalecte_paragraph" + sParagraphNum;
let xParagraph = document.getElementById(sParagraphId);
this.blockParagraph(xParagraph);
let sText = this.getPurgedTextOfParagraph(xParagraph.textContent);
xPort.postMessage({
sCommand: "parseAndSpellcheck1",
dParam: {sText: sText, sCountry: "FR", bDebug: false, bContext: false},
dInfo: {sParagraphId: sParagraphId}
});
this.oTAC.setParagraph(parseInt(sParagraphNum), sText);
this.oTAC.write();
//stopWaitIcon();
},
refreshParagraph: function (sParagraphId, oResult) {
try {
let xParagraph = document.getElementById(sParagraphId);
xParagraph.className = (oResult.aGrammErr.length || oResult.aSpellErr.length) ? "grammalecte_paragraph softred" : "grammalecte_paragraph";
xParagraph.textContent = "";
this._tagParagraph(xParagraph, oResult.sParagraph, sParagraphId.slice(21), oResult.aGrammErr, oResult.aSpellErr);
this.freeParagraph(xParagraph);
}
catch (e) {
showError(e);
}
},
_tagParagraph: function (xParagraph, sParagraph, sParaNum, aSpellErr, aGrammErr) {
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 nEndLastErr = 0;
for (let oErr of aGrammErr) {
let nStart = oErr["nStart"];
let nEnd = oErr["nEnd"];
if (nStart >= nEndLastErr) {
oErr['sErrorId'] = sParaNum + "-" + nErr.toString(); // error identifier
oErr['sIgnoredKey'] = sParaNum + ":" + nStart.toString() + ":" + sParagraph.slice(nStart, nEnd);
if (nEndLastErr < nStart) {
xParagraph.appendChild(document.createTextNode(sParagraph.slice(nEndLastErr, nStart)));
}
xParagraph.appendChild(this._createError(sParagraph.slice(nStart, nEnd), oErr));
xParagraph.insertAdjacentHTML("beforeend", "<!-- err_end -->");
nEndLastErr = nEnd;
}
|
|
|
|
>
>
>
>
>
|
|
|
|
|
<
|
|
|
|
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
|
addParagraphResult: function (oResult) {
try {
if (oResult) {
let xNodeDiv = createNode("div", {className: "grammalecte_paragraph_block"});
// actions
let xActionsBar = createNode("div", {className: "grammalecte_paragraph_actions"});
xActionsBar.appendChild(createNode("div", {id: "grammalecte_check" + oResult.iParaNum, className: "button green", textContent: "Réanalyser"}));
xActionsBar.appendChild(createNode("div", {id: "grammalecte_hide" + oResult.iParaNum, className: "button red bold", textContent: "×"}));
// paragraph
let xParagraph = createNode("p", {id: "grammalecte_paragraph"+oResult.iParaNum, lang: "fr", contentEditable: "true"}, {para_num: oResult.iParaNum});
xParagraph.setAttribute("spellcheck", "false"); // doesn’t seem possible to use “spellcheck” as a common attribute.
xParagraph.className = (oResult.aGrammErr.length || oResult.aSpellErr.length) ? "grammalecte_paragraph softred" : "grammalecte_paragraph";
xParagraph.addEventListener("keyup", function (xEvent) {
this.oTAC.setParagraph(parseInt(xEvent.target.dataset.para_num), this.purgeText(xEvent.target.textContent));
this.oTAC.write();
}.bind(this)
, true);
this._tagParagraph(xParagraph, oResult.sParagraph, oResult.iParaNum, oResult.aGrammErr, oResult.aSpellErr);
// creation
xNodeDiv.appendChild(xActionsBar);
xNodeDiv.appendChild(xParagraph);
this.xParagraphList.appendChild(xNodeDiv);
}
}
catch (e) {
showError(e);
}
},
recheckParagraph: function (iParaNum) {
let sParagraphId = "grammalecte_paragraph" + iParaNum;
let xParagraph = document.getElementById(sParagraphId);
this.blockParagraph(xParagraph);
let sText = this.purgeText(xParagraph.textContent);
xPort.postMessage({
sCommand: "parseAndSpellcheck1",
dParam: {sText: sText, sCountry: "FR", bDebug: false, bContext: false},
dInfo: {sParagraphId: sParagraphId}
});
this.oTAC.setParagraph(iParaNum, sText);
this.oTAC.write();
},
refreshParagraph: function (sParagraphId, oResult) {
try {
let xParagraph = document.getElementById(sParagraphId);
xParagraph.className = (oResult.aGrammErr.length || oResult.aSpellErr.length) ? "grammalecte_paragraph softred" : "grammalecte_paragraph";
xParagraph.textContent = "";
this._tagParagraph(xParagraph, oResult.sParagraph, sParagraphId.slice(21), oResult.aGrammErr, oResult.aSpellErr);
this.freeParagraph(xParagraph);
}
catch (e) {
showError(e);
}
},
_tagParagraph: function (xParagraph, sParagraph, iParaNum, aSpellErr, aGrammErr) {
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 nEndLastErr = 0;
for (let oErr of aGrammErr) {
let nStart = oErr["nStart"];
let nEnd = oErr["nEnd"];
if (nStart >= nEndLastErr) {
oErr['sErrorId'] = iParaNum + "-" + nErr.toString(); // error identifier
oErr['sIgnoredKey'] = iParaNum + ":" + nStart.toString() + ":" + sParagraph.slice(nStart, nEnd);
if (nEndLastErr < nStart) {
xParagraph.appendChild(document.createTextNode(sParagraph.slice(nEndLastErr, nStart)));
}
xParagraph.appendChild(this._createError(sParagraph.slice(nStart, nEnd), oErr));
xParagraph.insertAdjacentHTML("beforeend", "<!-- err_end -->");
nEndLastErr = nEnd;
}
|
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
|
xNodeErr.dataset.suggestions = oErr["aSuggestions"].join("|");
}
xNodeErr.className = (this.aIgnoredErrors.has(xNodeErr.dataset.ignored_key)) ? "ignored" : "error " + oErr['sType'];
return xNodeErr;
},
blockParagraph: function (xParagraph) {
xParagraph.style = "background-color: hsl(30, 100%, 80%)";
xParagraph.disabled = true;
xParagraph.contentEditable = "false";
},
freeParagraph: function (xParagraph) {
xParagraph.style = "";
xParagraph.contentEditable = "true";
},
applySuggestion: function (sNodeSuggId) { // sugg
try {
console.log(sNodeSuggId);
let sErrorId = document.getElementById(sNodeSuggId).dataset.error_id;
//let sParaNum = sErrorId.slice(0, sErrorId.indexOf("-"));
console.log("grammalecte_err"+sErrorId);
let xNodeErr = document.getElementById("grammalecte_err" + sErrorId);
xNodeErr.textContent = document.getElementById(sNodeSuggId).textContent;
xNodeErr.className = "corrected";
xNodeErr.removeAttribute("style");
this.oTooltip.hide();
this.recheckParagraph(sErrorId.slice(0, sErrorId.indexOf("-")));
}
catch (e) {
showError(e);
}
},
ignoreError: function (sIgnoreButtonId) { // ignore
|
<
<
<
|
|
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
|
xNodeErr.dataset.suggestions = oErr["aSuggestions"].join("|");
}
xNodeErr.className = (this.aIgnoredErrors.has(xNodeErr.dataset.ignored_key)) ? "ignored" : "error " + oErr['sType'];
return xNodeErr;
},
blockParagraph: function (xParagraph) {
xParagraph.contentEditable = "false";
},
freeParagraph: function (xParagraph) {
xParagraph.contentEditable = "true";
},
applySuggestion: function (sNodeSuggId) { // sugg
try {
console.log(sNodeSuggId);
let sErrorId = document.getElementById(sNodeSuggId).dataset.error_id;
//let sParaNum = sErrorId.slice(0, sErrorId.indexOf("-"));
console.log("grammalecte_err"+sErrorId);
let xNodeErr = document.getElementById("grammalecte_err" + sErrorId);
xNodeErr.textContent = document.getElementById(sNodeSuggId).textContent;
xNodeErr.className = "corrected";
xNodeErr.removeAttribute("style");
this.oTooltip.hide();
this.recheckParagraph(parseInt(sErrorId.slice(0, sErrorId.indexOf("-"))));
}
catch (e) {
showError(e);
}
},
ignoreError: function (sIgnoreButtonId) { // ignore
|
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
|
this.oTooltip.hide();
}
catch (e) {
showError(e);
}
},
getPurgedTextOfParagraph: function (sText) {
return sText.replace(/ /g, " ").replace(/</g, "<").replace(/>/g, ">").replace(/&/g, "&");
},
addSummary: function () {
// todo
},
|
|
|
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
|
this.oTooltip.hide();
}
catch (e) {
showError(e);
}
},
purgeText: function (sText) {
return sText.replace(/ /g, " ").replace(/</g, "<").replace(/>/g, ">").replace(/&/g, "&");
},
addSummary: function () {
// todo
},
|