forked from phonegap/phonegap-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPickerView.js
More file actions
54 lines (44 loc) · 1.34 KB
/
Copy pathPickerView.js
File metadata and controls
54 lines (44 loc) · 1.34 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
//
// PickerView.js
//
// Created by Olivier Louvignes on 11/28/2011.
// Added Cordova support on 04/09/2012
//
// Copyright 2011 Olivier Louvignes. All rights reserved.
// MIT Licensed
function PickerView() {}
PickerView.prototype.create = function(title, items, callback, options) {
if(!options) options = {};
var scope = options.scope || null;
delete options.scope;
var service = 'PickerView',
action = 'create',
callbackId = service + (cordova.callbackId + 1);
var config = {
title : title || ' ', // avoid blur with a !empty title
items : items || {},
style : options.style || 'default',
doneButtonLabel : options.doneButtonLabel || "Done",
cancelButtonLabel : options.cancelButtonLabel || "Cancel"
};
// Force strings for items data text
for (var key in items) {
for (var _key in items[key].data) {
items[key].data[_key].text = items[key].data[_key].text + '';
}
}
var _callback = function(result) {
var values = result.values,
buttonIndex = result.buttonIndex;
if(buttonIndex !== 0) { // Done
callback.call(scope, values, buttonIndex);
} else { // Cancel
callback.call(scope, {}, buttonIndex);
}
};
return cordova.exec(_callback, _callback, service, action, [config]);
};
cordova.addConstructor(function() {
if(!window.plugins) window.plugins = {};
window.plugins.pickerView = new PickerView();
});