Skip to content

Commit

Permalink
use a basicJQueryInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
GeoSot committed Apr 5, 2021
1 parent 83ca243 commit 9b2cbee
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
15 changes: 2 additions & 13 deletions js/src/scrollspy.js
Expand Up @@ -6,6 +6,7 @@
*/

import {
basicJQueryInterface,
defineJQueryPlugin,
getSelectorFromElement,
getUID,
Expand Down Expand Up @@ -277,19 +278,7 @@ class ScrollSpy extends BaseComponent {
// Static

static jQueryInterface(config) {
return this.each(function () {
const data = ScrollSpy.getInstance(this) || new ScrollSpy(this, typeof config === 'object' ? config : {})

if (typeof config !== 'string') {
return
}

if (typeof data[config] === 'undefined') {
throw new TypeError(`No method named "${config}"`)
}

data[config]()
})
return basicJQueryInterface(this, ScrollSpy, config)
}
}

Expand Down
19 changes: 19 additions & 0 deletions js/src/util/index.js
@@ -1,3 +1,5 @@
import Data from '../dom/data'

/**
* --------------------------------------------------------------------------
* Bootstrap (v5.0.0-beta3): util/index.js
Expand Down Expand Up @@ -230,6 +232,22 @@ const defineJQueryPlugin = (name, plugin) => {
})
}

const basicJQueryInterface = (jq, Plugin, config) => {
return jq.each(function () {
const data = Data.get(this, Plugin.DATA_KEY) || new Plugin(this, typeof config === 'object' ? config : {})

if (typeof config !== 'string') {
return
}

if (typeof data[config] === 'undefined') {
throw new TypeError(`No method named "${config}"`)
}

data[config]()
})
}

export {
getUID,
getSelectorFromElement,
Expand All @@ -247,5 +265,6 @@ export {
getjQuery,
onDOMContentLoaded,
isRTL,
basicJQueryInterface,
defineJQueryPlugin
}

0 comments on commit 9b2cbee

Please sign in to comment.