mirror of
https://github.com/purplecabbage/phonegap-plugins.git
synced 2026-04-24 03:00:11 -04:00
63 lines
1.6 KiB
JavaScript
63 lines
1.6 KiB
JavaScript
/**
|
|
* Cordova DatePicker Plugin
|
|
* Copyright (c) Greg Allen 2011
|
|
* MIT Licensed
|
|
*
|
|
* Updated for Cordova 2.1 by Robert (Jamie) Munro
|
|
*/
|
|
if (typeof cordova !== "undefined") {
|
|
/**
|
|
* Constructor
|
|
*/
|
|
function DatePicker() {
|
|
this._callback;
|
|
}
|
|
|
|
/**
|
|
* show - true to show the ad, false to hide the ad
|
|
*/
|
|
DatePicker.prototype.show = function(options, cb) {
|
|
var padDate = function(date) {
|
|
if (date.length == 1) {
|
|
return ("0" + date);
|
|
}
|
|
return date;
|
|
};
|
|
|
|
if (options.date) {
|
|
options.date = options.date.getFullYear() + "-" +
|
|
padDate(options.date.getMonth()+1) + "-" +
|
|
padDate(options.date.getDate()) +
|
|
"T" + padDate(options.date.getHours()) + ":" +
|
|
padDate(options.date.getMinutes()) + ":00Z";
|
|
}
|
|
var defaults = {
|
|
mode : 'datetime',
|
|
date : '',
|
|
allowOldDates : true,
|
|
allowFutureDates : true
|
|
};
|
|
|
|
for (var key in defaults) {
|
|
if (typeof options[key] !== "undefined")
|
|
defaults[key] = options[key];
|
|
}
|
|
this._callback = cb;
|
|
|
|
cordova.exec("DatePicker.show", defaults);
|
|
};
|
|
|
|
DatePicker.prototype._dateSelected = function(date) {
|
|
var d = new Date(parseFloat(date) * 1000);
|
|
if (this._callback)
|
|
this._callback(d);
|
|
}
|
|
|
|
cordova.addConstructor(function() {
|
|
if (!window.plugins) {
|
|
window.plugins = {};
|
|
}
|
|
window.plugins.datePicker = new DatePicker();
|
|
});
|
|
};
|