mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-26 06:11:37 +00:00
Bug 1288752
- mdndocs tooltip: consistent behavior on Visit MDN Page link click;r=bgrins
MozReview-Commit-ID: Kg0yYwi4nwV --HG-- extra : rebase_source : a794315867ab770a95c8d432dd1934bd9835efec
This commit is contained in:
parent
ae7bd89cb6
commit
70894bd879
@ -27,6 +27,7 @@
|
||||
const Services = require("Services");
|
||||
const defer = require("devtools/shared/defer");
|
||||
const {getCSSLexer} = require("devtools/shared/css-lexer");
|
||||
const EventEmitter = require("devtools/shared/event-emitter");
|
||||
const {gDevTools} = require("devtools/client/framework/devtools");
|
||||
|
||||
const XHTML_NS = "http://www.w3.org/1999/xhtml";
|
||||
@ -238,6 +239,8 @@ exports.getCssDocs = getCssDocs;
|
||||
* A DOM element where the MdnDocs widget markup should be created.
|
||||
*/
|
||||
function MdnDocsWidget(tooltipContainer) {
|
||||
EventEmitter.decorate(this);
|
||||
|
||||
tooltipContainer.innerHTML =
|
||||
`<header>
|
||||
<h1 class="mdn-property-name theme-fg-color5"></h1>
|
||||
@ -265,10 +268,11 @@ function MdnDocsWidget(tooltipContainer) {
|
||||
|
||||
// listen for clicks and open in the browser window instead
|
||||
let mainWindow = Services.wm.getMostRecentWindow(gDevTools.chromeWindowType);
|
||||
this.elements.linkToMdn.addEventListener("click", function (e) {
|
||||
this.elements.linkToMdn.addEventListener("click", (e) => {
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
mainWindow.openUILinkIn(e.target.href, "tab", { inBackground: true });
|
||||
mainWindow.openUILinkIn(e.target.href, "tab");
|
||||
this.emit("visitlink");
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -29,13 +29,14 @@ function CssDocsTooltip(toolbox) {
|
||||
stylesheet: "chrome://devtools/content/shared/widgets/mdn-docs.css",
|
||||
});
|
||||
this.widget = this.setMdnDocsContent();
|
||||
this._onVisitLink = this._onVisitLink.bind(this);
|
||||
this.widget.on("visitlink", this._onVisitLink);
|
||||
|
||||
// Initialize keyboard shortcuts
|
||||
this.shortcuts = new KeyShortcuts({ window: toolbox.doc.defaultView });
|
||||
this._onShortcut = this._onShortcut.bind(this);
|
||||
|
||||
this.shortcuts.on("Escape", this._onShortcut);
|
||||
this.shortcuts.on("Return", this._onShortcut);
|
||||
}
|
||||
|
||||
module.exports.CssDocsTooltip = CssDocsTooltip;
|
||||
@ -60,17 +61,13 @@ CssDocsTooltip.prototype = {
|
||||
if (!this.tooltip.isVisible()) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.stopPropagation();
|
||||
if (shortcut === "Return") {
|
||||
// If user is pressing return, do not prevent default and delay hiding the tooltip
|
||||
// in case the focus is on the "Visit MDN page" link.
|
||||
this.tooltip.doc.defaultView.setTimeout(this.hide.bind(this), 0);
|
||||
} else {
|
||||
// For any other key, preventDefault() and hide straight away.
|
||||
event.preventDefault();
|
||||
this.hide();
|
||||
}
|
||||
event.preventDefault();
|
||||
this.hide();
|
||||
},
|
||||
|
||||
_onVisitLink: function () {
|
||||
this.hide();
|
||||
},
|
||||
|
||||
/**
|
||||
@ -89,6 +86,9 @@ CssDocsTooltip.prototype = {
|
||||
},
|
||||
|
||||
destroy: function () {
|
||||
this.widget.off("visitlink", this._onVisitLink);
|
||||
this.widget.destroy();
|
||||
|
||||
this.shortcuts.destroy();
|
||||
this.tooltip.destroy();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user