some changes
[wl-mobile.git] / www / js / main.js
1 /*
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.
4  */
5
6 var WL = 'http://www.wolnelektury.pl';
7
8
9 // disable debugging
10 //debug = function(text) {};
11 debug = function(text) {console.log(text);};
12
13
14 function onLoad() {
15         debug('onLoad');
16         document.addEventListener("deviceready", onDeviceReady, false);
17 }
18
19 function onDeviceReady() {
20         debug('onDeviceReady');
21
22         var error = function(err) { alert(err); };
23
24         FileRepo.init(function() {
25                 debug('after FileRepo.init');
26                 Catalogue.init(function() {
27                         debug('after catalogue.init');
28                         History.init(function() {
29                                 debug('after history.init');
30                                 View.init(function() {
31                                         Menu.init(function() {
32                                                 Catalogue.sync();
33                                                 View.go();
34                                         }, error);
35                                 }, error);
36                         }, error);
37                 }, error);
38         });
39 }
40
41
42 var currentOffset = function() {
43         var scr = document.body.scrollTop;
44         var h = document.getElementById('nothing').offsetTop;
45         return scr/h;
46 };
47
48 var setOffset = function(offset) {
49         var h = document.getElementById('nothing').offsetTop;
50         setTimeout(function() {scroll(0, h*offset); }, 10);
51 };
52
53
54 var prettySize = function(size) {
55     if (!size) return "";
56     var units = ['B', 'KiB', 'MiB', 'GiB'];
57     size = size;
58     var unit = units.shift();
59     while (size > 1000 && units.length) {
60         size /= 1024;
61         unit = units.shift();
62     }
63     if (size < 10) {
64         return Math.round(size*10)/10 + ' ' + unit;
65     }
66     return Math.round(size) + ' ' + unit;
67 };
68