mirror of
https://github.com/purplecabbage/phonegap-plugins.git
synced 2026-04-24 03:00:11 -04:00
67 lines
1.6 KiB
JavaScript
67 lines
1.6 KiB
JavaScript
/**
|
|
Cordova DatePicker Plugin
|
|
Copyright (c) Greg Allen 2011
|
|
MIT Licensed
|
|
**/
|
|
|
|
if (!window.plugins.datePicker) {
|
|
|
|
/* shim to work in 1.5 and 1.6 */
|
|
if (!window.Cordova) {
|
|
window.Cordova = cordova;
|
|
};
|
|
|
|
/**
|
|
* 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
|
|
}
|
|
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();
|
|
});
|
|
};
|