date_popup.js 1.9 KB

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