Ver código fonte

Adding support for saving cards to the local store

Jeffrey Snell 8 anos atrás
pai
commit
bacbdb2c51
1 arquivos alterados com 26 adições e 1 exclusões
  1. 26
    1
      generator/js/ui.js

+ 26
- 1
generator/js/ui.js Ver arquivo

@@ -192,6 +192,7 @@ function ui_update_selected_card() {
192 192
         $("#card-color").val("").change();
193 193
     }
194 194
 
195
+    local_store_save();
195 196
     ui_render_selected_card();
196 197
 }
197 198
 
@@ -429,7 +430,31 @@ function ui_apply_default_icon_back() {
429 430
     ui_render_selected_card();
430 431
 }
431 432
 
433
+
434
+//Adding support for local store
435
+function local_store_save() {
436
+    if(window.localStorage){
437
+        try {
438
+            localStorage.setItem("card_data", JSON.stringify(card_data));
439
+        } catch (e){
440
+            //if the local store save failed should we notify the user that the data is not being saved?
441
+            console.log(e);
442
+        }
443
+    }
444
+}
445
+function local_store_load() {
446
+    if(window.localStorage){
447
+        try {
448
+            card_data = JSON.parse(localStorage.getItem("card_data")) || card_data;
449
+        } catch (e){
450
+            //if the local store load failed should we notify the user that the data load failed?
451
+            console.log(e);
452
+        }
453
+    }
454
+}
455
+
432 456
 $(document).ready(function () {
457
+    local_store_load();
433 458
     ui_setup_color_selector();
434 459
     $('.icon-list').typeahead({source:icon_names});
435 460
 
@@ -477,7 +502,7 @@ $(document).ready(function () {
477 502
 
478 503
     $("#sort-execute").click(ui_sort_execute);
479 504
     $("#filter-execute").click(ui_filter_execute);
480
-    
505
+
481 506
     ui_update_card_list();
482 507
 });
483 508
 

Carregando…
Cancelar
Salvar