PageSourceSearch

https://souqcity.ma/oc-content/themes/epsilon/js/global.js

js souqcity.ma collected 2026-10-02 01:04:42 UTC 57,584 bytes, 1,759 lines download raw bytes

1$(document).ready(function() {
2  // INITIAL SETUP
3  epsLazyLoadImages();
4  epsManageScroll();
5  epsShowUsefulScrollButtons();
6
7  // تقليل الضغط على الـ layout عند تعديل حجم النافذة عبر Debounce
8  var epsResizeTimer;
9  $(window).on('resize', function() {
10    clearTimeout(epsResizeTimer);
11    epsResizeTimer = setTimeout(function() {
12      epsShowUsefulScrollButtons();
13    }, 250);
14  });
15
16  // SHOW SHOWCASE BOX ON MOBILE
17  $('body').on('click', '#showcase-button', function(e) {
18    e.preventDefault();
19    $(this).toggleClass('active');
20    $('#showcase-box').slideToggle(200);
21  });
22
23
24  // CLEAN ALL RECENTLY VIEWED
25  $('body').on('click', '.clear-recently-viewed', function(e) {
26    e.preventDefault();
27    $(this).closest('.recent-ads').slideUp(200, function() {
28      $(this).remove();
29    });
30    
31    
32    $.ajax({
33      type: 'GET',
34      url: baseAjaxUrl + '&ajaxCleanRecentlyViewedAll=1',
35      success: function(data) {
36        //console.log(data);
37      }
38    });
39  });
40  
41  
42  // CLEAN LOCATION IF CHANGED IN LOCATION BOX
43  $('body').on('keyup change', 'form[name="item"] .picker.location input[name="sLocation"], form.profile .picker.location input[name="sLocation"]', function() {
44    var form = $(this).closest('form');
45    form.find('input[name="countryId"], input[name="regionId"], input[name="cityId"]').val('');
46  });
47  
48  
49  // CHECK IF HAS SHOWCASE
50  if($('#showcase-box').length) {
51    $('body').addClass('demo');
52  }
53  
54
55  // SEARCH FREE PRICE CHECKBOX
56  $('body').on('change', '.filter-menu input[name="bPriceCheckWithSeller"], .filter-menu input[name="bPriceFree"]', function(e) {
57    e.preventDefault();
58    var form = $(this).closest('form');
59    
60    if($(this).is(':checked')) {
61      //form.find('input[name="sPriceMin"], input[name="sPriceMax"]').val('').attr('disabled', true);
62      form.find('input[name="sPriceMin"], input[name="sPriceMax"]').val('');
63      form.find('input[name="bPriceFree"], input[name="bPriceCheckWithSeller"]').not(this).prop('checked', false);
64    } else {
65      //form.find('input[name="sPriceMin"], input[name="sPriceMax"]').val('').attr('disabled', false);
66      form.find('input[name="sPriceMin"], input[name="sPriceMax"]').val('');
67    }
68    
69    $(form).find('input.ajaxRun').change();
70  });
71
72  
73  $('body').on('click keyup change', '.filter-menu input[name="sPriceMin"], .filter-menu input[name="sPriceMax"]', function(e) {
74    var form = $(this).closest('form');
75    
76    if($(this).val() != '') {
77      form.find('input[name="bPriceFree"], input[name="bPriceCheckWithSeller"]').prop('checked', false);
78    }
79  });
80
81
82  // SHOW-HIDE SCROLL TO TOP
83  $(window).on('scroll', function(){
84    if($(document).scrollTop() > 720) {
85      $('#scroll-to-top').fadeIn(200);
86    } else {
87      $('#scroll-to-top').fadeOut(200);
88    }  
89  });
90
91  // ITEM RATING
92  $('body').on('click', '.is-rating-item', function(e) {
93    e.preventDefault();
94    $('input[name="rating"]').val($(this).attr('data-value'));
95    $('.comment-rating-selected').text('(' + $(this).attr('data-value') + ' of 5)');
96    $(this).parent().find('i.is-rating-item').addClass('fill');
97    $(this).nextAll('i.is-rating-item').removeClass('fill');
98  })
99  
100  // DISABLE DARK MODE
101  $('body').on('click', 'a.disable-dark-mode', function(e) {
102    e.preventDefault();
103    $(this).hide();
104    $('a.enable-dark-mode').show(0);
105    $('link[rel="stylesheet"][href*="dark.css"]').attr('disabled', true);
106    
107    $.ajax({
108      type: 'GET',
109      url: baseAjaxUrl + '&ajaxDarkMode=disable',
110      success: function(data) {
111        //console.log(data);
112      }
113    });
114  });
115  
116  
117  // ENABLE DARK MODE
118  $('body').on('click', 'a.enable-dark-mode', function(e) {
119    e.preventDefault();
120    $(this).hide();
121    $('a.disable-dark-mode').show(0);
122    $('link[rel="stylesheet"][href*="dark.css"]').attr('disabled', false);
123    
124    $.ajax({
125      type: 'GET',
126      url: baseAjaxUrl + '&ajaxDarkMode=enable',
127      success: function(data) {
128        //console.log(data);
129        
130        if(!$('link[rel="stylesheet"][href*="dark.css"]').length) {
131          $('head link[rel="stylesheet"]').last().after('<link rel="stylesheet" href="' + baseDir + 'oc-content/themes/epsilon/css/dark.css" type="text/css" media="screen">');
132
133          //window.location.reload();
134          //return false;
135        }
136      }
137    });
138  });
139  
140  
141  // RECHECK DARK MODE: Wait for DOM to be ready - in case theme loads late
142  window.setTimeout(() => {
143    if(darkMode == '1') {
144      $('link[rel="stylesheet"][href*="dark.css"]').removeAttr('disabled');
145      $('a.disable-dark-mode').hide();
146      $('a.enable-dark-mode').show();
147    } else {
148      $('link[rel="stylesheet"][href*="dark.css"]').attr('disabled', 'disabled');
149      $('a.disable-dark-mode').show();
150      $('a.enable-dark-mode').hide();
151    }
152  }, 100);
153  
154
155  // PRINT ITEM
156  $('body').on('click', 'a.print', function(e){
157    e.preventDefault();
158    $('body').addClass('print');
159    $('.phone, #item-main .description .read-more-desc').click();
160    $(window).scrollTop(0);
161    window.print();
162    $('body').removeClass('print');
163  });
164  
165
166  // SCROLL TO TOP
167  $('body').on('click', '#scroll-to-top', function(e) {
168    e.preventDefault();
169    $('html, body').animate({scrollTop: 0}, 500);
170  });
171  
172  
173  // FANCYBOX - OPEN ITEM FORM (COMMENT / SEND FRIEND / PUBLIC CONTACT / SELLER CONTACT)
174  $('body').on('click', '.open-form', function(e) {
175    e.preventDefault();
176    var height = 600;
177    var url = $(this).attr('href');
178    var formType = $(this).attr('data-type');
179
180    if(url.indexOf('loginRequired') !== -1) {
181      window.location.href = url;
182      return;
183    }
184    
185    if(formType == 'comment') {
186      height = (userLogged == 1 ? 490 : 640);
187      height += ($(this).hasClass('has-rating') ? 55 : 0);
188    } else if(formType == 'contact') {
189      height = (userLogged == 1 ? 490 : 640);
190    } else if(formType == 'friend') {
191      height = (userLogged == 1 ? 540 : 705);
192    } else if(formType == 'contact_public') {
193      height = (userLogged == 1 ? 490 : 640);
194    }
195    
196    epsModal({
197      width: 380,
198      height: height,
199      content: url, 
200      wrapClass: 'item-extra-form',
201      closeBtn: true, 
202      iframe: true, 
203      fullscreen: 'mobile',
204      transition: 200,
205      delay: 0,
206      lockScroll: true
207    });
208  });
209  
210  // OPEN REPORT BOX
211  $('body').on('click', '.report-button', function(e) {
212    e.preventDefault();
213
214    epsModal({
215      width: 420,
216      height: 490,
217      content: $('.report-wrap').html(), 
218      wrapClass: 'report-box',
219      closeBtn: true, 
220      iframe: false, 
221      fullscreen: 'mobile',
222      transition: 200,
223      delay: 0,
224      lockScroll: true
225    });
226  });
227  
228  // SHOW FULL ITEM DESCRIPTION
229  $('body').on('click', 'a.read-more-desc', function(e) { 
230    e.preventDefault();
231    var box = $(this).closest('.description');
232    
233    $(this).hide(0);
234    box.find('.text.visible').hide(0);
235    box.find('.text.hidden').show(0);
236  });
237  
238  
239  // LIGHTBOX GALLERY (تحميل كسول: السكربت يُحمّل عند أول نقرة لتحسين الأداء)
240  function epsInitLightGallery() {
241    if(typeof $.fn.lightGallery === 'undefined') return;
242    $('#item-image .swiper-container').lightGallery({
243      mode: 'lg-slide',
244      thumbnail: true,
245      cssEasing : 'cubic-bezier(0.25, 0, 0.25, 1)',
246      selector: 'li > a',
247      getCaptionFromTitleOrAlt: true,
248      download: false,
249      thumbWidth: 90,
250      thumbContHeight: 80,
251      share: false
252    });
253  }
254  if(typeof $.fn.lightGallery !== 'undefined') {
255    epsInitLightGallery();
256  } else if(window.epsLightgalleryLazy && window.epsLightgalleryJsUrl && $('#item-image .swiper-container').length) {
257    $('body').one('click', '#item-image .swiper-container li > a', function(e) {
258      e.preventDefault();
259      var $link = $(this);
260      var url = window.epsLightgalleryJsUrl;
261      var script = document.createElement('script');
262      script.src = url;
263      script.onload = function() {
264        epsInitLightGallery();
265        $link[0].click();
266      };
267      document.body.appendChild(script);
268    });
269  }
270  
271  
272  // WHEN LIGHTBOX IS LOADED, MAKE SURE LAZYLOAD DOES NOT BLOCK THUMBNAILS
273  var urlHash = window.location.hash;
274  
275  if(urlHash !== '' && urlHash.startsWith("#lg")) {
276    setTimeout(function() {
277      epsFixImgSources();
278    }, 600);
279  }
280  
281  // OPEN CONTACT SELLER BOX BASED ON HASH
282  if(urlHash !== '' && urlHash.startsWith("#contact") && $('#item-side .master-button').length) {
283    $('#item-side .master-button').click();
284  }
285  
286  $('body').on('click', '#item-image li > a', function(){
287    epsFixImgSources();
288  });
289  
290  
291  // SWIPER INITIATE
292  if(typeof(Swiper) !== 'undefined') { 
293    var swiper = new Swiper(".swiper-container", {
294      slideClass: "swiper-slide",
295      navigation: {
296        nextEl: ".swiper-next",
297        prevEl: ".swiper-prev",
298      },
299      pagination: {
300        el: ".swiper-pg",
301        type: "fraction",
302      },
303      on: {
304        afterInit: function () {
305          //epsLazyLoadGalleryImages();
306        },
307        activeIndexChange: function (swp) {
308          //moveItemThumb(swp);
309          epsLazyLoadImages('item-gallery');
310          
311          //(swp.activeIndex > 0 ? $('.swiper-button.swiper-prev').fadeIn(200) : $('.swiper-button.swiper-prev').fadeOut(200));
312          //(swp.activeIndex < swp.slides.length - 1 ? $('.swiper-button.swiper-next').fadeIn(200) : $('.swiper-button.swiper-next').fadeOut(200));
313
314          //(swp.activeIndex > 0 ? $('.swiper-button.swiper-prev').removeClass('disabled').fadeIn(100) : $('.swiper-button.swiper-prev').addClass('disabled'));
315          //(swp.activeIndex < swp.slides.length - 1 ? $('.swiper-button.swiper-next').removeClass('disabled').fadeIn(100) : $('.swiper-button.swiper-next').addClass('disabled'));
316
317          $('.swiper-thumbs li').removeClass('active');
318          $('.swiper-thumbs li[data-id="' + swp.activeIndex + '"]').addClass('active');
319        }
320      }
321    });
322  }
323  
324
325  // SWIPER THUMBS
326  $('body').on('click', '.swiper-thumbs li', function(e) {
327    e.preventDefault();
328    
329    $('.swiper-thumbs li').removeClass('active');
330    $(this).addClass('active');
331    var elemId = $(this).attr('data-id');
332
333    if(typeof(swiper) !== 'undefined') {
334      epsfixImgSourcesThumb();
335      swiper.slideToLoop(elemId);
336    }
337  });
338  
339  // NICE SCROLL - ACTION BUTTONS
340  $('body').on('click', '.nice-scroll-next, .nice-scroll-prev', function(e) {
341    e.preventDefault();
342    
343    if($(this).hasClass('scrolling')) {
344      return false;
345    }
346    
347    var scrollCards = 4;
348    var btn = $(this);
349    var elem = $(this).siblings('.nice-scroll');
350    var pos = elem.scrollLeft();
351    var len = elem.find(' > *').width() + parseFloat((elem.find(' > *').css('margin-left')).replace('px', '')) +  + parseFloat((elem.find(' > *').css('margin-right')).replace('px', ''));
352
353    $(this).addClass('scrolling');
354    
355    ($(window).width() - 10 < scrollCards*len ? scrollCards = 3 : '');
356    ($(window).width() - 10 < scrollCards*len ? scrollCards = 2 : '');
357    ($(window).width() - 10 < scrollCards*len ? scrollCards = 1 : '');
358  
359    len = len*scrollCards;
360    
361    if($(this).hasClass('nice-scroll-prev')) {
362      len = -len;
363    }
364    
365    elem.stop(false,false).animate({scrollLeft: pos + len}, 100 + scrollCards*80, function() {
366      btn.removeClass('scrolling');
367    });
368  });
369  
370  
371  if(ajaxSearch == '1') {
372    // AJAX SEARCH - initialize change events
373    $('body#search').on('change', '.sort-type select, form.search-side-form input, form.search-side-form select', function(event) {
374      epsAjaxSearch($(this), event);
375    });
376    
377    // AJAX SEARCH - initialize keyp events
378    $('body#search').on('keyup', 'form.search-side-form input[name="sPattern"]', function(event) {
379      epsAjaxSearch($(this), event);
380    });
381
382    // AJAX SEARCH - initialize click events
383    $('body#search').on('click', '.breadcrumb a, #search-category-box a, #search-filters a, #filter-user-type a, #latest-search a, .paginate a', function(event) {
384      epsAjaxSearch($(this), event);
385      return false;
386    });
387  }
388  
389  // MASKED ELEMENT UNHIDE
390  $('body').on('click', '.masked', function(e) {
391    if(!$(this).hasClass('revealed')) {
392      e.preventDefault();
393      var text = String($(this).attr('data-part1')) + String($(this).attr('data-part2'));
394
395      $(this).attr('href', $(this).attr('data-prefix')+ ':' + text).attr('title', '').addClass('revealed');
396      $(this).find('span').text(text);
397    }
398  });
399
400  
401  // SHOW HEADER QUICK INFOBAR ON MOBILE
402  if($('body#search').length || $('body#item').length) {
403    $(window).on('scroll', function(){
404      if(($(window).width() + scrollCompensate()) < 768) {
405        var elem = ($('body#search').length ? $('header .container.alt.cresults') : $('header .container.alt.citem'));
406        var limit = ($('body#search').length ? $('#search-quick-bar') : $('.description'));
407        
408        if($(this).scrollTop() > limit.offset().top) {
409          elem.hasClass('hidden') ? elem.removeClass('hidden').stop(true,true).slideDown(200) : '';
410        } else {
411          !elem.hasClass('hidden') ? elem.addClass('hidden').stop(true,true).slideUp(200) : '';
412        }
413      }
414    });
415  }
416  
417  
418  // DYNAMICALLY GENERATED LABELS ON MOBILE DOES NOT WORK
419  $('body').on('click', '#side-menu .filter-menu .input-box-check label', function(e) {
420    if(($(window).width() + scrollCompensate()) < 768) {
421      e.preventDefault();
422      var checkbox = $(this).siblings('input[type="checkbox"]');
423      checkbox.length ? checkbox.prop('checked', !checkbox.prop('checked')).change() : '';
424    }
425  });
426  
427  
428  // SEARCH ORDER UPDATE ON SELECT CHANGE
429  // $('body').on('change', '#search-quick-bar .sort-type select', function(e) {
430    // var form = $('form.search-side-form');
431    
432    // form.find('input[name="sOrder"]').val($(this).find(':selected').attr('data-type'));
433    // form.find('input[name="iOrderType"]').val($(this).find(':selected').attr('data-order'));
434
435
436    // if(ajaxSearch == 1) {
437      // form.find('input[name="iOrderType"]').change();
438    // } else {
439      // form.submit();
440    // }
441  // });
442
443  $('body').on('change', '#search-quick-bar .sort-type select', function(e) {
444    if(ajaxSearch != 1) {
445      e.preventDefault();
446      window.location.href = $(this).find(':selected').attr('data-link');
447      return false;
448    }
449  });
450  
451
452  // OPEN SEARCH FILTERS ON MOBILE
453  $('body').on('click', '#open-search-filters, .action.open-filters', function(e) {
454    e.preventDefault();
455    var menu = $('#side-menu');
456    $('#menu-cover').fadeIn(200);
457    $('#side-menu .box.filter').show(0);
458    $('#side-menu .box.filter .section').html($('.filter-menu').html());
459    
460    if(!isRtl) {
461      menu.css({'margin-left': '-50px', 'opacity': 0}).show(0).animate({'margin-left': 0, 'opacity': 1}, 300);
462    } else {
463      menu.css({'margin-right': '-50px', 'opacity': 0}).show(0).animate({'margin-right': 0, 'opacity': 1}, 300);
464    }
465    
466    $('#side-menu').addClass('box-open');
467  });
468  
469  // OPEN ALERT BOX
470  $('body').on('click', '.open-alert-box', function(e) {
471    e.preventDefault();
472
473    epsModal({
474      width: 490,
475      height: 440,
476      content: $('.alert-box').html(), 
477      wrapClass: 'alert-box-search',
478      closeBtn: true, 
479      iframe: false, 
480      fullscreen: 'mobile',
481      transition: 200,
482      delay: 0,
483      lockScroll: true
484    });
485  });
486  
487  
488  // LIST, GRID, DETAIL VIEW TYPE SWITCH
489  $('body').on('click', '#search-quick-bar .view-type a', function(e) { 
490    e.preventDefault();
491    var viewType = $(this).attr('data-view');
492
493    if(!$(this).hasClass('active')) {
494
495      $(this).closest('.view-type').find('a').removeClass('active');
496      $(this).addClass('active');
497      $('#search-items > .products').removeClass('list grid detail');
498      $('#search-items > .products').addClass(viewType);
499      
500      $('input[name="sShowAs"]').val(viewType);
501
502      // UPDATE CURRENT LINK
503      var href = $(this).attr('href');
504
505      if(href != '') {
506        var newNaviUrl = href;
507      } else {
508        //var newUrl = baseDir + 'index.php?' + $('form.search-side-form :input[value!=""], form.search-side-form select, form.search-side-form textarea').serialize();
509        var newNaviUrl = baseDir + "index.php?" + $('form.search-side-form').find(":input:not(:disabled)").filter(function () { return $.trim(this.value).length > 0}).serialize();
510      }
511
512      window.history.pushState(null, null, newNaviUrl);
513
514
515      // UPDATE PAGINATION AND OTHER LINKS
516      $('.paginate a, .user-type a, .sort-it a, #search-filters a, select.orderSelect option').each(function() {
517        var type = (typeof $(this).attr('data-link') !== 'undefined' ? 'data-link' : 'href');
518        var url = $(this).attr(type);
519
520        if(!url.indexOf("index.php") >= 0 && url.match(/\/$/)) {
521          url += (url.substr(-1) !== '/' ? '/' : '');
522        }
523
524        if(url.indexOf("sShowAs") >= 0) {
525          url += (url.substr(-1) !== '/' ? '/' : '');
526          var newUrl = url.replace(/(sShowAs,).*?(\/)/,'$1' + viewType + '$2').replace(/(sShowAs,).*?(\/)/,'$1' + viewType + '$2');
527
528        } else {
529          if(url.indexOf("index.php") >= 0) {
530            var newUrl = url + '&sShowAs=' + viewType;
531          } else {
532            var newUrl = url.replace(/\/+$/, '') + '?sShowAs=' + viewType;
533          }
534        }
535
536        newUrl = (newUrl.substr(-1) == '/' ? newUrl.slice(0, -1) : newUrl);
537        $(this).attr(type, newUrl);
538      });
539    }
540  });
541  
542  
543  // USER MENU HIGHLIGHT ACTIVE
544  var url = window.location.toString();
545
546  $('#user-menu a').each(function(){
547    if(!$('#user-menu a.active').length) {
548      var myHref = $(this).attr('href');
549
550      if(url == myHref) {
551        if(myHref.indexOf(url) >= 0)
552        $(this).addClass('active');
553        return;
554      }
555    }
556  });
557  
558  // MOVE TO CHANGE EMAIL
559  // SHOW TECHNICAL DETAILS ON ALERTS PAGE
560  $('body').on('click', '.profile-box label a.change-email', function(e) {
561    e.preventDefault();
562    $('html, body').animate({
563      scrollTop: $('.profile-box.change-mail').offset().top - 72
564    }, 1000);
565  });
566  
567
568  // SHOW TECHNICAL DETAILS ON ALERTS PAGE
569  $('body').on('click', '.show-technical-details', function(e) {
570    e.preventDefault();
571    $(this).closest('.alert').find('.details').slideToggle(300); 
572  });
573
574  
575  // DOUBLE ARROW PAGINATION FIX
576  $('.paginate').each(function() {
577    $(this).find('.searchPaginationNext').html('<i class="fas fa-angle-right"></i>');
578    $(this).find('.searchPaginationPrev').html('<i class="fas fa-angle-left"></i>');
579    //$(this).find('.searchPaginationFirst').html('<i class="fas fa-angle-double-left"></i>');
580    //$(this).find('.searchPaginationLast').html('<i class="fas fa-angle-double-right"></i>');
581    $(this).find('.searchPaginationFirst').html('<i class="fas fa-step-backward"></i>');
582    $(this).find('.searchPaginationLast').html('<i class="fas fa-step-forward"></i>');
583  });
584
585
586  // CLEAN INPUT WHEN CLEAN BUTTON CLICKED
587  $('body').on('click', '.picker .clean', function(e) {
588    e.preventDefault();
589    $(this).closest('.input-box').find('input').val('').focus().change();
590    console.log('aa');
591    //$(this).closest('form').find('.results').hide(0);
592    $(this).hide(0);
593  });
594  
595  
596  // CLEAN INPUT WHEN CLEAN BUTTON CLICKED
597  $('body').on('click', '.input-box .clean', function(e) {
598    e.preventDefault();
599    $(this).siblings('input').val('').focus().change();
600    $(this).hide(0);
601  });
602  
603  
604  // ADD CLEAN BUTTON
605  $('body').on('click keyup focus', '.input-box input', function(e) {
606    //if(ajaxSearch == 0 && $(this).closest('.input-box').find('.clean').length) {
607    if($(this).closest('.input-box').find('.clean').length) {
608      if($(this).val() != '') {
609        $(this).closest('.input-box').find('.clean').fadeIn(100);
610      } else {
611        $(this).closest('.input-box').find('.clean').fadeOut(100);
612      }
613    }
614  });
615
616
617  // SHOW BANNERS
618  $('body').on('click', 'a.show-banners', function(e) {
619    e.preventDefault();
620    $('.banner-theme#banner-theme.is-demo, .home-container.banner-box.is-demo').stop(true, true).slideToggle(300);
621    
622    var newText = $(this).attr('data-alt-text');
623    var oldText = $(this).text();
624    
625    $(this).attr('data-alt-text', oldText).text(newText);    
626  });
627  
628  
629  // ON FOUCS OUT INPUT BOX, HIDE CLEAN BUTTON WITH DELAY
630  $('body').on('focusout', '.input-box input', function(e) {
631    if($(this).closest('.input-box').find('.clean').length) {
632      $(this).closest('.input-box').find('.clean').delay(100).fadeOut(100);
633    }
634  });
635  
636  
637  // LATEST SEARCH TO INPUT BOX
638  $('.latest-search a').click(function(e) {
639    e.preventDefault();
640    $('body#home .home-search input[name="sPattern"]').val($(this).attr('data-text'));    
641  });
642  
643  
644  // ON HOME PAGE LOAD, FOCUS SEARCH INPUT
645  // if($('body#home .home-search input[name="sPattern"]').length) {
646    // $('body#home .home-search input[name="sPattern"]').focus();
647  // }
648  
649
650  // OPEN LOCATION SELETOR FROM HEADER MENU
651  $('header .links .btn.location').click(function(e) {
652    e.preventDefault();
653
654    epsModal({
655      width: 420,
656      height: 640,
657      content: '<div id="def-location" class="def-loc-box">' + $('#side-menu .box.location > .section').html() + '</div>', 
658      wrapClass: 'location-select',
659      closeBtn: true, 
660      iframe: false, 
661      fullscreen: 'mobile',
662      transition: 200,
663      delay: 0,
664      lockScroll: true
665    });
666  });
667  
668  
669  // ITEM PUBLISH UPDATE LOCATION
670  $('body').on('click', '.location-link .link-update.location, .change-location, .change-search-location', function(e) {
671    if(!$(e.target).hasClass('input-clean')) {
672      e.preventDefault();
673
674      if (($(window).width() + scrollCompensate()) >= 768) {
675        $('header .links .btn.location').click();
676      } else {
677        $('#navi-bar a.location').click();
678      }
679    }
680  });
681  
682
683  // OPEN LOCATION BOX FROM BOTTOM NAV BAR
684  $('#navi-bar a.location').on('click', function(e) {
685    e.preventDefault();
686    var menu = $('#side-menu');
687    $('#menu-cover').fadeIn(200);
688    $('#side-menu .box').hide(0);
689    $('#side-menu .box.location').show(0);
690    
691    if(!isRtl) {
692      menu.css({'margin-left': '-50px', 'opacity': 0}).show(0).animate({'margin-left': 0, 'opacity': 1}, 300);
693    } else {
694      menu.css({'margin-right': '-50px', 'opacity': 0}).show(0).animate({'margin-right': 0, 'opacity': 1}, 300);
695    }
696    
697    $('#side-menu').addClass('box-open');
698  });
699
700
701  // CLEAN LOCATION SEARCH FORM
702  $('body').on('click', '.picker.pattern .input-clean', function(e) {
703    e.preventDefault();
704    $(this).closest('.row').slideUp(200);
705    $(this).closest('form').find('input.loc-inp').remove();
706  });
707  
708  
709  // PATTERN PICKER LOADER KEYUP
710  $('body').on('keyup click change', '.picker.pattern input', function(event) {
711    var timeout = '';
712    epsLoadPatternSimple($(this), event);
713  });
714
715
716  // HIDE PATTERN RESULTS ON OUTSIDE CLICK
717  $(document).mouseup(function (e){
718    var container = $('.picker.pattern');
719
720    if(!container.is(e.target) && container.has(e.target).length === 0) {
721      container.closest('form').find('.results').hide(0);
722      //container.find('.results .loaded').html('').hide(0);
723    }
724  });
725
726  // LOCATION LOADER KEYUP
727  $('body').on('keyup click change', '.picker.location input', function(event) {
728    var timeout = '';
729
730    if($(this).closest('.picker').hasClass('only-search')) {
731      epsLoadLocationsSimple($(this), event);
732    } else {
733      epsLoadLocationsSimple($(this), event, 'COOKIE');
734    }
735  });
736  
737
738  // LOCATION LOADER KEYUP
739  $('body').on('keyup click change', '.picker.category input', function(event) {
740    var timeout = '';
741
742    if(!$(this).closest('.picker').hasClass('create-link')) {
743      epsLoadCategoriesSimple($(this), event);
744    } else {
745      epsLoadCategoriesSimple($(this), event, 'LINK');
746    }
747  });
748
749
750  // SELECT OPTION FROM LOCATION BOX
751  $('body').on('click', '.picker.location div.option', function(event) {
752    var form = $(this).closest('form');
753    
754    if($(this).closest('.picker').hasClass('is-publish') || !$('body#search').length) {
755      form.find('input[name="sCountry"], input[name="countryId"]').val($(this).attr('data-country'));
756      form.find('input[name="sRegion"], input[name="regionId"]').val($(this).attr('data-region'));
757      form.find('input[name="sCity"], input[name="cityId"]').val($(this).attr('data-city'));
758    } else {
759      if($(this).attr('data-city') != '') {
760        form.find('input[name="sCity"], input[name="cityId"]').val($(this).attr('data-city'));
761        form.find('input[name="sRegion"], input[name="sCountry"]').val('');
762      } else if ($(this).attr('data-region') != '') {
763        form.find('input[name="sRegion"], input[name="regionId"]').val($(this).attr('data-region'));
764        form.find('input[name="sCity"], input[name="sCountry"]').val('');
765      } else if ($(this).attr('data-country') != '') {
766        form.find('input[name="sCountry"], input[name="countryId"]').val($(this).attr('data-country'));
767        form.find('input[name="sRegion"], input[name="sCity"]').val('');
768      }
769    }
770    
771    // Trigger change on publish page
772    if($(this).closest('.picker').hasClass('is-publish')) {
773      form.find('input[name="countryId"]').change();
774    }
775
776    $(this).closest('.picker').find('input[type="text"]').val($(this).find('span').text());
777    $(this).closest('.results').hide(0);
778
779    if($(this).closest('.search-side-form').length) {
780      form.find('input[name="sCity"]').change();
781    }
782  });
783  
784  
785  // SELECT OPTION FROM CATEGORY BOX
786  $('body').on('click', '.picker.category div.option', function(event) {
787    var form = $(this).closest('form');
788
789    if($(this).attr('data-category') != '') {
790      form.find('input[name="catId"], input[name="sCategory"]').val($(this).attr('data-category'));
791    }
792
793    $(this).closest('.picker').find('input[type="text"]').val($(this).find('span').text());
794    $(this).closest('.results').hide(0);
795
796    if($(this).closest('.search-side-form').length) {
797      form.find('input[name="sCategory"]').change();
798    }
799    
800    if($(this).closest('form[name="item"]').length) {
801      form.find('input[name="catId"]').change();
802    }
803  });
804  
805  
806  // HIDE LOCATION RESULTS ON OUTSIDE CLICK
807  $(document).mouseup(function (e){
808    var container = $('.picker.location');
809
810    if(!container.is(e.target) && container.has(e.target).length === 0) {
811      container.closest('form').find('.results').hide(0);
812      //container.find('.results').html('').hide(0);
813    }
814  });
815  
816  
817  // LOCATE USING GEOLOCATION
818  $('body').on('click', '.navigator a.locate-me', function(e) {
819    if(!$(this).hasClass('completed')) {
820      e.preventDefault();
821      epsGeoLocate($(this).find('span.status'));
822    }
823  });
824  
825  // OPEN SIDE MENU
826  $('header .menu.btn').click(function(e) {
827    e.preventDefault();
828    var menu = $('#side-menu');
829    $('#menu-cover').fadeIn(200);
830    $('#side-menu').removeClass('box-open');
831    $('#side-menu .box').hide(0);
832
833    if(!isRtl) {
834      menu.css({'margin-left': '-50px', 'opacity': 0}).show(0).animate({'margin-left': 0, 'opacity': 1}, 300);
835    } else {
836      menu.css({'margin-right': '-50px', 'opacity': 0}).show(0).animate({'margin-right': 0, 'opacity': 1}, 300);
837    }
838  });
839  
840  // CLOSE SIDE MENU
841  $('#menu-cover').click(function(e) {
842    e.preventDefault();
843    var menu = $('#side-menu');
844    $('#menu-cover').fadeOut(200);
845    
846    if(!isRtl) {
847      menu.stop(true, true).animate({'margin-left': '-50px', 'opacity': 0}, 300, function() {
848        menu.css({'margin-left': 0, 'opacity': 1}).hide(0);
849      });
850    } else {
851      menu.stop(true, true).animate({'margin-right': '-50px', 'opacity': 0}, 300, function() {
852        menu.css({'margin-right': 0, 'opacity': 1}).hide(0);
853      }); 
854    }
855  });
856  
857  // SIDE MENU OPEN SUBSECTION
858  $('#side-menu .open-box').click(function(e) {
859    e.preventDefault();
860    var boxId = $(this).attr('data-box');
861    var box = $('#side-menu .box[data-box="' + boxId + '"]');
862    
863    if(!isRtl) {
864      box.show(0).css({'margin-left': '-50px', 'opacity': 0}).animate({'margin-left': 0, 'opacity': 1}, 300);
865    } else {
866      box.show(0).css({'margin-right': '-50px', 'opacity': 0}).animate({'margin-right': 0, 'opacity': 1}, 300);
867    }
868    
869    $('#side-menu').addClass('box-open');
870  });
871  
872  // SIDE MENU SUBSECTION BACK BUTTON
873  $('#side-menu .back').click(function(e) {
874    e.preventDefault();
875    if($(this).hasClass('close')) {
876      $('#menu-cover').click();
877      $(this).closest('.box').delay(300).hide(0);
878    } else {
879      var box = $(this).closest('.box');
880      
881      if(!isRtl) {
882        box.animate({'margin-left': '-50px', 'opacity': 0}, 300, function() {
883          box.css({'margin-left': 0, 'opacity': 1}).hide(0);
884        });
885      } else {
886        box.animate({'margin-right': '-50px', 'opacity': 0}, 300, function() {
887          box.css({'margin-right': 0, 'opacity': 1}).hide(0);
888        });
889      }
890      
891      $('#side-menu').removeClass('box-open');
892    }
893  });
894  
895  
896  // REMOVE EMPTY SECTIONS OF MOBILE SIDE MENU
897  $('#side-menu > .section').each(function() {
898    if(!$(this).find('a').length) {
899      $(this).hide(0); 
900    }
901  });
902  
903  // SUBMIT PUBLISH FORM VIA MIDDLE BUTTON
904  $('#navi-bar a.active.post').click(function(e) {
905    if($('form[name="item"]').length) {
906      e.preventDefault();
907      $('form[name="item"]').submit();
908    }
909  });
910  
911  
912  // MOBILE BACK BUTTON
913  $('header .csearch a.back').click(function(e) {
914    e.preventDefault();
915    $(this).closest('.container').slideUp(150);
916  });
917  
918  // SHOW SEARCH BAR ON MOBILE
919  $('header .links .search').click(function(e) {
920    e.preventDefault();
921    var box = $('header .csearch');
922    var input = box.find('input[type="text"]');
923    box.slideDown(150);
924    
925    var oldVal = input.val();
926    input.val('').val(oldVal).focus().click();
927  });
928
929
930  // PUBLISH PAGE - SWITCH PRICE
931  $('.item-publish .selection a').click(function(e) {
932    e.preventDefault();
933    var price = $(this).attr('data-price');
934
935    $('.item-publish .selection a').removeClass('active');
936    $(this).addClass('active');
937    $('.item-publish .enter').addClass('disable');
938    $('.item-publish .enter #price').val(price).attr('placeholder', '').attr('readonly', true);
939  });
940
941  $('.item-publish .enter .input-box').click(function(e) {
942    if($(this).closest('.enter').hasClass('disable')) {
943      $('.item-publish .selection a').removeClass('active');
944      $(this).parent().removeClass('disable');
945      $('.item-publish .enter #price').val('').attr('placeholder', '').attr('readonly', false);
946    }
947  });
948  
949  
950  // SHOW HIDE PASSWORD
951  $('.toggle-pass').click(function(e) {
952    e.preventDefault();
953
954    $(this).find('i').toggleClass('fa-eye fa-eye-slash');
955    var input = $(this).siblings('input');
956    
957    if (input.attr('type') == 'password') {
958      input.prop('type', 'text');
959    } else {
960      input.prop('type', 'password');
961    }
962  });
963  
964  
965  // SHOW HIDE TIP ON PUBLISH PAGE - DESKTOP
966  $('.item-publish .box section').click(function(e) {
967    if (($(window).width() + scrollCompensate()) >= 768) {
968      var box = $(this);
969      var tip = $(this).find('.tip');
970
971      if(tip.length && !tip.hasClass('shown') && !$(e.target).hasClass('close-tip') && !$(e.target.parentElement).hasClass('tabberactive')) {
972        $('.item-publish .box section .tip').removeClass('shown').hide(0);
973
974        if(!isRtl) {
975          tip.addClass('shown').show(0).css({'margin-right': '-16px', 'opacity': 0}).animate({'margin-right': '16px', 'opacity': 1}, 300);
976        } else {
977          tip.addClass('shown').show(0).css({'margin-left': '-16px', 'opacity': 0}).animate({'margin-left': '16px', 'opacity': 1}, 300);
978        }
979      }
980    }
981  });
982  
983  $('.item-publish .box section .show-tip').click(function(e) {
984    var box = $(this).closest('section');
985    var tip = $(this).closest('section').find('.tip');
986    
987    if(tip.length && !tip.hasClass('shown')) {
988      $('.item-publish .box section .tip').removeClass('shown').hide(0);
989      
990      if(($(window).width() + scrollCompensate()) >= 768) {
991        if(!isRtl) {
992          tip.addClass('shown').show(0).css({'margin-left': '-16px', 'opacity': 0}).animate({'margin-left': '16px', 'opacity': 1}, 300);
993        } else {
994          tip.addClass('shown').show(0).css({'margin-right': '-16px', 'opacity': 0}).animate({'margin-right': '16px', 'opacity': 1}, 300);
995        }
996      } else {
997        tip.addClass('shown').show(0).css({'margin-top': '-12px', 'opacity': 0}).animate({'margin-top': '6px', 'opacity': 1}, 300);
998      }
999    }
1000  });
1001  
1002  $('.item-publish .box .close-tip').click(function(e) {
1003    e.preventDefault();
1004    var tip = $(this).closest('.tip');
1005    tip.removeClass('shown').stop(true, true).fadeOut(200);
1006  });
1007  
1008  $(document).mouseup(function (e){
1009    if (($(window).width() + scrollCompensate()) < 768) {
1010      var container = $('.item-publish .box .tip');
1011
1012      if(!container.is(e.target) && container.has(e.target).length === 0 && container.hasClass('shown')) {
1013        container.removeClass('shown').stop(true, true).fadeOut(200);
1014      }
1015    }
1016  });
1017
1018});
1019
1020
1021// CUSTOM MODAL BOX
1022function epsModal(opt) {
1023  width = (typeof opt.width !== 'undefined' ? opt.width : 480);
1024  height = (typeof opt.height !== 'undefined' ? opt.height : 480);
1025  content = (typeof opt.content !== 'undefined' ? opt.content : '');
1026  wrapClass = (typeof opt.wrapClass !== 'undefined' ? ' ' + opt.wrapClass : '');
1027  closeBtn = (typeof opt.closeBtn !== 'undefined' ? opt.closeBtn : true);
1028  iframe = (typeof opt.iframe !== 'undefined' ? opt.iframe : true); 
1029  fullscreen = (typeof opt.fullscreen !== 'undefined' ? opt.fullscreen : false); 
1030  transition = (typeof opt.transition !== 'undefined' ? opt.transition : 200); 
1031  delay = (typeof opt.delay !== 'undefined' ? opt.delay : 0);
1032  lockScroll = (typeof opt.lockScroll !== 'undefined' ? opt.lockScroll : true); 
1033
1034  var id = Math.floor(Math.random() * 100) + 10;
1035  width = epsAdjustModalSize(width, 'width') + 'px';
1036  height = epsAdjustModalSize(height, 'height') + 'px';
1037
1038  var fullscreenClass = '';
1039  if(fullscreen === 'mobile') {
1040    if (($(window).width() + scrollCompensate()) < 768) {
1041      width = 'auto'; height = 'auto'; fullscreenClass = ' modal-fullscreen';
1042    }
1043  } else if (fullscreen === true) {
1044    width = 'auto'; height = 'auto'; fullscreenClass = ' modal-fullscreen';
1045  }
1046
1047  var html = '';
1048  html += '<div class="modal-cover" data-modal-id="' + id + '" onclick="epsModalClose(\'' + id + '\');"></div>';
1049  html += '<div id="epsModal" class="modal-box' + wrapClass + fullscreenClass + '" style="width:' + width + ';height:' + height + ';" data-modal-id="' + id + '">';
1050
1051  if(closeBtn) {
1052    html += '<div class="modal-close-alt" onclick="epsModalClose(\'' + id + '\');"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512" width="32px" height="32px"><path fill="currentColor" d="M193.94 256L296.5 153.44l21.15-21.15c3.12-3.12 3.12-8.19 0-11.31l-22.63-22.63c-3.12-3.12-8.19-3.12-11.31 0L160 222.06 36.29 98.34c-3.12-3.12-8.19-3.12-11.31 0L2.34 120.97c-3.12 3.12-3.12 8.19 0 11.31L126.06 256 2.34 379.71c-3.12 3.12-3.12 8.19 0 11.31l22.63 22.63c3.12 3.12 8.19 3.12 11.31 0L160 289.94 262.56 392.5l21.15 21.15c3.12 3.12 8.19 3.12 11.31 0l22.63-22.63c3.12-3.12 3.12-8.19 0-11.31L193.94 256z" class=""></path></svg></div>';
1053  }
1054  
1055  html += '<div class="modal-inside">';
1056  
1057  if(closeBtn) {
1058    html += '<div class="modal-close" onclick="epsModalClose(\'' + id + '\');"><i class="fas fa-times"></i></div>';
1059  }
1060    
1061  html += '<div class="modal-body ' + (iframe === true ? 'modal-is-iframe' : 'modal-is-inline') + '">';
1062  
1063  if(iframe === true) {
1064    html += '<div class="modal-content"><iframe class="modal-iframe" data-modal-id="' + id + '" src="' + content + '"/></div>';
1065  } else {
1066    html += '<div class="modal-content">' + content + '</div>';
1067  }
1068  
1069  html += '</div>';
1070  html += '</div>';
1071  html += '</div>';
1072  
1073  if(lockScroll) {
1074    $('body').css('overflow', 'hidden');
1075  }
1076  
1077  $('body').append(html);
1078  $('div[data-modal-id="' + id + '"].modal-cover').fadeIn(transition);
1079  $('div[data-modal-id="' + id + '"].modal-box').delay(delay).fadeIn(transition);
1080}
1081
1082
1083// Close modal by clicking on close button
1084function epsModalClose(id = '', elem = null) {
1085  if(id == '') {
1086    id = $(elem).closest('.modal-box').attr('data-modal-id');
1087  }
1088  
1089  $('body').css('overflow', 'initial');
1090  $('div[data-modal-id="' + id + '"]').fadeOut(200, function(e) {
1091    $(this).remove(); 
1092  });
1093  
1094  return false;
1095}
1096
1097
1098// Close modal by some action inside iframe
1099function epsModalCloseParent() {
1100  var boxId = $(window.frameElement, window.parent.document).attr('data-modal-id');
1101  window.parent.epsModalClose(boxId);
1102}
1103
1104
1105// Calculate maximum width/height of modal in case original width/height is larger than window width/height
1106function epsAdjustModalSize(size, type = 'width') {
1107  var size = parseInt(size);
1108  var windowSize = (type == 'width' ? $(window).width() : $(window).height());
1109  
1110  if(size <= 0) {
1111    size = (type == 'width' ? 640 : 480);  
1112  }
1113  
1114  if(size*0.9 > windowSize) {
1115    size = windowSize*0.9;
1116  }
1117  
1118  return Math.floor(size);
1119}
1120
1121
1122window.addEventListener('DOMContentLoaded', () => {
1123  var isPrinting = window.matchMedia('print');
1124  isPrinting.addListener((media) => {
1125    $('img.lazy').each(function() {
1126      $(this).attr('src', $(this).prop('data-src'));
1127    });
1128  })
1129});
1130
1131
1132// CALCULATE SCROLL WIDTH
1133function scrollCompensate() {
1134  var inner = document.createElement('p');
1135  inner.style.width = "100%";
1136  inner.style.height = "200px";
1137
1138  var outer = document.createElement('div');
1139  outer.style.position = "absolute";
1140  outer.style.top = "0px";
1141  outer.style.left = "0px";
1142  outer.style.visibility = "hidden";
1143  outer.style.width = "200px";
1144  outer.style.height = "150px";
1145  outer.style.overflow = "hidden";
1146  outer.appendChild(inner);
1147
1148  document.body.appendChild(outer);
1149  var w1 = inner.offsetWidth;
1150  outer.style.overflow = 'scroll';
1151  var w2 = inner.offsetWidth;
1152  if (w1 == w2) w2 = outer.clientWidth;
1153
1154  document.body.removeChild(outer);
1155
1156  return (w1 - w2);
1157}
1158
1159
1160// HTML5 GEOLOCATION
1161function epsGeoLocate(elem) {
1162  function success(position) {
1163    const latitude  = position.coords.latitude;
1164    const longitude = position.coords.longitude;
1165    
1166    $.ajax({
1167      type: 'GET',
1168      dataType: 'json',
1169      url: baseAjaxUrl + "&ajaxFindCity=1&latitude=" + latitude + "&longitude=" + longitude,
1170      success: function(data) {
1171        //console.log(data);
1172        //console.log(baseAjaxUrl + "&ajaxFindCity=1&latitude=" + latitude + "&longitude=" + longitude);
1173        
1174        if(data['success'] !== undefined) {
1175          if(data['success'] == true) {
1176            data['url'] = baseAjaxUrl + "&ajaxFindCity=1&latitude=" + latitude + "&longitude=" + longitude;
1177            elem.find('span').hide(0);
1178            elem.find('span.success').text(data['s_location']).show(0);
1179
1180            if(!elem.closest('.navigator-fill-selects').length) {
1181              elem.find('span.refresh').show(0);
1182              elem.closest('a').attr('href', (window.location.href).replace('#', '')).text(elem.closest('a').attr('data-alt-text')).addClass('completed');
1183              elem.closest('a').find('strong').text(elem.closest('a').find('strong').attr('data-alt-text'));
1184            } else {
1185              epsGeoToSelects(elem, data);
1186            }
1187            
1188            return;
1189          }
1190        }
1191        
1192        elem.find('span').hide(0);
1193        elem.find('span.failed-unfound').show(0);
1194        return;
1195      },
1196      error: function(data) {
1197        console.log(data);
1198        elem.find('span').hide(0);
1199        elem.find('span.failed-unfound').show(0);
1200        return;
1201      }
1202    });
1203  }
1204
1205  function error() {
1206    elem.find('span').hide(0);
1207    elem.find('span.failed').show(0);
1208  }
1209
1210  if(!navigator.geolocation) {
1211    elem.find('span').hide(0);
1212    elem.find('span.not-supported').show(0);
1213  } else {
1214    elem.find('span').hide(0);
1215    elem.find('span.loading').show(0);
1216
1217    navigator.geolocation.getCurrentPosition(success, error);
1218  }
1219
1220}
1221
1222
1223function epsGeoToSelects(elem, data) {
1224  var box = elem.closest('.navigator-fill-selects');
1225  var country = box.find('select[name="countryId"]');  
1226  var region = box.find('select[name="regionId"]');  
1227  var city = box.find('select[name="cityId"]');  
1228  
1229  if(country.length && data['fk_c_country_code'] !== undefined && data['fk_c_country_code'] != '') {
1230    country.val(data['fk_c_country_code']);
1231  }
1232  
1233  if(region.length && data['fk_i_region_id'] !== undefined && data['fk_i_region_id'] != '') {
1234    region.find('option').remove().end().append('<option value="' + data['fk_i_region_id'] + '">' + data['s_region'] + '</option>').val(data['fk_i_region_id']);
1235    region.attr('disabled', false);
1236  }
1237
1238  if(city.length && data['fk_i_city_id'] !== undefined && data['fk_i_city_id'] != '') {
1239    city.find('option').remove().end().append('<option value="' + data['fk_i_city_id'] + '">' + data['s_city'] + '</option>').val(data['fk_i_city_id']);
1240    city.attr('disabled', false);
1241  }
1242}
1243
1244var epsLoadLocationsSimpleTimeout = '';
1245var epsLoadLocationsSimpleValue = '';
1246
1247// SIMPLE LOCATION LOADER
1248function epsLoadLocationsSimple(elem, event, type = '') {
1249  var min = 1;
1250  var box = elem.closest('.picker').find('.results');
1251  var term = $(elem).val().trim();
1252
1253  term = (term.indexOf(',') > 1 ? term.substr(0, term.indexOf(',')) : term);
1254  term = (term.indexOf('-') > 1 ? term.substr(0, term.indexOf('-')) : term);
1255  term = encodeURIComponent(term).trim();
1256
1257
1258  if(epsLoadLocationsSimpleValue == term) {
1259    if(box.find('a, div').length) {
1260      box.show(0);
1261    }
1262    
1263    return false;
1264  } else {
1265    epsLoadLocationsSimpleValue = term; 
1266  }
1267  
1268  (typeof(epsLoadLocationsSimpleTimeout) !== undefined) ? clearTimeout(epsLoadLocationsSimpleTimeout) : ''; 
1269  (term.length > 0) ? elem.siblings('.clean').show(0) : elem.siblings('.clean').hide(0);
1270  (term != '' && term.length >= min) ? elem.closest('.picker').addClass('loading') : '';
1271  
1272  epsLoadLocationsSimpleTimeout = setTimeout(function() {
1273    if(term != '' && term.length >= min) {
1274      $.ajax({
1275        type: 'GET',
1276        url: baseAjaxUrl + '&ajaxLoc=1&dataType=' + type + '&term=' + term,
1277        success: function(data) {
1278          //console.log(data);
1279          
1280          elem.closest('.picker').removeClass('loading');
1281          box.html(data).show(0);
1282          box.find('fieldset').remove();   // DB debug
1283          
1284          if(box.find('a, div').length <= 0) {
1285            box.html('').hide(0);
1286          }
1287        },
1288        error: function(data) {
1289          elem.closest('.picker').removeClass('loading');
1290          box.html('').hide(0);
1291        }
1292      });
1293    } else {
1294      elem.closest('.picker').removeClass('loading');
1295      box.html('').hide(0); 
1296    }
1297  }, 300);
1298}
1299
1300
1301var epsLoadCategoriesSimpleTimeout = '';
1302var epsLoadCategoriesSimpleValue = '';
1303
1304// SIMPLE CATEGORY LOADER
1305function epsLoadCategoriesSimple(elem, event, type = '') {
1306  var min = 1;
1307  var box = elem.closest('.picker').find('.results');
1308  var term = $(elem).val().trim();
1309
1310  term = (term.indexOf(',') > 1 ? term.substr(0, term.indexOf(',')) : term);
1311  term = (term.indexOf('-') > 1 ? term.substr(0, term.indexOf('-')) : term);
1312  term = encodeURIComponent(term).trim();
1313
1314
1315  if(epsLoadCategoriesSimpleValue == term) {
1316    if(box.find('a, div').length) {
1317      box.show(0);
1318    }
1319    
1320    return false;
1321  } else {
1322    epsLoadCategoriesSimpleValue = term; 
1323  }
1324  
1325  (typeof(epsLoadCategoriesSimpleTimeout) !== undefined) ? clearTimeout(epsLoadCategoriesSimpleTimeout) : ''; 
1326  (term.length > 0) ? elem.siblings('.clean').show(0) : elem.siblings('.clean').hide(0);
1327  (term != '' && term.length >= min) ? elem.closest('.picker').addClass('loading') : '';
1328  
1329  epsLoadCategoriesSimpleTimeout = setTimeout(function() {
1330    if(term != '' && term.length >= min) {
1331      $.ajax({
1332        type: 'GET',
1333        url: baseAjaxUrl + '&ajaxCat=1&dataType=' + type + '&term=' + term,
1334        success: function(data) {
1335          //console.log(data);
1336          
1337          elem.closest('.picker').removeClass('loading');
1338          box.html(data).show(0);
1339          box.find('fieldset').remove();   // DB debug
1340          
1341          if(box.find('a, div').length <= 0) {
1342            box.html('').hide(0);
1343          }
1344        },
1345        error: function(data) {
1346          elem.closest('.picker').removeClass('loading');
1347          box.html('').hide(0);
1348        }
1349      });
1350    } else {
1351      elem.closest('.picker').removeClass('loading');
1352      box.html('').hide(0); 
1353    }
1354  }, 300);
1355}
1356
1357
1358
1359var epsLoadPatternSimpleTimeout = '';
1360var epsLoadPatternSimpleValue = '';
1361
1362// SIMPLE LOCATION LOADER
1363function epsLoadPatternSimple(elem, event) {
1364  var min = 1;
1365  var form = elem.closest('form');
1366  var box = form.find('.results');
1367  var boxLoaded = form.find('.results .loaded');
1368  var boxDefault = form.find('.results .default');
1369  var term = encodeURIComponent($(elem).val().trim());
1370
1371  if(epsLoadPatternSimpleValue == term) {
1372    if(term.length >= min) {
1373      box.show(0);
1374      boxLoaded.show(0);
1375      boxDefault.hide(0);
1376      
1377      if(boxLoaded.find('a, div').length <= 0) {
1378        box.hide(0);
1379      }
1380    } else {
1381      box.show(0);
1382      boxLoaded.hide(0);
1383      boxDefault.show(0);
1384    }
1385    
1386    return false;
1387  } else {
1388    epsLoadPatternSimpleValue = term; 
1389  }
1390
1391  (typeof(epsLoadPatternSimpleTimeout) !== undefined) ? clearTimeout(epsLoadPatternSimpleTimeout) : '';  
1392  (term.length > 0) ? elem.siblings('.clean').show(0) : elem.siblings('.clean').hide(0);
1393  (term != '' && term.length >= min) ? elem.closest('.picker').addClass('loading') : '';
1394  (term.length < min) ? boxDefault.find('.minlength span.min').text(min - term.length) : '';
1395  
1396  epsLoadPatternSimpleTimeout = setTimeout(function() {
1397    if(term != '' && term.length >= min) {
1398      $.ajax({
1399        type: 'GET',
1400        url: baseAjaxUrl + '&ajaxPatternSearch=1&term=' + term,
1401        success: function(data) {
1402          //console.log(data);
1403          elem.closest('.picker').removeClass('loading');
1404          box.show(0);
1405          boxLoaded.html(data).show(0);
1406          boxLoaded.find('fieldset').remove();   // DB debug
1407          boxDefault.hide(0);
1408          
1409          if(boxLoaded.find('a, div').length <= 0) {
1410            box.hide(0);
1411            boxLoaded.html('').hide(0);
1412          }
1413        },
1414        error: function(data) {
1415          elem.closest('.picker').removeClass('loading');
1416          box.hide(0);
1417          boxLoaded.html('').hide(0);
1418        }
1419      });
1420    } else {
1421      elem.closest('.picker').removeClass('loading');
1422      box.show(0);
1423      boxDefault.show(0);
1424      boxLoaded.html('').hide(0); 
1425    }
1426  }, 300);
1427}
1428
1429
1430
1431var epsAjaxSearchTimeout = '';
1432
1433// AJAX SEARCH - core function
1434function epsAjaxSearch(elem, event) {
1435  (typeof(epsAjaxSearchTimeout) !== undefined) ? clearTimeout(epsAjaxSearchTimeout) : '';  
1436
1437  var delay = (event.type == 'keyup' ? 200 : 50);
1438  var scrollToTop = false;
1439  var ajaxStop = false;
1440  var ajaxSearchUrl = '';
1441  var sidebarReload = true;
1442  
1443  if(elem.closest('form.search-side-form').length) {
1444    var sidebar = elem.closest('form.search-side-form').last();
1445  } else {
1446    var sidebar = $('form.search-side-form').last();
1447  }
1448
1449
1450  // Breadcrumb home button
1451  if(elem.closest('li.first-child').length && elem.attr('href') == baseDir) {
1452    window.location.href = elem.attr('href');
1453    return false;
1454  }
1455  
1456  if($(event.target).attr('name') == 'sLocation') {
1457    ajaxStop = true;
1458    return false;
1459  }
1460
1461  if(elem.attr('name') == 'sCity' || elem.attr('name') == 'sRegion' || elem.attr('name') == 'sCountry') {
1462    // sidebarReload = true;
1463    
1464  } else if ((elem.attr('name')?.startsWith('atr_') || elem.attr('data-attr-id') != '') && ($(window).width() + scrollCompensate()) < 768) {  // Attributes plugin
1465    // sidebarReload = true;
1466    
1467  } else if (elem.closest('.sidebar-hooks').length || elem.closest('.input-box-check').length || (elem.closest('.search-side-form').length && elem.attr('name') != 'sCategory') || event.type == 'keyup') {
1468    sidebarReload = false;
1469  }
1470  
1471  // Make sure no sidebar reload for Car Attributes PRO inputs
1472  if(elem.closest('.cap-input-box').length) {
1473    sidebarReload = false;
1474  }
1475
1476  if(elem.closest('.paginate').length || elem.closest('#latest-search').length) {
1477    scrollToTop = true;
1478  }
1479  
1480  if (event.type == 'click' && !elem.is('input:radio')) {
1481    if(typeof elem.attr('href') !== typeof undefined && elem.attr('href') !== false && elem.attr('href') != '') {
1482      ajaxSearchUrl = elem.attr('href');
1483    }
1484  } else if (event.type == 'change' || event.type == 'keyup' || elem.is('input:radio')) {
1485    if (elem.hasClass('orderSelect')) {
1486      ajaxSearchUrl = elem.find(':selected').attr('data-link');
1487    } else {
1488      ajaxSearchUrl = baseDir + "index.php?" + sidebar.find(":input").filter(function () { return $.trim(this.value).length > 0}).serialize();
1489    }
1490  }
1491
1492  epsAjaxSearchTimeout = setTimeout(function() {
1493    if(ajaxSearch == 1 && $('input.ajaxRun').val() != 1 && (ajaxSearchUrl != '#' && ajaxSearchUrl != '') && ajaxStop !== true) {
1494      if(ajaxSearchUrl == $(location).attr('href')) {
1495        return false;
1496      }
1497
1498      sidebar.find('.init-search').addClass('loading').addClass('disabled').attr('disabled', true);
1499      sidebar.find('input.ajaxRun').val(1);
1500      $('#search-main').addClass('loading');
1501      $('#search-main .ajax-load-failed').hide(0);
1502
1503      $.ajax({
1504        url: ajaxSearchUrl,
1505        type: "GET",
1506        timeout: 10000,
1507        success: function(response){
1508          var data = $(response).contents().find('#search-main').html();
1509          var bread = $(response).contents().find('ul.breadcrumb').html();
1510          //var filter = $(response).contents().find('.filter-menu').html();
1511          
1512          var sideForm = $(response).contents().find('.filter-menu > .wrap > form').html();
1513          var sideCat = $(response).contents().find('.filter-menu > #search-category-box').html();
1514
1515          sidebar.find('.init-search').removeClass('loading').removeClass('disabled').attr('disabled', false);
1516          sidebar.find('input.ajaxRun').val('');
1517
1518          $('#search-main').removeClass('loading').html(data);
1519          
1520          if(sidebarReload) {
1521            $('.filter-menu > .wrap > form').html(sideForm);
1522            $('.filter-menu > #search-category-box').html(sideCat);
1523          }
1524          
1525          // sidebarReload ? $('.filter-menu').html(filter) : '';
1526          // sidebarReload ? $('.search-side-form').last().remove() : '';
1527
1528          $('ul.breadcrumb').html(bread);
1529          
1530          epsLazyLoadImages('search-items');
1531          epsLazyLoadImages('search-premium-items');
1532          epsManageScroll();
1533          epsShowUsefulScrollButtons();
1534
1535          // Update URL
1536          var ajaxSearchUrlCleaned = baseDir + "index.php?" + $('.filter-menu form.search-side-form').find(":input").filter(function () { return $.trim(this.value).length > 0}).serialize();
1537          window.history.pushState(null, null, ajaxSearchUrl);
1538          
1539          //(scrollToTop ? $(window).scrollTop(0) : '');
1540          (scrollToTop ? $(window).scrollTop($('#search-quick-bar .view-type').offset().top - parseInt($('header').height()) - 12) : '');
1541        },
1542
1543        error: function(response){
1544          // There was some problem
1545          console.log(response);
1546          
1547          sidebar.find('.init-search').removeClass('loading').removeClass('disabled').attr('disabled', false);
1548          sidebar.find('input.ajaxRun').val('');
1549
1550          $('#search-main').removeClass('loading');
1551          $('#search-main .ajax-load-failed').show(0);
1552        }
1553      });
1554
1555      if(!elem.is('input:radio')) {
1556        return false;
1557      }
1558    }
1559  }, delay);
1560}
1561
1562
1563
1564// Lazyload images
1565function epsLazyLoadImages(type = '') {
1566  if(epsLazy != "1" ) {
1567    return false;
1568  }
1569  
1570  $('#item-image li a img').height(parseFloat($('#item-main').width())/parseFloat(imgPreviewRatio));
1571
1572  
1573  // standard initialization
1574  if(type == '' || type == 'basic') {
1575    $('img.lazy').Lazy({
1576      appendScroll: window,
1577      scrollDirection: 'both',
1578      effect: 'fadeIn',
1579      effectTime: 100,
1580      afterLoad: function(element) {
1581        element.addClass('loaded');
1582        setTimeout(function() {
1583          element.css('transition', '0.2s');
1584        }, 100);
1585      }
1586    });
1587  }
1588  
1589  // search items
1590  if(type == 'search-items') {
1591    $('#search-items img.lazy').Lazy({
1592      appendScroll: window,
1593      scrollDirection: 'both',
1594      effect: 'fadeIn',
1595      effectTime: 100,
1596      afterLoad: function(element) {
1597        element.addClass('loaded');
1598        setTimeout(function() {
1599          element.css('transition', '0.2s');
1600        }, 100);
1601      }
1602    });
1603  }
1604  
1605  if(type == '' || type == 'search-premium-items') {
1606    $('#search-premium-items img.lazy').Lazy({
1607      appendScroll: window,
1608      scrollDirection: 'both',
1609      effect: 'fadeIn',
1610      effectTime: 100,
1611      afterLoad: function(element) {
1612        element.addClass('loaded');
1613        setTimeout(function() {
1614          element.css('transition', '0.2s');
1615        }, 100);
1616      }
1617    });
1618    
1619    $('#search-premium-items img.lazy').Lazy({
1620      appendScroll: '.nice-scroll, .mobile-scroll',
1621      scrollDirection: 'both',
1622      effect: 'fadeIn',
1623      effectTime: 100,
1624      afterLoad: function(element) {
1625        element.addClass('loaded');
1626        setTimeout(function() {
1627          element.css('transition', '0.2s');
1628        }, 100);
1629      }
1630    });
1631    
1632    if(type == 'search-premium-items') {
1633      $('#search-premium-items .nice-scroll').scrollLeft(1).delay(10).scrollLeft(0);
1634    }
1635  }
1636  
1637  
1638  // initialization in nice-scroll slider
1639  if(type == '') {
1640    $('.nice-scroll img.lazy, .mobile-scroll img.lazy').Lazy({
1641      appendScroll: '.nice-scroll, .mobile-scroll',
1642      scrollDirection: 'both',
1643      effect: 'fadeIn',
1644      effectTime: 100,
1645      afterLoad: function(element) {
1646        element.addClass('loaded');
1647        setTimeout(function() {
1648          element.css('transition', '0.2s');
1649        }, 100);
1650      }
1651    });
1652  }
1653  
1654  // item gallery swiper move
1655  if(type == 'item-gallery') {
1656    $('#item-image li a img.lazy').Lazy({
1657      appendScroll: '.swiper-wrapper, .swiper-container',
1658      scrollDirection: 'both',
1659      effect: 'fadeIn',
1660      effectTime: 100,
1661      afterLoad: function(element) {
1662        element.addClass('loaded');
1663        setTimeout(function() {
1664          element.css('transition', '0.2s');
1665        }, 100);
1666      }
1667    });
1668  }
1669  
1670}
1671
1672
1673// Fix lazyload large pictures when using thumbnails
1674function epsfixImgSourcesThumb() {
1675  $('#item-image li img').each(function() {
1676    if(typeof $(this).attr('data-src') !== 'undefined') {
1677      $(this).attr('src', $(this).attr('data-src'));
1678    }
1679  });
1680}
1681
1682
1683// Fix lazyload thumbnails for light gallery
1684function epsFixImgSources() {
1685  $('#item-image li img').each(function() {
1686    if(typeof $(this).attr('data-src') !== 'undefined') {
1687      var imgDataSrc = $(this).attr('data-src');
1688    } else {
1689      var imgDataSrc = $(this).attr('src');
1690    }
1691    
1692    if(typeof imgDataSrc !== 'undefined') {
1693      var index = $(this).closest('li').index();
1694      $('.lg-thumb .lg-thumb-item').eq(index).find('img').attr('src', imgDataSrc);
1695    }
1696  });
1697}
1698
1699
1700function epsManageScroll() {
1701  // NICE SCROLL - MANAGE FADERS
1702  $('.nice-scroll').on('scroll', function(e) {
1703    var box = $(this);
1704    var scrollLeft = (isRtl ? -1 : 1) * box.scrollLeft();
1705    var padding = parseFloat((box.css('padding-left')).replace('px', '')) + parseFloat((box.css('padding-right')).replace('px', ''));
1706    var maxScroll = box.prop('scrollWidth') - scrollLeft - box.width() - padding;
1707    var prev = box.siblings('.nice-scroll-prev');
1708    var next = box.siblings('.nice-scroll-next');
1709
1710    if (scrollLeft < 20) {
1711      //(isRtl ? next.fadeOut(100) : prev.fadeOut(100));
1712      (isRtl ? next.addClass('disabled') : prev.addClass('disabled'));
1713    } else {
1714      //(isRtl ? next.fadeIn(100) : prev.fadeIn(100));
1715      (isRtl ? next.removeClass('disabled').show(100) : prev.removeClass('disabled').show(100));
1716    }
1717
1718    if (maxScroll < 20) {
1719      //(isRtl ? prev.fadeOut(100) : next.fadeOut(100));
1720      (isRtl ? prev.addClass('disabled') : next.addClass('disabled'));
1721    } else {
1722      //(isRtl ? prev.fadeIn(100) : next.fadeIn(100));
1723      (isRtl ? prev.removeClass('disabled').show(100) : next.removeClass('disabled').show(100));
1724    }
1725  });
1726}
1727
1728
1729function epsShowUsefulScrollButtons() {
1730  $('.nice-scroll').each(function() {
1731    var box = $(this);
1732    var boxWidth = parseInt($(this).outerWidth());
1733    var boxInnerWidth = parseInt($(this)[0].scrollWidth);
1734    var prev = box.siblings('.nice-scroll-prev');
1735    var next = box.siblings('.nice-scroll-next');
1736    
1737    if(boxWidth < boxInnerWidth - 2) {   // 2 is there as buffer for roun
1737ding etc
1738      //(isRtl ? prev.fadeIn(200) : next.fadeIn(200));
1739      (isRtl ? prev.removeClass('disabled').fadeIn(100) : next.removeClass('disabled').fadeIn(100));
1740      $(this).parent().addClass('nice-scroll-have-overflow').removeClass('nice-scroll-nothave-overflow');
1741    } else {
1742      //(isRtl ? prev.hide(0) : next.hide(0));
1743      (isRtl ? prev.addClass('disabled') : next.addClass('disabled'));
1744      $(this).parent().removeClass('nice-scroll-have-overflow').addClass('nice-scroll-nothave-overflow');
1745    }
1746  });
1747}
1748
1749
1750function epsHideUselessScrollButtons() {
1751  // HIDE FADERS WHEN NOT NEEDED
1752  $('.nice-scroll').each(function() {
1753    var box = $(this);
1754 
1755    if(box.prop('scrollWidth') - box.width() <= 0) {
1756      box.siblings('.nice-scroll-prev, .nice-scroll-next').hide(0);
1757    }
1758  });
1759}

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.