forked from hiediutley/HelloPhoneGap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNativeControls.js
More file actions
executable file
·211 lines (183 loc) · 6.44 KB
/
Copy pathNativeControls.js
File metadata and controls
executable file
·211 lines (183 loc) · 6.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/*
// This code is adapted from the work of:
// Created by Michael Nachbaur on 13/04/09.
// Copyright 2009 Decaf Ninja Software. All rights reserved.
// MIT licensed
*/
/**
* This class exposes mobile phone interface controls to JavaScript, such as
* native tab and tool bars, etc.
* @constructor
*/
function NativeControls() {
this.tabBarTag = 0;
this.tabBarCallbacks = {};
}
/**
* Create a native tab bar that can have tab buttons added to it which can respond to events.
*/
NativeControls.prototype.createTabBar = function() {
PhoneGap.exec("NativeControls.createTabBar");
};
/**
* Show a tab bar. The tab bar has to be created first.
* @param {Object} [options] Options indicating how the tab bar should be shown:
* - \c height integer indicating the height of the tab bar (default: \c 49)
* - \c position specifies whether the tab bar will be placed at the \c top or \c bottom of the screen (default: \c bottom)
*/
NativeControls.prototype.showTabBar = function(options) {
if (!options) options = {};
PhoneGap.exec("NativeControls.showTabBar", options);
};
/**
* Hide a tab bar. The tab bar has to be created first.
*/
NativeControls.prototype.hideTabBar = function(animate) {
if (animate == undefined || animate == null)
animate = true;
PhoneGap.exec("NativeControls.hideTabBar", { animate: animate });
};
/**
* Create a new tab bar item for use on a previously created tab bar. Use ::showTabBarItems to show the new item on the tab bar.
*
* If the supplied image name is one of the labels listed below, then this method will construct a tab button
* using the standard system buttons. Note that if you use one of the system images, that the \c title you supply will be ignored.
*
* <b>Tab Buttons</b>
* - tabButton:More
* - tabButton:Favorites
* - tabButton:Featured
* - tabButton:TopRated
* - tabButton:Recents
* - tabButton:Contacts
* - tabButton:History
* - tabButton:Bookmarks
* - tabButton:Search
* - tabButton:Downloads
* - tabButton:MostRecent
* - tabButton:MostViewed
* @param {String} name internal name to refer to this tab by
* @param {String} [title] title text to show on the tab, or null if no text should be shown
* @param {String} [image] image filename or internal identifier to show, or null if now image should be shown
* @param {Object} [options] Options for customizing the individual tab item
* - \c badge value to display in the optional circular badge on the item; if null or unspecified, the badge will be hidden
*/
NativeControls.prototype.createTabBarItem = function(name, label, image, options) {
var tag = this.tabBarTag++;
if (options && 'onSelect' in options && typeof(options['onSelect']) == 'function') {
this.tabBarCallbacks[tag] = {'onSelect':options.onSelect,'name':name};
//delete options.onSelect;
}
PhoneGap.exec("NativeControls.createTabBarItem", name, label, image, tag, options);
};
/**
* Update an existing tab bar item to change its badge value.
* @param {String} name internal name used to represent this item when it was created
* @param {Object} options Options for customizing the individual tab item
* - \c badge value to display in the optional circular badge on the item; if null or unspecified, the badge will be hidden
*/
NativeControls.prototype.updateTabBarItem = function(name, options) {
if (!options) options = {};
PhoneGap.exec("NativeControls.updateTabBarItem", name, options);
};
/**
* Show previously created items on the tab bar
* @param {String} arguments... the item names to be shown
* @param {Object} [options] dictionary of options, notable options including:
* - \c animate indicates that the items should animate onto the tab bar
* @see createTabBarItem
* @see createTabBar
*/
NativeControls.prototype.showTabBarItems = function() {
var parameters = [ "NativeControls.showTabBarItems" ];
for (var i = 0; i < arguments.length; i++) {
parameters.push(arguments[i]);
//alert(arguments[i]);
}
PhoneGap.exec.apply(this, parameters);
};
/**
* Manually select an individual tab bar item, or nil for deselecting a currently selected tab bar item.
* @param {String} tabName the name of the tab to select, or null if all tabs should be deselected
* @see createTabBarItem
* @see showTabBarItems
*/
NativeControls.prototype.selectTabBarItem = function(tab) {
PhoneGap.exec("NativeControls.selectTabBarItem", tab);
};
/**
* Function called when a tab bar item has been selected.
* @param {Number} tag the tag number for the item that has been selected
*/
NativeControls.prototype.tabBarItemSelected = function(tag)
{
if (typeof(this.tabBarCallbacks[tag].onSelect) == 'function')
this.tabBarCallbacks[tag].onSelect(this.tabBarCallbacks[tag].name);
};
/**
* Create a toolbar.
*/
NativeControls.prototype.createToolBar = function()
{
PhoneGap.exec("NativeControls.createToolBar");
};
/**
* Function called when a tab bar item has been selected.
* @param {String} title the title to set within the toolbar
*/
NativeControls.prototype.setToolBarTitle = function(title)
{
PhoneGap.exec("NativeControls.setToolBarTitle", title);
};
NativeControls.prototype.createActionSheet = function(buttonTitles,actionSheetTitle,cancelButtonIndex,destructiveButtonIndex)
{
var options = {};
if(actionSheetTitle != null)
{
options.title = actionSheetTitle;
}
if(cancelButtonIndex != null)
{
options.cancelButtonIndex = cancelButtonIndex;
}
if(destructiveButtonIndex != null)
{
options.destructiveButtonIndex = destructiveButtonIndex;
}
var params = [ "NativeControls.createActionSheet",options ];
for (var i = 0; i < buttonTitles.length; i++)
{
params.push(buttonTitles[i]);
}
PhoneGap.exec.apply(this, params);
this.actionSheetDelegate = {};
return this.actionSheetDelegate;
}
NativeControls.prototype._onActionSheetDismissed = function(index)
{
this.actionSheetDelegate.onActionSheetDismissed(index);
}
PhoneGap.addConstructor(function()
{
if(!window.plugins)
{
window.plugins = {};
}
window.plugins.nativeControls = new NativeControls();
});
function StatusBar()
{
}
StatusBar.prototype.setHidden = function(bHide)
{
PhoneGap.exec("StatusBar.setHidden",bHide);
}
PhoneGap.addConstructor(
function()
{
if (typeof window.plugins == "undefined")
window.plugins = {};
if (typeof window.plugins.statusBar == "undefined")
window.plugins.statusBar = new StatusBar();
}
);