|
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 && |
|
301 | 302 | $scope.days.push(i); |
302 | 303 | } |
303 | 304 |
|
304 | | - //get previous month days is first day in month is not Sunday |
305 | | - if (firstDayMonthNumber === 0) { |
| 305 | + //get previous month days if first day in month is not first day in week |
| 306 | + if (firstDayMonthNumber === $scope.dateWeekStartDay) { |
306 | 307 |
|
307 | 308 | //no need for it |
308 | 309 | $scope.prevMonthDays = []; |
309 | 310 | } else { |
310 | 311 |
|
311 | | - howManyPreviousDays = firstDayMonthNumber; |
| 312 | + howManyPreviousDays = firstDayMonthNumber - $scope.dateWeekStartDay; |
312 | 313 | //get previous month |
313 | 314 | if (Number(month) === 1) { |
314 | 315 |
|
|
326 | 327 | $scope.prevMonthDays = prevMonthDays.slice(-howManyPreviousDays); |
327 | 328 | } |
328 | 329 |
|
329 | | - //get next month days is first day in month is not Sunday |
330 | | - if (lastDayMonthNumber < 6) { |
331 | | - |
332 | | - howManyNextDays = 6 - lastDayMonthNumber; |
| 330 | + //get next month days if last day in month is not last day in week |
| 331 | + if (lastDayMonthNumber === $scope.dateWeekEndDay) { |
| 332 | + //no need for it |
| 333 | + $scope.nextMonthDays = []; |
| 334 | + } else { |
| 335 | + howManyNextDays = 6 - lastDayMonthNumber + $scope.dateWeekStartDay; |
333 | 336 | //get previous month |
334 | 337 |
|
335 | 338 | //return next month days |
|
339 | 342 | } |
340 | 343 | //attach previous month days |
341 | 344 | $scope.nextMonthDays = nextMonthDays; |
342 | | - } else { |
343 | | - //no need for it |
344 | | - $scope.nextMonthDays = []; |
345 | 345 | } |
346 | 346 | } |
347 | 347 | , unregisterDataSetWatcher = $scope.$watch('dateSet', function dateSetWatcher(newValue) { |
|
692 | 692 | $scope.month = $filter('date')(date, 'MMMM');//december-November like |
693 | 693 | $scope.monthNumber = Number($filter('date')(date, 'MM')); // 01-12 like |
694 | 694 | $scope.day = Number($filter('date')(date, 'dd')); //01-31 like |
| 695 | + $scope.dateWeekStartDay = parseInt($scope.dateWeekStartDay, 10); |
| 696 | + // making sure that the given option is valid |
| 697 | + if (!Number.isInteger($scope.dateWeekStartDay) || $scope.dateWeekStartDay < 0 || $scope.dateWeekStartDay > 6) { |
| 698 | + $scope.dateWeekStartDay = 0; |
| 699 | + } |
695 | 700 |
|
696 | 701 | if ($scope.dateMaxLimit) { |
697 | 702 |
|
|
701 | 706 | $scope.year = Number($filter('date')(date, 'yyyy'));//2014 like |
702 | 707 | } |
703 | 708 | $scope.months = datetime.MONTH; |
704 | | - $scope.daysInString = ['0', '1', '2', '3', '4', '5', '6'].map(function mappingFunc(el) { |
| 709 | + |
| 710 | + $scope.daysInString = ['0', '1', '2', '3', '4', '5', '6']; |
| 711 | + if ($scope.dateWeekStartDay > 0) { |
| 712 | + // shifting the first day of the week according to the given option |
| 713 | + for (n = 0; n < $scope.dateWeekStartDay; n += 1) { |
| 714 | + $scope.daysInString.push($scope.daysInString.shift()); |
| 715 | + } |
| 716 | + } |
| 717 | + $scope.daysInString.map(function mappingFunc(el) { |
705 | 718 |
|
706 | 719 | return $filter('date')(new Date(new Date('06/08/2014').valueOf() + A_DAY_IN_MILLISECONDS * el), 'EEE'); |
707 | 720 | }); |
708 | 721 |
|
| 722 | + $scope.dateWeekEndDay = $scope.daysInString[7]; |
| 723 | + |
709 | 724 | //create the calendar holder and append where needed |
710 | 725 | if ($scope.datepickerAppendTo && |
711 | 726 | $scope.datepickerAppendTo.indexOf('.') !== -1) { |
|
819 | 834 | 'dateDisabledDates': '@', |
820 | 835 | 'dateSetHidden': '@', |
821 | 836 | 'dateTyper': '@', |
| 837 | + 'dateWeekStartDay': '@', |
822 | 838 | 'datepickerAppendTo': '@', |
823 | 839 | 'datepickerToggle': '@', |
824 | 840 | 'datepickerClass': '@', |
|
0 commit comments