jquery - JQUI Week picker won't start on this week -
i have week-picker [fiddle], can't have current week selected on load. far have current day selected.
also, there easier way week-picker this?
here's code:
var startdate; var enddate; var selectcurrentweek = function (where) { console.log(where); window.settimeout(function () { $('.week-picker').find('.ui-datepicker-current-day a').addclass('ui-state-active'); }, 1); } $('.week-picker').datepicker({ showothermonths: true, selectothermonths: true, onselect: function (datetext, inst) { var date = $(this).datepicker('getdate'); startdate = new date(date.getfullyear(), date.getmonth(), date.getdate() - date.getday()); enddate = new date(date.getfullyear(), date.getmonth(), date.getdate() - date.getday() + 6); var dateformat = inst.settings.dateformat || $.datepicker._defaults.dateformat; $('#startdate').text($.datepicker.formatdate(dateformat, startdate, inst.settings)); $('#enddate').text($.datepicker.formatdate(dateformat, enddate, inst.settings)); selectcurrentweek("week-picker"); }, beforeshowday: function (date) { var cssclass = ''; if (date >= startdate && date <= enddate) cssclass = 'ui-datepicker-current-day'; return [true, cssclass]; }, onchangemonthyear: function (year, month, inst) { selectcurrentweek("change"); } }); $(document).on('mousemove', '.week-picker .ui-datepicker-calendar tr', function () { $(this).find('td a').addclass('ui-state-hover'); }); $(document).on('mouseleave', '.week-picker .ui-datepicker-calendar tr', function () { $(this).find('td a').removeclass('ui-state-hover'); });
this ghetto way it, works. basically, want trigger click event on current day. added $(document).ready function:
$(document).ready(function () { $(".ui-datepicker-today").trigger("click"); });
if has better solution, great.
Comments
Post a Comment