@@ -22,6 +22,7 @@ var ViewSwitcher = require('ampersand-view-switcher');
2222var View = require ( 'ampersand-view' ) ;
2323var localLinks = require ( 'local-links' ) ;
2424var async = require ( 'async' ) ;
25+ var shell = window . require ( 'shell' ) ;
2526
2627var QueryOptions = require ( './models/query-options' ) ;
2728var 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+
275313app . 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 ( {
0 commit comments