From 54c4eb950b787e395f9532b5c4ad254724798d7b Mon Sep 17 00:00:00 2001 From: Jelle Versele Date: Mon, 24 Aug 2015 14:45:49 +0200 Subject: fixes #17097: Go back to using jQuery's text and html methods since innerText is nonstandard and not present in Firefox Closes #17272 by merging a tweaked version of it. [skip validator] --- js/src/tooltip.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'js/src/tooltip.js') diff --git a/js/src/tooltip.js b/js/src/tooltip.js index a65caf26e..aa5c73945 100644 --- a/js/src/tooltip.js +++ b/js/src/tooltip.js @@ -358,9 +358,9 @@ const Tooltip = (($) => { setContent() { let tip = this.getTipElement() let title = this.getTitle() - let method = this.config.html ? 'innerHTML' : 'innerText' + let method = this.config.html ? 'html' : 'text' - $(tip).find(Selector.TOOLTIP_INNER)[0][method] = title + $(tip).find(Selector.TOOLTIP_INNER)[method](title) $(tip) .removeClass(ClassName.FADE) -- cgit v1.2.3 From c7d8e7a0777da91df2359655a7132e2b55482c0a Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Mon, 31 Aug 2015 00:57:16 +0100 Subject: Accept elements as the tooltip / popover content When a DOM node is passed to an HTML tooltip, the `title` node is only moved if it is not already in the tooltip. Otherwise, `empty()` is used instead of `detach()` before appending the `title` to avoid memory leaks. If a DOM node is passed to a plain text tooltip, its text is copied via jQuery `.text()`. Replaces `.detach()` with `.empty()`, as `.detach()` is almost never useful but instead leaks memory. The difference between `empty` and `detach` is that the latter keeps all the attached jQuery events/data. However, since we do not return the previous children, the user would have to keep these themselves, thus they can `detach()` if necessary. This is a port of https://github.com/twbs/bootstrap/pull/14552 to v4. --- js/src/tooltip.js | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'js/src/tooltip.js') diff --git a/js/src/tooltip.js b/js/src/tooltip.js index aa5c73945..151cd6f51 100644 --- a/js/src/tooltip.js +++ b/js/src/tooltip.js @@ -43,7 +43,7 @@ const Tooltip = (($) => { const DefaultType = { animation : 'boolean', template : 'string', - title : '(string|function)', + title : '(string|element|function)', trigger : 'string', delay : '(number|object)', html : 'boolean', @@ -356,19 +356,33 @@ const Tooltip = (($) => { } setContent() { - let tip = this.getTipElement() - let title = this.getTitle() - let method = this.config.html ? 'html' : 'text' + let $tip = $(this.getTipElement()) - $(tip).find(Selector.TOOLTIP_INNER)[method](title) + this.setElementContent($tip.find(Selector.TOOLTIP_INNER), this.getTitle()) - $(tip) + $tip .removeClass(ClassName.FADE) .removeClass(ClassName.IN) this.cleanupTether() } + setElementContent($element, content) { + let html = this.config.html + if (typeof content === 'object' && (content.nodeType || content.jquery)) { + // content is a DOM node or a jQuery + if (html) { + if (!$(content).parent().is($element)) { + $element.empty().append(content) + } + } else { + $element.text($(content).text()) + } + } else { + $element[html ? 'html' : 'text'](content) + } + } + getTitle() { let title = this.element.getAttribute('data-original-title') -- cgit v1.2.3