From 5f8de423f190bbb79a62f804151bc24824fa32d8 Mon Sep 17 00:00:00 2001 From: "Matt A. Tobin" Date: Fri, 2 Feb 2018 04:16:08 -0500 Subject: Add m-esr52 at 52.6.0 --- devtools/shared/gcli/commands/mdn.js | 83 ++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 devtools/shared/gcli/commands/mdn.js (limited to 'devtools/shared/gcli/commands/mdn.js') diff --git a/devtools/shared/gcli/commands/mdn.js b/devtools/shared/gcli/commands/mdn.js new file mode 100644 index 000000000..57e582e40 --- /dev/null +++ b/devtools/shared/gcli/commands/mdn.js @@ -0,0 +1,83 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +"use strict"; + +const l10n = require("gcli/l10n"); + +var MdnDocsWidget; +try { + MdnDocsWidget = require("devtools/client/shared/widgets/MdnDocsWidget"); +} catch (e) { + // DevTools MdnDocsWidget only available in Firefox Desktop +} + +exports.items = [{ + name: "mdn", + description: l10n.lookup("mdnDesc") +}, { + item: "command", + runAt: "client", + name: "mdn css", + description: l10n.lookup("mdnCssDesc"), + returnType: "cssPropertyOutput", + params: [{ + name: "property", + type: { name: "string" }, + defaultValue: null, + description: l10n.lookup("mdnCssProp") + }], + exec: function(args) { + if (!MdnDocsWidget) { + return null; + } + + return MdnDocsWidget.getCssDocs(args.property).then(result => { + return { + data: result, + url: MdnDocsWidget.PAGE_LINK_URL + args.property, + property: args.property + }; + }, error => { + return { error, property: args.property }; + }); + } +}, { + item: "converter", + from: "cssPropertyOutput", + to: "dom", + exec: function(result, context) { + let propertyName = result.property; + + let document = context.document; + let root = document.createElement("div"); + + if (result.error) { + // The css property specified doesn't exist. + root.appendChild(document.createTextNode( + l10n.lookupFormat("mdnCssPropertyNotFound", [ propertyName ]) + + " (" + result.error + ")")); + } else { + let title = document.createElement("h2"); + title.textContent = propertyName; + root.appendChild(title); + + let link = document.createElement("p"); + link.classList.add("gcli-mdn-url"); + link.textContent = l10n.lookup("mdnCssVisitPage"); + root.appendChild(link); + + link.addEventListener("click", () => { + let mainWindow = context.environment.chromeWindow; + mainWindow.openUILinkIn(result.url, "tab"); + }); + + let summary = document.createElement("p"); + summary.textContent = result.data.summary; + root.appendChild(summary); + } + + return root; + } +}]; -- cgit v1.2.3