Overview
Comment: | [fx] panel button: stop observing page content, just create one button and move according to the focus (much simplier and more reliable) |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk | fx |
Files: | files | file ages | folders |
SHA3-256: |
d330b8f101a62c8404607c3120d30501 |
User & Date: | olr on 2020-03-31 15:39:03 |
Other Links: | manifest | tags |
Context
2020-03-31
| ||
15:41 | [fx] remove rescanPage command check-in: 45bce0a282 user: olr tags: trunk, fx | |
15:39 | [fx] panel button: stop observing page content, just create one button and move according to the focus (much simplier and more reliable) check-in: d330b8f101 user: olr tags: trunk, fx | |
07:42 | [fr] faux positif et ajustements check-in: b4883f6fda user: olr tags: trunk, fr | |
Changes
Modified gc_lang/fr/webext/content_scripts/init.js from [f2766d89f6] to [e2ae031877].
︙ | ︙ | |||
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | const oGrammalecte = { nButton: 0, lButton: [], oTFPanel: null, oGCPanel: null, oMessageBox: null, xRightClickedNode: null, xObserver: null, sExtensionUrl: null, oOptions: null, bAutoRefresh: true, | > | > > > > > > > > | < < < < < < | < < < < < < < < < < < < | < < < < < < < < < < < < < < < | < < < < < < < < < < < | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 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 | const oGrammalecte = { nButton: 0, lButton: [], oPanelButton: null, oTFPanel: null, oGCPanel: null, oMessageBox: null, xRightClickedNode: null, xObserver: null, sExtensionUrl: null, oOptions: null, bAutoRefresh: true, listen: function () { document.addEventListener("click", (xEvent) => { //console.log("click", xEvent.target.id); this.oPanelButton.examineNode(xEvent.target); }); document.addEventListener("keyup", (xEvent) => { //console.log("keyup", document.activeElement.id); this.oPanelButton.examineNode(document.activeElement); }); // Node where a right click is done // Bug report: https://bugzilla.mozilla.org/show_bug.cgi?id=1325814 document.addEventListener('contextmenu', (xEvent) => { this.xRightClickedNode = xEvent.target; }, true); }, clearRightClickedNode: function () { this.xRightClickedNode = null; }, createButton: function () { if (this.oPanelButton === null) { this.oPanelButton = new GrammalecteButton(); this.oPanelButton.insertIntoPage(); } }, createTFPanel: function () { if (this.oTFPanel === null) { this.oTFPanel = new GrammalecteTextFormatter("grammalecte_tf_panel", "Formateur de texte", 760, 595, false); this.oTFPanel.insertIntoPage(); } |
︙ | ︙ | |||
243 244 245 246 247 248 249 | return xNode; } catch (e) { showError(e); } }, | | | | 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 | return xNode; } catch (e) { showError(e); } }, getCaretPosition: function (xElement) { // JS awfulness again. // recepie from https://stackoverflow.com/questions/4811822/get-a-ranges-start-and-end-offsets-relative-to-its-parent-container let nCaretOffsetStart = 0; let nCaretOffsetEnd = 0; let xSelection = window.getSelection(); if (xSelection.rangeCount > 0) { let xRange = xSelection.getRangeAt(0); let xPreCaretRange = xRange.cloneRange(); xPreCaretRange.selectNodeContents(xElement); xPreCaretRange.setEnd(xRange.endContainer, xRange.endOffset); nCaretOffsetStart = xPreCaretRange.toString().length; nCaretOffsetEnd = nCaretOffsetStart + xRange.toString().length; } return [nCaretOffsetStart, nCaretOffsetEnd]; // for later: solution with multilines text // https://stackoverflow.com/questions/4811822/get-a-ranges-start-and-end-offsets-relative-to-its-parent-container/4812022 }, setCaretPosition: function (xElement, nCaretOffsetStart, nCaretOffsetEnd) { // JS awfulness again. // recipie from https://stackoverflow.com/questions/6249095/how-to-set-caretcursor-position-in-contenteditable-element-div let iChar = 0; let xRange = document.createRange(); xRange.setStart(xElement, 0); xRange.collapse(true); |
︙ | ︙ | |||
296 297 298 299 300 301 302 303 304 305 306 307 308 309 | lNode.push(xNode.childNodes[i]); } } } let xSelection = window.getSelection(); xSelection.removeAllRanges(); xSelection.addRange(xRange); } }; function autoRefreshOption (oSavedOptions=null) { // auto recallable function if (oSavedOptions === null) { | > > > > > > > > > > > > > > | 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 | lNode.push(xNode.childNodes[i]); } } } let xSelection = window.getSelection(); xSelection.removeAllRanges(); xSelection.addRange(xRange); }, getElementCoord: function (xElem) { // https://stackoverflow.com/questions/5598743/finding-elements-position-relative-to-the-document let xBox = xElem.getBoundingClientRect(); let scrollTop = document.documentElement.scrollTop || document.body.scrollTop; let scrollLeft = document.documentElement.scrollLeft || document.body.scrollLeft; let clientTop = document.documentElement.clientTop || document.body.clientTop || 0; let clientLeft = document.documentElement.clientLeft || document.body.clientLeft || 0; let top = xBox.top + scrollTop - clientTop; let left = xBox.left + scrollLeft - clientLeft; let bottom = xBox.bottom + scrollTop - clientTop; let right = xBox.right + scrollLeft - clientLeft; return { top: Math.round(top), left: Math.round(left), bottom: Math.round(bottom), right: Math.round(right) }; } }; function autoRefreshOption (oSavedOptions=null) { // auto recallable function if (oSavedOptions === null) { |
︙ | ︙ | |||
355 356 357 358 359 360 361 | getListOfTokens: function (sText) { this.xConnect.postMessage({ sCommand: "getListOfTokens", oParam: { sText: sText }, oInfo: {} }); }, parseFull: function (sText) { this.xConnect.postMessage({ sCommand: "parseFull", | | | 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 | getListOfTokens: function (sText) { this.xConnect.postMessage({ sCommand: "getListOfTokens", oParam: { sText: sText }, oInfo: {} }); }, parseFull: function (sText) { this.xConnect.postMessage({ sCommand: "parseFull", oParam: { sText: sText, sCountry: "FR", bDebug: false, bContext: false }, oInfo: {} }); }, getVerb: function (sVerb, bStart=true, bPro=false, bNeg=false, bTpsCo=false, bInt=false, bFem=false) { this.xConnect.postMessage({ sCommand: "getVerb", |
︙ | ︙ | |||
389 390 391 392 393 394 395 | }, /* Messages from the background */ listen: function () { this.xConnect.onMessage.addListener(function (oMessage) { | | | | < | 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 | }, /* Messages from the background */ listen: function () { this.xConnect.onMessage.addListener(function (oMessage) { let { sActionDone, result, oInfo, bEnd, bError } = oMessage; switch (sActionDone) { case "init": oGrammalecte.sExtensionUrl = oMessage.sUrl; oGrammalecte.listen(); oGrammalecte.createButton(); break; case "parseAndSpellcheck": if (oInfo.sDestination == "__GrammalectePanel__") { if (!bEnd) { oGrammalecte.oGCPanel.addParagraphResult(result); } else { oGrammalecte.oGCPanel.stopWaitIcon(); |
︙ | ︙ |
Modified gc_lang/fr/webext/content_scripts/menu.css from [949d2c4a43] to [caed9e4799].
1 2 | /* CSS | | < < < | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | /* CSS Button for Grammalecte */ div.grammalecte_menu_main_button { all: initial; position: absolute; box-sizing: border-box; display: none; margin: -12px 0 0 -12px; width: 16px; height: 16px; background-color: hsla(210, 80%, 95%, .5); border: 3px solid hsla(210, 80%, 50%, .9); border-top: 3px solid hsla(210, 80%, 90%, .9); border-left: 3px solid hsla(210, 80%, 90%, .9); border-radius: 50%; |
︙ | ︙ | |||
40 41 42 43 44 45 46 | box-shadow: 0 0 0 10px hsla(210, 50%, 50%, 0); } 100% { transform: rotate(360deg) scale(1); box-shadow: 0 0 0 0 hsla(210, 50%, 50%, 0); } } | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 37 38 39 40 41 42 43 | box-shadow: 0 0 0 10px hsla(210, 50%, 50%, 0); } 100% { transform: rotate(360deg) scale(1); box-shadow: 0 0 0 0 hsla(210, 50%, 50%, 0); } } |
Modified gc_lang/fr/webext/content_scripts/menu.js from [628a40a497] to [85adf4425a].
1 2 3 4 5 6 7 8 | // JavaScript /* jshint esversion:6, -W097 */ /* jslint esversion:6 */ /* global oGrammalecte, showError, window, document */ "use strict"; | < | | | > | > > > > > > > > > > > > > | > > > > | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | | | > | | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 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 | // JavaScript /* jshint esversion:6, -W097 */ /* jslint esversion:6 */ /* global oGrammalecte, showError, window, document */ "use strict"; class GrammalecteButton { constructor () { // the pearl button this.xButton = oGrammalecte.createNode("div", { className: "grammalecte_menu_main_button", textContent: " " }); this.xButton.onclick = () => { if (this.xTextNode) { oGrammalecte.startGCPanel(this.xTextNode); } }; // about the text node this.xTextNode = null; // read user config this._bTextArea = true; this._bEditableNode = true; this._bIframe = false; if (bChrome) { browser.storage.local.get("ui_options", this.setOptions.bind(this)); } else { browser.storage.local.get("ui_options").then(this.setOptions.bind(this), showError); } } setOptions (oOptions) { if (oOptions.hasOwnProperty("ui_options")) { this._bTextArea = oOptions.ui_options.textarea; this._bEditableNode = oOptions.ui_options.editablenode; } } examineNode (xNode) { if (xNode && xNode instanceof HTMLElement && ( ((xNode.tagName == "TEXTAREA" || xNode.tagName == "INPUT") && this._bTextArea && xNode.getAttribute("spellcheck") !== "false") || (xNode.isContentEditable && this._bEditableNode) || (xNode.tagName == "IFRAME" && this._bIframe) ) && xNode.style.display !== "none" && xNode.style.visibility !== "hidden" && !(xNode.dataset.grammalecte_button && xNode.dataset.grammalecte_button == "false")) { this.xTextNode = xNode; this.show() } else { this.xTextNode = null; this.hide(); } } show () { if (this.xTextNode) { this.xButton.style.display = "none"; // we hide it before showing it again to relaunch the animation let oCoord = oGrammalecte.getElementCoord(this.xTextNode); //console.log("top:", oCoord.left, "bottom:", oCoord.top, "left:", oCoord.bottom, "right:", oCoord.right); this.xButton.style.top = `${oCoord.bottom}px`; this.xButton.style.left = `${oCoord.left}px`; this.xButton.style.display = "block"; } } hide () { this.xButton.style.display = "none"; } insertIntoPage () { this.bShadow = document.body.createShadowRoot || document.body.attachShadow; if (this.bShadow) { this.xShadowBtn = oGrammalecte.createNode("div", { style: "display:none; position:absolute; width:0; height:0;" }); this.xShadowBtnNode = this.xShadowBtn.attachShadow({ mode: "open" }); oGrammalecte.createStyle("content_scripts/menu.css", null, this.xShadowBtnNode); this.xShadowBtnNode.appendChild(this.xButton); document.body.appendChild(this.xShadowBtnNode); } else { if (!document.getElementById("grammalecte_cssmenu")) { oGrammalecte.createStyle("content_scripts/menu.css", "grammalecte_cssmenu", document.head); } document.body.appendChild(this.xButton); } } } |