Skip to content

Commit

Permalink
Improve cleanup tether class by using a regex thanks to @vanduynslagerp
Browse files Browse the repository at this point in the history
  • Loading branch information
Johann-S committed Mar 28, 2017
1 parent bf3a8a2 commit 0fb0ca8
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions js/src/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const Tooltip = (($) => {
const JQUERY_NO_CONFLICT = $.fn[NAME]
const TRANSITION_DURATION = 150
const CLASS_PREFIX = 'bs-tether'
const TETHER_PREFIX_REGEX = new RegExp(`(^|\\s)${CLASS_PREFIX}\\S+`, 'g')

const Default = {
animation : true,
Expand Down Expand Up @@ -441,18 +442,9 @@ const Tooltip = (($) => {

_cleanTipClass() {
const $tip = $(this.getTipElement())
let tabClassStr = $tip.attr('class')
let tabClass = tabClassStr.split(' ')
let i = 0
while (tabClassStr.indexOf(CLASS_PREFIX) !== -1) {
if (tabClass[i].indexOf(CLASS_PREFIX) !== -1) {
$tip.removeClass(tabClass[i])
tabClassStr = $tip.attr('class')
tabClass = tabClassStr.split(' ')
i = 0
} else {
i++
}
const tabClass = $tip.attr('class').match(TETHER_PREFIX_REGEX)
if (tabClass !== null && tabClass.length > 0) {
$tip.removeClass(tabClass.join(''))
}
}

Expand Down

0 comments on commit 0fb0ca8

Please sign in to comment.