Skip to content

Commit

Permalink
Optimize the implementation of the getBootstrapVersion method
Browse files Browse the repository at this point in the history
  • Loading branch information
wenzhixin committed Dec 18, 2024
1 parent f85d707 commit caaa0ce
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,20 @@ export default {
getBootstrapVersion () {
let bootstrapVersion = 5

try {
const rawVersion = $.fn.dropdown.Constructor.VERSION
if (typeof window !== 'undefined' && window.bootstrap?.Tooltip?.VERSION) {
const rawVersion = window.bootstrap.Tooltip.VERSION

// Only try to parse VERSION if it is defined.
// It is undefined in older versions of Bootstrap (tested with 3.1.1).
if (rawVersion !== undefined) {
bootstrapVersion = parseInt(rawVersion, 10)
}
} catch (e) {
console.error(e)
}

try {
// eslint-disable-next-line no-undef
const rawVersion = bootstrap.Tooltip.VERSION
} else if (typeof $ !== 'undefined' && $.fn.dropdown?.Constructor?.VERSION) {
const rawVersion = $.fn.dropdown.Constructor.VERSION

// Only try to parse VERSION if it is defined.
// It is undefined in older versions of Bootstrap (tested with 3.1.1).
if (rawVersion !== undefined) {
bootstrapVersion = parseInt(rawVersion, 10)
}
} catch (e) {
console.error(e)
}

return bootstrapVersion
Expand Down

0 comments on commit caaa0ce

Please sign in to comment.