From 78f3c0e9893d36e0ce039c2b79ede8a92ebe468a Mon Sep 17 00:00:00 2001 From: Unknown Date: Sun, 1 Oct 2017 00:24:20 -0400 Subject: Adding the code --- apps/notes/js/scripts.js | 103 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 apps/notes/js/scripts.js (limited to 'apps/notes/js') diff --git a/apps/notes/js/scripts.js b/apps/notes/js/scripts.js new file mode 100644 index 0000000..28963b2 --- /dev/null +++ b/apps/notes/js/scripts.js @@ -0,0 +1,103 @@ +(function ($, $S) { + //$ jQuery + //$S window.localStorage + //Variables Declaration + var $board = $('#board'), + //Board where the Posticks are sticked + Postick, //Singleton Object containing the Functions to work with the LocalStorage + len = 0, + //Length of Objects in the LocalStorage + currentNotes = '', + //Storage the html construction of the posticks + o; //Actual Postick data in the localStorage + + + + //Manage the Posticks in the Local Storage + //Each postick is saved in the localStorage as an Object + Postick = { + add: function (obj) { + obj.id = $S.length; + $S.setItem(obj.id, JSON.stringify(obj)); + }, + + retrive: function (id) { + return JSON.parse($S.getItem(id)); + }, + + remove: function (id) { + $S.removeItem(id); + }, + + removeAll: function () { + $S.clear(); + } + + }; + + //If exist any postick, Create it/them + len = $S.length; + if (len) { + for (var i = 0; i < len; i++) { + //Create all posticks saved in localStorage + var key = $S.key(i); + o = Postick.retrive(key); + currentNotes += '
x
'); + $(".postick").draggable({ + cancel: '.editable' + }); + }); + + //Save all the posticks when the user leaves the page + window.onbeforeunload = function () { + //Clean the localStorage + Postick.removeAll(); + //Then insert each postick into the LocalStorage + //Saving their position on the page, in order to position them when the page is loaded again + $('.postick').each(function () { + var $this = $(this); + Postick.add({ + top: parseInt($this.position().top), + left: parseInt($this.position().left), + text: $this.children('.editable').text() + }); + }); + } +})(jQuery, window.localStorage); \ No newline at end of file -- cgit v1.2.3