SCENARIO_IMAGES_SOURCE_THIS_PROGRAM = 1 ; SCENARIO_IMAGES_SOURCE_INTERNET = 2 ; gUserSettings = Cookies.getJSON( "user-settings" ) || { "scenario-images-source": SCENARIO_IMAGES_SOURCE_THIS_PROGRAM } ; USER_SETTINGS = { "snippet-font-family": "text", "snippet-font-size": "text", "date-format": "droplist", "scenario-images-source": "droplist", "hide-unavailable-ma-notes": "checkbox", "include-vasl-images-in-snippets": "checkbox", "include-flags-in-snippets": "checkbox", "custom-list-bullets": "checkbox", "vo-notes-as-images": "checkbox", } ; // -------------------------------------------------------------------- function user_settings() { function load_settings() { // load each user setting for ( var name in USER_SETTINGS ) { var $elem = $( ".ui-dialog.user-settings [name='" + name + "']" ) ; var func = handlers[ "load_" + USER_SETTINGS[name] ] ; func( $elem, gUserSettings[name] ) ; } update_ui() ; } function unload_settings() { // unload each user setting var settings = {} ; for ( var name in USER_SETTINGS ) { var $elem = $( ".ui-dialog.user-settings [name='" + name + "']" ) ; func = handlers[ "unload_" + USER_SETTINGS[name] ] ; settings[name] = func( $elem ) ; } return settings ; } function update_ui() { // update the UI var images_source = $( ".ui-dialog.user-settings select[name='scenario-images-source']" ).val() ; $( ".ui-dialog.user-settings img.need-localhost.sometimes" ).css( "display", (images_source == SCENARIO_IMAGES_SOURCE_THIS_PROGRAM) ? "inline-block" : "none" ) ; // update the UI var rc = false ; $( ".ui-dialog.user-settings input.need-localhost:checked" ).each( function() { if ( $(this).hasClass( "sometimes" ) ) { if ( images_source == SCENARIO_IMAGES_SOURCE_THIS_PROGRAM ) rc = true ; } else rc = true ; } ) ; $( ".ui-dialog.user-settings div.need-localhost" ).css( "display", rc ? "block" : "none" ) ; } var handlers = { load_checkbox: function( $elem, val ) { $elem.prop( "checked", val?true:false ) ; }, unload_checkbox: function( $elem ) { return $elem.prop( "checked" ) ; }, load_droplist: function( $elem, val ) { if ( val ) $elem.val( val ) ; }, unload_droplist: function( $elem ) { return $elem.children(":selected").val() ; }, load_text: function( $elem, val ) { $elem.val( val ? val.trim() : "" ) ; }, unload_text: function( $elem ) { return $elem.val().trim() ; }, } ; // show the "user settings" dialog $( "#user-settings" ).dialog( { title: "User settings", dialogClass: "user-settings", modal: true, width: 460, height: 320, resizable: false, create: function() { init_dialog( $(this), "OK", true ) ; // initialize the "this program must be running" warnings $( "input.need-localhost" ).each( function() { var $img = $( "" ) ; if ( $(this).hasClass( "sometimes" ) ) $img.addClass( "sometimes" ) ; $img.attr( "title", "If you turn this option on, this program must be running\nbefore you load scenarios into VASSAL." ) ; $(this).next().before( $img ) ; } ) ; var $btn_pane = $(".ui-dialog.user-settings .ui-dialog-buttonpane") ; $btn_pane.prepend( $( "