OSDN Git Service

[feature]sessionStorageを使用して選択を記憶
authorHabu <habu@users.sourceforge.jp>
Tue, 27 Mar 2018 11:50:26 +0000 (20:50 +0900)
committerHabu <habu@users.sourceforge.jp>
Tue, 27 Mar 2018 11:50:26 +0000 (20:50 +0900)
score/popularity_ranking.js
score/tablesorter-theme/style.css

index 2a758fe..e4af128 100644 (file)
@@ -1,10 +1,45 @@
+function storageAvailable(type) {
+         try {
+                   var storage = window[type],
+                             x = '__storage_test__';
+                   storage.setItem(x, x);
+                   storage.removeItem(x);
+                   return true;
+         }
+    catch(e) {
+        return e instanceof DOMException && (
+            // everything except Firefox
+            e.code === 22 ||
+                // Firefox
+                e.code === 1014 ||
+                // test name field too, because code might not be present
+                // everything except Firefox
+                e.name === 'QuotaExceededError' ||
+                // Firefox
+                e.name === 'NS_ERROR_DOM_QUOTA_REACHED') &&
+            // acknowledge QuotaExceededError only if there's something already stored
+            storage.length !== 0;
+    }
+}
+
 function select_table(table_id)
 {
+    if (table_id === null) {
+        if (storageAvailable('sessionStorage')) {
+            table_id = sessionStorage.getItem('selected_table');
+        }
+        table_id = table_id ? table_id : "race_id";
+    }
+
     $("table.statistics_table").hide();
     $("div#" + table_id + " table.statistics_table").show();
 
     $("a.table_select").css('font-weight', 'normal').css('font-size', 'small');
     $("a.table_select#" + table_id).css('font-weight', 'bold').css('font-size', 'large');
+
+    if (storageAvailable('sessionStorage')) {
+        sessionStorage.setItem('selected_table', table_id);
+    }
 }
 
 $(function(){
@@ -18,5 +53,5 @@ $(function(){
         select_table($(this).attr("id"));
     });
 
-    select_table("race_id"); //初期は種族を表示
+    select_table(null);
 });
index 891e570..e45ea50 100644 (file)
@@ -49,3 +49,7 @@ table.tablesorter thead tr .headerSortDown {
 table.tablesorter thead tr .headerSortDown, table.tablesorter thead tr .headerSortUp {
        border: 3px ridge #d27d00;
 }
+
+table.statistics_table {
+    display: none;
+}