Handle opening external links in a new browser window properly.

master
Pacman Ghost 5 years ago
parent 82677e5d32
commit ed3ec863a2
  1. 1
      vasl_templates/webapp/static/extras.js
  2. 3
      vasl_templates/webapp/static/main.js
  3. 1
      vasl_templates/webapp/static/simple_notes.js
  4. 13
      vasl_templates/webapp/static/utils.js

@ -90,6 +90,7 @@ function _show_extra_template( template_id )
buf.push( "<button class='generate' data-id='" + template_info.template_id + "'>Snippet</button>" ) ;
buf.push( "</div>" ) ;
var $form = $( buf.join("") ) ;
fixup_external_links( $form ) ;
// initialize the "generate" button
init_snippet_button( $form.find( "button.generate" ) ) ;

@ -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( $("<div id='_startup-msgs-ready_'></div>") ) ;
show_startup_msgs( resp, "error" ) ;

@ -134,6 +134,7 @@ function _make_simple_note( note_type, caption )
}
buf.push( caption, "</div>" ) ;
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" ) ; }

@ -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

Loading…
Cancel
Save