@@ -52,7 +52,8 @@ define(function (require, exports, module) {
5252 UnitTestReporter = require ( "test/UnitTestReporter" ) . UnitTestReporter ,
5353 NodeConnection = require ( "utils/NodeConnection" ) ,
5454 BootstrapReporterView = require ( "test/BootstrapReporterView" ) . BootstrapReporterView ,
55- ColorUtils = require ( "utils/ColorUtils" ) ;
55+ ColorUtils = require ( "utils/ColorUtils" ) ,
56+ NativeApp = require ( "utils/NativeApp" ) ;
5657
5758 // Load modules that self-register and just need to get included in the main project
5859 require ( "document/ChangedDocumentTracker" ) ;
@@ -357,6 +358,30 @@ define(function (require, exports, module) {
357358
358359 $ ( window . document ) . ready ( _documentReadyHandler ) ;
359360 } ) ;
361+
362+
363+ // Prevent clicks on any link from navigating to a different page (which could lose unsaved
364+ // changes). We can't use a simple .on("click", "a") because of http://bugs.jquery.com/ticket/3861:
365+ // jQuery hides non-left clicks from such event handlers, yet middle-clicks still cause CEF to
366+ // navigate. Also, a capture handler is more reliable than bubble.
367+ window . document . body . addEventListener ( "click" , function ( e ) {
368+ // Check parents too, in case link has inline formatting tags
369+ var node = e . target , url ;
370+ console . log ( 1 ) ;
371+ while ( node ) {
372+ console . log ( node . tagName ) ;
373+ if ( node . tagName === "A" ) {
374+ url = node . getAttribute ( "href" ) ;
375+ console . log ( url ) ;
376+ if ( url && url . match ( / ^ h t t p / ) ) {
377+ NativeApp . openURLInDefaultBrowser ( url ) ;
378+ e . preventDefault ( ) ;
379+ }
380+ break ;
381+ }
382+ node = node . parentElement ;
383+ }
384+ } , true ) ;
360385 }
361386
362387 /**
0 commit comments