From a89537ae3d78fcb7147a0160d2ae72814ee00930 Mon Sep 17 00:00:00 2001 From: MewenLeHo Date: Fri, 28 Jan 2022 17:39:11 +0100 Subject: [PATCH] feat #113 (quantity selector): add jQueryInterface --- js/src/quantity-selector.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/js/src/quantity-selector.js b/js/src/quantity-selector.js index b8ea0f5fc6..afcf935e90 100644 --- a/js/src/quantity-selector.js +++ b/js/src/quantity-selector.js @@ -132,6 +132,22 @@ class QuantitySelector extends BaseComponent { btnUp.setAttribute('disabled', '') } } + + static jQueryInterface(config) { + return this.each(function () { + const data = QuantitySelector.getOrCreateInstance(this, config) + + if (typeof config !== 'string') { + return + } + + if (typeof data[config] === 'undefined') { + throw new TypeError(`No method named "${config}"`) + } + + data[config]() + }) + } } /**