// -------------------------------------------------------------------- function make_app_url( url, for_snippet ) { // generate a URL that accesses this webapp var base_url = window.location.origin ; if ( for_snippet && gAppConfig.ALTERNATE_WEBAPP_BASE_URL ) base_url = gAppConfig.ALTERNATE_WEBAPP_BASE_URL ; return base_url + url ; } function get_nationality_display_name( nat_id ) { // get the nationality's display name if ( ! gTemplatePack.nationalities || ! gTemplatePack.nationalities[nat_id] ) return null ; 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_sorted_nats() { // sort the nationalities by display name var nats = Object.keys( gTemplatePack.nationalities ) ; nats.sort( function( lhs, rhs ) { lhs = gTemplatePack.nationalities[lhs].display_name.toUpperCase() ; rhs = gTemplatePack.nationalities[rhs].display_name.toUpperCase() ; if ( lhs < rhs ) return -1 ; else if ( lhs > rhs ) return +1 ; else return 0 ; } ) ; return nats ; } function get_player_colors( player_no ) { // get the colors for the specified player // NOTE: The returned color array holds the following values: // [ background, hover background, border ] 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 if ( $elem.attr( "id" ).substr( 0, 18 ) === "ob_notes-sortable_" ) return null ; 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( nat, for_snippet ) { if ( ! gTemplatePack.nationalities ) return null ; if ( for_snippet && gUserSettings["scenario-images-source"] == SCENARIO_IMAGES_SOURCE_INTERNET ) return gAppConfig.ONLINE_IMAGES_URL_BASE + "/flags/" + nat + ".png" ; else { var url = "/flags/" + nat ; return make_app_url( url, for_snippet ) ; } } 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 ; // NOTE: Returning a Javascript Date object creates massive headaches since it is adjusted // for the current timezone, so we avoid problems by extracting the date fields here, and // discarding the time fields. var date=scenario_date.getDate(), month=1+scenario_date.getMonth(), year=scenario_date.getFullYear() ; return [ date, month, year, year + "-" + pad(month,2,"0") + "-" + pad(date,2,"0"), date + " " + get_month_name(month) + ", " + year ] ; } function is_template_available( template_id ) { // check if the specified template is available if ( template_id.match( /^ob_(vehicles|ordnance).*_[12]$/ ) ) template_id = template_id.substring( 0, template_id.length-2 ) ; else if ( template_id === "nat_caps_1" || template_id === "nat_caps_2" ) template_id = "nat_caps" ; return gTemplatePack.templates[ template_id ] !== undefined ; } // -------------------------------------------------------------------- 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( $("