Skip to content

Commit c60353b

Browse files
committed
Make it work under window.plugins
require throw errors in Cordova -v = 3.4.0-0.1.3. Cordova.exec is already available. Add the plugin under window.plugins object.
1 parent d831b44 commit c60353b

File tree

1 file changed

+56
-40
lines changed

1 file changed

+56
-40
lines changed

www/android/DatePicker.js

Lines changed: 56 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,49 +3,65 @@
33
* Reused and ported to Android plugin by Daniel van 't Oever
44
*/
55

6-
var exec = require('cordova/exec');
6+
// var exec = require('cordova/exec');
77
/**
88
* Constructor
99
*/
1010
function DatePicker() {
11-
//this._callback;
11+
//this._callback;
1212
}
1313

14-
/**
15-
* show - true to show the ad, false to hide the ad
16-
*/
17-
DatePicker.prototype.show = function(options, cb) {
18-
if (options.date) {
19-
options.date = (options.date.getMonth() + 1) + "/" + (options.date.getDate()) + "/" + (options.date.getFullYear()) + "/"
20-
+ (options.date.getHours()) + "/" + (options.date.getMinutes());
21-
}
22-
var defaults = {
23-
mode : '',
24-
date : '',
25-
minDate: 0,
26-
maxDate: 0
27-
};
28-
29-
for ( var key in defaults) {
30-
if (typeof options[key] !== "undefined")
31-
defaults[key] = options[key];
32-
}
33-
//this._callback = cb;
34-
35-
var callback = function(message) {
36-
cb(new Date(message));
37-
}
38-
39-
exec(callback,
40-
null,
41-
"DatePickerPlugin",
42-
defaults.mode,
43-
[defaults]
44-
);
45-
46-
//return gap.exec(cb, failureCallback, 'DatePickerPlugin', defaults.mode, new Array(defaults));
47-
48-
};
49-
50-
var datePicker = new DatePicker();
51-
module.exports = datePicker
14+
/**
15+
* show - true to show the ad, false to hide the ad
16+
*/
17+
DatePicker.prototype.show = function(options, cb) {
18+
19+
if (options.date) {
20+
options.date = (options.date.getMonth() + 1) + "/" +
21+
(options.date.getDate()) + "/" +
22+
(options.date.getFullYear()) + "/" +
23+
(options.date.getHours()) + "/" +
24+
(options.date.getMinutes());
25+
}
26+
27+
var defaults = {
28+
mode : '',
29+
date : '',
30+
minDate: 0,
31+
maxDate: 0
32+
};
33+
34+
for (var key in defaults) {
35+
if (typeof options[key] !== "undefined") {
36+
defaults[key] = options[key];
37+
}
38+
}
39+
40+
//this._callback = cb;
41+
42+
var callback = function(message) {
43+
cb(new Date(message));
44+
}
45+
46+
cordova.exec(callback,
47+
null,
48+
"DatePickerPlugin",
49+
defaults.mode,
50+
[defaults]
51+
);
52+
53+
//return gap.exec(cb, failureCallback, 'DatePickerPlugin', defaults.mode, new Array(defaults));
54+
};
55+
56+
//-------------------------------------------------------------------
57+
58+
if(!window.plugins) {
59+
window.plugins = {};
60+
}
61+
if (!window.plugins.datePicker) {
62+
window.plugins.datePicker = new DatePicker();
63+
}
64+
65+
if (module.exports) {
66+
module.exports = window.plugins.datePicker;
67+
}

0 commit comments

Comments
 (0)