2 * This file is part of WolneLektury-Mobile, licensed under GNU Affero GPLv3 or later.
3 * Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
6 var History = new function() {
9 self.init = function(success, error) {
10 debug('History.init');
13 //navigator.app.overrideBackbutton(); FIXME!!!
14 //document.addEventListener("backbutton", History.goBack, true);
19 self.visit = function(url, offset) {
21 self.viewStack.push(View.current);
23 debug('History.visit: ' + url);
24 View.enter(url, offset);
27 self.goBack = function() {
28 if (self.viewStack.length > 0) {
29 var url = self.viewStack.pop();
30 debug('History.goBack: ' + url);
31 if (self.viewStack.length == 0)
36 debug('History: exiting');
37 navigator.app.exitApp();
42 self.lastRead = function() {
43 var last_read = window.localStorage.getItem('History.last_ids');
45 return last_read.split(';');
51 self.addRead = function(id, offset) {
52 id = "" + id; // this should check if int
53 debug("History.addRead: " + id);
54 var last_read = self.lastRead();
55 var lastly = last_read.indexOf(id);
57 last_read.splice(lastly, 1);
59 while (last_read.length >= 10) {
62 last_read.unshift(id);
63 window.localStorage.setItem('History.last_ids', last_read.join(';'));
67 self.bookmarks = function() {
68 var bookmarks = window.localStorage.getItem('History.bookmarks');
70 return JSON.parse(bookmarks) || [];
76 self.addBookmark = function(name) {
77 var id=(new Date).getTime();
78 debug("History.addBookmark: " + id);
80 var bms = self.bookmarks();
84 title: View.currentTitle,
85 view: View.currentView,
87 offset: currentOffset()
89 window.localStorage.setItem('History.bookmarks', JSON.stringify(bms));
92 self.deleteBookmark = function(id) {
93 debug("History.deleteBookmark: " + id);
94 var bms = self.bookmarks();
96 if (bms[b].id == id) {
100 window.localStorage.setItem('History.bookmarks', JSON.stringify(bms));
101 View.onBookmarkChange();