From: Ciro Scognamiglio Date: Tue, 4 Mar 2014 09:45:05 +0000 (+0100) Subject: myslice object X-Git-Tag: myslice-1.1~246 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=3ff83a1eb0abe5b3fc3212a2769b0c4c95dd53a1;p=unfold.git myslice object --- diff --git a/portal/static/js/myslice.js b/portal/static/js/myslice.js new file mode 100644 index 00000000..e1a6de17 --- /dev/null +++ b/portal/static/js/myslice.js @@ -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(); + +});