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/popover.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'js/src/popover.js') diff --git a/js/src/popover.js b/js/src/popover.js index 30c0e4acb..99e48e64f 100644 --- a/js/src/popover.js +++ b/js/src/popover.js @@ -116,12 +116,12 @@ const Popover = (($) => { let tip = this.getTipElement() let title = this.getTitle() let content = this._getContent() - let titleElement = $(tip).find(Selector.TITLE)[0] + let $titleElement = $(tip).find(Selector.TITLE) - if (titleElement) { - titleElement[ - this.config.html ? 'innerHTML' : 'innerText' - ] = title + if ($titleElement) { + $titleElement[ + this.config.html ? 'html' : 'text' + ](title) } // we use append for html objects to maintain js events -- 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/popover.js | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) (limited to 'js/src/popover.js') diff --git a/js/src/popover.js b/js/src/popover.js index 99e48e64f..b8b24a1c4 100644 --- a/js/src/popover.js +++ b/js/src/popover.js @@ -34,7 +34,7 @@ const Popover = (($) => { }) const DefaultType = $.extend({}, Tooltip.DefaultType, { - content : '(string|function)' + content : '(string|element|function)' }) const ClassName = { @@ -113,24 +113,13 @@ const Popover = (($) => { } setContent() { - let tip = this.getTipElement() - let title = this.getTitle() - let content = this._getContent() - let $titleElement = $(tip).find(Selector.TITLE) - - if ($titleElement) { - $titleElement[ - this.config.html ? 'html' : 'text' - ](title) - } + let $tip = $(this.getTipElement()) // we use append for html objects to maintain js events - $(tip).find(Selector.CONTENT).children().detach().end()[ - this.config.html ? - (typeof content === 'string' ? 'html' : 'append') : 'text' - ](content) + this.setElementContent($tip.find(Selector.TITLE), this.getTitle()) + this.setElementContent($tip.find(Selector.CONTENT), this._getContent()) - $(tip) + $tip .removeClass(ClassName.FADE) .removeClass(ClassName.IN) -- cgit v1.2.3