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

feat(tooltip): arrow position #5502

Merged
merged 1 commit into from
Feb 22, 2016
Merged
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
17 changes: 8 additions & 9 deletions src/position/position.js
Original file line number Diff line number Diff line change
Expand Up @@ -476,10 +476,17 @@ angular.module('ui.bootstrap.position', [])
return;
}

var arrowCss = {
top: '',
bottom: '',
left: '',
right: ''
};

placement = this.parsePlacement(placement);
if (placement[1] === 'center') {
// no adjustment necessary - just reset styles
angular.element(arrowElem).css({top: '', bottom: '', right: '', left: '', margin: ''});
angular.element(arrowElem).css(arrowCss);
return;
}

Expand All @@ -495,14 +502,6 @@ angular.module('ui.bootstrap.position', [])
borderRadiusProp += '-radius';
var borderRadius = $window.getComputedStyle(isTooltip ? innerElem : elem)[borderRadiusProp];

var arrowCss = {
top: 'auto',
bottom: 'auto',
left: 'auto',
right: 'auto',
margin: 0
};

switch (placement[0]) {
case 'top':
arrowCss.bottom = isTooltip ? '0' : '-' + borderWidth;
Expand Down
22 changes: 22 additions & 0 deletions src/tooltip/tooltip.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[uib-tooltip-popup].tooltip.top-left > .tooltip-arrow,
[uib-tooltip-popup].tooltip.top-right > .tooltip-arrow,
[uib-tooltip-popup].tooltip.bottom-left > .tooltip-arrow,
[uib-tooltip-popup].tooltip.bottom-right > .tooltip-arrow,
[uib-tooltip-popup].tooltip.left-top > .tooltip-arrow,
[uib-tooltip-popup].tooltip.left-bottom > .tooltip-arrow,
[uib-tooltip-popup].tooltip.right-top > .tooltip-arrow,
[uib-tooltip-popup].tooltip.right-bottom > .tooltip-arrow,
[uib-popover-popup].popover.top-left > .arrow,
[uib-popover-popup].popover.top-right > .arrow,
[uib-popover-popup].popover.bottom-left > .arrow,
[uib-popover-popup].popover.bottom-right > .arrow,
[uib-popover-popup].popover.left-top > .arrow,
[uib-popover-popup].popover.left-bottom > .arrow,
[uib-popover-popup].popover.right-top > .arrow,
[uib-popover-popup].popover.right-bottom > .arrow {
top: auto;
bottom: auto;
left: auto;
right: auto;
margin: 0;
}
35 changes: 12 additions & 23 deletions src/tooltip/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ angular.module('ui.bootstrap.tooltip', ['ui.bootstrap.position', 'ui.bootstrap.s
var isOpenParse = angular.isDefined(attrs[prefix + 'IsOpen']) ? $parse(attrs[prefix + 'IsOpen']) : false;
var contentParse = options.useContentExp ? $parse(attrs[ttType]) : false;
var observers = [];
var lastPlacement;

var positionTooltip = function() {
// check if tooltip exists and is not empty
Expand All @@ -168,29 +169,16 @@ angular.module('ui.bootstrap.tooltip', ['ui.bootstrap.position', 'ui.bootstrap.s
var ttPosition = $position.positionElements(element, tooltip, ttScope.placement, appendToBody);
tooltip.css({ top: ttPosition.top + 'px', left: ttPosition.left + 'px', visibility: 'visible' });

// If the placement class is prefixed, still need
// to remove the TWBS standard class.
if (options.placementClassPrefix) {
tooltip.removeClass('top bottom left right');
}
if (ttPosition.placement !== lastPlacement) {
tooltip.removeClass(lastPlacement.split('-')[0]);
tooltip.addClass(ttPosition.placement.split('-')[0]);

tooltip.removeClass(options.placementClassPrefix + lastPlacement);
tooltip.addClass(options.placementClassPrefix + ttPosition.placement);

tooltip.removeClass(
options.placementClassPrefix + 'top ' +
options.placementClassPrefix + 'top-left ' +
options.placementClassPrefix + 'top-right ' +
options.placementClassPrefix + 'bottom ' +
options.placementClassPrefix + 'bottom-left ' +
options.placementClassPrefix + 'bottom-right ' +
options.placementClassPrefix + 'left ' +
options.placementClassPrefix + 'left-top ' +
options.placementClassPrefix + 'left-bottom ' +
options.placementClassPrefix + 'right ' +
options.placementClassPrefix + 'right-top ' +
options.placementClassPrefix + 'right-bottom');

var placement = ttPosition.placement.split('-');
tooltip.addClass(placement[0] + ' ' + options.placementClassPrefix + ttPosition.placement);
$position.positionArrow(tooltip, ttPosition.placement);
$position.positionArrow(tooltip, ttPosition.placement);
lastPlacement = ttPosition.placement;
}

positionTimeout = null;
}, 0, false);
Expand Down Expand Up @@ -365,6 +353,7 @@ 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 delay = parseInt(attrs[prefix + 'PopupDelay'], 10);
var closeDelay = parseInt(attrs[prefix + 'PopupCloseDelay'], 10);
Expand Down Expand Up @@ -540,7 +529,7 @@ angular.module('ui.bootstrap.tooltip', ['ui.bootstrap.position', 'ui.bootstrap.s
}

appendToBody = angular.isDefined(appendToBodyVal) ? appendToBodyVal : appendToBody;

// Make sure tooltip is destroyed and removed.
scope.$on('$destroy', function onDestroyTooltip() {
unregisterTriggers();
Expand Down