michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: "use strict"; michael@0: michael@0: const { on } = require("../system/events"); michael@0: const core = require("./core"); michael@0: const { id: jetpackId} = require('../self'); michael@0: michael@0: const OPTIONS_DISPLAYED = "addon-options-displayed"; michael@0: michael@0: function onOptionsDisplayed({ subject: document, data: addonId }) { michael@0: if (addonId !== jetpackId) michael@0: return; michael@0: let query = 'setting[data-jetpack-id="' + jetpackId + '"][pref-name], ' + michael@0: 'button[data-jetpack-id="' + jetpackId + '"][pref-name]'; michael@0: let nodes = document.querySelectorAll(query); michael@0: for (let node of nodes) { michael@0: let name = node.getAttribute("pref-name"); michael@0: if (node.tagName == "setting") { michael@0: let desc = core.get(name + "_description"); michael@0: if (desc) michael@0: node.setAttribute("desc", desc); michael@0: let title = core.get(name + "_title"); michael@0: if (title) michael@0: node.setAttribute("title", title); michael@0: michael@0: for (let item of node.querySelectorAll("menuitem, radio")) { michael@0: let key = name + "_options." + item.getAttribute("label"); michael@0: let label = core.get(key); michael@0: if (label) michael@0: item.setAttribute("label", label); michael@0: } michael@0: } michael@0: else if (node.tagName == "button") { michael@0: let label = core.get(name + "_label"); michael@0: if (label) michael@0: node.setAttribute("label", label); michael@0: } michael@0: } michael@0: } michael@0: on(OPTIONS_DISPLAYED, onOptionsDisplayed);