function get_player_colors( player_no )
{
// get the colors for the specified player
var player_nat = $( "select[name='PLAYER_" + player_no + "']" ).val() ;
return gTemplatePack.nationalities[ player_nat ].ob_colors ;
}
function get_player_colors_for_element( $elem )
{
// get the player colors (if any) for the specified element
if ( $.contains( $("#tabs-ob1")[0], $elem[0] ) )
return get_player_colors( 1 ) ;
else if ( $.contains( $("#tabs-ob2")[0], $elem[0] ) )
return get_player_colors( 2 ) ;
return null ;
}
// --------------------------------------------------------------------
function copyToClipboard( val )
{
if ( getUrlParam( "store_clipboard" ) ) {
// store the value where the tests can retrieve it
$("#_clipboard_").text( val ) ;
return ;
}
// IE-specific code path to prevent textarea being shown while dialog is visible
if ( window.clipboardData && window.clipboardData.setData ) {
clipboardData.setData( "Text", val ) ;
return ;
}
if ( document.queryCommandSupported && document.queryCommandSupported("copy") ) {
// create a textarea to hold the content
var textarea = document.createElement( "textarea" ) ;
textarea.style.position = "fixed" ; // prevent scrolling to bottom in MS Edge
document.body.appendChild( textarea ) ;
textarea.textContent = val ;
// copy the textarea content to the clipboard
textarea.select() ;
try {
document.execCommand( "copy" ) ;
if ( getUrlParam("log-clipboard") )
console.log( "CLIPBOARD:", val ) ;
}
catch( ex ) {
showErrorMsg( "Can't copy to the clipboard:
" + escapeHTML(ex) + "
" ) ;
}
finally {
document.body.removeChild( textarea ) ;
}
}
}
// --------------------------------------------------------------------
// Connect a text box to a select box, and filter the available options.
( function( $ ) {
$.fn.filterByText = function( $textbox )
{
function compressSpaces( val ) { return val.replace( /\s/g, "" ).trim() ; }
return this.each( function() {
// initialize
var $select = $(this) ;
var $options = [] ;
$select.find( "option" ).each( function() {
$options.push( { value: $(this).val(), text: $(this).text() } ) ;
} ) ;
$select.data( "options", $options ) ;
$textbox.bind( "input", function() {
// prepare the value we will filter on
var val = $(this).val() ;
var adjustCase ;
if ( val !== val.toLowerCase() )
adjustCase = function(val) { return val ; } ; // nb: mixed-case => case-sensitive filtering
else
adjustCase = function(val) { return val.toLowerCase() ; } ;
val = compressSpaces( adjustCase( val ) ) ;
// filter the options
var $options = $select.empty().scrollTop(0).data( "options" ) ;
$.each( $options, function(i) {
var $opt = $options[i] ;
var optVal = compressSpaces( adjustCase( $opt.text ) ) ;
if ( optVal.indexOf( val ) !== -1 ) {
$select.append(
$("