Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 KB | None | 0 0
  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7. function loadCustomDatepicker() {
  8. if (!window.jQuery || !window.jQuery.fn || !window.jQuery.fn.datepicker) {
  9. setTimeout(loadCustomDatepicker, 500);
  10. return;
  11. }
  12.  
  13. var datepickerInput = window.Shoppad.$('#infiniteoptions-container .datepicker');
  14.  
  15. if (datepickerInput.length) {
  16. datepickerInput.datepicker('option', {
  17. beforeShowDay: function(date) {
  18.  
  19.  
  20.  
  21. var timedBlock = true;
  22. var timedBlockClosingHour = 24;
  23. var timedBlockClosingMinute = 00;
  24.  
  25.  
  26.  
  27. // example: no delivery on sundays or saturdays
  28. var onlySpecificDays = false;
  29. var specificDaysAllowed = [
  30. // checks for 0-6, starting with Sunday being 0.
  31.  
  32. ];
  33.  
  34.  
  35. var blockUntilDate = null;
  36.  
  37.  
  38.  
  39. var blockSpecificDates = [
  40. new Date(2000,01,01),
  41.  
  42. new Date(2019,8,02),
  43. new Date(2019,9,24),
  44.  
  45. ];
  46.  
  47. // Specific day not added yet
  48. var now = new Date();
  49. var isToday = date.getFullYear() == now.getFullYear() &&
  50. date.getMonth() == now.getMonth() &&
  51. date.getDate() == now.getDate();
  52.  
  53. var isEnabled = true;
  54.  
  55. if (onlySpecificDays) {
  56. isEnabled = specificDaysAllowed.indexOf(date.getDay()) > -1;
  57. }
  58.  
  59. if (isToday && timedBlock) {
  60. if (now.getHours() > timedBlockClosingHour) {
  61. isEnabled = false;
  62. }
  63. else if (now.getHours() == timedBlockClosingHour && now.getMinutes() >= timedBlockClosingMinute) {
  64. isEnabled = false;
  65. }
  66. }
  67.  
  68. if (blockUntilDate != null && date.getTime() < blockUntilDate.getTime()) {
  69. isEnabled = false;
  70. }
  71.  
  72. for (var i = 0; i < blockSpecificDates.length; i++) {
  73. var checkDate = blockSpecificDates[i];
  74. if (date.getFullYear() == checkDate.getFullYear() &&
  75. date.getMonth() == checkDate.getMonth() &&
  76. date.getDay() == checkDate.getDay()) {
  77. isEnabled = false;
  78. }
  79. }
  80.  
  81. return [isEnabled];
  82. }
  83. });
  84. }
  85. }
  86.  
  87. loadCustomDatepicker();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement