diff --git a/build/angular-date-range-picker.js b/build/angular-date-range-picker.js index 7f9dbe9..92a6e31 100644 --- a/build/angular-date-range-picker.js +++ b/build/angular-date-range-picker.js @@ -12,6 +12,7 @@ template: "\n \n {{ model.start.format(\"ll\") }} - {{ model.end.format(\"ll\") }}\n Select date range\n \n \n {{ model.format(\"ll\") }}\n Select date\n \n", scope: { model: "=ngModel", + limitingRange: "=limitingRange", customSelectOptions: "=", ranged: "=", pastDates: "@" @@ -127,6 +128,9 @@ dis = date <= moment(); } } + if ($scope.limitingRange && !date.within($scope.limitingRange)) { + dis = true; + } (_base = $scope.months)[m] || (_base[m] = { name: date.format("MMMM YYYY"), weeks: [] diff --git a/build/angular-date-range-picker.min.js b/build/angular-date-range-picker.min.js index bdc94b7..750e778 100644 --- a/build/angular-date-range-picker.min.js +++ b/build/angular-date-range-picker.min.js @@ -1,2 +1,2 @@ -/*! angular-date-range-picker 2014-03-26 */ -(function(){angular.module("dateRangePicker",["pasvaz.bindonce"]),angular.module("dateRangePicker").directive("dateRangePicker",["$compile",function(a){var b,c;return c='
\n
\n \n
\n
\n \n \n \n \n \n \n
\n \n
\n
\n
\n
\n \n
\n
\n
\n Select range: \n
\n
\n Apply\n cancel\n
\n
\n
',b="CUSTOM",{restrict:"AE",replace:!0,template:'\n \n {{ model.start.format("ll") }} - {{ model.end.format("ll") }}\n Select date range\n \n \n {{ model.format("ll") }}\n Select date\n \n',scope:{model:"=ngModel",customSelectOptions:"=",ranged:"=",pastDates:"@"},link:function(d,e){var f,g,h,i,j,k;return d.quickListDefinitions=d.customSelectOptions,null==d.quickListDefinitions&&(d.quickListDefinitions=[{label:"This week",range:moment().range(moment().startOf("week").startOf("day"),moment().endOf("week").startOf("day"))},{label:"Next week",range:moment().range(moment().startOf("week").add(1,"week").startOf("day"),moment().add(1,"week").endOf("week").startOf("day"))},{label:"This fortnight",range:moment().range(moment().startOf("week").startOf("day"),moment().add(1,"week").endOf("week").startOf("day"))},{label:"This month",range:moment().range(moment().startOf("month").startOf("day"),moment().endOf("month").startOf("day"))},{label:"Next month",range:moment().range(moment().startOf("month").add(1,"month").startOf("day"),moment().add(1,"month").endOf("month").startOf("day"))}]),d.quick=null,d.range=null,d.selecting=!1,d.visible=!1,d.start=null,d.showRanged=void 0===d.ranged?!0:d.ranged,j=function(a){var c,e,f,g,h;if(null==a&&(a=!1),d.showRanged){for(d.quickList=[],a&&d.quickList.push({label:"Custom",range:b}),g=d.quickListDefinitions,h=[],e=0,f=g.length;f>e;e++)c=g[e],h.push(d.quickList.push(c));return h}},h=function(){var a,b;return d.showRanged?d.range=d.selection?(b=d.selection.start.clone().startOf("month").startOf("day"),a=b.clone().add(2,"months").endOf("month").startOf("day"),moment().range(b,a)):moment().range(moment().startOf("month").subtract(1,"month").startOf("day"),moment().endOf("month").add(1,"month").startOf("day")):(d.selection=!1,d.selection=d.model||!1,d.date=d.model||moment(),d.range=moment().range(moment(d.date).startOf("month"),moment(d.date).endOf("month")))},i=function(){var a,c,e,f;if(d.showRanged&&d.selection){for(f=d.quickList,c=0,e=f.length;e>c;c++)if(a=f[c],a.range!==b&&d.selection.start.startOf("day").unix()===a.range.start.startOf("day").unix()&&d.selection.end.startOf("day").unix()===a.range.end.startOf("day").unix())return d.quick=a.range,void j();return d.quick=b,j(!0)}},k=function(){var a,b,c,e,f,g;for(d.months=[],c=12*d.range.start.year()+d.range.start.month(),b=moment().startOf("week").day(),d.range.by("days",function(a){var e,f,g,h,i,j,k;return e=a.day()-b,0>e&&(e=7+e),g=12*a.year()+a.month()-c,i=parseInt((7+a.date()-e)/7),h=!1,f=!1,d.showRanged?d.start?(h=a===d.start,f=ae;e++)a=g[e],a.weeks[0]||a.weeks.splice(0,1);return i()},d.show=function(){return d.selection=d.model,h(),k(),d.visible=!0},d.hide=function(a){return null!=a&&"function"==typeof a.stopPropagation&&a.stopPropagation(),d.visible=!1,d.start=null},d.prevent_select=function(a){return null!=a&&"function"==typeof a.stopPropagation?a.stopPropagation():void 0},d.ok=function(a){return null!=a&&"function"==typeof a.stopPropagation&&a.stopPropagation(),d.model=d.selection,d.hide()},d.select=function(a,b){return null!=b&&"function"==typeof b.stopPropagation&&b.stopPropagation(),a.disabled?void 0:(d.showRanged?(d.selecting=!d.selecting,d.selecting?d.start=a.date:(d.selection=moment().range(d.start,a.date),d.start=null)):d.selection=a.date,k())},d.move=function(a,b){return null!=b&&"function"==typeof b.stopPropagation&&b.stopPropagation(),d.showRanged?d.range=moment().range(d.range.start.add(a,"months").startOf("month").startOf("day"),d.range.start.clone().add(2,"months").endOf("month").startOf("day")):(d.date=moment().month(d.date.month()+a),d.range=moment().range(moment(d.date).startOf("month"),moment(d.date).endOf("month"))),k()},d.handlePickerClick=function(a){return null!=a&&"function"==typeof a.stopPropagation?a.stopPropagation():void 0},d.$watch("quick",function(a){return a&&a!==b?(d.selection=d.quick,d.selecting=!1,d.start=null,h(),k()):void 0}),d.$watch("customSelectOptions",function(a){return"undefined"!=typeof customSelectOptions&&null!==customSelectOptions?d.quickListDefinitions=a:void 0}),g=a(angular.element(c))(d),e.append(g),e.bind("click",function(a){return null!=a&&"function"==typeof a.stopPropagation&&a.stopPropagation(),d.$apply(function(){return d.visible?d.hide():d.show()})}),f=function(){return d.$apply(function(){return d.hide()}),!0},angular.element(document).bind("click",f),d.$on("$destroy",function(){return angular.element(document).unbind("click",f)}),j(),h(),k()}}}])}).call(this); \ No newline at end of file +/*! angular-date-range-picker 2014-03-31 */ +(function(){angular.module("dateRangePicker",["pasvaz.bindonce"]),angular.module("dateRangePicker").directive("dateRangePicker",["$compile",function(a){var b,c;return c='
\n
\n \n
\n
\n \n \n \n \n \n \n
\n \n
\n
\n
\n
\n \n
\n
\n
\n Select range: \n
\n
\n Apply\n cancel\n
\n
\n
',b="CUSTOM",{restrict:"AE",replace:!0,template:'\n \n {{ model.start.format("ll") }} - {{ model.end.format("ll") }}\n Select date range\n \n \n {{ model.format("ll") }}\n Select date\n \n',scope:{model:"=ngModel",limitingRange:"=limitingRange",customSelectOptions:"=",ranged:"=",pastDates:"@"},link:function(d,e){var f,g,h,i,j,k;return d.quickListDefinitions=d.customSelectOptions,null==d.quickListDefinitions&&(d.quickListDefinitions=[{label:"This week",range:moment().range(moment().startOf("week").startOf("day"),moment().endOf("week").startOf("day"))},{label:"Next week",range:moment().range(moment().startOf("week").add(1,"week").startOf("day"),moment().add(1,"week").endOf("week").startOf("day"))},{label:"This fortnight",range:moment().range(moment().startOf("week").startOf("day"),moment().add(1,"week").endOf("week").startOf("day"))},{label:"This month",range:moment().range(moment().startOf("month").startOf("day"),moment().endOf("month").startOf("day"))},{label:"Next month",range:moment().range(moment().startOf("month").add(1,"month").startOf("day"),moment().add(1,"month").endOf("month").startOf("day"))}]),d.quick=null,d.range=null,d.selecting=!1,d.visible=!1,d.start=null,d.showRanged=void 0===d.ranged?!0:d.ranged,j=function(a){var c,e,f,g,h;if(null==a&&(a=!1),d.showRanged){for(d.quickList=[],a&&d.quickList.push({label:"Custom",range:b}),g=d.quickListDefinitions,h=[],e=0,f=g.length;f>e;e++)c=g[e],h.push(d.quickList.push(c));return h}},h=function(){var a,b;return d.showRanged?d.range=d.selection?(b=d.selection.start.clone().startOf("month").startOf("day"),a=b.clone().add(2,"months").endOf("month").startOf("day"),moment().range(b,a)):moment().range(moment().startOf("month").subtract(1,"month").startOf("day"),moment().endOf("month").add(1,"month").startOf("day")):(d.selection=!1,d.selection=d.model||!1,d.date=d.model||moment(),d.range=moment().range(moment(d.date).startOf("month"),moment(d.date).endOf("month")))},i=function(){var a,c,e,f;if(d.showRanged&&d.selection){for(f=d.quickList,c=0,e=f.length;e>c;c++)if(a=f[c],a.range!==b&&d.selection.start.startOf("day").unix()===a.range.start.startOf("day").unix()&&d.selection.end.startOf("day").unix()===a.range.end.startOf("day").unix())return d.quick=a.range,void j();return d.quick=b,j(!0)}},k=function(){var a,b,c,e,f,g;for(d.months=[],c=12*d.range.start.year()+d.range.start.month(),b=moment().startOf("week").day(),d.range.by("days",function(a){var e,f,g,h,i,j,k;return e=a.day()-b,0>e&&(e=7+e),g=12*a.year()+a.month()-c,i=parseInt((7+a.date()-e)/7),h=!1,f=!1,d.showRanged?d.start?(h=a===d.start,f=ae;e++)a=g[e],a.weeks[0]||a.weeks.splice(0,1);return i()},d.show=function(){return d.selection=d.model,h(),k(),d.visible=!0},d.hide=function(a){return null!=a&&"function"==typeof a.stopPropagation&&a.stopPropagation(),d.visible=!1,d.start=null},d.prevent_select=function(a){return null!=a&&"function"==typeof a.stopPropagation?a.stopPropagation():void 0},d.ok=function(a){return null!=a&&"function"==typeof a.stopPropagation&&a.stopPropagation(),d.model=d.selection,d.hide()},d.select=function(a,b){return null!=b&&"function"==typeof b.stopPropagation&&b.stopPropagation(),a.disabled?void 0:(d.showRanged?(d.selecting=!d.selecting,d.selecting?d.start=a.date:(d.selection=moment().range(d.start,a.date),d.start=null)):d.selection=a.date,k())},d.move=function(a,b){return null!=b&&"function"==typeof b.stopPropagation&&b.stopPropagation(),d.showRanged?d.range=moment().range(d.range.start.add(a,"months").startOf("month").startOf("day"),d.range.start.clone().add(2,"months").endOf("month").startOf("day")):(d.date=moment().month(d.date.month()+a),d.range=moment().range(moment(d.date).startOf("month"),moment(d.date).endOf("month"))),k()},d.handlePickerClick=function(a){return null!=a&&"function"==typeof a.stopPropagation?a.stopPropagation():void 0},d.$watch("quick",function(a){return a&&a!==b?(d.selection=d.quick,d.selecting=!1,d.start=null,h(),k()):void 0}),d.$watch("customSelectOptions",function(a){return"undefined"!=typeof customSelectOptions&&null!==customSelectOptions?d.quickListDefinitions=a:void 0}),g=a(angular.element(c))(d),e.append(g),e.bind("click",function(a){return null!=a&&"function"==typeof a.stopPropagation&&a.stopPropagation(),d.$apply(function(){return d.visible?d.hide():d.show()})}),f=function(){return d.$apply(function(){return d.hide()}),!0},angular.element(document).bind("click",f),d.$on("$destroy",function(){return angular.element(document).unbind("click",f)}),j(),h(),k()}}}])}).call(this); \ No newline at end of file diff --git a/src/angular-date-range-picker.coffee b/src/angular-date-range-picker.coffee index fd1f458..6d119b9 100644 --- a/src/angular-date-range-picker.coffee +++ b/src/angular-date-range-picker.coffee @@ -58,6 +58,7 @@ angular.module("dateRangePicker").directive "dateRangePicker", ["$compile", ($co """ scope: model: "=ngModel" # can't use ngModelController, we need isolated scope + limitingRange: "=limitingRange" customSelectOptions: "=" ranged: "=" pastDates: "@" @@ -174,6 +175,8 @@ angular.module("dateRangePicker").directive "dateRangePicker", ["$compile", ($co sel = date.isSame($scope.selection) dis = date <= moment() if $scope.pastDates + dis = true if $scope.limitingRange and not date.within($scope.limitingRange) + $scope.months[m] ||= {name: date.format("MMMM YYYY"), weeks: []} $scope.months[m].weeks[w] ||= [] $scope.months[m].weeks[w][d] =