DatePicker.js 1.64 KB
Newer Older
李晓兵's avatar
李晓兵 committed
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
/**
* Phonegap DatePicker Plugin Copyright (c) Greg Allen 2011 MIT Licensed
* Reused and ported to Android plugin by Daniel van 't Oever
* Reused and ported to Windows plugin by Thomas Uher
*/
/**
* Constructor
*/
function DatePicker() {
	//this._callback;
}

/**
 * Android themes
 * @todo Avoid error when an Android theme is define...
 */
DatePicker.prototype.ANDROID_THEMES = {
  THEME_TRADITIONAL          : 1, // default
  THEME_HOLO_DARK            : 2,
  THEME_HOLO_LIGHT           : 3,
  THEME_DEVICE_DEFAULT_DARK  : 4,
  THEME_DEVICE_DEFAULT_LIGHT : 5
};

/**
* show - true to show the ad, false to hide the ad
*/
DatePicker.prototype.show = function(options, cb) {
	if (options.date) {
		options.date = (options.date.getMonth() + 1) + "/" +
		(options.date.getDate()) + "/" +
		(options.date.getFullYear()) + "/" +
		(options.date.getHours()) + "/" +
		(options.date.getMinutes());
	}
	var defaults = {
		mode : 'date',
		date : '',
		minDate: 0,
		maxDate: 0,
		clearText: 'Clear'
	};
	for (var key in defaults) {
		if (typeof options[key] !== "undefined") {
			defaults[key] = options[key];
		}
	}
	//this._callback = cb;
	var callback = function(message) {
		if(message == -1){
			cb(message);
		} 
		else {
			var timestamp = Date.parse(message);
			if(isNaN(timestamp) == false) {
				cb(new Date(message));
			}
			else {
				cb();
			}
		}
	}
	cordova.exec(callback,
		null,
		"DatePickerPlugin",
		defaults.mode,
		[defaults]
	);
};

var datePicker = new DatePicker();
module.exports = datePicker;
// Make plugin work under window.plugins
if (!window.plugins) {
	window.plugins = {};
}
if (!window.plugins.datePicker) {
	window.plugins.datePicker = datePicker;
}