myslice object
authorCiro Scognamiglio <ciro.scognamiglio@cslash.net>
Tue, 4 Mar 2014 09:45:05 +0000 (10:45 +0100)
committerCiro Scognamiglio <ciro.scognamiglio@cslash.net>
Tue, 4 Mar 2014 09:45:05 +0000 (10:45 +0100)
portal/static/js/myslice.js [new file with mode: 0644]

diff --git a/portal/static/js/myslice.js b/portal/static/js/myslice.js
new file mode 100644 (file)
index 0000000..e1a6de1
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * MySlice Class
+ */
+
+var myslice = {
+    pending: [],
+    
+    add: function(resource) {
+       if (!this.has(resource)) {
+               this.pending.push(resource);
+               this.save();
+       }
+    },
+    
+    del: function(resource) {
+       if (this.has(resource)) {
+               this.pending.splice(index, 1);
+       }
+    },
+    
+    has: function(resource) {
+       index = jQuery.inArray( resource, this.pending );
+       if (index != -1) {
+               return true;
+       }
+       return false;
+    },
+    
+    count: function() {
+       return this.pending.length;
+    },
+    
+    save: function() {
+       localStorage.setItem('pending', JSON.stringify(this.pending));
+    },
+    
+    load: function() {
+       this.pending = JSON.parse(localStorage.getItem('pending'));
+       if (!this.pending) {
+               this.pending = [];
+       }
+    }
+    
+};
+
+$(document).ready(function() {
+       // Put the object into storage
+       //localStorage.setItem('testObject', JSON.stringify(testObject));
+
+       // Retrieve the object from storage
+       myslice.load();
+
+});