diff --git a/vasl_templates/webapp/static/extras.js b/vasl_templates/webapp/static/extras.js index 44a0bec..d8a623e 100644 --- a/vasl_templates/webapp/static/extras.js +++ b/vasl_templates/webapp/static/extras.js @@ -90,6 +90,7 @@ function _show_extra_template( template_id ) buf.push( "" ) ; buf.push( "" ) ; var $form = $( buf.join("") ) ; + fixup_external_links( $form ) ; // initialize the "generate" button init_snippet_button( $form.find( "button.generate" ) ) ; diff --git a/vasl_templates/webapp/static/main.js b/vasl_templates/webapp/static/main.js index c1dc007..095ade9 100644 --- a/vasl_templates/webapp/static/main.js +++ b/vasl_templates/webapp/static/main.js @@ -34,6 +34,7 @@ $(document).ready( function () { // FUDGE! If the page finishes loading before the web channel is ready, // the desktop won't get this notification. To be sure, we issue it again... gWebChannelHandler.on_app_loaded() ; + fixup_external_links( $("body") ) ; // ditto for this :-/ } ) ; } ) ; } @@ -518,7 +519,7 @@ function update_page_load_status( id ) // notify the PyQT desktop application if ( gWebChannelHandler ) gWebChannelHandler.on_app_loaded() ; - // show any startuup messages + // show any startup messages $.get( gGetStartupMsgsUrl, function( resp ) { $("body").append( $("
") ) ; show_startup_msgs( resp, "error" ) ; diff --git a/vasl_templates/webapp/static/simple_notes.js b/vasl_templates/webapp/static/simple_notes.js index 21c62b4..2289460 100644 --- a/vasl_templates/webapp/static/simple_notes.js +++ b/vasl_templates/webapp/static/simple_notes.js @@ -134,6 +134,7 @@ function _make_simple_note( note_type, caption ) } buf.push( caption, "" ) ; var $content = $( buf.join("") ) ; + fixup_external_links( $content ) ; $content.children( "img" ).hover( function() { $(this).attr( "src", gImagesBaseUrl + "/snippet-hot.png" ) ; }, function() { $(this).attr( "src", gImagesBaseUrl + "/snippet.png" ) ; } diff --git a/vasl_templates/webapp/static/utils.js b/vasl_templates/webapp/static/utils.js index 1d7d2c6..3e73efc 100644 --- a/vasl_templates/webapp/static/utils.js +++ b/vasl_templates/webapp/static/utils.js @@ -345,6 +345,19 @@ function add_flag_to_dialog_titlebar( $dlg, player_no ) // -------------------------------------------------------------------- +function fixup_external_links( $root ) +{ + // NOTE: We want to open externals links in a new browser window, but simply adding target="_blank" + // breaks the desktop app's ability to intercept clicks (in AppWebPage.acceptNavigationRequest()), + // so we do it dynamically here. + var regex = new RegExp( "^https?://" ) ; + $root.find( "a" ).each( function() { + var url = $(this).attr( "href" ) ; + if ( url && url.match( regex ) ) + $(this).attr( "target", gWebChannelHandler?"":"_blank" ) ; + } ) ; +} + function getUrlParam( param ) { // look for the specified URL parameter