]> git.ipfire.org Git - thirdparty/bootstrap.git/commitdiff
use a class private getter to decouple same methods usage
authorGeoSot <geo.sotis@gmail.com>
Thu, 10 Jun 2021 07:48:35 +0000 (10:48 +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 5a3b3263173cce8c255a6a1634d1fdc4b8dc62c0..a08e4c4dd4bdc63b552333016c705c14feb70950 100644 (file)
@@ -19,7 +19,6 @@ const NAME = 'popover'
 const DATA_KEY = 'bs.popover'
 const EVENT_KEY = `.${DATA_KEY}`
 const CLASS_PREFIX = 'bs-popover'
-const BSCLS_PREFIX_REGEX = new RegExp(`(^|\\s)${CLASS_PREFIX}\\S+`, 'g')
 
 const Default = {
   ...Tooltip.Default,
@@ -124,21 +123,12 @@ class Popover extends Tooltip {
 
   // Private
 
-  _addAttachmentClass(attachment) {
-    this.getTipElement().classList.add(`${CLASS_PREFIX}-${this.updateAttachment(attachment)}`)
-  }
-
   _getContent() {
     return this._element.getAttribute('data-bs-content') || this._config.content
   }
 
-  _cleanTipClass() {
-    const tip = this.getTipElement()
-    const tabClass = tip.getAttribute('class').match(BSCLS_PREFIX_REGEX)
-    if (tabClass !== null && tabClass.length > 0) {
-      tabClass.map(token => token.trim())
-        .forEach(tClass => tip.classList.remove(tClass))
-    }
+  _getBasicClassPrefix() {
+    return CLASS_PREFIX
   }
 
   // Static
index cd4a2878e03fe55902bcb776205eeb2f9cf7fb72..cdc9b1e5d59becd000a2f801833f1e90740c71c0 100644 (file)
@@ -37,7 +37,6 @@ const NAME = 'tooltip'
 const DATA_KEY = 'bs.tooltip'
 const EVENT_KEY = `.${DATA_KEY}`
 const CLASS_PREFIX = 'bs-tooltip'
-const BSCLS_PREFIX_REGEX = new RegExp(`(^|\\s)${CLASS_PREFIX}\\S+`, 'g')
 const DISALLOWED_ATTRIBUTES = new Set(['sanitize', 'allowList', 'sanitizeFn'])
 
 const DefaultType = {
@@ -514,7 +513,7 @@ class Tooltip extends BaseComponent {
   }
 
   _addAttachmentClass(attachment) {
-    this.getTipElement().classList.add(`${CLASS_PREFIX}-${this.updateAttachment(attachment)}`)
+    this.getTipElement().classList.add(`${this._getBasicClassPrefix()}-${this.updateAttachment(attachment)}`)
   }
 
   _getAttachment(placement) {
@@ -699,13 +698,18 @@ class Tooltip extends BaseComponent {
 
   _cleanTipClass() {
     const tip = this.getTipElement()
-    const tabClass = tip.getAttribute('class').match(BSCLS_PREFIX_REGEX)
+    const basicClassPrefixRegex = new RegExp(`(^|\\s)${this._getBasicClassPrefix()}\\S+`, 'g')
+    const tabClass = tip.getAttribute('class').match(basicClassPrefixRegex)
     if (tabClass !== null && tabClass.length > 0) {
       tabClass.map(token => token.trim())
         .forEach(tClass => tip.classList.remove(tClass))
     }
   }
 
+  _getBasicClassPrefix() {
+    return CLASS_PREFIX
+  }
+
   _handlePopperPlacementChange(popperData) {
     const { state } = popperData