Skip to content

Commit

Permalink
Fix several issues
Browse files Browse the repository at this point in the history
  • Loading branch information
xibre committed Aug 13, 2017
1 parent 28c312d commit 163d4f6
Show file tree
Hide file tree
Showing 6 changed files with 874 additions and 848 deletions.
20 changes: 18 additions & 2 deletions app/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@


<!DOCTYPE html>
<html>
<head>
Expand Down Expand Up @@ -39,7 +39,13 @@ <h2>Custom formats</h2>
<h5>{{format}}</h5>
<input type="text" date-time ng-model="dates.today" view="hours" format="{{format}}">
</div>
<hr />

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

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

Expand Down Expand Up @@ -187,6 +193,16 @@ <h4>Select a date from either picker</h4>
"lll",
];

$scope.weekDays = [
['Sunday', 0],
['Monday', 1],
['Tuesday', 2],
['Wednesday', 3],
['Thursday', 4],
['Friday', 5],
['Saturday', 6],
];

$scope.timezones = [
['London, UK', 'Europe/London'],
['Hong Kong, China', 'Asia/Hong_Kong'],
Expand Down
11 changes: 8 additions & 3 deletions app/scripts/datePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,15 @@ Module.constant('datePickerConfig', {
//Moment format filter.
Module.filter('mFormat', function () {
return function (m, format, tz) {
if (!(moment.isMoment(m))) {
return moment(m).format(format);
if (!m) {
return '';
}

if (tz) {
return moment.tz(m, tz).format(format);
} else {
return moment.isMoment(m) ? m.format(format) : moment(m).format(format);
}
return tz ? moment.tz(m, tz).format(format) : m.format(format);
};
});

Expand Down
19 changes: 14 additions & 5 deletions app/scripts/datePickerUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,15 @@ angular.module('datePicker').factory('datePickerUtils', function () {
scopeSearch: function (scope, name, comparisonFn) {
var parentScope = scope,
nameArray = name.split('.'),
target, i, j = nameArray.length;
target, i, j = nameArray.length,
lastTarget;

do {
target = parentScope = parentScope.$parent;
lastTarget = target = parentScope = parentScope.$parent;

//Loop through provided names.
for (i = 0; i < j; i++) {
lastTarget = target;
target = target[nameArray[i]];
if (!target) {
continue;
Expand All @@ -174,7 +176,7 @@ angular.module('datePicker').factory('datePickerUtils', function () {
//function. If the comparison function is happy, return
//found result. Otherwise, continue to the next parent scope
if (target && comparisonFn(target)) {
return target;
return [target, lastTarget];
}

} while (parentScope.$parent);
Expand All @@ -183,17 +185,24 @@ angular.module('datePicker').factory('datePickerUtils', function () {
},
findFunction: function (scope, name) {
//Search scope ancestors for a matching function.
return this.scopeSearch(scope, name, function (target) {
var result = this.scopeSearch(scope, name, function (target) {
//Property must also be a function
return angular.isFunction(target);
});


return result ? function () {
result[0].apply(result[1], arguments);
} : false;
},
findParam: function (scope, name) {
//Search scope ancestors for a matching parameter.
return this.scopeSearch(scope, name, function () {
var result = this.scopeSearch(scope, name, function () {
//As long as the property exists, we're good
return true;
});

return result ? result[0] : false;
},
createMoment: function (m) {
if (tz) {
Expand Down
Loading

0 comments on commit 163d4f6

Please sign in to comment.