2 var History = new function() {
5 self.init = function(success, error) {
6 console.log('History.init');
9 navigator.app.overrideBackbutton();
10 document.addEventListener("backbutton", History.goBack, true);
15 self.visit = function(url, offset) {
17 self.viewStack.push(View.current);
18 console.log('History.visit: ' + url);
19 View.enter(url, offset);
22 self.goBack = function() {
23 if (self.viewStack.length > 0) {
24 var url = self.viewStack.pop();
25 console.log('History.goBack: ' + url);
29 console.log('History: exiting');
30 navigator.app.exitApp();
35 self.lastRead = function() {
36 var last_read = window.localStorage.getItem('History.last_ids');
38 return last_read.split(';');
44 self.addRead = function(id, offset) {
45 id = "" + id; // this should check if int
46 console.log("History.addRead: " + id);
47 var last_read = self.lastRead();
48 var lastly = last_read.indexOf(id);
50 last_read.splice(lastly, 1);
52 while (last_read.length >= 10) {
55 last_read.unshift(id);
56 window.localStorage.setItem('History.last_ids', last_read.join(';'));
60 self.bookmarks = function() {
61 var bookmarks = window.localStorage.getItem('History.bookmarks');
63 return JSON.parse(bookmarks) || [];
69 self.addBookmark = function(name) {
70 var id=(new Date).getTime();
71 console.log("History.addBookmark: " + id);
73 var bms = self.bookmarks();
77 title: View.currentTitle,
78 view: View.currentView,
80 offset: currentOffset()
82 window.localStorage.setItem('History.bookmarks', JSON.stringify(bms));
85 self.deleteBookmark = function(id) {
86 console.log("History.deleteBookmark: " + id);
87 var bms = self.bookmarks();
89 if (bms[b].id == id) {
93 window.localStorage.setItem('History.bookmarks', JSON.stringify(bms));
94 View.onBookmarkChange();