DatePicker.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. */
  5. /**
  6. * Constructor
  7. */
  8. function DatePicker() {
  9. //this._callback;
  10. }
  11. /**
  12. * Android themes
  13. */
  14. DatePicker.prototype.ANDROID_THEMES = {
  15. THEME_TRADITIONAL : 1, // default
  16. THEME_HOLO_DARK : 2,
  17. THEME_HOLO_LIGHT : 3,
  18. THEME_DEVICE_DEFAULT_DARK : 4,
  19. THEME_DEVICE_DEFAULT_LIGHT : 5
  20. };
  21. /**
  22. * show - true to show the ad, false to hide the ad
  23. */
  24. DatePicker.prototype.show = function(options, cb, errCb) {
  25. if (options.date && options.date instanceof Date) {
  26. options.date = (options.date.getMonth() + 1) + "/" +
  27. (options.date.getDate()) + "/" +
  28. (options.date.getFullYear()) + "/" +
  29. (options.date.getHours()) + "/" +
  30. (options.date.getMinutes());
  31. }
  32. var defaults = {
  33. mode : 'date',
  34. date : '',
  35. minDate: 0,
  36. maxDate: 0,
  37. titleText: '',
  38. cancelText: '',
  39. okText: '',
  40. todayText: '',
  41. nowText: '',
  42. is24Hour: false,
  43. androidTheme : window.datePicker.ANDROID_THEMES.THEME_TRADITIONAL, // Default theme
  44. };
  45. for (var key in defaults) {
  46. if (typeof options[key] !== "undefined") {
  47. defaults[key] = options[key];
  48. }
  49. }
  50. //this._callback = cb;
  51. var callback = function(message) {
  52. if(message != 'error'){
  53. var timestamp = Date.parse(message);
  54. if(isNaN(timestamp) == false) {
  55. cb(new Date(message));
  56. }
  57. else {
  58. cb();
  59. }
  60. } else {
  61. // TODO error popup?
  62. }
  63. }
  64. var errCallback = function(message) {
  65. if (typeof errCb === 'function') {
  66. errCb(message);
  67. }
  68. }
  69. cordova.exec(callback,
  70. errCallback,
  71. "DatePickerPlugin",
  72. defaults.mode,
  73. [defaults]
  74. );
  75. };
  76. var datePicker = new DatePicker();
  77. module.exports = datePicker;
  78. // Make plugin work under window.plugins
  79. if (!window.plugins) {
  80. window.plugins = {};
  81. }
  82. if (!window.plugins.datePicker) {
  83. window.plugins.datePicker = datePicker;
  84. }