Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed next month function, removed callback on each changeDaySelected event #325

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/ionic-datepicker.bundle.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/ionic-datepicker-modal.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ <h1 class="title">{{mainObj.titleLabel || selctedDateEpoch | date : mainObj.date
</div>
<div class="col col-10 right_arrow" ng-click="nextMonth()">
<button class=" button-clear font_22px"
ng-class="{'pointer_events_none':((lastDayEpoch + 86400000)> toDate)}">
ng-class="{'pointer_events_none':((lastDayEpoch + 86400000) > toDate)}">
<i class="icon ion-chevron-right"></i>
</button>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/ionic-datepicker-popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
</div>
<div class="col col-10 next_btn_section col-center" ng-click="nextMonth()">
<button class="button-clear"
ng-class="{'pointer_events_none':((lastDayEpoch + 86400000)> toDate)}">
ng-class="{'pointer_events_none':((lastDayEpoch + 86400000) > toDate)}">
<i class="icon ion-chevron-right"></i>
</button>
</div>
Expand Down
57 changes: 22 additions & 35 deletions src/ionic-datepicker.provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ angular.module('ionic-datepicker.provider', [])
var provider = {};

var $scope = $rootScope.$new();
$scope.today = resetHMSM(new Date()).getTime();
$scope.disabledDates = [];
$scope.data = {};

Expand All @@ -39,6 +38,19 @@ angular.module('ionic-datepicker.provider', [])
return currentDate;
}

function getDatePickerDay(dateObj) {
var disabled = (dateObj.getTime() < $scope.fromDate) || (dateObj.getTime() > $scope.toDate) || $scope.mainObj.disableWeekdays.indexOf(dateObj.getDay()) >= 0;

return {
date: dateObj.getDate(),
month: dateObj.getMonth(),
year: dateObj.getFullYear(),
day: dateObj.getDay(),
epoch: dateObj.getTime(),
disabled: disabled
};
}

//Previous month
$scope.prevMonth = function () {
if ($scope.currentDate.getMonth() === 1) {
Expand All @@ -56,21 +68,18 @@ angular.module('ionic-datepicker.provider', [])
if ($scope.currentDate.getMonth() === 11) {
$scope.currentDate.setFullYear($scope.currentDate.getFullYear());
}
$scope.currentDate.setDate(1);
$scope.currentDate.setMonth($scope.currentDate.getMonth() + 1);
$scope.data.currentMonth = $scope.mainObj.monthsList[$scope.currentDate.getMonth()];
$scope.data.currentYear = $scope.currentDate.getFullYear();
$scope.monthChanged($scope.currentDate.getMonth());
refreshDateList(new Date());
refreshDateList($scope.currentDate);
changeDaySelected();
};

var changeDaySelected = function() {
var changeDaySelected = function () {
var newSelectedDate = new Date($scope.selctedDateEpoch);
newSelectedDate.setMonth($scope.currentDate.getMonth());
newSelectedDate.setYear($scope.currentDate.getFullYear());
$scope.selctedDateEpoch = newSelectedDate.getTime();
$scope.mainObj.callback($scope.selctedDateEpoch);
}

//Date selected
Expand All @@ -87,9 +96,10 @@ angular.module('ionic-datepicker.provider', [])
}
};

//Set today as date for the modal
//Set today as date for the modal and popup
$scope.setIonicDatePickerTodayDate = function () {
$scope.dateSelected($scope.today);
refreshDateList(new Date($scope.today));
$scope.dateSelected(getDatePickerDay(new Date($scope.today)));
};

//Set date for the modal
Expand Down Expand Up @@ -136,16 +146,7 @@ angular.module('ionic-datepicker.provider', [])

for (var i = firstDay; i <= lastDay; i++) {
tempDate = new Date(currentDate.getFullYear(), currentDate.getMonth(), i);
disabled = (tempDate.getTime() < $scope.fromDate) || (tempDate.getTime() > $scope.toDate) || $scope.mainObj.disableWeekdays.indexOf(tempDate.getDay()) >= 0;

$scope.dayList.push({
date: tempDate.getDate(),
month: tempDate.getMonth(),
year: tempDate.getFullYear(),
day: tempDate.getDay(),
epoch: tempDate.getTime(),
disabled: disabled
});
$scope.dayList.push(getDatePickerDay(tempDate));
}

//To set Monday as the first day of the week.
Expand Down Expand Up @@ -231,6 +232,7 @@ angular.module('ionic-datepicker.provider', [])
delete $scope.fromDate;
delete $scope.toDate;

$scope.today = resetHMSM(new Date()).getTime();
$scope.mainObj = angular.extend({}, config, ipObj);
if ($scope.mainObj.from) {
$scope.fromDate = resetHMSM(new Date($scope.mainObj.from)).getTime();
Expand Down Expand Up @@ -259,23 +261,8 @@ angular.module('ionic-datepicker.provider', [])
text: $scope.mainObj.todayLabel,
type: 'button_today',
onTap: function (e) {
var today = new Date($scope.today);
var today_obj = {
date: today.getDate(),
month: today.getMonth(),
year: today.getFullYear(),
day: today.getDay(),
epoch: today.getTime(),
disabled: false
};
$scope.dateSelected(today_obj);

refreshDateList(new Date());
$scope.selctedDateEpoch = resetHMSM(today).getTime();
$scope.mainObj.callback($scope.selctedDateEpoch);
if (!$scope.mainObj.closeOnSelect) {
e.preventDefault();
}
e.preventDefault();
$scope.setIonicDatePickerTodayDate();
}
});
}
Expand Down