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

fix(position): move inline styles to a class #5535

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions src/datepicker/datepicker.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@
.uib-datepicker-popup.dropdown-menu {
display: block;
float: none;
visibility: hidden;
margin: 0;
top: -9999px;
left: -9999px;
}

.uib-button-bar {
Expand Down
7 changes: 5 additions & 2 deletions src/datepicker/datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -1231,10 +1231,13 @@ function($scope, $element, $attrs, $compile, $log, $parse, $window, $document, $

function positionPopup() {
if ($scope.isOpen) {
var dpElement = $popup[0].querySelector('.uib-datepicker-popup');
var dpElement = angular.element($popup[0].querySelector('.uib-datepicker-popup'));
var placement = $attrs.popupPlacement ? $attrs.popupPlacement : datepickerPopupConfig.placement;
var position = $position.positionElements($element, dpElement, placement, appendToBody);
angular.element(dpElement).css({top: position.top + 'px', left: position.left + 'px', visibility: 'visible'});
dpElement.css({top: position.top + 'px', left: position.left + 'px'});
if (dpElement.hasClass('uib-position-measure')) {
dpElement.removeClass('uib-position-measure');
}
}
}

Expand Down
15 changes: 15 additions & 0 deletions src/position/position.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.uib-position-measure {
display: block !important;
visibility: hidden !important;
position: absolute !important;
top: -9999px !important;
left: -9999px !important;
}

.uib-position-scrollbar-measure {
position: absolute;
top: -9999px;
width: 50px;
height: 50px;
overflow: scroll;
}
2 changes: 1 addition & 1 deletion src/position/position.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ angular.module('ui.bootstrap.position', [])
*/
scrollbarWidth: function() {
if (angular.isUndefined(SCROLLBAR_WIDTH)) {
var scrollElem = angular.element('<div style="position: absolute; top: -9999px; width: 50px; height: 50px; overflow: scroll;"></div>');
var scrollElem = angular.element('<div class="uib-position-scrollbar-measure"></div>');
$document.find('body').append(scrollElem);
SCROLLBAR_WIDTH = scrollElem[0].offsetWidth - scrollElem[0].clientWidth;
SCROLLBAR_WIDTH = isFinite(SCROLLBAR_WIDTH) ? SCROLLBAR_WIDTH : 0;
Expand Down
4 changes: 4 additions & 0 deletions src/tooltip/tooltip.css
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,8 @@
left: auto;
right: auto;
margin: 0;
}

[uib-popover-popup].popover {
display: block !important;
}
29 changes: 18 additions & 11 deletions src/tooltip/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ angular.module('ui.bootstrap.tooltip', ['ui.bootstrap.position', 'ui.bootstrap.s
'animation="animation" ' +
'is-open="isOpen"' +
'origin-scope="origScope" ' +
'style="visibility: hidden; display: block; top: -9999px; left: -9999px;"' +
'class="uib-position-measure"' +
'>' +
'</div>';

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

if (!positionTimeout) {
positionTimeout = $timeout(function() {
// Reset the positioning.
tooltip.css({ top: 0, left: 0 });

// Now set the calculated positioning.
var ttPosition = $position.positionElements(element, tooltip, ttScope.placement, appendToBody);
tooltip.css({ top: ttPosition.top + 'px', left: ttPosition.left + 'px', visibility: 'visible' });
tooltip.css({ top: ttPosition.top + 'px', left: ttPosition.left + 'px' });

if (ttPosition.placement !== lastPlacement) {
if (!tooltip.hasClass(ttPosition.placement.split('-')[0])) {
tooltip.removeClass(lastPlacement.split('-')[0]);
tooltip.addClass(ttPosition.placement.split('-')[0]);
}

if (!tooltip.hasClass(options.placementClassPrefix + ttPosition.placement)) {
tooltip.removeClass(options.placementClassPrefix + lastPlacement);
tooltip.addClass(options.placementClassPrefix + ttPosition.placement);
}

// first time through tt element will have the
// uib-position-measure class or if the placement
// has changed we need to position the arrow.
if (tooltip.hasClass('uib-position-measure')) {
$position.positionArrow(tooltip, ttPosition.placement);
tooltip.removeClass('uib-position-measure');
} else if (lastPlacement !== ttPosition.placement) {
$position.positionArrow(tooltip, ttPosition.placement);
lastPlacement = ttPosition.placement;
}
lastPlacement = ttPosition.placement;

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

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

var delay = parseInt(attrs[prefix + 'PopupDelay'], 10);
var closeDelay = parseInt(attrs[prefix + 'PopupCloseDelay'], 10);
Expand Down Expand Up @@ -443,6 +450,8 @@ angular.module('ui.bootstrap.tooltip', ['ui.bootstrap.position', 'ui.bootstrap.s
observers.push(
attrs.$observe(prefix + 'Placement', function(val) {
ttScope.placement = val ? val : options.placement;
var placement = $position.parsePlacement(ttScope.placement);
lastPlacement = placement[1] ? placement[0] + '-' + placement[1] : placement[0];
if (ttScope.isOpen) {
positionTooltip();
}
Expand Down Expand Up @@ -631,8 +640,6 @@ function ($animate, $sce, $compile, $templateRequest) {
// // in TWBS, so we need the primary position.
var position = $uibPosition.parsePlacement(scope.placement);
element.addClass(position[0]);
} else {
element.addClass('top');
}

if (scope.popupClass) {
Expand Down
2 changes: 1 addition & 1 deletion template/datepicker/popup.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div>
<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()">
<ul class="uib-datepicker-popup dropdown-menu uib-position-measure" dropdown-nested ng-if="isOpen" ng-keydown="keydown($event)" ng-click="$event.stopPropagation()">
<li ng-transclude></li>
<li ng-if="showButtonBar" class="uib-button-bar">
<span class="btn-group pull-left">
Expand Down