|
136 | 136 | return anElement.currentStyle; |
137 | 137 | } |
138 | 138 | } |
139 | | - , removeAppendedTip = function removeAppendedTip(theTooltipElement) { |
| 139 | + , getAppendedTip = function getAppendedTip(theTooltipElement) { |
140 | 140 | var tipsInBody = window.document.querySelectorAll('._exradicated-tooltip') |
141 | 141 | , aTipInBody |
142 | 142 | , tipsInBodyIndex = 0 |
|
152 | 152 | if (angularizedElement.data('_tooltip-parent') && |
153 | 153 | angularizedElement.data('_tooltip-parent') === theTooltipElement) { |
154 | 154 |
|
155 | | - angularizedElement.remove(); |
| 155 | + return angularizedElement; |
156 | 156 | } |
157 | 157 | } |
158 | 158 | } |
159 | 159 | } |
| 160 | + , removeAppendedTip = function removeAppendedTip(theTooltipElement) { |
| 161 | + var tipElement = getAppendedTip(theTooltipElement); |
| 162 | + |
| 163 | + if (tipElement) { |
| 164 | + |
| 165 | + tipElement.remove(); |
| 166 | + } |
| 167 | + } |
160 | 168 | , isOutOfPage = function isOutOfPage(theTipElement) { |
161 | 169 |
|
162 | 170 | if (theTipElement) { |
|
254 | 262 | $attrs.tooltipCloseButton = $attrs.tooltipCloseButton || tooltipsConf.closeButton.toString(); |
255 | 263 | $attrs.tooltipSize = $attrs.tooltipSize || tooltipsConf.size; |
256 | 264 | $attrs.tooltipSpeed = $attrs.tooltipSpeed || tooltipsConf.speed; |
| 265 | + $attrs.tooltipAppendToBody = $attrs.tooltipAppendToBody === 'true'; |
257 | 266 |
|
258 | 267 | $transcludeFunc($scope, function onTransclusionDone(element, scope) { |
259 | 268 | var attributes = getAttributesToAdd(element) |
|
405 | 414 | , aStyleKey |
406 | 415 | , tipTipCssToSet = {} |
407 | 416 | , tipCssToSet = {} |
408 | | - , tipArrowCssToSet = {}; |
| 417 | + , tipArrowCssToSet = {} |
| 418 | + , paddingTopValue |
| 419 | + , paddingBottomValue |
| 420 | + , paddingLeftValue |
| 421 | + , paddingRightValue; |
409 | 422 |
|
410 | 423 | tipElement.removeClass('_hidden'); |
411 | 424 | exradicatedTipElement.removeClass('_hidden'); |
|
451 | 464 | tipCssToSet[aStyleKey] = tipElementStyle.getPropertyValue(aStyleKey); |
452 | 465 | } |
453 | 466 | } |
| 467 | + paddingTopValue = window.parseInt(tipElementStyle.getPropertyValue('padding-top'), 10); |
| 468 | + paddingBottomValue = window.parseInt(tipElementStyle.getPropertyValue('padding-bottom'), 10); |
| 469 | + paddingLeftValue = window.parseInt(tipElementStyle.getPropertyValue('padding-left'), 10); |
| 470 | + paddingRightValue = window.parseInt(tipElementStyle.getPropertyValue('padding-right'), 10); |
454 | 471 |
|
455 | | - tipCssToSet.top = tipElementBoundingClientRect.top + 'px'; |
456 | | - tipCssToSet.left = tipElementBoundingClientRect.left + 'px'; |
457 | | - tipCssToSet.height = tipElementBoundingClientRect.height - ( |
458 | | - window.parseInt(tipElementStyle.getPropertyValue('padding-top'), 10) + |
459 | | - window.parseInt(tipElementStyle.getPropertyValue('padding-bottom'), 10)) + 'px'; |
460 | | - tipCssToSet.width = tipElementBoundingClientRect.width - ( |
461 | | - window.parseInt(tipElementStyle.getPropertyValue('padding-left'), 10) + |
462 | | - window.parseInt(tipElementStyle.getPropertyValue('padding-right'), 10)) + 'px'; |
| 472 | + tipCssToSet.top = tipElementBoundingClientRect.top + window.scrollY + 'px'; |
| 473 | + tipCssToSet.left = tipElementBoundingClientRect.left + window.scrollX + 'px'; |
| 474 | + tipCssToSet.height = tipElementBoundingClientRect.height - (paddingTopValue + paddingBottomValue) + 'px'; |
| 475 | + tipCssToSet.width = tipElementBoundingClientRect.width - (paddingLeftValue + paddingRightValue) + 'px'; |
463 | 476 |
|
464 | 477 | exradicatedTipElement.css(tipCssToSet); |
465 | 478 |
|
466 | 479 | exradicatedTipElement.children().css(tipTipCssToSet); |
467 | 480 | exradicatedTipElement.children().next().css(tipArrowCssToSet); |
468 | | - |
469 | | - if (event) { |
| 481 | + if (event && |
| 482 | + $attrs.tooltipHidden !== 'true') { |
470 | 483 |
|
471 | 484 | exradicatedTipElement.addClass('_exradicated-tooltip'); |
472 | 485 | angular.element(window.document.body).append(exradicatedTipElement); |
|
485 | 498 |
|
486 | 499 | if ($attrs.tooltipAppendToBody) { |
487 | 500 |
|
488 | | - //removeAppendedTip(tooltipElement); |
| 501 | + removeAppendedTip(tooltipElement); |
489 | 502 | } else { |
490 | 503 |
|
491 | 504 | tooltipElement.removeClass('active'); |
492 | 505 | } |
493 | 506 | } |
| 507 | + , registerOnScrollFrom = function registerOnScrollFrom(theElement) { |
| 508 | + var parentElement = theElement.parent() |
| 509 | + , timer; |
| 510 | + |
| 511 | + if (theElement[0] && |
| 512 | + (theElement[0].scrollHeight > theElement[0].clientHeight || |
| 513 | + theElement[0].scrollWidth > theElement[0].clientWidth)) { |
| 514 | + |
| 515 | + theElement.on('scroll', function onScroll() { |
| 516 | + var that = this; |
| 517 | + |
| 518 | + if (timer) { |
| 519 | + |
| 520 | + $timeout.cancel(timer); |
| 521 | + } |
| 522 | + |
| 523 | + timer = $timeout(function doLater() { |
| 524 | + |
| 525 | + var theTipElement = getAppendedTip(tooltipElement) |
| 526 | + , tooltipBoundingRect = tooltipElement[0].getBoundingClientRect() |
| 527 | + , thatBoundingRect = that.getBoundingClientRect(); |
| 528 | + |
| 529 | + if (tooltipBoundingRect.top < thatBoundingRect.top || |
| 530 | + tooltipBoundingRect.bottom > thatBoundingRect.bottom || |
| 531 | + tooltipBoundingRect.left < thatBoundingRect.left || |
| 532 | + tooltipBoundingRect.right > thatBoundingRect.right) { |
| 533 | + |
| 534 | + removeAppendedTip(tooltipElement); |
| 535 | + } else if (theTipElement) { |
| 536 | + |
| 537 | + onTooltipShow(true); |
| 538 | + } |
| 539 | + }); |
| 540 | + }); |
| 541 | + } |
| 542 | + |
| 543 | + if (parentElement && |
| 544 | + parentElement.length) { |
| 545 | + |
| 546 | + registerOnScrollFrom(parentElement); |
| 547 | + } |
| 548 | + } |
494 | 549 | , onTooltipTemplateChange = function onTooltipTemplateChange(newValue) { |
495 | 550 |
|
496 | 551 | if (newValue) { |
|
677 | 732 | tooltipElement.append(tipElement); |
678 | 733 | $element.after(tooltipElement); |
679 | 734 |
|
| 735 | + if ($attrs.tooltipAppendToBody) { |
| 736 | + |
| 737 | + resizeObserver.add(function onResize() { |
| 738 | + |
| 739 | + registerOnScrollFrom(tooltipElement); |
| 740 | + }); |
| 741 | + registerOnScrollFrom(tooltipElement); |
| 742 | + } |
| 743 | + |
680 | 744 | resizeObserver.add(function registerResize() { |
681 | 745 |
|
682 | 746 | calculateIfMultiLine(); |
|
0 commit comments