|
159 | 159 | , pageDatepickers |
160 | 160 | , hours24h = 86400000 |
161 | 161 | , htmlTemplate = generateHtmlTemplate(prevButton, nextButton) |
| 162 | + , n |
162 | 163 | , onClickOnWindow = function onClickOnWindow() { |
163 | 164 |
|
164 | 165 | if (!isMouseOn && |
|
292 | 293 | , nextMonthDays = [] |
293 | 294 | , howManyNextDays |
294 | 295 | , howManyPreviousDays |
295 | | - , monthAlias; |
| 296 | + , monthAlias |
| 297 | + , dateWeekEndDay; |
296 | 298 |
|
297 | 299 | $scope.days = []; |
| 300 | + $scope.dateWeekStartDay = $scope.validateWeekDay($scope.dateWeekStartDay); |
| 301 | + dateWeekEndDay = ($scope.dateWeekStartDay + 6) % 7; |
298 | 302 |
|
299 | 303 | for (i = 1; i <= limitDate; i += 1) { |
300 | 304 |
|
301 | 305 | $scope.days.push(i); |
302 | 306 | } |
303 | 307 |
|
304 | | - //get previous month days is first day in month is not Sunday |
305 | | - if (firstDayMonthNumber === 0) { |
| 308 | + //get previous month days if first day in month is not first day in week |
| 309 | + if (firstDayMonthNumber === $scope.dateWeekStartDay) { |
306 | 310 |
|
307 | 311 | //no need for it |
308 | 312 | $scope.prevMonthDays = []; |
309 | 313 | } else { |
310 | 314 |
|
311 | | - howManyPreviousDays = firstDayMonthNumber; |
| 315 | + howManyPreviousDays = firstDayMonthNumber - $scope.dateWeekStartDay; |
| 316 | + |
| 317 | + if (firstDayMonthNumber < $scope.dateWeekStartDay) { |
| 318 | + |
| 319 | + howManyPreviousDays += 7; |
| 320 | + } |
| 321 | + |
312 | 322 | //get previous month |
313 | 323 | if (Number(month) === 1) { |
314 | 324 |
|
|
326 | 336 | $scope.prevMonthDays = prevMonthDays.slice(-howManyPreviousDays); |
327 | 337 | } |
328 | 338 |
|
329 | | - //get next month days is first day in month is not Sunday |
330 | | - if (lastDayMonthNumber < 6) { |
| 339 | + //get next month days if last day in month is not last day in week |
| 340 | + if (lastDayMonthNumber === dateWeekEndDay) { |
| 341 | + //no need for it |
| 342 | + $scope.nextMonthDays = []; |
| 343 | + } else { |
| 344 | + howManyNextDays = 6 - lastDayMonthNumber + $scope.dateWeekStartDay; |
| 345 | + |
| 346 | + if (lastDayMonthNumber < $scope.dateWeekStartDay) { |
331 | 347 |
|
332 | | - howManyNextDays = 6 - lastDayMonthNumber; |
| 348 | + howManyNextDays -= 7; |
| 349 | + } |
333 | 350 | //get previous month |
334 | 351 |
|
335 | 352 | //return next month days |
|
339 | 356 | } |
340 | 357 | //attach previous month days |
341 | 358 | $scope.nextMonthDays = nextMonthDays; |
342 | | - } else { |
343 | | - //no need for it |
344 | | - $scope.nextMonthDays = []; |
345 | 359 | } |
346 | 360 | } |
347 | 361 | , unregisterDataSetWatcher = $scope.$watch('dateSet', function dateSetWatcher(newValue) { |
|
683 | 697 | return true; |
684 | 698 | }; |
685 | 699 |
|
| 700 | + $scope.validateWeekDay = function isValidWeekDay(weekDay) { |
| 701 | + var validWeekDay = Number(weekDay, 10); |
| 702 | + // making sure that the given option is valid |
| 703 | + if (!validWeekDay || validWeekDay < 0 || validWeekDay > 6) { |
| 704 | + |
| 705 | + validWeekDay = 0; |
| 706 | + } |
| 707 | + return validWeekDay; |
| 708 | + }; |
| 709 | + |
686 | 710 | // respect previously configured interpolation symbols. |
687 | 711 | htmlTemplate = htmlTemplate.replace(/{{/g, $interpolate.startSymbol()).replace(/}}/g, $interpolate.endSymbol()); |
688 | 712 | $scope.dateMonthTitle = $scope.dateMonthTitle || 'Select month'; |
|
692 | 716 | $scope.month = $filter('date')(date, 'MMMM');//december-November like |
693 | 717 | $scope.monthNumber = Number($filter('date')(date, 'MM')); // 01-12 like |
694 | 718 | $scope.day = Number($filter('date')(date, 'dd')); //01-31 like |
| 719 | + $scope.dateWeekStartDay = $scope.validateWeekDay($scope.dateWeekStartDay); |
695 | 720 |
|
696 | 721 | if ($scope.dateMaxLimit) { |
697 | 722 |
|
|
701 | 726 | $scope.year = Number($filter('date')(date, 'yyyy'));//2014 like |
702 | 727 | } |
703 | 728 | $scope.months = datetime.MONTH; |
704 | | - $scope.daysInString = ['0', '1', '2', '3', '4', '5', '6'].map(function mappingFunc(el) { |
| 729 | + |
| 730 | + $scope.daysInString = []; |
| 731 | + for (n = $scope.dateWeekStartDay; n <= $scope.dateWeekStartDay + 6; n += 1) { |
| 732 | + |
| 733 | + $scope.daysInString.push(n % 7); |
| 734 | + } |
| 735 | + $scope.daysInString = $scope.daysInString.map(function mappingFunc(el) { |
705 | 736 |
|
706 | 737 | return $filter('date')(new Date(new Date('06/08/2014').valueOf() + A_DAY_IN_MILLISECONDS * el), 'EEE'); |
707 | 738 | }); |
|
819 | 850 | 'dateDisabledDates': '@', |
820 | 851 | 'dateSetHidden': '@', |
821 | 852 | 'dateTyper': '@', |
| 853 | + 'dateWeekStartDay': '@', |
822 | 854 | 'datepickerAppendTo': '@', |
823 | 855 | 'datepickerToggle': '@', |
824 | 856 | 'datepickerClass': '@', |
|
0 commit comments