From 85208ae5570aeefe4e94c1ceb29ca3b6ffdf83a1 Mon Sep 17 00:00:00 2001 From: alpadev <2838324+alpadev@users.noreply.github.com> Date: Tue, 8 Dec 2020 07:16:50 +0100 Subject: Refactor components to use a utility function to define jQuery plugins (#32285) * refactor: use an utility function to define jQuery plugins * test: add spec for defineJQueryPlugin utility function * Update .bundlewatch.config.json Co-authored-by: XhmikosR --- js/src/util/index.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'js/src/util') diff --git a/js/src/util/index.js b/js/src/util/index.js index f1bf6c9fc..1bf9fe954 100644 --- a/js/src/util/index.js +++ b/js/src/util/index.js @@ -188,6 +188,22 @@ const onDOMContentLoaded = callback => { const isRTL = document.documentElement.dir === 'rtl' +const defineJQueryPlugin = (name, plugin) => { + onDOMContentLoaded(() => { + const $ = getjQuery() + /* istanbul ignore if */ + if ($) { + const JQUERY_NO_CONFLICT = $.fn[name] + $.fn[name] = plugin.jQueryInterface + $.fn[name].Constructor = plugin + $.fn[name].noConflict = () => { + $.fn[name] = JQUERY_NO_CONFLICT + return plugin.jQueryInterface + } + } + }) +} + export { TRANSITION_END, getUID, @@ -204,5 +220,6 @@ export { reflow, getjQuery, onDOMContentLoaded, - isRTL + isRTL, + defineJQueryPlugin } -- cgit v1.2.3