cordova - Make theme settings in Phonegap app persistent - with jQuery cookies -


i've got phonegap app different theme options. make theme selection persistent each app start, want set cookie jquery. after each refresh in browser (where test), standard theme back.

can u give me hints?

that's markup @ beginning of app:

<body>   <div class="theme1">    <div id="page1">    (...) // app markup   <script src="js/jquery.js"></script>   <script src="js/jquery.cookie.js"></script>   <script>here goes script</script> </body> 

there set standard theme.

now, do, is, when click on theme (#theme8, instance) happens in my script:

    $('#theme8').bind('click', function () {      if ($('body > div').hasclass('theme8')) {       // go home screen    } else {         $('body > div').removeclass();         $('body > div').addclass("theme8");        // go homescreen    }      $.cookie('theme_eight', 'applied');    }); 

that's cookie:

var theme_eight = $.cookie('theme_eight'); if (theme_eight == 'applied') {      $('body > div').removeclass();     $('body > div').addclass("theme8"); }; 

same goes other 7 themes. wrong that? why theme choice not persist? there neater solution accomplish that?

rather cookie @ localstorage. persistent , better using cookies

http://docs.phonegap.com/en/2.7.0/cordova_storage_storage.md.html#localstorage

 function ondeviceready() {         window.localstorage.setitem("key", "value");         var keyname = window.localstorage.key(i);         // keyname equal "key"         var value = window.localstorage.getitem("key");         // value equal "value"         window.localstorage.removeitem("key");         window.localstorage.setitem("key2", "value2");         window.localstorage.clear();         // localstorage empty     } 

Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -