// -------------------------------------------------------------------- function get_nationality_display_name( nat_id ) { // get the nationality's display name return gTemplatePack.nationalities[ nat_id ].display_name ; } function get_player_nat( player_no ) { // get the player's nationality if ( player_no === null ) return null ; return $( "select[name='PLAYER_" + player_no + "']" ).val() ; } function get_player_colors( player_no ) { // get the colors for the specified player var player_nat = get_player_nat( player_no ) ; return gTemplatePack.nationalities[ player_nat ].ob_colors ; } function get_player_colors_for_element( $elem ) { // get the player colors (if any) for the specified element var player_no = get_player_no_for_element( $elem ) ; if ( player_no === null ) return null ; return get_player_colors( player_no ) ; } function make_player_flag_url( player_nat ) { return APP_URL_BASE + "/flags/" + player_nat ; } function get_player_no_for_element( $elem ) { // get the player that owns the specified element if ( $.contains( $("#tabs-ob1")[0], $elem[0] ) ) return 1 ; if ( $.contains( $("#tabs-ob2")[0], $elem[0] ) ) return 2 ; return null ; } function get_scenario_date() { // get the scenario date var scenario_date = $("input[name='SCENARIO_DATE']").datepicker( "getDate" ) ; if ( ! scenario_date ) return null ; scenario_date.setMinutes( scenario_date.getMinutes() - scenario_date.getTimezoneOffset() ) ; return scenario_date ; } // -------------------------------------------------------------------- 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( $("