PageSourceSearch

https://www.natuurproduct.com/wp-content/plugins/wrk-buy-again/assets/js/frontend.js?ver=1.3.0

js natuurproduct.com collected 2026-10-08 09:13:04 UTC 3,892 bytes, 145 lines download raw bytes

1(function ($) {
2  function ensureNoticesWrapper() {
3    var selectors = [
4      '.woocommerce-notices-wrapper',
5      '.woocommerce-MyAccount-content .woocommerce-notices-wrapper',
6      '.entry-content .woocommerce-notices-wrapper',
7      'main .woocommerce-notices-wrapper'
8    ];
9
10    for (var i = 0; i < selectors.length; i += 1) {
11      var existing = $(selectors[i]).first();
12      if (existing.length) {
13        return existing;
14      }
15    }
16
17    var container = $('.woocommerce-MyAccount-content').first();
18    if (!container.length) {
19      container = $('.entry-content').first();
20    }
21    if (!container.length) {
22      container = $('main').first();
23    }
24    if (!container.length) {
25      container = $('body');
26    }
27
28    var wrapper = $('<div class="woocommerce-notices-wrapper"></div>');
29    container.prepend(wrapper);
30    return wrapper;
31  }
32
33  function renderNotices(html) {
34    var wrapper = ensureNoticesWrapper();
35
36    if (!html) {
37      wrapper.html('');
38      return;
39    }
40
41    wrapper.html(html);
42
43    if (wrapper.offset()) {
44      $('html, body').animate({
45        scrollTop: Math.max(wrapper.offset().top - 30, 0)
46      }, 200);
47    }
48  }
49
50  function replaceFragments(fragments) {
51    if (!fragments) {
52      return;
53    }
54
55    $.each(fragments, function (selector, html) {
56      var $target = $(selector);
57      if ($target.length) {
58        $target.replaceWith(html);
59      }
60    });
61  }
62
63  $(document).on('click', '.wrk-buy-again__qty-btn', function (event) {
64    var button = event.currentTarget;
65    var wrapper = button.closest('.wrk-buy-again__qty');
66    var input = wrapper ? wrapper.querySelector('.wrk-buy-again__qty-input') : null;
67
68    if (!input || input.disabled) {
69      return;
70    }
71
72    var min = parseInt(wrapper.getAttribute('data-min') || input.min || '1', 10);
73    var max = parseInt(wrapper.getAttribute('data-max') || input.max || '999', 10);
74    var value = parseInt(input.value || '1', 10);
75
76    if (isNaN(min)) {
77      min = 1;
78    }
79
80    if (isNaN(max)) {
81      max = 999;
82    }
83
84    if (isNaN(value)) {
85      value = min;
86    }
87
88    if (button.getAttribute('data-direction') === 'minus') {
89      value = Math.max(min, value - 1);
90    } else {
91      value = Math.min(max, value + 1);
92    }
93
94    input.value = value;
95    input.dispatchEvent(new Event('change', { bubbles: true }));
96  });
97
98  $(document).on('submit', '.wrk-buy-again__form, .wrk-buy-again__compact-form', function (event) {
99    event.preventDefault();
100
101    var $form = $(this);
102    var $button = $form.find('button[type="submit"]').first();
103    var originalText = $button.text();
104
105    if ($button.prop('disabled')) {
106      return;
107    }
108
109    $button.prop('disabled', true).addClass('loading');
110
111    $.ajax({
112      url: wrkBuyAgain.ajaxUrl,
113      type: 'POST',
114      dataType: 'json',
115      data: $form.serialize() + '&action=wrk_buy_again_add_to_cart',
116      success: function (response) {
117        if (!response || !response.success) {
118          renderNotices(
119            response && response.notices_html
120              ? response.notices_html
121              : '<div class="woocommerce-error" role="alert">' + wrkBuyAgain.messages.genericError + '</div>'
122          );
123          return;
124        }
125
126        replaceFragments(response.fragments);
127        $(document.body).trigger('added_to_cart', [response.fragments || {}, response.cart_hash || '', $button]);
128        renderNotices(response.notices_html || '');
129      },
130      error: function () {
131        renderNotices('<div class="woocommerce-error" role="alert">' + wrkBuyAgain.messages.genericError + '</div>');
132      },
133      complete: function () {
134        $button.prop('disabled', false).removeClass('loading').text(originalText);
135      }
136    });
137  });
138
139  $(document).on('change', '.wrk-buy-again__filters select', function () {
140    var form = this.form;
141    if (form) {
142      form.submit();
143    }
144  });
145})(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.