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