Index: gc_lang/fr/webext/content_scripts/message_box.js ================================================================== --- gc_lang/fr/webext/content_scripts/message_box.js +++ gc_lang/fr/webext/content_scripts/message_box.js @@ -1,15 +1,30 @@ // JavaScript // Panel creator +/* jshint esversion:6, -W097 */ +/* jslint esversion:6 */ +/* global oGrammalecte, xGrammalectePort, showError, window, document, console */ + "use strict"; class GrammalecteMessageBox { - constructor (sId, sTitle) { + constructor (sUrl, sId, sTitle) { this.sId = sId; + this.sUrl = sUrl; + + this.bShadow = document.body.createShadowRoot || document.body.attachShadow; + if (this.bShadow){ + this.oShadowPanel = oGrammalecte.createNode("div", {id: this.sId+"_shadow", style: "width:0;height:0;"}); + this.oShadow = this.oShadowPanel.attachShadow({mode: "open"}); + this.oParent = this.oShadow; + } else { + this.oParent = document; + } + this.xMessageBoxBar = oGrammalecte.createNode("div", {className: "grammalecte_message_box_bar"}); this.xMessageBoxContent = oGrammalecte.createNode("div", {className: "grammalecte_message_box_content"}); this.xMessageBox = this._createPanel(sTitle); } @@ -48,11 +63,22 @@ xButton.onclick = function () { this.hide(); }.bind(this); // better than writing “let that = this;” before the function? return xButton; } insertIntoPage () { - document.body.appendChild(this.xMessageBox); + if (this.bShadow){ + this.oShadow.appendChild( + oGrammalecte.createNode("link", {rel: "stylesheet", type: "text/css", media: "all", href: this.sUrl+"content_scripts/panel.css"}) + ); + this.oShadow.appendChild( + oGrammalecte.createNode("link", {rel: "stylesheet", type: "text/css", media: "all", href: this.sUrl+"content_scripts/message_box.css"}) + ); + this.oShadow.appendChild(this.xMessageBox); + document.body.appendChild(this.oShadowPanel); + } else { + document.body.appendChild(this.xMessageBox); + } } show () { this.xMessageBox.style.display = "block"; }