PageSourceSearch

https://notalar.uz/catalog/view/javascript/ocdevwizard/cart/main.js?v=1.1.1

js notalar.uz collected 2026-10-08 01:39:16 UTC 13,261 bytes, 377 lines download raw bytes

1$(function() {
2  $("#cart > button")
3    .removeAttr("data-toggle")
4    .off("click.bs.dropdown.data-api")
5    .on("click", function() {
6      ocdw_cart_open({});
7      return false;
8    });
9
10  ocdw_cart_action();
11});
12
13function ocdw_cart_mark_in_cart($el, product_id, content) {
14  if (!$el.data('ocdwOriginal')) {
15    $el.data('ocdwOriginal', {
16      onclick: $el.attr('onclick'),
17      content: $el.is('input') ? $el.val() : $el.html()
18    });
19  }
20
21  $el.attr('data-ocdw-product-id', product_id);
22  $el.attr('onclick', 'return ocdw_cart_toggle_remove(this);');
23  $el.addClass('ocdw_cart-call-button');
24
25  if ($el.is('input')) {
26    $el.val(content);
27  } else {
28    $el.html(content);
29  }
30}
31
32function ocdw_cart_restore_button($el) {
33  let original = $el.data('ocdwOriginal');
34
35  if (original) {
36    $el.attr('onclick', original.onclick);
37
38    if ($el.is('input')) {
39      $el.val(original.content);
40    } else {
41      $el.html(original.content);
42    }
43  }
44
45  $el.removeClass('ocdw_cart-call-button').removeAttr('data-ocdw-product-id');
46}
47
48function ocdw_cart_toggle_remove(el) {
49  let $el = $(el),
50      product_id = $el.attr('data-ocdw-product-id');
51
52  if (!product_id) {
53    return false;
54  }
55
56  $.ajax({
57    type: 'post',
58    url: 'index.php?route=checkout/cart/remove',
59    data: {product_id: product_id},
60    dataType: 'json',
61    success: function() {
62      ocdw_cart_action();
63    }
64  });
65
66  return false;
67}
68
69function ocdw_cart_action() {
70  let product_id_on_page = $("#product input[name='product_id']").val(),
71      add_function_selector = ["cart.add","addToCart"];
72
73  $.ajax({
74    type: 'post',
75    url: 'index.php?route=extension/ocdevwizard/cart/get_products',
76    dataType: 'json',
77    success: function (json) {
78      let display_type = 1,
79          sidebar_type = 1,
80          button_class_global = '',
81          button_class_product_page = '',
82          add_id_selector = ["#button-cart"],
83          products_in_cart = $.map(json['products'], function(value) { return String(value); });
84
85      $.each(json['products'], function(i,value) {
86        $.each(add_function_selector, function(i,selector) {
87          $('[onclick^="'+selector+'(\''+value+'\'"], [data-ocdw-product-id="'+value+'"]').each(function() {
88            ocdw_cart_mark_in_cart($(this), value, json['text_in_cart']);
89          });
90        });
91
92        if (typeof(product_id_on_page) != 'undefined') {
93          $.each(add_id_selector, function(i,selector) {
94            if (product_id_on_page == value) {
95              ocdw_cart_mark_in_cart($(selector), value, json['text_in_cart_product_page']);
96            }
97          });
98        }
99      });
100
101      // Revert buttons for products no longer in the cart back to "add to cart" state
102      $('.ocdw_cart-call-button[data-ocdw-product-id]').each(function() {
103        let $this = $(this);
104
105        if ($.inArray(String($this.attr('data-ocdw-product-id')), products_in_cart) === -1) {
106          ocdw_cart_restore_button($this);
107        }
108      });
109
110      if (display_type == 2) {
111        let sidebar_position = (sidebar_type == 1) ? 'left' : 'right';
112
113        if (!$('#ocdw_cart-sidebar').length) {
114          $('body').prepend('<div id="ocdw_cart-sidebar" class="ocdw_cart-sidebar sidebar-'+sidebar_position+' no-active"><div class="ocdw_cart-sidebar-bg"></div><div class="ocdw_cart-sidebar-body"></div></div>');
115        }
116      }
117      
118      $('#cart > button').html('<span class="cart-icon"><svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 22.443 22.443"><path d="M7.733,19.954A2.244,2.244,0,1,0,9.977,22.2,2.241,2.241,0,0,0,7.733,19.954ZM1,2V4.244H3.244l4.04,8.517L5.769,15.511a2.17,2.17,0,0,0-.281,1.077,2.251,2.251,0,0,0,2.244,2.244H21.2V16.588H8.2a.278.278,0,0,1-.281-.281l.034-.135,1.01-1.829h8.36a2.234,2.234,0,0,0,1.964-1.156l4.017-7.283a1.1,1.1,0,0,0,.135-.539,1.125,1.125,0,0,0-1.122-1.122H5.724L4.669,2H1ZM18.954,19.954A2.244,2.244,0,1,0,21.2,22.2,2.241,2.241,0,0,0,18.954,19.954Z" transform="translate(-1 -2)"/></svg><span class="cart-count">'+json['products'].length+'</span></span><span id="cart-total">'+json['total']+'</span>');
119$('#cart > ul').load('index.php?route=common/cart/info ul li');
120
121    }
122  });
123}
124
125function ocdw_cart_sidebar_close() {
126  $('body,#ocdw_cart-sidebar').removeClass('sidebar-active');
127}
128
129function ocdw_cart_open(options) {
130  if ($('#ocdw_cart-block.cart-page').length) {
131    cart_page_update_cart({b: 'reload'});
132  }
133  
134  let element = options.a || '',
135      display_type = options.b || 1,
136      product_id = options.c || '',
137      popup_background_type = 1,
138      popup_animation_type = 'mfp-zoom-in',
139      post_data = (product_id) ? {product_id: product_id,display_type: display_type} : {display_type: display_type},
140      url = (product_id) ? 'index.php?route=extension/ocdevwizard/cart/options' : 'index.php?route=extension/ocdevwizard/cart';
141    
142  if (display_type == 1) {
143    ocdw_cart_load_css('catalog/view/javascript/ocdevwizard/helper/magnific-popup/magnific-popup.min.css', 'helper-magnific',function() {
144      ocdw_cart_load_js('catalog/view/javascript/ocdevwizard/helper/magnific-popup/jquery.magnific-popup.min.js', 'helper-magnific',function() {
145        $.magnificPopup.open({
146          tLoading: '<div class="spinner"><div class="bounce1"></div><div class="bounce2"></div><div class="bounce3"></div></div>',
147          items: {src: url},
148          type: 'ajax',
149          ajax: {
150            settings: {
151              type: 'post',
152              data: post_data
153            }
154          },
155          closeOnContentClick: 0,
156          closeOnBgClick: 1,
157          closeBtnInside: 1,
158          enableEscapeKey: 1,
159          alignTop: 0,
160          showCloseBtn: 0,
161          removalDelay: (popup_animation_type) ? 300 : 0,
162          mainClass: popup_animation_type,
163          callbacks: {
164            beforeOpen: function() {
165              this.wrap.removeAttr('tabindex');
166            },
167            open: function() {
168              $('.mfp-content').addClass('mfp-with-anim');
169              $('.mfp-container').removeClass('mfp-ajax-holder').addClass('mfp-iframe-holder');
170            }
171          }
172        });
173    
174        $('.spinner > div').css({
175          'background-color': '#ffffff'
176        });
177    
178        $('.mfp-bg').css({
179          'background': (popup_background_type == 1) ? 'url(image/catalog/ocdevwizard/cart/background/bg_7.png)' : '#000000',
180          'opacity': '0.8'
181        });
182      });
183    });
184  } else if (display_type == 2) {
185    $.ajax({
186      type: 'post',
187      url: url,
188      data: post_data,
189      dataType: 'html',
190      beforeSend: function() {
191        $(element).prop('disabled', true);
192      },
193      complete: function() {
194        $(element).prop('disabled', false);
195      },
196      success: function(data) {
197        $('body').addClass('sidebar-active');
198
199        $('#ocdw_cart-sidebar .ocdw_cart-sidebar-bg').css({
200          'background': (popup_background_type == 1) ? 'url(image/catalog/ocdevwizard/cart/background/bg_7.png)' : '#000000'
201        });
202
203        $('#ocdw_cart-sidebar .ocdw_cart-sidebar-body').html(data);
204        $('#ocdw_cart-sidebar').addClass('sidebar-active');
205      }
206    });
207  } else if (display_type == 3) {
208    $.ajax({
209      url: 'index.php?route=extension/ocdevwizard/cart/module',
210      type: 'post',
211      data: {static_load: '1'},
212      dataType: 'html',
213      success: function (data) {
214        $('#ocdw_cart-block.static').html($(data).children());
215        $('#ocdw_cart-block #toggle-inner').addClass('active');
216      }
217    });
218  }
219}
220
221$(document).ajaxSuccess(function (event, xhr, settings) {
222  let action_on_product_with_options = 1;
223  
224  if (settings.url == 'index.php?route=checkout/cart/add') {
225    if (xhr.responseText.indexOf('error') <= 0) {
226      ocdw_cart_action();
227    } else if (action_on_product_with_options == 1) {
228      ocdw_cart_load_css('catalog/view/javascript/ocdevwizard/helper/magnific-popup/magnific-popup.min.css', 'helper-magnific',function() {
229        ocdw_cart_load_js('catalog/view/javascript/ocdevwizard/helper/magnific-popup/jquery.magnific-popup.min.js', 'helper-magnific',function() {
230          $.magnificPopup.close();
231        });
232      });
233      setTimeout(ocdw_cart_open,400,{b: '1',c: ocdw_cart_get_product_id(settings.data)});
234    }
235
236    $('html,body').stop();
237  }
238});
239
240function ocdw_cart_get_product_id(data) {
241  let product_id = 0,
242      arr = data.split('&');
243  for (let i = 0; i < arr.length; i++) {
244    let product_id = arr[i].split('=');
245    
246    if (product_id[0] === 'product_id') {
247      return product_id[1];
248    }
249  }
250}
251
252function ocdw_cart_prepare_module(options) {
253  let language_code = options.b || '',
254      block = options.c || '',
255      flatpickr_close_type = 3;
256
257  $(block).each(function () {
258    if (typeof $(this).data('mask') !== 'undefined') {
259      let that = this;
260      
261      ocdw_cart_load_js('catalog/view/javascript/ocdevwizard/helper/inputmask/inputmask.min.js', 'helper-inputmask-1',function() {
262        ocdw_cart_load_js('catalog/view/javascript/ocdevwizard/helper/inputmask/inputmask.extensions.min.js', 'helper-inputmask-2',function() {
263          ocdw_cart_load_js('catalog/view/javascript/ocdevwizard/helper/inputmask/jquery.inputmask.min.js', 'helper-inputmask-3',function() {
264            $(that).find('input').inputmask($(that).data('mask'), {showMaskOnHover: false});
265          });
266        });
267      });
268    }
269
270    if (typeof $(this).data('datepick') !== 'undefined') {
271      if ($(this).data('datepick') == 'time') {
272        var date_format = "H:i",
273            enable_time = true,
274            enable_date = true;
275      } else if ($(this).data('datepick') == 'datetime') {
276        var date_format = "Y-m-d H:i",
277            enable_time = true,
278            enable_date = false;
279      } else if ($(this).data('datepick') == 'date') {
280        var date_format = "Y-m-d",
281            enable_time = false,
282            enable_date = false;
283      }
284
285      let input_field = $(this).find('input'),
286          flatpickr_lang = (language_code == 'ru' || language_code == 'uk') ? language_code : 'en';
287
288      $(input_field).on('focus', function() {
289        $(input_field.next()).addClass('active');
290      });
291
292      ocdw_cart_load_css('catalog/view/javascript/ocdevwizard/helper/flatpickr/flatpickr.min.css', 'helper-flatpickr',function() {
293        ocdw_cart_load_js('catalog/view/javascript/ocdevwizard/helper/flatpickr/flatpickr.min.js', 'helper-flatpickr-1',function() {
294          ocdw_cart_load_js('catalog/view/javascript/ocdevwizard/helper/flatpickr/l10n/'+flatpickr_lang+'.js', 'helper-flatpickr-2',function() {
295            setTimeout(function(){
296              input_field.flatpickr({
297                enableTime: enable_time,
298                noCalendar: enable_date,
299                dateFormat: date_format,
300                time_24hr: true,
301                allowInput: true,
302                locale: flatpickr_lang,
303                inline: true,
304                onChange:function(selectedDates, dateStr, instance) {
305                  if (flatpickr_close_type == 1 || flatpickr_close_type == 3) {
306                    $(input_field.next()).removeClass('active').blur();
307                    $(input_field).blur();
308                  }
309                }
310              });
311            },400);
312          });
313        });
314      });
315      
316      if (flatpickr_close_type == 2 || flatpickr_close_type == 3) {
317        $(document).click(function (e) {
318          if ($(e.target).parents('.inner-center').length === 0) {
319            $(input_field.next()).removeClass('active');
320          }
321        });
322      }
323    }
324  });
325}
326
327function ocdw_cart_validate_input(input) {
328  input.value = input.value.replace(/[^\d,]/g, '');
329}
330
331function ocdw_cart_load_js(src, src_type, callback) {
332  var element = ((document.getElementById(src_type+'-js')) ? true:false);
333
334  if (!element) {
335    var s = document.createElement('script');
336    
337    s.src = src;
338    s.id = src_type+'-js';
339    s.onreadystatechange = s.onload = function () {
340      var state = s.readyState;
341      if (!callback.done && (!state || /loaded|complete/.test(state))) {
342        callback.done = true;
343        callback();
344      }
345    };
346    
347    document.getElementsByTagName('head')[0].appendChild(s);
348  } else {
349    callback.done = true;
350    callback();
351  }
352}
353
354function ocdw_cart_load_css(src, src_type, callback) {
355  var element = ((document.getElementById(src_type+'-css')) ? true:false);
356
357  if (!element) {
358    var s = document.createElement('link');
359    
360    s.rel = 'stylesheet';
361    s.type = 'text/css';
362    s.href = src;
363    s.id = src_type+'-css';
364    s.onreadystatechange = s.onload = function () {
365      var state = s.readyState;
366      if (!callback.done && (!state || /loaded|complete/.test(state))) {
367        callback.done = true;
368        callback();
369      }
370    };
371    
372    document.getElementsByTagName('head')[0].appendChild(s);
373  } else {
374    callback.done = true;
375    callback();
376  }
377}

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.