aboutsummaryrefslogtreecommitdiff
path: root/js/src/tooltip.js
diff options
context:
space:
mode:
authorGleb Mazovetskiy <[email protected]>2015-08-31 13:03:09 +0100
committerGleb Mazovetskiy <[email protected]>2015-08-31 13:03:09 +0100
commit33a510c63c9a898d68da807205afbbb8e1dfce16 (patch)
treec953ef46e464dd1556c3b11fab8b10b300bc8b29 /js/src/tooltip.js
parent8941bdfbda237bed621935cac439520eddc79150 (diff)
parentc7d8e7a0777da91df2359655a7132e2b55482c0a (diff)
downloadbootstrap-33a510c63c9a898d68da807205afbbb8e1dfce16.tar.xz
bootstrap-33a510c63c9a898d68da807205afbbb8e1dfce16.zip
Merge pull request #17402 from twbs/pr-14552-v4
Accept elements as the tooltip / popover content
Diffstat (limited to 'js/src/tooltip.js')
-rw-r--r--js/src/tooltip.js26
1 files changed, 20 insertions, 6 deletions
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')