diff --git a/.gitignore b/.gitignore
index 986ea28..0e62170 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,3 +3,4 @@
/bower_components
.sass-cache
*.map
+.idea
diff --git a/build/angular-mighty-datepicker.css b/build/angular-mighty-datepicker.css
index a2d856b..24bcce0 100644
--- a/build/angular-mighty-datepicker.css
+++ b/build/angular-mighty-datepicker.css
@@ -33,6 +33,10 @@
color: #3b5;
font-weight: bold;
}
+.mighty-picker-calendar__day--selected-to {
+ color: orange;
+ font-weight: bold;
+}
.mighty-picker__month {
display: inline-block;
margin: 0 6px;
diff --git a/build/angular-mighty-datepicker.js b/build/angular-mighty-datepicker.js
index 47616d0..ba6a96e 100644
--- a/build/angular-mighty-datepicker.js
+++ b/build/angular-mighty-datepicker.js
@@ -4,7 +4,7 @@
angular.module("mightyDatepicker").directive("mightyDatepicker", [
"$compile", function($compile) {
var options, pickerTemplate;
- pickerTemplate = "
\n
\n
\n
\n
\n \n \n | \n
\n \n \n \n \n | \n
\n
\n
\n
\n
";
+ pickerTemplate = "\n
\n
\n
\n
\n \n \n | \n
\n \n \n \n \n | \n
\n
\n
\n
\n
";
options = {
mode: "simple",
months: 1,
@@ -28,7 +28,7 @@
rangeTo: '='
},
link: function($scope, $element, $attrs) {
- var _bake, _build, _buildMonth, _buildWeek, _getMarker, _indexMarkers, _indexOfMoment, _isInRange, _isSelected, _prepare, _setup, _withinLimits;
+ var _bake, _build, _buildMonth, _buildWeek, _getMarker, _indexMarkers, _indexOfMoment, _isInRange, _isSelected, _isSelectedTo, _prepare, _setup, _withinLimits;
_bake = function() {
var domEl;
domEl = $compile(angular.element($scope.options.template))($scope);
@@ -83,19 +83,45 @@
switch ($scope.options.mode) {
case "multiple":
return _indexOfMoment($scope.model, day, 'day') > -1;
+ case "range":
+ if ($scope.model) {
+ return day.isSame($scope.model.start, 'day');
+ }
+ break;
default:
return $scope.model && day.isSame($scope.model, 'day');
}
};
+ _isSelectedTo = function(day) {
+ switch ($scope.options.mode) {
+ case "range":
+ if ($scope.model) {
+ return day.isSame($scope.model.end, 'day');
+ }
+ break;
+ default:
+ return false;
+ }
+ };
_isInRange = function(day) {
- if ($scope.options.rangeMode) {
- if ($scope.options.rangeMode === "from") {
- return moment.range($scope.model, $scope.before).contains(day) || day.isSame($scope.before, 'day');
- } else {
- return moment.range($scope.after, $scope.model).contains(day) || day.isSame($scope.after, 'day');
- }
- } else {
- return false;
+ switch ($scope.options.mode) {
+ case "multiple":
+ if ($scope.options.rangeMode) {
+ if ($scope.options.rangeMode === "from") {
+ return moment.range($scope.model, $scope.before).contains(day) || day.isSame($scope.before, 'day');
+ } else {
+ return moment.range($scope.after, $scope.model).contains(day) || day.isSame($scope.after, 'day');
+ }
+ } else {
+ return false;
+ }
+ break;
+ case "range":
+ if ($scope.model.start) {
+ return $scope.model.contains(day);
+ } else {
+ return false;
+ }
}
};
_buildWeek = function(time, month) {
@@ -114,6 +140,7 @@
return {
date: day,
selected: _isSelected(day) && withinMonth,
+ selectedTo: _isSelectedTo(day) && withinMonth,
inRange: _isInRange(day),
disabled: !(withinLimits && withinMonth && filter),
marker: withinMonth ? _getMarker(day) : void 0
@@ -169,6 +196,15 @@
$scope.model = [];
}
break;
+ case "range":
+ if ($scope.model && $scope.model.start) {
+ if ($scope.model.start.isValid()) {
+ start = $scope.model.start;
+ }
+ } else {
+ $scope.model = moment.range();
+ }
+ break;
default:
if ($scope.model) {
start = moment($scope.model);
@@ -204,7 +240,7 @@
_prepare();
};
$scope.select = function(day) {
- var ix;
+ var endValid, ix, startValid;
if (!day.disabled) {
switch ($scope.options.mode) {
case "multiple":
@@ -215,6 +251,19 @@
$scope.model.push(moment(day.date));
}
break;
+ case "range":
+ startValid = $scope.model.start.isValid();
+ endValid = $scope.model.end.isValid();
+ if ((startValid && endValid) || (!startValid && !endValid)) {
+ $scope.model = moment.range(moment(day.date), moment(null));
+ } else if (startValid && !endValid) {
+ if (moment(day.date).isBefore($scope.model.start, 'day') || moment(day.date).isSame($scope.model.start, 'day')) {
+ $scope.model.start = moment(day.date);
+ } else {
+ $scope.model.end = moment(day.date);
+ }
+ }
+ break;
default:
$scope.model = day.date;
}
@@ -236,6 +285,11 @@
return _prepare();
});
break;
+ case "range":
+ $scope.$watch('model', function(newVal, oldVal) {
+ return _prepare();
+ });
+ break;
case "simple":
$scope.$watch('model', function(newVal, oldVal) {
if (!moment.isMoment(newVal)) {
diff --git a/demo/index.html b/demo/index.html
index 950aac6..396bb7f 100644
--- a/demo/index.html
+++ b/demo/index.html
@@ -55,6 +55,9 @@
$scope.dateDbB = moment().add('day', 2);
$scope.optionsDbB = {};
+ $scope.optionsR = {mode: "range"};
+ $scope.range = moment.range(moment().subtract('day', 8), moment().subtract('day', 2));
+
$scope.addMarker = function() {
$scope.markers.push({day: $scope.mark, marker: 'new marker'});
}
@@ -101,6 +104,10 @@ Double datepicker for data range
+
+
Single datepicker for date range
+
+