date_popup.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /**
  2. * Attaches the calendar behavior to all required fields
  3. */
  4. (function ($) {
  5. Drupal.behaviors.date_popup = {
  6. attach: function (context) {
  7. for (var id in Drupal.settings.datePopup) {
  8. $('#'+ id).bind('focus', Drupal.settings.datePopup[id], function(e) {
  9. if (!$(this).hasClass('date-popup-init')) {
  10. var datePopup = e.data;
  11. // Explicitely filter the methods we accept.
  12. switch (datePopup.func) {
  13. case 'datepicker':
  14. $(this)
  15. .datepicker(datePopup.settings)
  16. .addClass('date-popup-init')
  17. $(this).click(function(){
  18. $(this).focus();
  19. });
  20. break;
  21. case 'timeEntry':
  22. $(this)
  23. .timeEntry(datePopup.settings)
  24. .addClass('date-popup-init')
  25. $(this).click(function(){
  26. $(this).focus();
  27. });
  28. break;
  29. case 'timepicker':
  30. // Translate the PHP date format into the style the timepicker uses.
  31. datePopup.settings.timeFormat = datePopup.settings.timeFormat
  32. // 12-hour, leading zero,
  33. .replace('h', 'hh')
  34. // 12-hour, no leading zero.
  35. .replace('g', 'h')
  36. // 24-hour, leading zero.
  37. .replace('H', 'HH')
  38. // 24-hour, no leading zero.
  39. .replace('G', 'H')
  40. // AM/PM.
  41. .replace('A', 'p')
  42. // Minutes with leading zero.
  43. .replace('i', 'mm')
  44. // Seconds with leading zero.
  45. .replace('s', 'ss');
  46. datePopup.settings.startTime = new Date(datePopup.settings.startTime);
  47. $(this)
  48. .timepicker(datePopup.settings)
  49. .addClass('date-popup-init');
  50. $(this).click(function(){
  51. $(this).focus();
  52. });
  53. break;
  54. }
  55. }
  56. });
  57. }
  58. }
  59. };
  60. })(jQuery);