PageSourceSearch

https://www.biologement.fr/modules/alma/views/js/alma-product.js

js biologement.fr collected 2026-10-07 20:58:24 UTC 5,375 bytes, 136 lines download raw bytes

1/**
2 * 2018-2024 Alma SAS
3 *
4 * THE MIT LICENSE
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
7 * documentation files (the "Software"), to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
9 * to permit persons to whom the Software is furnished to do so, subject to the following conditions:
10 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
11 * Software.
12 *
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
14 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
16 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
17 * IN THE SOFTWARE.
18 *
19 * @author    Alma SAS <[email protected]>
20 * @copyright 2018-2024 Alma SAS
21 * @license   https://opensource.org/licenses/MIT The MIT License
22 */
23(function ($) {
24    $(function () {
25        function initWidget(
26            merchantId,
27            apiMode,
28            containerId,
29            purchaseAmount,
30            locale,
31            showIfNotEligible,
32            plans
33        ) {
34            callApiMode = Alma.ApiMode.LIVE;
35            if (apiMode === 'test') {
36                callApiMode = Alma.ApiMode.TEST;
37            }
38            var widgets = Alma.Widgets.initialize(merchantId, callApiMode);
39
40            widgets.add(Alma.Widgets.PaymentPlans, {
41                container: containerId,
42                purchaseAmount: purchaseAmount,
43                locale: locale,
44                hideIfNotEligible: !showIfNotEligible,
45                plans: plans,
46            });
47        }
48
49        function debounce(func, wait, immediate) {
50            var timeout;
51            return function () {
52                var context = this,
53                    args = arguments;
54                var later = function () {
55                    timeout = null;
56                    if (!immediate) func.apply(context, args);
57                };
58                var callNow = immediate && !timeout;
59                clearTimeout(timeout);
60                timeout = setTimeout(later, wait);
61                if (callNow) func.apply(context, args);
62            };
63        }
64
65        var refreshWidgets = debounce(function (evt, initialRefresh) {
66            var selectors = JSON.parse($("#alma-widget-config").val());
67            $(".alma-pp-container").each(function () {
68                var $widget = $(this).find(".alma-widget-container");
69                if (!$widget.length) {
70                    return;
71                }
72
73                var settings = $widget.data("settings");
74
75                var purchaseAmount = settings.amount;
76                if (!initialRefresh || settings.refreshPrice) {
77                    var $price = $(selectors.price);
78                    if ($price.length === 0) {
79                        throw new Error(
80                            'Could not find price element with query selector "' +
81                                selectors.price +
82                                '"'
83                        );
84                    }
85
86                    purchaseAmount = $price
87                        .text()
88                        .replace(settings.thousandSeparator, "")
89                        .replace(settings.decimalSeparator, ".")
90                        .replace(/[^\d.]/g, "");
91
92                    purchaseAmount = Alma.Utils.priceToCents(purchaseAmount);
93
94                    var $quantityWanted = $(selectors.quantity);
95                    if ($quantityWanted.length) {
96                        purchaseAmount *= Number($quantityWanted.val());
97                    }
98                }
99
100                let position =
101                    1 == selectors.isCustom
102                        ? selectors.position
103                        : "#" + $widget.attr("id");
104
105                initWidget(
106                    settings.merchantId,
107                    settings.apiMode,
108                    position,
109                    purchaseAmount,
110                    settings.locale,
111                    settings.showIfNotEligible,
112                    settings.plans
113                );
114            });
115        }, 150);
116
117        if ($("#alma-widget-config").length) {
118            var selectors = JSON.parse($("#alma-widget-config").val());
119            if (window.prestashop != null && window.prestashop.on != null) {
120                prestashop.on("updatedProduct", refreshWidgets);
121            } else {
122                let $body = $("body");
123                $body.on("change", selectors.attrSelect, refreshWidgets);
124                $body.on("click", selectors.attrRadio, refreshWidgets);
125                $body.on("click", selectors.colorPick, refreshWidgets);
126                $body.on("keyup", selectors.quantity, refreshWidgets);
127                $body.on("change", selectors.quantity, refreshWidgets);
128            }
129
130            refreshWidgets(null, true);
131        }
132
133        window.__alma_refreshWidgets = refreshWidgets;
134
135    });
136})(jQuery);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.