@@ -22,6 +22,7 @@ var ViewSwitcher = require('ampersand-view-switcher');
22
22
var View = require ( 'ampersand-view' ) ;
23
23
var localLinks = require ( 'local-links' ) ;
24
24
var async = require ( 'async' ) ;
25
+ var shell = window . require ( 'shell' ) ;
25
26
26
27
var QueryOptions = require ( './models/query-options' ) ;
27
28
var Connection = require ( './models/connection' ) ;
@@ -258,10 +259,16 @@ var Application = View.extend({
258
259
this . pageSwitcher . set ( view ) ;
259
260
} ,
260
261
onLinkClick : function ( event ) {
262
+ debug ( 'onLinkClick' , event ) ;
261
263
var pathname = localLinks . getLocalPathname ( event ) ;
262
264
if ( pathname ) {
263
265
event . preventDefault ( ) ;
264
266
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 ) ;
265
272
}
266
273
}
267
274
} ) ;
@@ -272,6 +279,37 @@ var state = new Application({
272
279
connection_id : connectionId
273
280
} ) ;
274
281
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
+
275
313
app . extend ( {
276
314
client : null ,
277
315
config : {
@@ -301,6 +339,8 @@ app.extend({
301
339
return ;
302
340
}
303
341
342
+ handleIntercomLinks ( ) ;
343
+
304
344
app . statusbar . show ( 'Retrieving connection details...' ) ;
305
345
306
346
state . connection = new Connection ( {
0 commit comments