Overview
Comment: | [fx][js] gc_panel revamping (part 1) |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | fx | kill_innerHTML |
Files: | files | file ages | folders |
SHA3-256: |
a83903f529c65b658fd4284d24d1442d |
User & Date: | olr on 2017-07-13 16:44:06 |
Original Comment: | [core][js] gc_panel revamping (part 1) |
Other Links: | branch diff | manifest | tags |
Context
2017-07-13
| ||
17:30 | [fx][js] gc_panel revamping (part 2) check-in: 96809cd8cd user: olr tags: fx, kill_innerHTML | |
16:44 | [fx][js] gc_panel revamping (part 1) check-in: a83903f529 user: olr tags: fx, kill_innerHTML | |
07:12 | [fr][js] lexicographe: nettoyage check-in: 3996597b39 user: olr tags: fr, kill_innerHTML | |
Changes
Modified compile_rules.py from [1657201ddf] to [02451fe9a0].
︙ | ︙ | |||
447 448 449 450 451 452 453 | def pyRuleToJS (lRule): lRuleJS = copy.deepcopy(lRule) del lRule[-1] # tGroups positioning codes are useless for Python # error messages for aAction in lRuleJS[6]: if aAction[1] == "-": aAction[2] = aAction[2].replace(" ", " ") # nbsp --> nnbsp | | | 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 | def pyRuleToJS (lRule): lRuleJS = copy.deepcopy(lRule) del lRule[-1] # tGroups positioning codes are useless for Python # error messages for aAction in lRuleJS[6]: if aAction[1] == "-": aAction[2] = aAction[2].replace(" ", " ") # nbsp --> nnbsp aAction[4] = aAction[4].replace("« ", "« ").replace(" »", " »") # js regexes lRuleJS[1], lNegLookBehindRegex = regex2js( dJSREGEXES.get(lRuleJS[3], lRuleJS[1]) ) lRuleJS.append(lNegLookBehindRegex) return lRuleJS def writeRulesToJSArray (lRules): |
︙ | ︙ |
Modified gc_lang/fr/xpi/data/gc_panel.css from [96f3d08e72] to [3928e567ee].
︙ | ︙ | |||
71 72 73 74 75 76 77 78 79 80 81 82 83 84 | border-radius: 3px; text-align: center; } #errorlist p.green { background-color: hsla(120, 10%, 50%, 1); color: hsla(120, 0%, 96%, 1); } .paragraph { background-color: hsla(0, 0%, 90%, 1); padding: 10px; border-radius: 2px; font-size: 14px; font-family : "Courier New", Courier, "Lucida Sans Typewriter", "Lucida Typewriter", monospace; | > > > > | 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | border-radius: 3px; text-align: center; } #errorlist p.green { background-color: hsla(120, 10%, 50%, 1); color: hsla(120, 0%, 96%, 1); } .paragraph_block { margin: 0 0 30px 0; } .paragraph { background-color: hsla(0, 0%, 90%, 1); padding: 10px; border-radius: 2px; font-size: 14px; font-family : "Courier New", Courier, "Lucida Sans Typewriter", "Lucida Typewriter", monospace; |
︙ | ︙ | |||
264 265 266 267 268 269 270 | } .error:hover { background-color: hsl(240, 10%, 40%); color: hsl(240, 0%, 100%); } /* elems */ | | | | 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 | } .error:hover { background-color: hsl(240, 10%, 40%); color: hsl(240, 0%, 100%); } /* elems */ .WORD { background-color: hsl(0, 50%, 50%); color: hsl(0, 0%, 96%); /*text-decoration: underline wavy hsl(0, 50%, 50%);*/ } .WORD:hover { background-color: hsl(0, 60%, 40%); color: hsl(0, 0%, 100%); } /* elems */ .typo, .esp, .nbsp, .eif, .maj, .virg, .tu, .num, .unit, .nf, .liga, .mapos, .chim { background-color: hsl(30, 70%, 50%); |
︙ | ︙ |
Modified gc_lang/fr/xpi/data/gc_panel.js from [74635d32f6] to [6a9e1bc61d].
1 2 3 4 5 6 7 8 9 | // JavaScript let nPanelWidth = 0; // must be set at launch let bExpanded = true; /* Events */ | < < < < < | < < | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | // JavaScript let nPanelWidth = 0; // must be set at launch let bExpanded = true; /* Events */ showSpecialMessage(); document.getElementById('close').addEventListener("click", function (event) { bExpanded = true; // size is reset in ui.js self.port.emit('closePanel'); }); |
︙ | ︙ | |||
40 41 42 43 44 45 46 | closeMessageBox(); }); self.port.on("setPanelWidth", function (n) { nPanelWidth = n; }); | | | > | < > > | 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | closeMessageBox(); }); self.port.on("setPanelWidth", function (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); }); self.port.on("refreshParagraph", function (sIdParagr, sHtml) { document.getElementById("paragr"+sIdParagr).innerHTML = sHtml; let sClassName = (sHtml.includes('<u id="err')) ? "paragraph softred" : "paragraph softgreen"; document.getElementById("paragr"+sIdParagr).className = sClassName; }); |
︙ | ︙ | |||
72 73 74 75 76 77 78 | self.port.on("end", function() { stopWaitIcon(); document.getElementById("copy_to_clipboard").style.display = "block"; }); self.port.on("suggestionsFor", function (sWord, sSuggestions, sTooltipId) { | < < < < < < < | < < < < < < < | 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | self.port.on("end", function() { stopWaitIcon(); document.getElementById("copy_to_clipboard").style.display = "block"; }); self.port.on("suggestionsFor", function (sWord, sSuggestions, sTooltipId) { setSpellSuggestionsFor(sWord, sSuggestions, sTooltipId); }); window.addEventListener( "click", function (xEvent) { let xElem = xEvent.target; |
︙ | ︙ | |||
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | false ); /* Actions */ function closeMessageBox () { document.getElementById("messagebox").style.display = "none"; document.getElementById("message").textContent = ""; } function applySuggestion (sElemId) { // sugg try { let sIdParagr = sElemId.slice(4, sElemId.indexOf("_")); startWaitIcon("paragr"+sIdParagr); let sIdErr = "err" + sElemId.slice(4, sElemId.indexOf("-")); document.getElementById(sIdErr).textContent = document.getElementById(sElemId).textContent; document.getElementById(sIdErr).className = "corrected"; document.getElementById(sIdErr).removeAttribute("style"); self.port.emit("correction", sIdParagr, getPurgedTextOfElem("paragr"+sIdParagr)); stopWaitIcon("paragr"+sIdParagr); | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | < > | 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 | false ); /* Actions */ function showError (e) { console.error("\n" + e.fileName + "\n" + e.name + "\nline: " + e.lineNumber + "\n" + e.message); } 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.className = (true) ? "paragraph" : "paragraph softred"; xParagraph.lang = "fr"; xParagraph.style.spellchecker = "false"; let oErrors = JSON.parse(sJSON); let aSpellErr = oErrors.aSpellErr; let aGrammErr = oErrors.aGrammErr; _tagParagraph(sText, xParagraph, iParagraph, aGrammErr, 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 _tagParagraph (sParagraph, xParagraph, iParagraph, 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["sId"] = iParagraph.toString() + "_" + nErr.toString(); // error identifier if (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))); } } 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.setAttribute("href", "#"); xNodeErr.setAttribute("onclick", "return false;"); let xTooltip = (oErr['sType'] !== "WORD") ? _getGrammarTooltip(oErr) : _getSpellingTooltip(oErr); xNodeErr.appendChild(xTooltip); return xNodeErr; } function _getGrammarTooltip (oErr) { let xSpan = document.createElement("span"); xSpan.id = "tooltip" + oErr['sId']; xSpan.className = "tooltip"; xSpan.setAttribute("contenteditable", "false"); xSpan.appendChild(document.createTextNode(oErr["sMessage"]+" ")); xSpan.appendChild(_createIgnoreButton(oErr["sId"])); if (oErr["URL"] !== "") { xSpan.appendChild(_createInfoLink(oErr["URL"])); } if (oErr["aSuggestions"].length > 0) { xSpan.appendChild(document.createElement("br")); xSpan.appendChild(_createSuggestionLabel()); xSpan.appendChild(document.createElement("br")); let iSugg = 0; for (let sSugg of oErr["aSuggestions"]) { xSpan.appendChild(_createSuggestion(oErr["sId"], iSugg, sSugg)); xSpan.appendChild(document.createTextNode(" ")); iSugg += 1; } } return xSpan; } function _getSpellingTooltip (oErr) { let xSpan = document.createElement("span"); xSpan.id = "tooltip" + oErr['sId']; xSpan.className = "tooltip"; xSpan.setAttribute("contenteditable", "false"); xSpan.appendChild(document.createTextNode("Mot inconnu du dictionnaire. ")); xSpan.appendChild(_createIgnoreButton(oErr["sId"])); xSpan.appendChild(document.createElement("br")); xSpan.appendChild(_createSuggestionLabel()); xSpan.appendChild(document.createElement("br")); return xSpan; } function _createIgnoreButton (sErrorId) { let xIgnore = document.createElement("a"); xIgnore.id = "ignore" + sErrorId; xIgnore.className = "ignore"; xIgnore.setAttribute("href", "#"); xIgnore.setAttribute("onclick", "return false;"); xIgnore.textContent = "IGNORER"; return xIgnore; } function _createInfoLink (sURL) { let xInfo = document.createElement("a"); xInfo.setAttribute("href", sURL); xInfo.setAttribute("onclick", "return false;"); xInfo.textContent = "Infos…"; return xInfo; } function _createSuggestionLabel () { let xNode = document.createElement("s"); xNode.textContent = "Suggestions :"; return xNode; } 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.textContent = sSugg; return xNodeSugg; } function closeMessageBox () { document.getElementById("messagebox").style.display = "none"; document.getElementById("message").textContent = ""; } function applySuggestion (sElemId) { // sugg try { let sIdParagr = sElemId.slice(4, sElemId.indexOf("_")); startWaitIcon("paragr"+sIdParagr); let sIdErr = "err" + sElemId.slice(4, sElemId.indexOf("-")); document.getElementById(sIdErr).textContent = document.getElementById(sElemId).textContent; document.getElementById(sIdErr).className = "corrected"; document.getElementById(sIdErr).removeAttribute("style"); self.port.emit("correction", sIdParagr, getPurgedTextOfElem("paragr"+sIdParagr)); stopWaitIcon("paragr"+sIdParagr); } catch (e) { showError(e); } } function ignoreError (sElemId) { // ignore let sIdErr = "err" + sElemId.slice(6); let xTooltipElem = document.getElementById("tooltip"+sElemId.slice(6)); document.getElementById(sIdErr).removeChild(xTooltipElem); |
︙ | ︙ | |||
164 165 166 167 168 169 170 | let xTooltipElem = document.getElementById(sTooltipId); let nLimit = nPanelWidth - 300; // paragraph width - tooltip width if (document.getElementById(sElemId).offsetLeft > nLimit) { xTooltipElem.style.left = "-" + (document.getElementById(sElemId).offsetLeft - nLimit) + "px"; } xTooltipElem.setAttribute("contenteditable", false); xTooltipElem.className = 'tooltip_on'; | | | 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 | let xTooltipElem = document.getElementById(sTooltipId); let nLimit = nPanelWidth - 300; // paragraph width - tooltip width if (document.getElementById(sElemId).offsetLeft > nLimit) { xTooltipElem.style.left = "-" + (document.getElementById(sElemId).offsetLeft - nLimit) + "px"; } xTooltipElem.setAttribute("contenteditable", false); xTooltipElem.className = 'tooltip_on'; if (document.getElementById(sElemId).className === "error WORD" && xTooltipElem.textContent.endsWith(":")) { // spelling mistake self.port.emit("getSuggestionsForTo", document.getElementById(sElemId).innerHTML.replace(/<span .*$/, "").trim(), sTooltipId); } } function switchEdition (sElemId) { // edit let sId = "paragr" + sElemId.slice(4); |
︙ | ︙ | |||
232 233 234 235 236 237 238 239 240 241 242 243 244 245 | function hideAllTooltips () { for (let xElem of document.getElementsByClassName("tooltip_on")) { xElem.className = "tooltip"; xElem.removeAttribute("style"); } } function copyToClipboard () { startWaitIcon(); try { document.getElementById("clipboard_msg").textContent = "copie en cours…"; let sText = ""; for (let xNode of document.getElementById("errorlist").getElementsByClassName("paragraph")) { | > > > > > > > > > > > > > > > > > > > > | 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 | function hideAllTooltips () { for (let xElem of document.getElementsByClassName("tooltip_on")) { xElem.className = "tooltip"; xElem.removeAttribute("style"); } } function setSpellSuggestionsFor (sWord, sSuggestions, sTooltipId) { // spell checking suggestions //console.log(sWord + ": " + sSuggestions); let xTooltip = document.getElementById(sTooltipId); if (sSuggestions === "") { xTooltip.appendChild(document.createTextNode("Aucune.")); } else if (sSuggestions.startsWith("#")) { xTooltip.appendChild(document.createTextNode(sSuggestions)); } else { let lSugg = sSuggestions.split("|"); let iSugg = 0; let sElemId = sTooltipId.slice(7); for (let sSugg of lSugg) { xTooltip.appendChild(_createSuggestion(sElemId, iSugg, sSugg)); xTooltip.appendChild(document.createTextNode(" ")); iSugg += 1; } } } function copyToClipboard () { startWaitIcon(); try { document.getElementById("clipboard_msg").textContent = "copie en cours…"; let sText = ""; for (let xNode of document.getElementById("errorlist").getElementsByClassName("paragraph")) { |
︙ | ︙ | |||
267 268 269 270 271 272 273 | function stopWaitIcon (sIdParagr=null) { if (sIdParagr) { document.getElementById(sIdParagr).disabled = false; document.getElementById(sIdParagr).style.opacity = 1; } document.getElementById("waiticon").hidden = true; } | > > > > > > > > > > > | 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 | function stopWaitIcon (sIdParagr=null) { 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); } } } |
Modified gc_lang/fr/xpi/ui.js from [60cc552c6c] to [f61d089690].
︙ | ︙ | |||
414 415 416 417 418 419 420 | let iParagraph = 0; // index of paragraphs, used for identification let nParagraph = 0; // non empty paragraphs let sRes = ""; try { sText = sText.normalize("NFC"); // remove combining diacritics for (let sParagraph of text.getParagraph(sText)) { if (sParagraph.trim() !== "") { | | | | | | 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 | let iParagraph = 0; // index of paragraphs, used for identification let nParagraph = 0; // non empty paragraphs let sRes = ""; try { sText = sText.normalize("NFC"); // remove combining diacritics for (let sParagraph of text.getParagraph(sText)) { if (sParagraph.trim() !== "") { sRes = await xGCEWorker.post('parseAndSpellcheck', [sParagraph, "FR", false, false]); xGCPanel.port.emit("addParagraph", sParagraph, iParagraph, sRes); nParagraph += 1; } iParagraph += 1; } xGCPanel.port.emit("addMessage", 'message', _("numberOfParagraphs") + " " + nParagraph); } catch (e) { xGCPanel.port.emit("addMessage", 'bug', e.message); } xGCPanel.port.emit("end"); } /* Text Formatter |
︙ | ︙ |