can3p (can3p) wrote in changelog,
can3p
can3p
changelog

[ljcom] r11098: LJSUP-10083: Add syntax highlighting to ...

Committer: dpetrov
LJSUP-10083: Add syntax highlighting to the s2 layers editor
U   trunk/htdocs/js/jquery/jquery.storage.js
Modified: trunk/htdocs/js/jquery/jquery.storage.js
===================================================================
--- trunk/htdocs/js/jquery/jquery.storage.js	2011-10-14 13:28:02 UTC (rev 11097)
+++ trunk/htdocs/js/jquery/jquery.storage.js	2011-10-14 14:39:30 UTC (rev 11098)
@@ -9,6 +9,24 @@
  * Plugin supports IE5.5+, Firefox 3.5+, Opera 10.5+, Google Chrome, Apple Safari 4+
  */
 ( function( $ ) {
+
+    function stringify(val) {
+        return JSON.stringify(val);
+    }
+
+    function parse(val) {
+        var ret;
+
+        try {
+            ret = JSON.parse(val);
+        } catch(e) {
+            ret = val;
+        }
+
+        return ret;
+    }
+
+
     /**
      * @namespace $.storage
      */
@@ -38,7 +56,7 @@
                  * @param {String} val
                  */
                 setItem: function( name, val ) {
-                    node.setAttribute( name, val );
+                    node.setAttribute( name, stringify(val) );
                     node.save( storageName );
                 },
                 /**
@@ -48,7 +66,7 @@
                  * @return {Object|String} Item value or null it it does not exist.
                  */
                 getItem: function( name ) {
-                    return node.getAttribute( name );
+                    return parse(node.getAttribute(name));
                 },
                 /**
                  * Remove item from the storage
@@ -71,14 +89,14 @@
             _create();
 
             return {
-                setItem: function( name, val ) {
-                    localStorage.setItem( name, val );
+                setItem: function(name, val) {
+                    localStorage.setItem(name, stringify(val));
                 },
-                getItem: function( name ) {
-                    return localStorage.getItem( name );
+                getItem: function(name) {
+                    return parse(localStorage.getItem(name));
                 },
                 removeItem: function( name ) {
-                    localStorage.removeItem( name );
+                    localStorage.removeItem(name);
                 }
             }
         };

Tags: can3p, dpetrov, js, ljcom
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments