Advertisement
Guest User

Untitled

a guest
Mar 24th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. // JavaScript code that finds dates for today, this weekend, this month, next month
  2. // This weekend = next Sat and Sun
  3. // This month = today to end of this month
  4. // Next month = 1st of next month = end of next month
  5. // Useful on Business Catalyst web app search form for searching from-to dates
  6. // Requires jquery and moment.js
  7.  
  8. $(document).ready(function(){
  9. $('#today_nav').on("click", function(){
  10. dateSearch(moment().format('DD-MMM-YYYY'),moment().format('DD-MMM-YYYY'));
  11. });
  12.  
  13. $('#thisweekend_nav').on("click", function(){
  14. dateSearch(moment().day(6).format('DD-MMM-YYYY'),moment().day(7).format('DD-MMM-YYYY'));
  15. });
  16.  
  17. $('#thismonth_nav').on("click", function(){
  18. dateSearch(moment().format('DD-MMM-YYYY'),moment().add('months', 1).date(0).format('DD-MMM-YYYY'));
  19. });
  20.  
  21. $('#nextmonth_nav').on("click", function(){
  22. var next_month = moment().get('month') + 1;
  23. var now = moment();
  24. var first_next_month = nextMonth(now,next_month).format('DD-MMM-YYYY');
  25. dateSearch(first_next_month,moment().add('months', 2).date(0).format('DD-MMM-YYYY'));
  26. });
  27.  
  28. $('#featured_nav').on("click", function(){
  29. $('#featured_checkbox').prop('checked', true);
  30. $('#geelong_search_form').submit();
  31. });
  32.  
  33. function dateSearch(from_date,to_date){
  34. $('#from_date').val(from_date);
  35. $('#to_date').val(to_date);
  36. $('#geelong_search_form').submit();
  37. }
  38.  
  39. function nextMonth(date, month) {
  40. var input = moment(date);
  41. var output = input.clone().startOf('month').month(month);
  42. return output > input ? output : output.add('years', 1);
  43. }
  44.  
  45. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement