Skip to content
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
27 changes: 26 additions & 1 deletion app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,15 @@ <h5>Date range button</h5>
</div>
</div>
</div>

<div class="span6" ng-controller="onSetDateCtrl">
<h3>Callback on set date</h3>

<h5>Execute callback on month set</h5>

<div date-picker="callbackStart" min-view="month" view="year" on-set-date="a.b.callback"></div>

</div>
</div>

<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.js"></script>
Expand All @@ -175,7 +184,23 @@ <h5>Date range button</h5>
<script src="scripts/dateRange.js"></script>
<script src="scripts/input.js"></script>
<script>
angular.module('sample', ['datePicker', 'ui.bootstrap']);
var module = angular.module('sample', ['datePicker', 'ui.bootstrap']);

module.controller('onSetDateCtrl', onSetDateCtrl);

function onSetDateCtrl($scope) {
var now = new Date(Date.now());
$scope.callbackStart = now.toISOString();
$scope.a = {
b: {
callback: callback
}
};

function callback() {
alert('callback executed!');
}
}
</script>
</body>
</html>
20 changes: 18 additions & 2 deletions app/scripts/datePicker.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* global _ */
'use strict';

var Module = angular.module('datePicker', []);
Expand Down Expand Up @@ -40,6 +39,23 @@ Module.directive('datePicker', ['datePickerConfig', 'datePickerUtils', function
},
link: function (scope, element, attrs, ngModel) {

function getField(obj, field) {
if (!obj) {
return;
}
if (!field) {
return obj;
}

var subFields = field.split('.');

if (!obj[subFields[0]]) {
return;
}

return getField(obj[subFields[0]], field.substr(subFields[0].length+1));
}

var arrowClick = false;

scope.date = new Date(scope.model || new Date());
Expand All @@ -48,7 +64,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;
scope.callbackOnSetDate = attrs.onSetDate ? getField(scope.$parent, attrs.onSetDate) : undefined;

var step = parseInt(attrs.step || datePickerConfig.step, 10);
var partial = !!attrs.partial;
Expand Down
8 changes: 3 additions & 5 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.21",
"version": "1.0.22",
"main": [
"./dist/angular-datepicker.js",
"./dist/angular-datepicker.css"
Expand All @@ -21,14 +21,12 @@
"package.json"
],
"dependencies": {
"angular": "1.2.14",
"lodash": "~3.10.1"
"angular": "1.2.14"
},
"devDependencies": {
"angular": "1.2.14",
"angular-mocks": "1.2.14",
"angular-scenario": "1.2.14",
"angular-bootstrap": "~0.3.0",
"lodash": "~3.10.1"
"angular-bootstrap": "~0.3.0"
}
}
20 changes: 18 additions & 2 deletions dist/angular-datepicker.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';
(function(angular){
/* global _ */
var Module = angular.module('datePicker', []);

Module.constant('datePickerConfig', {
Expand Down Expand Up @@ -40,6 +39,23 @@ Module.directive('datePicker', ['datePickerConfig', 'datePickerUtils', function
},
link: function (scope, element, attrs, ngModel) {

function getField(obj, field) {
if (!obj) {
return;
}
if (!field) {
return obj;
}

var subFields = field.split('.');

if (!obj[subFields[0]]) {
return;
}

return getField(obj[subFields[0]], field.substr(subFields[0].length+1));
}

var arrowClick = false;

scope.date = new Date(scope.model || new Date());
Expand All @@ -48,7 +64,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;
scope.callbackOnSetDate = attrs.onSetDate ? getField(scope.$parent, attrs.onSetDate) : undefined;

var step = parseInt(attrs.step || datePickerConfig.step, 10);
var partial = !!attrs.partial;
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.21",
"version": "1.0.22",
"main": "dist/angular-datepicker.js",
"repository": {
"url": "https://github.com/g00fy-/angular-datepicker.git"
Expand Down