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 +++++----- js/src/tooltip.js | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'js/src') 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 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/popover.js | 21 +++++---------------- js/src/tooltip.js | 26 ++++++++++++++++++++------ 2 files changed, 25 insertions(+), 22 deletions(-) (limited to 'js/src') 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) 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 From 3af4560c672bc3435565499586ae85d4bc159cd1 Mon Sep 17 00:00:00 2001 From: muzige2000 Date: Thu, 3 Sep 2015 17:18:53 +0900 Subject: Modals: Fix bad paddingRight calculation; fixes #17399 We want to sum two numbers, not concatenate their stringifications. Closes #17457 by merging a tweaked version of it. --- js/src/modal.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'js/src') diff --git a/js/src/modal.js b/js/src/modal.js index 128863273..f57131e7e 100644 --- a/js/src/modal.js +++ b/js/src/modal.js @@ -427,7 +427,7 @@ const Modal = (($) => { if (this._isBodyOverflowing) { document.body.style.paddingRight = - bodyPadding + `${this._scrollbarWidth}px` + `${bodyPadding + this._scrollbarWidth}px` } } -- cgit v1.2.3