PageSourceSearch

https://www.freedomdreads.co.za/wp-content/plugins/wpc-order-tip/assets/js/frontend.js?ver=3.3.3

js freedomdreads.co.za collected 2026-10-04 21:45:02 UTC 5,132 bytes, 179 lines download raw bytes

1(function($) {
2  'use strict';
3
4  $(function() {
5    // ready
6    $('.wpcot-tip-value.active-default').each(function() {
7      var $this = $(this);
8      var key = $this.closest('.wpcot-tip').data('key');
9
10      if (!$this.hasClass('active') &&
11          (get_cookie('wpcot_tip_' + wpcot_vars.user_id + '_' + key) == '')) {
12        $this.trigger('click');
13      }
14    });
15  });
16
17  $('body').on('click touch touchstart', '.wpcot-tip-value', function(e) {
18    e.preventDefault();
19    apply_tip($(this));
20  });
21
22  $('body').on('click touch touchstart', '.wpcot-tip-value-custom', function(e) {
23    e.preventDefault();
24
25    $(this).closest('.wpcot-tip').find('.wpcot-tip-custom').slideToggle();
26  });
27
28  $('body').on('click touch touchstart', '.wpcot-tip-custom-add', function(e) {
29    e.preventDefault();
30
31    var $this = $(this);
32    var $tip = $this.closest('.wpcot-tip');
33    var value = $tip.find('.wpcot-tip-custom-value').val();
34    var key = $tip.data('key');
35    var name = $tip.data('name');
36
37    if (value) {
38      $this.closest('.wpcot-tip-custom-form').addClass('disabled');
39      $tip.find('.wpcot-tip-value-custom').addClass('loading');
40
41      // mark as selected
42      set_cookie('wpcot_tip_' + wpcot_vars.user_id + '_' + key, value, 1);
43
44      $.ajax({
45        type: 'POST',
46        url: wpcot_vars.wc_ajax_url.toString().
47            replace('%%endpoint%%', 'wpcot_apply_tip'),
48        dataType: 'json',
49        data: ({
50          action: 'wpcot_apply_tip',
51          key: key,
52          name: name,
53          value: value,
54          security: wpcot_vars.a_nonce,
55        }),
56        success: function(response) {
57          $this.closest('.wpcot-tip-custom-form').removeClass('disabled');
58          $tip.find('.wpcot-tip-value').removeClass('active');
59          $tip.find('.wpcot-tip-value-custom').
60              removeClass('loading').
61              addClass('active');
62
63          $('body').trigger('update_checkout');
64
65          if ($('button[name="update_cart"]').length) {
66            $('button[name="update_cart"]').
67                attr('aria-disabled', false).
68                removeAttr('disabled').
69                trigger('click');
70          }
71        },
72      });
73    } else {
74      $tip.find('.wpcot-tip-custom-value').focus();
75    }
76  });
77
78  function apply_tip($value) {
79    var value = $value.data('value');
80    var key = $value.closest('.wpcot-tip').data('key');
81    var name = $value.closest('.wpcot-tip').data('name');
82
83    // mark as selected
84    set_cookie('wpcot_tip_' + wpcot_vars.user_id + '_' + key, value, 1);
85
86    $value.addClass('loading');
87
88    if (($value.hasClass('active') && (wpcot_vars.click_again === 'yes')) ||
89        $value.hasClass('wpcot-tip-value-none')) {
90      // remove tip
91      $.ajax({
92        type: 'POST',
93        url: wpcot_vars.wc_ajax_url.toString().
94            replace('%%endpoint%%', 'wpcot_remove_tip'),
95        dataType: 'json',
96        data: ({
97          action: 'wpcot_remove_tip', key: key, security: wpcot_vars.r_nonce,
98        }),
99        success: function(response) {
100          $value.closest('.wpcot-tip').
101              find('.wpcot-tip-value').
102              removeClass('active loading');
103
104          if ($value.hasClass('wpcot-tip-value-none')) {
105            $value.addClass('active');
106          }
107
108          $('body').trigger('update_checkout');
109
110          if ($('button[name="update_cart"]').length) {
111            $('button[name="update_cart"]').
112                attr('aria-disabled', false).
113                removeAttr('disabled').
114                trigger('click');
115          }
116        },
117      });
118    } else {
119      // apply tip
120      $.ajax({
121        type: 'POST',
122        url: wpcot_vars.wc_ajax_url.toString().
123            replace('%%endpoint%%', 'wpcot_apply_tip'),
124        dataType: 'json',
125        data: ({
126          action: 'wpcot_apply_tip',
127          key: key,
128          name: name,
129          value: value,
130          security: wpcot_vars.a_nonce,
131        }),
132        success: function(response) {
133          $value.closest('.wpcot-tip').
134              find('.wpcot-tip-value').
135              removeClass('active');
136          $value.removeClass('loading').addClass('active');
137
138          $('body').trigger('update_checkout');
139
140          if ($('button[name="update_cart"]').length) {
141            $('button[name="update_cart"]').
142                attr('aria-disabled', false).
143                removeAttr('disabled').
144                trigger('click');
145          }
146        },
147      });
148    }
149  }
150
151  function set_cookie(cname, cvalue, exdays) {
152    var d = new Date();
153
154    d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
155
156    var expires = 'expires=' + d.toUTCString();
157
158    document.cookie = cname + '=' + cvalue + '; ' + expires + '; path=/';
159  }
160
161  function get_cookie(cname) {
162    var name = cname + '=';
163    var ca = document.cookie.split(';');
164
165    for (var i = 0; i < ca.length; i++) {
166      var c = ca[i];
167
168      while (c.charAt(0) == ' ') {
169        c = c.substring(1);
170      }
171
172      if (c.indexOf(name) == 0) {
173        return decodeURIComponent(c.substring(name.length, c.length));
174      }
175    }
176
177    return '';
178  }
179})(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.