slotted-node-editor.js (1653B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 "use strict"; 6 7 const { LocalizationHelper } = require("resource://devtools/shared/l10n.js"); 8 const INSPECTOR_L10N = new LocalizationHelper( 9 "devtools/client/locales/inspector.properties" 10 ); 11 12 class SlottedNodeEditor { 13 constructor(container, node) { 14 this.container = container; 15 this.markup = this.container.markup; 16 this.buildMarkup(); 17 this.tag.textContent = "<" + node.nodeName.toLowerCase() + ">"; 18 19 // Make the "tag" part of this editor focusable. 20 this.tag.setAttribute("tabindex", "-1"); 21 } 22 buildMarkup() { 23 const doc = this.markup.doc; 24 25 this.elt = doc.createElement("span"); 26 this.elt.classList.add("editor"); 27 28 this.tag = doc.createElement("span"); 29 this.tag.classList.add("tag"); 30 this.elt.appendChild(this.tag); 31 32 this.revealLink = doc.createElement("span"); 33 this.revealLink.setAttribute("role", "link"); 34 this.revealLink.setAttribute("tabindex", -1); 35 this.revealLink.title = INSPECTOR_L10N.getStr( 36 "markupView.revealLink.tooltip" 37 ); 38 this.revealLink.classList.add("reveal-link"); 39 this.elt.appendChild(this.revealLink); 40 } 41 42 destroy() { 43 // We might be already destroyed. 44 if (!this.elt) { 45 return; 46 } 47 48 this.elt.remove(); 49 this.elt = null; 50 this.tag = null; 51 this.revealLink = null; 52 } 53 54 /** 55 * Stub method for consistency with ElementEditor. 56 */ 57 getInfoAtNode() { 58 return null; 59 } 60 } 61 62 module.exports = SlottedNodeEditor;