ios version
[wl-mobile.git] / www / js / menu.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 Menu = new function() {
7         var self = this;
8         var infoView = 'ProjectInfo';
9         var showInfo = true;
10
11         self.init = function(success) {
12                 window.plugins.nativeControls.createTabBar(); 
13                 window.plugins.nativeControls.createTabBarItem("start", "Początek","/www/img/icon-Last.png", {onSelect: Menu.start}); 
14                 window.plugins.nativeControls.createTabBarItem("addmark","Dodaj zakładkę","/www/img/icon-Bookmarks.png", {onSelect: Menu.bookmark}); 
15                 
16                 //window.plugins.nativeControls.createTabBarItem("info",self.infoLabel,"/www/img/icon-Tag.png", {onSelect: Menu.info}); 
17                 //window.plugins.nativeControls.createTabBarItem("night","Tryb nocny","", {onSelect: Menu.toggleNightMode}); 
18                 //window.plugins.nativeControls.showTabBarItems("start", "addmark", "info", "night"); 
19                 //window.plugins.nativeControls.showTabBar();
20                 self.setInfoButton(self.infoView, 'O projekcie', self.showInfo);
21                 self.setNightModeLabel();
22                 success && success();
23         };
24
25         self.start = function() {
26                 History.visit('');
27                 window.plugins.nativeControls.selectTabBarItem('');
28         };
29
30         self.info = function() {
31                 History.visit(self.infoView + '/' + View.currentPar);
32                 window.plugins.nativeControls.selectTabBarItem('');
33         };
34
35         self.bookmark = function() {
36                 var name = prompt('Nazwa zakładki');
37                 if (name != null)
38                         History.addBookmark(name);
39                 window.plugins.nativeControls.selectTabBarItem('');
40         };
41
42         self.setNightModeLabel = function() {
43                 var label = 'Tryb nocny';
44                 if (View.getNightMode()) label = 'Tryb dzienny';
45                 window.plugins.nativeControls.createTabBarItem("night",label,"/www/img/icon-Tag.png", {onSelect: Menu.toggleNightMode}); 
46         };
47
48         self.refresh = function() {
49                 var items = new Array();
50                 if (View.currentView != 'Index')
51                         items.push('start');
52                 items.push("addmark");
53                 if (self.showInfo)
54                         items.push("info");
55                 items.push("night");
56                 window.plugins.nativeControls.showTabBarItems.apply(this, items);
57                 window.plugins.nativeControls.showTabBar();
58         };
59
60         self.toggleNightMode = function() {
61                 View.toggleNightMode();
62                 self.setNightModeLabel();
63         };
64
65         self.setInfoButton = function(view, label, enabled) {
66                 self.infoView = view;
67                 self.showInfo = enabled;
68                 window.plugins.nativeControls.createTabBarItem("info",label,"/www/img/icon-Tag.png", {onSelect: Menu.info}); 
69         };
70 }