Skip to content

Commit

Permalink
Merge pull request #172 from keenondrums/master
Browse files Browse the repository at this point in the history
Feature -> Callback On Set Date
  • Loading branch information
eralha committed Oct 13, 2015
2 parents 2fca5c7 + 879ab82 commit 19807ba
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 7 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,21 @@ Inject the dependency `angular.module('testApp', ['datePicker'])`
<div date-picker="start" watch-direct-changes></div>
```

##### Execute callback upon date set

<p>Execute callback when a new date set in a highest resolution available, e.g. if you specify min-view="hour" the callback will be executed only when the user picks an hour, not just date, month or year. Alternatively, you can bind to a new event 'setMaxDate'.</p>

<p>Within your controller</p>
```js
function callback() {
doStuff();
}
```
<p>In your html</p>
```html
<div date-picker="start" on-set-date="callback"></div>
```

##### input as datepicker

```html
Expand Down
13 changes: 12 additions & 1 deletion app/scripts/datePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Module.filter('time',function () {
};
});

Module.directive('datePicker', ['datePickerConfig', 'datePickerUtils', function datePickerDirective(datePickerConfig, datePickerUtils) {
Module.directive('datePicker', ['datePickerConfig', 'datePickerUtils', 'lodash', function datePickerDirective(datePickerConfig, datePickerUtils, _) {

//noinspection JSUnusedLocalSymbols
return {
Expand All @@ -47,6 +47,7 @@ Module.directive('datePicker', ['datePickerConfig', 'datePickerUtils', function
scope.now = new Date();
scope.template = attrs.template || datePickerConfig.template;
scope.watchDirectChanges = attrs.watchDirectChanges !== undefined;
scope.callbackOnSetDate = attrs.onSetDate ? _.get(scope.$parent, attrs.onSetDate) : undefined;

var step = parseInt(attrs.step || datePickerConfig.step, 10);
var partial = !!attrs.partial;
Expand Down Expand Up @@ -127,6 +128,16 @@ Module.directive('datePicker', ['datePickerConfig', 'datePickerUtils', function
case 'year':
scope.model.setFullYear(date.getFullYear());
}

if (!nextView && scope.model) {
scope.$emit('setMaxDate', attrs.datePicker, scope.model, scope.view);

if (scope.callbackOnSetDate) {
scope.callbackOnSetDate();
}

}

scope.$emit('setDate', scope.model, scope.view);
}

Expand Down
8 changes: 5 additions & 3 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "angular-datepicker",
"license": "MIT",
"version": "1.0.17",
"version": "1.0.18",
"main": [
"./dist/angular-datepicker.js",
"./dist/angular-datepicker.css"
Expand All @@ -21,12 +21,14 @@
"package.json"
],
"dependencies": {
"angular": "1.2.14"
"angular": "1.2.14",
"lodash": "~3.10.1"
},
"devDependencies": {
"angular": "1.2.14",
"angular-mocks": "1.2.14",
"angular-scenario": "1.2.14",
"angular-bootstrap": "~0.3.0"
"angular-bootstrap": "~0.3.0",
"lodash": "~3.10.1"
}
}
13 changes: 12 additions & 1 deletion dist/angular-datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Module.filter('time',function () {
};
});

Module.directive('datePicker', ['datePickerConfig', 'datePickerUtils', function datePickerDirective(datePickerConfig, datePickerUtils) {
Module.directive('datePicker', ['datePickerConfig', 'datePickerUtils', 'lodash', function datePickerDirective(datePickerConfig, datePickerUtils, _) {

//noinspection JSUnusedLocalSymbols
return {
Expand All @@ -47,6 +47,7 @@ Module.directive('datePicker', ['datePickerConfig', 'datePickerUtils', function
scope.now = new Date();
scope.template = attrs.template || datePickerConfig.template;
scope.watchDirectChanges = attrs.watchDirectChanges !== undefined;
scope.callbackOnSetDate = attrs.onSetDate ? _.get(scope.$parent, attrs.onSetDate) : undefined;

var step = parseInt(attrs.step || datePickerConfig.step, 10);
var partial = !!attrs.partial;
Expand Down Expand Up @@ -127,6 +128,16 @@ Module.directive('datePicker', ['datePickerConfig', 'datePickerUtils', function
case 'year':
scope.model.setFullYear(date.getFullYear());
}

if (!nextView && scope.model) {
scope.$emit('setMaxDate', attrs.datePicker, scope.model, scope.view);

if (scope.callbackOnSetDate) {
scope.callbackOnSetDate();
}

}

scope.$emit('setDate', scope.model, scope.view);
}

Expand Down
2 changes: 1 addition & 1 deletion dist/angular-datepicker.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-datepicker",
"version": "1.0.17",
"version": "1.0.18",
"main": "dist/angular-datepicker.js",
"repository": {
"url": "https://github.com/g00fy-/angular-datepicker.git"
Expand Down

0 comments on commit 19807ba

Please sign in to comment.