DatePicker.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /**
  2. * Phonegap DatePicker Plugin Copyright (c) Greg Allen 2011 MIT Licensed
  3. * Reused and ported to Android plugin by Daniel van 't Oever
  4. * Reused and ported to Windows plugin by Thomas Uher
  5. */
  6. /**
  7. * Constructor
  8. */
  9. function DatePicker() {
  10. //this._callback;
  11. }
  12. /**
  13. * Android themes
  14. * @todo Avoid error when an Android theme is define...
  15. */
  16. DatePicker.prototype.ANDROID_THEMES = {
  17. THEME_TRADITIONAL : 1, // default
  18. THEME_HOLO_DARK : 2,
  19. THEME_HOLO_LIGHT : 3,
  20. THEME_DEVICE_DEFAULT_DARK : 4,
  21. THEME_DEVICE_DEFAULT_LIGHT : 5
  22. };
  23. /**
  24. * show - true to show the ad, false to hide the ad
  25. */
  26. DatePicker.prototype.show = function(options, cb) {
  27. if (options.date) {
  28. options.date = (options.date.getMonth() + 1) + "/" +
  29. (options.date.getDate()) + "/" +
  30. (options.date.getFullYear()) + "/" +
  31. (options.date.getHours()) + "/" +
  32. (options.date.getMinutes());
  33. }
  34. var defaults = {
  35. mode : 'date',
  36. date : '',
  37. minDate: 0,
  38. maxDate: 0,
  39. clearText: 'Clear'
  40. };
  41. for (var key in defaults) {
  42. if (typeof options[key] !== "undefined") {
  43. defaults[key] = options[key];
  44. }
  45. }
  46. //this._callback = cb;
  47. var callback = function(message) {
  48. if(message == -1){
  49. cb(message);
  50. }
  51. else {
  52. var timestamp = Date.parse(message);
  53. if(isNaN(timestamp) == false) {
  54. cb(new Date(message));
  55. }
  56. else {
  57. cb();
  58. }
  59. }
  60. }
  61. cordova.exec(callback,
  62. null,
  63. "DatePickerPlugin",
  64. defaults.mode,
  65. [defaults]
  66. );
  67. };
  68. var datePicker = new DatePicker();
  69. module.exports = datePicker;
  70. // Make plugin work under window.plugins
  71. if (!window.plugins) {
  72. window.plugins = {};
  73. }
  74. if (!window.plugins.datePicker) {
  75. window.plugins.datePicker = datePicker;
  76. }