Skip to content

Commit 38f12f3

Browse files
rueckstiesskangas
authored andcommitted
INT-959 Open links in external browser
(cherry picked from commit b634647)
1 parent 5343c44 commit 38f12f3

File tree

3 files changed

+49
-10
lines changed

3 files changed

+49
-10
lines changed

src/app.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ var ViewSwitcher = require('ampersand-view-switcher');
2222
var View = require('ampersand-view');
2323
var localLinks = require('local-links');
2424
var async = require('async');
25+
var shell = window.require('shell');
2526

2627
var QueryOptions = require('./models/query-options');
2728
var Connection = require('./models/connection');
@@ -258,10 +259,16 @@ var Application = View.extend({
258259
this.pageSwitcher.set(view);
259260
},
260261
onLinkClick: function(event) {
262+
debug('onLinkClick', event);
261263
var pathname = localLinks.getLocalPathname(event);
262264
if (pathname) {
263265
event.preventDefault();
264266
this.router.history.navigate(pathname);
267+
return;
268+
} else if (event.currentTarget.getAttribute('href') !== '#') {
269+
event.preventDefault();
270+
event.stopPropagation();
271+
shell.openExternal(event.target.href);
265272
}
266273
}
267274
});
@@ -272,6 +279,37 @@ var state = new Application({
272279
connection_id: connectionId
273280
});
274281

282+
function handleIntercomLinks() {
283+
function getNodeObserver(fn) {
284+
var observer = new MutationObserver(function(mutations) {
285+
mutations.forEach(function(mutation) {
286+
if (!mutation.addedNodes) {
287+
return;
288+
}
289+
[].forEach.call(mutation.addedNodes, fn);
290+
});
291+
});
292+
return observer;
293+
}
294+
295+
var lookForLinks = getNodeObserver(function(element) {
296+
if (element.nodeName === 'A') {
297+
$(element).click(state.onLinkClick.bind(state));
298+
}else {
299+
$(element).find('a').click(state.onLinkClick.bind(state));
300+
}
301+
});
302+
303+
var waitForIntercom = getNodeObserver(function(element) {
304+
if (element.id === 'intercom-container') { // if intercom is now available...
305+
lookForLinks.observe(element, {childList: true, subtree: true});
306+
waitForIntercom.disconnect(); // stop waiting for intercom
307+
}
308+
});
309+
310+
waitForIntercom.observe(document.body, {childList: true});
311+
}
312+
275313
app.extend({
276314
client: null,
277315
config: {
@@ -301,6 +339,8 @@ app.extend({
301339
return;
302340
}
303341

342+
handleIntercomLinks();
343+
304344
app.statusbar.show('Retrieving connection details...');
305345

306346
state.connection = new Connection({

src/help/entries/dev-how-help-works.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,12 @@ a help entry like so:
9797
![](./images/help/my_image.png)
9898
```
9999

100+
##### External Links
101+
102+
External links are supported and detected automatically, see for example the
103+
[MongoDB Manual](https://docs.mongodb.org/manual/). It should open in the user's
104+
default browser, not Compass.
105+
100106
### Known Issues
101107

102108
- The help system currently doesn't support external links yet.
103-
- The help window is not yet a singleton
104-
- The help window is too big
105-
- The help window needs styling
106-
- The sidebar should have some hierarchy to find articles faster
107-
- The sidebar should have a filter at the top to find articles faster
108-
- The help system should be accessible from the Help menu

src/help/index.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,10 @@ var HelpPage = View.extend({
6767
this.listenTo(app, 'show-help-entry', this.show.bind(this));
6868
},
6969
onLinkClicked: function(evt) {
70-
evt.preventDefault();
71-
evt.stopPropagation();
72-
// @todo handle external links
7370
var entryId = evt.delegateTarget.hash.slice(1);
74-
if (entryId) {
71+
if (entryId && entries.get(entryId)) {
72+
evt.preventDefault();
73+
evt.stopPropagation();
7574
this.show(entryId);
7675
}
7776
},

0 commit comments

Comments
 (0)