]> git.ipfire.org Git - thirdparty/bootstrap.git/commitdiff
Use on private method to set content & cleanup template
authorGeoSot <geo.sotis@gmail.com>
Thu, 10 Jun 2021 08:00:05 +0000 (11:00 +0300)
committerXhmikosR <xhmikosr@gmail.com>
Thu, 22 Jul 2021 14:20:38 +0000 (17:20 +0300)
js/src/popover.js
js/src/tooltip.js

index 87df36086ac1ca9013efd38b94c99c43e71dc074..15deaafe23153d2a64737e68888d18e0f71ea8b5 100644 (file)
@@ -6,7 +6,6 @@
  */
 
 import { defineJQueryPlugin } from './util/index'
-import SelectorEngine from './dom/selector-engine'
 import Tooltip from './tooltip'
 
 /**
@@ -85,35 +84,11 @@ class Popover extends Tooltip {
     return this.getTitle() || this._getContent()
   }
 
-  getTipElement() {
-    if (this.tip) {
-      return this.tip
-    }
-
-    this.tip = super.getTipElement()
-
-    if (!this.getTitle()) {
-      SelectorEngine.findOne(SELECTOR_TITLE, this.tip).remove()
-    }
-
-    if (!this._getContent()) {
-      SelectorEngine.findOne(SELECTOR_CONTENT, this.tip).remove()
-    }
-
-    return this.tip
-  }
-
   setContent() {
     const tip = this.getTipElement()
 
-    // we use append for html objects to maintain js events
-    this.setElementContent(SelectorEngine.findOne(SELECTOR_TITLE, tip), this.getTitle())
-    let content = this._getContent()
-    if (typeof content === 'function') {
-      content = content.call(this._element)
-    }
-
-    this.setElementContent(SelectorEngine.findOne(SELECTOR_CONTENT, tip), content)
+    this._sanitizeAndSetContent(tip, this.getTitle(), SELECTOR_TITLE)
+    this._sanitizeAndSetContent(tip, this._getContent(), SELECTOR_CONTENT)
   }
 
   // Private
index fa364a1e6811229083b9b8f6acd655cdd8849375..e09a53b5ceea002277ff784d27d93f06b93ee776 100644 (file)
@@ -376,8 +376,18 @@ class Tooltip extends BaseComponent {
 
   setContent() {
     const tip = this.getTipElement()
-    this.setElementContent(SelectorEngine.findOne(SELECTOR_TOOLTIP_INNER, tip), this.getTitle())
-    tip.classList.remove(CLASS_NAME_FADE, CLASS_NAME_SHOW)
+    this._sanitizeAndSetContent(tip, this.getTitle(), SELECTOR_TOOLTIP_INNER)
+  }
+
+  _sanitizeAndSetContent(template, content, selector) {
+    const templateElement = SelectorEngine.findOne(selector, template)
+    if (!content) {
+      templateElement.remove()
+      return
+    }
+
+    // we use append for html objects to maintain js events
+    this.setElementContent(templateElement, content)
   }
 
   setElementContent(element, content) {