diff --git a/build/angular-date-range-picker.js b/build/angular-date-range-picker.js index e64b5c3..db741d1 100644 --- a/build/angular-date-range-picker.js +++ b/build/angular-date-range-picker.js @@ -2,7 +2,7 @@ angular.module("dateRangePicker", ['pasvaz.bindonce']); angular.module("dateRangePicker").directive("dateRangePicker", [ - "$compile", function($compile) { + "$compile", "$timeout", function($compile, $timeout) { var CUSTOM, pickerTemplate; pickerTemplate = "
\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
"; CUSTOM = "CUSTOM"; @@ -174,9 +174,11 @@ } } $scope.model = $scope.selection; - if ($scope.callback) { - $scope.callback(); - } + $timeout(function() { + if ($scope.callback) { + return $scope.callback(); + } + }); return $scope.hide(); }; $scope.select = function(day, $event) { diff --git a/build/angular-date-range-picker.min.js b/build/angular-date-range-picker.min.js index 94965e8..91f8de2 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-05-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:"@",callback:"&"},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=a0)),(j=d.months)[g]||(j[g]={name:a.format("MMMM YYYY"),weeks:[]}),(k=d.months[g].weeks)[i]||(k[i]=[]),d.months[g].weeks[i][e]={date:a,selected:h,disabled:f,start:d.start&&d.start.unix()===a.unix()}}),g=d.months,e=0,f=g.length;f>e;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.callback&&d.callback(),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.add(a,"months"),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 +(function(){angular.module("dateRangePicker",["pasvaz.bindonce"]),angular.module("dateRangePicker").directive("dateRangePicker",["$compile","$timeout",function(a,b){var c,d;return d='
\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
',c="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:"@",callback:"&"},link:function(e,f){var g,h,i,j,k,l;return e.quickListDefinitions=e.customSelectOptions,null==e.quickListDefinitions&&(e.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"))}]),e.quick=null,e.range=null,e.selecting=!1,e.visible=!1,e.start=null,e.showRanged=void 0===e.ranged?!0:e.ranged,k=function(a){var b,d,f,g,h;if(null==a&&(a=!1),e.showRanged){for(e.quickList=[],a&&e.quickList.push({label:"Custom",range:c}),g=e.quickListDefinitions,h=[],d=0,f=g.length;f>d;d++)b=g[d],h.push(e.quickList.push(b));return h}},i=function(){var a,b;return e.showRanged?e.range=e.selection?(b=e.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")):(e.selection=!1,e.selection=e.model||!1,e.date=e.model||moment(),e.range=moment().range(moment(e.date).startOf("month"),moment(e.date).endOf("month")))},j=function(){var a,b,d,f;if(e.showRanged&&e.selection){for(f=e.quickList,b=0,d=f.length;d>b;b++)if(a=f[b],a.range!==c&&e.selection.start.startOf("day").unix()===a.range.start.startOf("day").unix()&&e.selection.end.startOf("day").unix()===a.range.end.startOf("day").unix())return e.quick=a.range,void k();return e.quick=c,k(!0)}},l=function(){var a,b,c,d,f,g;for(e.months=[],c=12*e.range.start.year()+e.range.start.month(),b=moment().startOf("week").day(),e.range.by("days",function(a){var d,f,g,h,i,j,k;return d=a.day()-b,0>d&&(d=7+d),g=12*a.year()+a.month()-c,i=parseInt((7+a.date()-d)/7),h=!1,f=!1,e.showRanged?e.start?(h=a===e.start,f=a0)),(j=e.months)[g]||(j[g]={name:a.format("MMMM YYYY"),weeks:[]}),(k=e.months[g].weeks)[i]||(k[i]=[]),e.months[g].weeks[i][d]={date:a,selected:h,disabled:f,start:e.start&&e.start.unix()===a.unix()}}),g=e.months,d=0,f=g.length;f>d;d++)a=g[d],a.weeks[0]||a.weeks.splice(0,1);return j()},e.show=function(){return e.selection=e.model,i(),l(),e.visible=!0},e.hide=function(a){return null!=a&&"function"==typeof a.stopPropagation&&a.stopPropagation(),e.visible=!1,e.start=null},e.prevent_select=function(a){return null!=a&&"function"==typeof a.stopPropagation?a.stopPropagation():void 0},e.ok=function(a){return null!=a&&"function"==typeof a.stopPropagation&&a.stopPropagation(),e.model=e.selection,b(function(){return e.callback?e.callback():void 0}),e.hide()},e.select=function(a,b){return null!=b&&"function"==typeof b.stopPropagation&&b.stopPropagation(),a.disabled?void 0:(e.showRanged?(e.selecting=!e.selecting,e.selecting?e.start=a.date:(e.selection=moment().range(e.start,a.date),e.start=null)):e.selection=a.date,l())},e.move=function(a,b){return null!=b&&"function"==typeof b.stopPropagation&&b.stopPropagation(),e.showRanged?e.range=moment().range(e.range.start.add(a,"months").startOf("month").startOf("day"),e.range.start.clone().add(2,"months").endOf("month").startOf("day")):(e.date.add(a,"months"),e.range=moment().range(moment(e.date).startOf("month"),moment(e.date).endOf("month"))),l()},e.handlePickerClick=function(a){return null!=a&&"function"==typeof a.stopPropagation?a.stopPropagation():void 0},e.$watch("quick",function(a){return a&&a!==c?(e.selection=e.quick,e.selecting=!1,e.start=null,i(),l()):void 0}),e.$watch("customSelectOptions",function(a){return"undefined"!=typeof customSelectOptions&&null!==customSelectOptions?e.quickListDefinitions=a:void 0}),h=a(angular.element(d))(e),f.append(h),f.bind("click",function(a){return null!=a&&"function"==typeof a.stopPropagation&&a.stopPropagation(),e.$apply(function(){return e.visible?e.hide():e.show()})}),g=function(){return e.$apply(function(){return e.hide()}),!0},angular.element(document).bind("click",g),e.$on("$destroy",function(){return angular.element(document).unbind("click",g)}),k(),i(),l()}}}])}).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 ea14843..82a42c9 100644 --- a/src/angular-date-range-picker.coffee +++ b/src/angular-date-range-picker.coffee @@ -1,6 +1,6 @@ angular.module "dateRangePicker", ['pasvaz.bindonce'] -angular.module("dateRangePicker").directive "dateRangePicker", ["$compile", ($compile) -> +angular.module("dateRangePicker").directive "dateRangePicker", ["$compile", "$timeout", ($compile, $timeout) -> # constants pickerTemplate = """
@@ -208,7 +208,7 @@ angular.module("dateRangePicker").directive "dateRangePicker", ["$compile", ($co $scope.ok = ($event) -> $event?.stopPropagation?() $scope.model = $scope.selection - $scope.callback() if $scope.callback + $timeout -> $scope.callback() if $scope.callback $scope.hide() $scope.select = (day, $event) -> diff --git a/test/index.html b/test/index.html index 6e215b2..3d9d4bb 100644 --- a/test/index.html +++ b/test/index.html @@ -16,8 +16,8 @@ $scope.range2 = moment().range("2012-11-15", "2012-12-25") } - $scope.fireCallback = function() { - console.log('callback fired!'); + $scope.fireCallback = function(range) { + console.log(range); }; $scope.date = null @@ -37,7 +37,7 @@

Date range picker

{{ range.start.toDate() }} - {{ range.end.toDate() }}
- +