]> git.sesse.net Git - remoteglot/commitdiff
Store sound and sorting settings in HTML5 local storage.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 22 Nov 2014 01:43:52 +0000 (02:43 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 22 Nov 2014 01:43:52 +0000 (02:43 +0100)
www/js/remoteglot.js

index cd2ffa5ccb04c548aa706cf05be73f6ad2c7c4d9..ac3f8e97adc6d29a08f92ed4027de9f5dac5e582 100644 (file)
@@ -829,6 +829,9 @@ var format_move_with_number = function(move, move_num, white_to_play) {
  */
 var resort_refutation_lines = function(sort_by_score) {
        sort_refutation_lines_by_score = sort_by_score;
+       if (supports_html5_storage()) {
+               localStorage['sort_refutation_lines_by_score'] = sort_by_score ? 1 : 0;
+       }
        update_refutation_lines();
 }
 window['resort_refutation_lines'] = resort_refutation_lines;
@@ -964,12 +967,26 @@ var set_sound = function(param_enable_sound) {
                $("#soundon").html("<a href=\"javascript:set_sound(true)\">On</a>");
                $("#soundoff").html("<strong>Off</strong>");
        }
+       if (supports_html5_storage()) {
+               localStorage['enable_sound'] = enable_sound ? 1 : 0;
+       }
 }
 window['set_sound'] = set_sound;
 
 var init = function() {
        unique = get_unique();
-       set_sound(false);
+
+       // Load settings from HTML5 local storage if available.
+       if (supports_html5_storage() && localStorage['enable_sound']) {
+               set_sound(parseInt(localStorage['enable_sound']));
+       } else {
+               set_sound(false);
+       }
+       if (supports_html5_storage() && localStorage['sort_refutation_lines_by_score']) {
+               sort_refutation_lines_by_score = parseInt(localStorage['sort_refutation_lines_by_score']);
+       } else {
+               sort_refutation_lines_by_score = true;
+       }
 
        // Create board.
        board = new window.ChessBoard('board', 'start');