pretty much working version
[wl-mobile.git] / assets / www / js / main.js
1 var VERSION = '1.0';
2 var WL = 'http://www.wolnelektury.pl';
3
4
5 function onLoad() {
6         console.log('onLoad');
7         document.addEventListener("deviceready", onDeviceReady, false);
8 }
9
10 function onDeviceReady() {
11         console.log('onDeviceReady');
12         var error = function(err) { alert(err); };
13
14         FileRepo.init(function() {
15                 console.log('after FileRepo.init');
16                 Catalogue.init(function() {
17                         console.log('after catalogue.init');
18                         History.init(function() {
19                                 console.log('after history.init');
20                                 View.init(function() {
21                                         Catalogue.sync(function() {
22                                                 Catalogue.updateLocal();
23                                         }, error);
24                                 }, error);
25                         }, error);
26                 }, error);
27         });
28 }
29
30
31 var currentOffset = function() {
32         var scr = document.body.scrollTop;
33         var h = document.getElementById('nothing').offsetTop;
34         return scr/h;document.getElementById('nothing')
35 };
36
37 var setOffset = function(offset) {
38         var h = document.getElementById('nothing').offsetTop;
39         scroll(0, h*offset); 
40 };
41
42
43 var prettySize = function(size) {
44     if (!size) return "";
45     var units = ['B', 'KiB', 'MiB', 'GiB'];
46     size = size;
47     var unit = units.shift();
48     while (size > 1000 && units.length) {
49         size /= 1024;
50         unit = units.shift();
51     }
52     if (size < 10) {
53         return Math.round(size*10)/10 + ' ' + unit;
54     }
55     return Math.round(size) + ' ' + unit;
56 }