Skip to content

Fix several issues #324

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
18 changes: 17 additions & 1 deletion app/index.html
Original file line number Diff line number Diff line change
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 @@ -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