Skip to content

Commit 163d4f6

Browse files
committed
Fix several issues
See https://github.com/g00fy-/angular-datepicker/pull/324 pull request for details
1 parent 28c312d commit 163d4f6

File tree

6 files changed

+874
-848
lines changed

6 files changed

+874
-848
lines changed

app/index.html

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-

1+
22
<!DOCTYPE html>
33
<html>
44
<head>
@@ -39,7 +39,13 @@ <h2>Custom formats</h2>
3939
<h5>{{format}}</h5>
4040
<input type="text" date-time ng-model="dates.today" view="hours" format="{{format}}">
4141
</div>
42+
<hr />
4243

44+
<h2>First day</h2>
45+
<div ng-repeat="weekDay in weekDays">
46+
<h5>First Day: {{weekDay[0]}}</h5>
47+
<div date-picker="dates.today" view="date" first-day="{{weekDay[1]}}" watch-direct-changes="true"></div>
48+
</div>
4349
</div>
4450
<div class="span4">
4551
<h2>Minimum / Maximum dates</h2>
@@ -68,7 +74,7 @@ <h4>Input with popup (date-time directive)</h4>
6874

6975
<form name="demoForm">
7076
<div>
71-
<h5>Min ({{demoForm.pickerMinDate.$error.min ? 'Min: invalid' : 'Min: valid'}})</h5>
77+
<h5>Min ({{demoForm.pickerMinDate.$error.min ? 'Min: invalid' : 'Min: valid'}})</h5>
7278
<input date-time name="pickerMinDate" ng-model="dates.today" id="pickerMinDate" min-date="minDate" view="date" min-view="hours" timezone="UTC" format="lll">
7379
</div>
7480

@@ -187,6 +193,16 @@ <h4>Select a date from either picker</h4>
187193
"lll",
188194
];
189195

196+
$scope.weekDays = [
197+
['Sunday', 0],
198+
['Monday', 1],
199+
['Tuesday', 2],
200+
['Wednesday', 3],
201+
['Thursday', 4],
202+
['Friday', 5],
203+
['Saturday', 6],
204+
];
205+
190206
$scope.timezones = [
191207
['London, UK', 'Europe/London'],
192208
['Hong Kong, China', 'Asia/Hong_Kong'],

app/scripts/datePicker.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,15 @@ Module.constant('datePickerConfig', {
2424
//Moment format filter.
2525
Module.filter('mFormat', function () {
2626
return function (m, format, tz) {
27-
if (!(moment.isMoment(m))) {
28-
return moment(m).format(format);
27+
if (!m) {
28+
return '';
29+
}
30+
31+
if (tz) {
32+
return moment.tz(m, tz).format(format);
33+
} else {
34+
return moment.isMoment(m) ? m.format(format) : moment(m).format(format);
2935
}
30-
return tz ? moment.tz(m, tz).format(format) : m.format(format);
3136
};
3237
});
3338

app/scripts/datePickerUtils.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,13 +156,15 @@ angular.module('datePicker').factory('datePickerUtils', function () {
156156
scopeSearch: function (scope, name, comparisonFn) {
157157
var parentScope = scope,
158158
nameArray = name.split('.'),
159-
target, i, j = nameArray.length;
159+
target, i, j = nameArray.length,
160+
lastTarget;
160161

161162
do {
162-
target = parentScope = parentScope.$parent;
163+
lastTarget = target = parentScope = parentScope.$parent;
163164

164165
//Loop through provided names.
165166
for (i = 0; i < j; i++) {
167+
lastTarget = target;
166168
target = target[nameArray[i]];
167169
if (!target) {
168170
continue;
@@ -174,7 +176,7 @@ angular.module('datePicker').factory('datePickerUtils', function () {
174176
//function. If the comparison function is happy, return
175177
//found result. Otherwise, continue to the next parent scope
176178
if (target && comparisonFn(target)) {
177-
return target;
179+
return [target, lastTarget];
178180
}
179181

180182
} while (parentScope.$parent);
@@ -183,17 +185,24 @@ angular.module('datePicker').factory('datePickerUtils', function () {
183185
},
184186
findFunction: function (scope, name) {
185187
//Search scope ancestors for a matching function.
186-
return this.scopeSearch(scope, name, function (target) {
188+
var result = this.scopeSearch(scope, name, function (target) {
187189
//Property must also be a function
188190
return angular.isFunction(target);
189191
});
192+
193+
194+
return result ? function () {
195+
result[0].apply(result[1], arguments);
196+
} : false;
190197
},
191198
findParam: function (scope, name) {
192199
//Search scope ancestors for a matching parameter.
193-
return this.scopeSearch(scope, name, function () {
200+
var result = this.scopeSearch(scope, name, function () {
194201
//As long as the property exists, we're good
195202
return true;
196203
});
204+
205+
return result ? result[0] : false;
197206
},
198207
createMoment: function (m) {
199208
if (tz) {

0 commit comments

Comments
 (0)