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

Commit

Permalink
feat(datepicker): datepicker position attr
Browse files Browse the repository at this point in the history
  • Loading branch information
hxtpoe committed Jun 29, 2015
1 parent eb3b32e commit ad667c9
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ lib-cov
*.swp
*.swo
.DS_Store
.idea

pids
logs
Expand Down
29 changes: 26 additions & 3 deletions src/datepicker/datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,9 @@ function ($compile, $parse, $document, $position, dateFilter, dateParser, datepi
clearText: '@',
closeText: '@',
dateDisabled: '&',
customClass: '&'
customClass: '&',
position: '@'

},
link: function(scope, element, attrs, ngModel) {
var dateFormat,
Expand Down Expand Up @@ -681,8 +683,29 @@ function ($compile, $parse, $document, $position, dateFilter, dateParser, datepi
scope.$watch('isOpen', function(value) {
if (value) {
scope.$broadcast('datepicker.focus');
scope.position = appendToBody ? $position.offset(element) : $position.position(element);
scope.position.top = scope.position.top + element.prop('offsetHeight');
scope.popupPosition = appendToBody ? $position.offset(element) : $position.position(element);

var clearPosition = function() {
scope.popupPosition.top = scope.popupPosition.bottom = scope.popupPosition.left = scope.popupPosition.right = 'initial';
};

if (!scope.position || scope.position === 'bottom-left') {
clearPosition();
scope.popupPosition.left = 0;
scope.popupPosition.top = $position.position(element).height + 'px';
} else if (scope.position === 'bottom-right') {
clearPosition();
scope.popupPosition.right = 0;
scope.popupPosition.top = $position.position(element).height + 'px';
} else if (scope.position === 'top-right') {
clearPosition();
scope.popupPosition.right = 0;
scope.popupPosition.bottom = $position.position(element).height + 'px';
} else if (scope.position === 'top-left') {
clearPosition();
scope.popupPosition.left = 0;
scope.popupPosition.bottom = $position.position(element).height + 'px';
}

$document.bind('click', documentClickBind);
} else {
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 @@ -22,7 +22,7 @@ <h4>Popup</h4>
<div class="row">
<div class="col-md-6">
<p class="input-group">
<input type="text" class="form-control" datepicker-popup="{{format}}" ng-model="dt" is-open="opened" min-date="minDate" max-date="'2015-06-22'" datepicker-options="dateOptions" date-disabled="disabled(date, mode)" ng-required="true" close-text="Close" />
<input type="text" class="form-control" position="top-right" datepicker-popup="{{format}}" ng-model="dt" is-open="opened" min-date="minDate" max-date="'2015-06-22'" datepicker-options="dateOptions" date-disabled="disabled(date, mode)" ng-required="true" close-text="Close" />
<span class="input-group-btn">
<button type="button" class="btn btn-default" ng-click="open($event)"><i class="glyphicon glyphicon-calendar"></i></button>
</span>
Expand Down
4 changes: 4 additions & 0 deletions src/datepicker/docs/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ Specific settings for the `datepicker-popup`, that can globally configured throu
_(Default: false)_:
Append the datepicker popup element to `body`, rather than inserting after `datepicker-popup`. For global configuration, use `datepickerPopupConfig.appendToBody`.

* `position`
_(Default: 'bottom-left')_ :
Where datepicker should be displayed. Options _(bottom-left|bottom-right|top-left|top-right)_

### Keyboard Support ###

Depending on datepicker's current mode, the date may reffer either to day, month or year. Accordingly, the term view reffers either to a month, year or year range.
Expand Down
17 changes: 11 additions & 6 deletions template/datepicker/popup.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
<ul class="dropdown-menu" ng-style="{display: (isOpen && 'block') || 'none', top: position.top+'px', left: position.left+'px'}" ng-keydown="keydown($event)">
<li ng-transclude></li>
<li ng-if="showButtonBar" style="padding:10px 9px 2px">
<ul class="dropdown-menu" ng-style="{display: (isOpen && 'block') || 'none',
position: 'absolute',
top: popupPosition.top,
left: popupPosition.left,
right: popupPosition.right,
bottom: popupPosition.bottom}" ng-keydown="keydown($event)">
<li ng-transclude></li>
<li ng-if="showButtonBar" style="padding:10px 9px 2px">
<span class="btn-group pull-left">
<button type="button" class="btn btn-sm btn-info" ng-click="select('today')">{{ getText('current') }}</button>
<button type="button" class="btn btn-sm btn-danger" ng-click="select(null)">{{ getText('clear') }}</button>
</span>
<button type="button" class="btn btn-sm btn-success pull-right" ng-click="close()">{{ getText('close') }}</button>
</li>
</ul>
<button type="button" class="btn btn-sm btn-success pull-right" ng-click="close()">{{ getText('close') }}</button>
</li>
</ul>

0 comments on commit ad667c9

Please sign in to comment.