Index: gc_lang/fr/webext/content_scripts/init.js ================================================================== --- gc_lang/fr/webext/content_scripts/init.js +++ gc_lang/fr/webext/content_scripts/init.js @@ -96,11 +96,11 @@ observePage: function () { /* When a textarea is added via jascript we add the menu :) */ - let this.xObserver = new MutationObserver(function (mutations) { + this.xObserver = new MutationObserver(function (mutations) { mutations.forEach(function (mutation) { for (let i = 0; i < mutation.addedNodes.length; i++){ if (mutation.addedNodes[i].getElementsByTagName) { if (mutation.addedNodes[i].tagName == "TEXTAREA") { oGrammalecte.lMenu.push(new GrammalecteMenu(oGrammalecte.nMenu, mutation.addedNodes[i])); Index: gc_lang/fr/webext/content_scripts/menu.js ================================================================== --- gc_lang/fr/webext/content_scripts/menu.js +++ gc_lang/fr/webext/content_scripts/menu.js @@ -11,32 +11,29 @@ this.xButton = oGrammalecte.createNode("div", {className: "grammalecte_menu_main_button", textContent: " "}); this.xButton.onclick = () => { this.switchMenu(); }; this.xButton.style.zIndex = (xNode.style.zIndex.search(/^[0-9]+$/) !== -1) ? (parseInt(xNode.style.zIndex) + 1).toString() : xNode.style.zIndex; this.xMenu = this._createMenu(); - let style = window.getComputedStyle(this.xNode); - let topMargin = -1 * (8 + parseInt(style.marginBottom.replace('px', ''), 10)); - - let insAfterThis = this.xNode; - if ( document.location.host == "twitter.com" && this.xNode.classList.contains('rich-editor')){ - insAfterThis = this.xNode.parentNode; - } - - this._insertAfter(this.xButton, insAfterThis); - this.xButton.style.marginTop = topMargin + 'px'; - - this._insertAfter(this.xMenu, insAfterThis); - this.xMenu.style.marginTop = (topMargin + 8) + 'px'; - - this._createListenersOnReferenceNode(); - } - - _insertAfter (xNewNode, xReferenceNode) { - xReferenceNode.parentNode.insertBefore(xNewNode, xReferenceNode.nextSibling); - } - - _createListenersOnReferenceNode () { + let xStyle = window.getComputedStyle(this.xNode); + let nMarginTop = -1 * (8 + parseInt(xStyle.marginBottom.replace('px', ''), 10)); + + let xNodeInsertAfter = this.xNode; + if (document.location.host == "twitter.com" && this.xNode.classList.contains('rich-editor')) { + xNodeInsertAfter = this.xNode.parentNode; + } + + this._insertAfter(this.xButton, xNodeInsertAfter, nMarginTop); + this._insertAfter(this.xMenu, xNodeInsertAfter, nMarginTop + 8); + this._createListeners(); + } + + _insertAfter (xNewNode, xReferenceNode, nMarginTop) { + xReferenceNode.parentNode.insertBefore(xNewNode, xReferenceNode.nextSibling); + xNewNode.style.marginTop = nMarginTop + "px"; + } + + _createListeners () { this.xNode.addEventListener('focus', (e) => { this.xButton.style.display = "block"; }); this.xNode.addEventListener('blur', (e) => { window.setTimeout(() => {this.xButton.style.display = "none";}, 300);