Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

Commit

Permalink
fix(datepicker): compatibility with angular 1.1.5 and no jquery
Browse files Browse the repository at this point in the history
Closes #760
  • Loading branch information
Swiip authored and pkozlowski-opensource committed Aug 10, 2013
1 parent b08e993 commit bf30898
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
15 changes: 11 additions & 4 deletions src/datepicker/datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,8 @@ function ($compile, $parse, $document, $position, dateFilter, datepickerPopupCon
ngModel.$parsers.push(parseDate);

var getIsOpen, setIsOpen;
if ( attrs.open ) {
getIsOpen = $parse(attrs.open);
if ( attrs.isOpen ) {
getIsOpen = $parse(attrs.isOpen);
setIsOpen = getIsOpen.assign;

originalScope.$watch(getIsOpen, function updateOpen(value) {
Expand Down Expand Up @@ -386,15 +386,22 @@ function ($compile, $parse, $document, $position, dateFilter, datepickerPopupCon
scope.position.top = scope.position.top + element.prop('offsetHeight');
}

var documentBindingInitialized = false, elementFocusInitialized = false;
scope.$watch('isOpen', function(value) {
if (value) {
updatePosition();
$document.bind('click', documentClickBind);
element.unbind('focus', elementFocusBind);
if(elementFocusInitialized) {
element.unbind('focus', elementFocusBind);
}
element[0].focus();
documentBindingInitialized = true;
} else {
$document.unbind('click', documentClickBind);
if(documentBindingInitialized) {
$document.unbind('click', documentClickBind);
}
element.bind('focus', elementFocusBind);
elementFocusInitialized = true;
}

if ( setIsOpen ) {
Expand Down
2 changes: 1 addition & 1 deletion src/datepicker/docs/demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</div>

<div class="form-horizontal">
<input type="text" datepicker-popup="dd-MMMM-yyyy" ng-model="dt" open="opened" min="minDate" max="'2015-06-22'" datepicker-options="dateOptions" date-disabled="disabled(date, mode)" ng-required="true" />
<input type="text" datepicker-popup="dd-MMMM-yyyy" ng-model="dt" is-open="opened" min="minDate" max="'2015-06-22'" datepicker-options="dateOptions" date-disabled="disabled(date, mode)" ng-required="true" />
<button class="btn" ng-click="open()"><i class="icon-calendar"></i></button>
</div>

Expand Down
2 changes: 1 addition & 1 deletion src/datepicker/test/datepicker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,7 @@ describe('datepicker directive', function () {
describe('toggles programatically by `open` attribute', function () {
beforeEach(inject(function() {
$rootScope.open = true;
var wrapElement = $compile('<div><input ng-model="date" datepicker-popup open="open"><div>')($rootScope);
var wrapElement = $compile('<div><input ng-model="date" datepicker-popup is-open="open"><div>')($rootScope);
$rootScope.$digest();
assignElements(wrapElement);
}));
Expand Down

0 comments on commit bf30898

Please sign in to comment.