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