ios version
[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                                                 View.go();
33                                                 Catalogue.sync(function() {
34                                                         Catalogue.updateLocal();
35                                                 }, error);
36                                         }, error);
37                                 }, error);
38                         }, error);
39                 }, error);
40         });
41 }
42
43
44 var currentOffset = function() {
45         var scr = document.body.scrollTop;
46         var h = document.getElementById('nothing').offsetTop;
47         return scr/h;
48 };
49
50 var setOffset = function(offset) {
51         var h = document.getElementById('nothing').offsetTop;
52         setTimeout(function() {scroll(0, h*offset); }, 10);
53 };
54
55
56 var prettySize = function(size) {
57     if (!size) return "";
58     var units = ['B', 'KiB', 'MiB', 'GiB'];
59     size = size;
60     var unit = units.shift();
61     while (size > 1000 && units.length) {
62         size /= 1024;
63         unit = units.shift();
64     }
65     if (size < 10) {
66         return Math.round(size*10)/10 + ' ' + unit;
67     }
68     return Math.round(size) + ' ' + unit;
69 };
70