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

Commit d140395

Browse files
committed
feat(datepicker): datepicker position attr
1 parent eb3b32e commit d140395

File tree

5 files changed

+45
-11
lines changed

5 files changed

+45
-11
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ lib-cov
99
*.swp
1010
*.swo
1111
.DS_Store
12+
.idea
1213

1314
pids
1415
logs

src/datepicker/datepicker.js

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,9 @@ function ($compile, $parse, $document, $position, dateFilter, dateParser, datepi
471471
clearText: '@',
472472
closeText: '@',
473473
dateDisabled: '&',
474-
customClass: '&'
474+
customClass: '&',
475+
position: '@'
476+
475477
},
476478
link: function(scope, element, attrs, ngModel) {
477479
var dateFormat,
@@ -681,8 +683,29 @@ function ($compile, $parse, $document, $position, dateFilter, dateParser, datepi
681683
scope.$watch('isOpen', function(value) {
682684
if (value) {
683685
scope.$broadcast('datepicker.focus');
684-
scope.position = appendToBody ? $position.offset(element) : $position.position(element);
685-
scope.position.top = scope.position.top + element.prop('offsetHeight');
686+
scope.popupPosition = appendToBody ? $position.offset(element) : $position.position(element);
687+
688+
var clearPosition = function() {
689+
scope.popupPosition.top = scope.popupPosition.bottom = scope.popupPosition.left = scope.popupPosition.right = 'initial';
690+
};
691+
692+
if (!scope.position || scope.position === 'bottom-left') {
693+
clearPosition();
694+
scope.popupPosition.left = 0;
695+
scope.popupPosition.top = $position.position(element).height + 'px';
696+
} else if (scope.position === 'bottom-right') {
697+
clearPosition();
698+
scope.popupPosition.right = 0;
699+
scope.popupPosition.top = $position.position(element).height + 'px';
700+
} else if (scope.position === 'top-right') {
701+
clearPosition();
702+
scope.popupPosition.right = 0;
703+
scope.popupPosition.bottom = $position.position(element).height + 'px';
704+
} else if (scope.position === 'top-left') {
705+
clearPosition();
706+
scope.popupPosition.left = 0;
707+
scope.popupPosition.bottom = $position.position(element).height + 'px';
708+
}
686709

687710
$document.bind('click', documentClickBind);
688711
} else {

src/datepicker/docs/demo.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ <h4>Popup</h4>
2222
<div class="row">
2323
<div class="col-md-6">
2424
<p class="input-group">
25-
<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" />
25+
<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" />
2626
<span class="input-group-btn">
2727
<button type="button" class="btn btn-default" ng-click="open($event)"><i class="glyphicon glyphicon-calendar"></i></button>
2828
</span>

src/datepicker/docs/readme.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ Specific settings for the `datepicker-popup`, that can globally configured throu
119119
_(Default: false)_:
120120
Append the datepicker popup element to `body`, rather than inserting after `datepicker-popup`. For global configuration, use `datepickerPopupConfig.appendToBody`.
121121

122+
* `position`
123+
_(Default: 'bottom-left')_ :
124+
Where datepicker should be displayed. Options _(bottom-left|bottom-right|top-left|top-right)_
125+
122126
### Keyboard Support ###
123127

124128
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.

template/datepicker/popup.html

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1-
<ul class="dropdown-menu" ng-style="{display: (isOpen && 'block') || 'none', top: position.top+'px', left: position.left+'px'}" ng-keydown="keydown($event)">
2-
<li ng-transclude></li>
3-
<li ng-if="showButtonBar" style="padding:10px 9px 2px">
1+
<ul class="dropdown-menu" ng-style="{display: (isOpen && 'block') || 'none',
2+
position: 'absolute',
3+
top: popupPosition.top,
4+
left: popupPosition.left,
5+
right: popupPosition.right,
6+
bottom: popupPosition.bottom}" ng-keydown="keydown($event)">
7+
<li ng-transclude></li>
8+
<li ng-if="showButtonBar" style="padding:10px 9px 2px">
49
<span class="btn-group pull-left">
5-
<button type="button" class="btn btn-sm btn-info" ng-click="select('today')">{{ getText('current') }}</button>
10+
<button type="button" class="btn btn-sm btn-info" ng-click="select('today')">{{ getText('current') }}
11+
</button>
612
<button type="button" class="btn btn-sm btn-danger" ng-click="select(null)">{{ getText('clear') }}</button>
713
</span>
8-
<button type="button" class="btn btn-sm btn-success pull-right" ng-click="close()">{{ getText('close') }}</button>
9-
</li>
10-
</ul>
14+
<button type="button" class="btn btn-sm btn-success pull-right" ng-click="close()">{{ getText('close') }}</button>
15+
</li>
16+
</ul>

0 commit comments

Comments
 (0)