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

Commit 4bb178a

Browse files
RobJacobswesleycho
authored andcommitted
fix(position): move inline styles to a class
- Move all inline styles supporting the auto position and flicker suppression to a class. - Refine how placement classes get applied to the tooltip Closes #5535 Fixes #5470
1 parent bbc4912 commit 4bb178a

File tree

7 files changed

+44
-18
lines changed

7 files changed

+44
-18
lines changed

src/datepicker/datepicker.css

-3
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@
99
.uib-datepicker-popup.dropdown-menu {
1010
display: block;
1111
float: none;
12-
visibility: hidden;
1312
margin: 0;
14-
top: -9999px;
15-
left: -9999px;
1613
}
1714

1815
.uib-button-bar {

src/datepicker/datepicker.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -1207,10 +1207,13 @@ function($scope, $element, $attrs, $compile, $log, $parse, $window, $document, $
12071207

12081208
function positionPopup() {
12091209
if ($scope.isOpen) {
1210-
var dpElement = $popup[0].querySelector('.uib-datepicker-popup');
1210+
var dpElement = angular.element($popup[0].querySelector('.uib-datepicker-popup'));
12111211
var placement = $attrs.popupPlacement ? $attrs.popupPlacement : datepickerPopupConfig.placement;
12121212
var position = $position.positionElements($element, dpElement, placement, appendToBody);
1213-
angular.element(dpElement).css({top: position.top + 'px', left: position.left + 'px', visibility: 'visible'});
1213+
dpElement.css({top: position.top + 'px', left: position.left + 'px'});
1214+
if (dpElement.hasClass('uib-position-measure')) {
1215+
dpElement.removeClass('uib-position-measure');
1216+
}
12141217
}
12151218
}
12161219

src/position/position.css

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
.uib-position-measure {
2+
display: block !important;
3+
visibility: hidden !important;
4+
position: absolute !important;
5+
top: -9999px !important;
6+
left: -9999px !important;
7+
}
8+
9+
.uib-position-scrollbar-measure {
10+
position: absolute;
11+
top: -9999px;
12+
width: 50px;
13+
height: 50px;
14+
overflow: scroll;
15+
}

src/position/position.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ angular.module('ui.bootstrap.position', [])
8080
*/
8181
scrollbarWidth: function() {
8282
if (angular.isUndefined(SCROLLBAR_WIDTH)) {
83-
var scrollElem = angular.element('<div style="position: absolute; top: -9999px; width: 50px; height: 50px; overflow: scroll;"></div>');
83+
var scrollElem = angular.element('<div class="uib-position-scrollbar-measure"></div>');
8484
$document.find('body').append(scrollElem);
8585
SCROLLBAR_WIDTH = scrollElem[0].offsetWidth - scrollElem[0].clientWidth;
8686
SCROLLBAR_WIDTH = isFinite(SCROLLBAR_WIDTH) ? SCROLLBAR_WIDTH : 0;

src/tooltip/tooltip.css

+4
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,8 @@
1919
left: auto;
2020
right: auto;
2121
margin: 0;
22+
}
23+
24+
[uib-popover-popup].popover {
25+
display: block !important;
2226
}

src/tooltip/tooltip.js

+18-11
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ angular.module('ui.bootstrap.tooltip', ['ui.bootstrap.position', 'ui.bootstrap.s
131131
'animation="animation" ' +
132132
'is-open="isOpen"' +
133133
'origin-scope="origScope" ' +
134-
'style="visibility: hidden; display: block; top: -9999px; left: -9999px;"' +
134+
'class="uib-position-measure"' +
135135
'>' +
136136
'</div>';
137137

@@ -162,23 +162,29 @@ angular.module('ui.bootstrap.tooltip', ['ui.bootstrap.position', 'ui.bootstrap.s
162162

163163
if (!positionTimeout) {
164164
positionTimeout = $timeout(function() {
165-
// Reset the positioning.
166-
tooltip.css({ top: 0, left: 0 });
167-
168-
// Now set the calculated positioning.
169165
var ttPosition = $position.positionElements(element, tooltip, ttScope.placement, appendToBody);
170-
tooltip.css({ top: ttPosition.top + 'px', left: ttPosition.left + 'px', visibility: 'visible' });
166+
tooltip.css({ top: ttPosition.top + 'px', left: ttPosition.left + 'px' });
171167

172-
if (ttPosition.placement !== lastPlacement) {
168+
if (!tooltip.hasClass(ttPosition.placement.split('-')[0])) {
173169
tooltip.removeClass(lastPlacement.split('-')[0]);
174170
tooltip.addClass(ttPosition.placement.split('-')[0]);
171+
}
175172

173+
if (!tooltip.hasClass(options.placementClassPrefix + ttPosition.placement)) {
176174
tooltip.removeClass(options.placementClassPrefix + lastPlacement);
177175
tooltip.addClass(options.placementClassPrefix + ttPosition.placement);
176+
}
178177

178+
// first time through tt element will have the
179+
// uib-position-measure class or if the placement
180+
// has changed we need to position the arrow.
181+
if (tooltip.hasClass('uib-position-measure')) {
182+
$position.positionArrow(tooltip, ttPosition.placement);
183+
tooltip.removeClass('uib-position-measure');
184+
} else if (lastPlacement !== ttPosition.placement) {
179185
$position.positionArrow(tooltip, ttPosition.placement);
180-
lastPlacement = ttPosition.placement;
181186
}
187+
lastPlacement = ttPosition.placement;
182188

183189
positionTimeout = null;
184190
}, 0, false);
@@ -353,7 +359,8 @@ angular.module('ui.bootstrap.tooltip', ['ui.bootstrap.position', 'ui.bootstrap.s
353359

354360
ttScope.popupClass = attrs[prefix + 'Class'];
355361
ttScope.placement = angular.isDefined(attrs[prefix + 'Placement']) ? attrs[prefix + 'Placement'] : options.placement;
356-
lastPlacement = '';
362+
var placement = $position.parsePlacement(ttScope.placement);
363+
lastPlacement = placement[1] ? placement[0] + '-' + placement[1] : placement[0];
357364

358365
var delay = parseInt(attrs[prefix + 'PopupDelay'], 10);
359366
var closeDelay = parseInt(attrs[prefix + 'PopupCloseDelay'], 10);
@@ -443,6 +450,8 @@ angular.module('ui.bootstrap.tooltip', ['ui.bootstrap.position', 'ui.bootstrap.s
443450
observers.push(
444451
attrs.$observe(prefix + 'Placement', function(val) {
445452
ttScope.placement = val ? val : options.placement;
453+
var placement = $position.parsePlacement(ttScope.placement);
454+
lastPlacement = placement[1] ? placement[0] + '-' + placement[1] : placement[0];
446455
if (ttScope.isOpen) {
447456
positionTooltip();
448457
}
@@ -631,8 +640,6 @@ function ($animate, $sce, $compile, $templateRequest) {
631640
// // in TWBS, so we need the primary position.
632641
var position = $uibPosition.parsePlacement(scope.placement);
633642
element.addClass(position[0]);
634-
} else {
635-
element.addClass('top');
636643
}
637644

638645
if (scope.popupClass) {

template/datepicker/popup.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<div>
2-
<ul class="uib-datepicker-popup dropdown-menu" dropdown-nested ng-if="isOpen" ng-style="{top: position.top+'px', left: position.left+'px'}" ng-keydown="keydown($event)" ng-click="$event.stopPropagation()">
2+
<ul class="uib-datepicker-popup dropdown-menu uib-position-measure" dropdown-nested ng-if="isOpen" ng-keydown="keydown($event)" ng-click="$event.stopPropagation()">
33
<li ng-transclude></li>
44
<li ng-if="showButtonBar" class="uib-button-bar">
55
<span class="btn-group pull-left">

0 commit comments

Comments
 (0)