Skip to content

Commit

Permalink
feat(datepicker): add open-on-focus option
Browse files Browse the repository at this point in the history
  • Loading branch information
greenboxal committed Jul 25, 2014
1 parent 7512b93 commit b663a7d
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/datepicker/datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,8 @@ angular.module('ui.bootstrap.datepicker', ['ui.bootstrap.dateparser', 'ui.bootst
showButtonBar: true
})

.directive('datepickerPopup', ['$compile', '$parse', '$document', '$position', 'dateFilter', 'dateParser', 'datepickerPopupConfig',
function ($compile, $parse, $document, $position, dateFilter, dateParser, datepickerPopupConfig) {
.directive('datepickerPopup', ['$compile', '$parse', '$document', '$position', '$timeout', 'dateFilter', 'dateParser', 'datepickerPopupConfig',
function ($compile, $parse, $document, $position, $timeout, dateFilter, dateParser, datepickerPopupConfig) {
return {
restrict: 'EA',
require: 'ngModel',
Expand All @@ -440,7 +440,8 @@ function ($compile, $parse, $document, $position, dateFilter, dateParser, datepi
currentText: '@',
clearText: '@',
closeText: '@',
dateDisabled: '&'
dateDisabled: '&',
openOnFocus: '@'
},
link: function(scope, element, attrs, ngModel) {
var dateFormat,
Expand Down Expand Up @@ -564,6 +565,16 @@ function ($compile, $parse, $document, $position, dateFilter, dateParser, datepi
};
element.bind('keydown', keydown);

var focus = function(evt) {
$timeout(function() {
scope.isOpen = true;
});
};

if (scope.openOnFocus) {
element.bind('focus', focus);
}

scope.keydown = function(evt) {
if (evt.which === 27) {
evt.preventDefault();
Expand Down Expand Up @@ -614,6 +625,7 @@ function ($compile, $parse, $document, $position, dateFilter, dateParser, datepi
scope.$on('$destroy', function() {
$popup.remove();
element.unbind('keydown', keydown);
element.unbind('focus', focus);
$document.unbind('click', documentClickBind);
});
}
Expand Down

0 comments on commit b663a7d

Please sign in to comment.