1// * * * * * * * * * * 2// MAIN MENU 3// * * * * * * * * * * 4 5function openMainMenu() { 6 $('body').removeClass('show-basket-menu'); 7 $('body').addClass('show-overlay show-main-menu'); 8} 9function openBasketMenu() { 10 $('body').removeClass('show-main-menu'); 11 $('body').addClass('show-overlay show-basket-menu'); 12} 13function openLocationsMenu() { 14 $('body').removeClass('show-main-menu'); 15 $('body').addClass('show-overlay show-location-menu'); 16} 17function openUserMenu() { 18 $('body').addClass('show-overlay show-user-menu'); 19} 20function openCategoryMenu() { 21 $('body').addClass('show-category-menu'); 22} 23function openSearchMenu() { 24 $('body').addClass('show-overlay show-search-menu'); 25 $('input#txtSearch').focus(); 26} 27function closeMainMenu() { 28 $('body').removeClass('show-overlay show-main-menu'); 29} 30function closeBasketMenu() { 31 $('body').removeClass('show-overlay show-basket-menu'); 32} 33function closeLocationMenu() { 34 $('body').removeClass('show-overlay show-location-menu'); 35} 36function closeUserMenu() { 37 $('body').removeClass('show-overlay show-user-menu'); 38} 39function closeCategoryMenu() { 40 $('body').removeClass('show-category-menu'); 41} 42function closeSearchMenu() { 43 $('body').removeClass('show-overlay show-search-menu'); 44} 45 46document.addEventListener('click', function (e) { 47 if (e.target.id === 'txtSearch') { 48 $(document).ready(function () { 49 if ($(window).width() < 575) { 50 $('body').addClass('show-overlay'); 51 } 52 }); 53 document.querySelector('.search-menu').style.zIndex = '6'; 54 } 55}); 56 57// search ispisivanje kategorija u placeholder 58let words = document.querySelectorAll( 59 '#HorizontalMenuZone .lvl1-outer .lvl1-inner .level1-menu-ascx-horiz .level1 .level1-link' 60); 61let totalWords = words.length; 62let wordIndex = 0; 63let letterIndex = 0; 64 65function changePlaceholder() { 66 if (wordIndex < words.length) { 67 let word = words[wordIndex].innerText; 68 let placeholder = ''; 69 70 if (letterIndex < word.length) { 71 placeholder = word.substring(0, letterIndex + 1); 72 letterIndex++; 73 } else { 74 letterIndex = 0; 75 wordIndex = (wordIndex + 1) % totalWords; 76 word = words[wordIndex].innerText; 77 placeholder = word.substring(0, letterIndex + 1); 78 letterIndex++; 79 } 80 81 document.getElementById( 82 'txtSearch' 83 ).placeholder = `Pretražite ... "${placeholder.toLowerCase()}"`; 84 85 setTimeout(changePlaceholder, 200); 86 } 87} 88changePlaceholder(); 89 90// STICKY NAV 91// const header = document.querySelector('header'); 92// const nav = document.querySelector('.buttons-search'); 93// const headerHeight = header.getBoundingClientRect().height; 94// // console.log(header); 95// // console.log(headerHeight); 96 97// const stickyNav = function (entries) { 98// const entry = entries[0]; 99// // console.log(entry); 100// if (!entry.isIntersecting) { 101// nav.classList.add('sticky'); 102// } else { 103// nav.classList.remove('sticky'); 104// } 105// } 106 107// const headerObserver = new IntersectionObserver(stickyNav, { 108// root: null, 109// threshold: 0, // kada je 0% banera vidljivo onda observe 110// // rootMargin: `${headerHeight}px`, 111// }); 112// headerObserver.observe(header); 113 114// LIST BTN LOADING 115function handleLoadingState(btn) { 116 let width = btn.offsetWidth; 117 $(btn).addClass('adding-to-basket'); 118 // $(btn).css('width', `${width - 50}px`); 119} 120 121// DROPDOWN 122$('body').on('click', '.dropdown > .dropdown-toggle', function (e) { 123 e.stopPropagation(); // Prevent click from propagating 124 $('.dropdown').not($(this).parent()).removeClass('open'); // Close other dropdowns 125 $(this).parent().toggleClass('open'); 126}); 127// Close dropdown when clicking outside, but not inside the dropdown-body 128$(document).on('click', function (e) { 129 if (!$(e.target).closest('.dropdown').length) { 130 $('.dropdown').removeClass('open'); 131 } 132}); 133 134// SORT 135$('#sort-filter').on('click', '.filter-wrapper > .filter-dropdown', function () { 136 if ($(this).closest('.filter-wrapper').hasClass('open')) { 137 $(this).closest('.filter-wrapper').removeClass('open'); 138 } else { 139 $('.filter-wrapper').removeClass('open'); 140 $(this).closest('.filter-wrapper').addClass('open'); 141 } 142}); 143 144$('#sort-filter').on('click', '.filter-wrapper > ul', function () { 145 $(this).closest('.filter-wrapper').removeClass('open'); 146}); 147 148// FILTERS COLLAPSE 149$('#filtersTop').on('click', '.section-title-5', function () { 150 $(this).closest('.filter-wrapper').toggleClass('open'); 151 $(this).next().slideToggle(); 152}); 153 154// Filtriranje (pretraga) varijacija 155$('.product-details').on('keyup', '#variationsFilter', function () { 156 var value = $(this) 157 .val() 158 .toLowerCase() 159 .replaceAll('Ä', 'c') 160 .replaceAll('Ä', 'c') 161 .replaceAll('ž', 'z') 162 .replaceAll('Å¡', 's') 163 .replaceAll('Ä', 'dj'); 164 // console.log(value); 165 $('.variation-item').filter(function () { 166 $(this).toggle( 167 $(this) 168 .text() 169 .toLowerCase() 170 .replaceAll('Ä', 'c') 171 .replaceAll('Ä', 'c') 172 .replaceAll('ž', 'z') 173 .replaceAll('Å¡', 's') 174 .replaceAll('Ä', 'dj') 175 .indexOf(value) > -1 176 ); 177 }); 178}); 179 180// SCROLL horizontalnog menija 181$(document).ready(function () { 182 var startX, 183 scrollLeft, 184 isDown = false;
185 var isScrolling = false; 186 const inner = document.querySelector('.lvl1-inner'); 187 188 // Pokaži ili sakrij strelice na osnovu Å¡irine 189 function checkScroll() { 190 const innerContainer = document.querySelector('.lvl1-inner'); 191 const outerContainer = document.querySelector('.lvl1-outer'); 192 if (innerContainer && outerContainer) { 193 $('.lvl1-scroll').toggle(innerContainer.scrollWidth > outerContainer.clientWidth); 194 } 195 } 196 197 // Skrolovanje po klikovima 198 function scrollByDirection(direction) { 199 inner?.scrollBy({ left: direction * 96, behavior: 'smooth' }); 200 } 201 202 // Mouse/Touch funkcije 203 function startScroll(e, isTouch) { 204 isDown = true; 205 startX = (isTouch ? e.touches[0].pageX : e.pageX) - inner.offsetLeft; 206 scrollLeft = inner.scrollLeft; 207 isScrolling = false; 208 } 209 210 function moveScroll(e, isTouch) { 211 if (!isDown) return; 212 e.preventDefault(); 213 const x = (isTouch ? e.touches[0].pageX : e.pageX) - inner.offsetLeft; 214 const walk = (x - startX) * 1.5; 215 inner.scrollLeft = scrollLeft - walk; 216 } 217 218 // Pokreni skrolovanje na osnovu dodira ili miÅ¡a 219 if (inner) { 220 inner.addEventListener('mousedown', (e) => startScroll(e, false)); 221 inner.addEventListener('mousemove', (e) => moveScroll(e, false)); 222 inner.addEventListener('mouseup', () => (isDown = false)); 223 inner.addEventListener('mouseleave', () => (isDown = false)); 224 inner.addEventListener('touchstart', (e) => startScroll(e, true)); 225 inner.addEventListener('touchmove', (e) => moveScroll(e, true)); 226 inner.addEventListener('touchend', () => (isDown = false)); 227 } 228 229 // Skrolovanje pomoÄu strelica 230 $('.lvl1-scroll.left').click(() => scrollByDirection(-1)); 231 $('.lvl1-scroll.right').click(() => scrollByDirection(1)); 232 233 // Proveri prikaz strelica pri inicijalizaciji i promeni veliÄine prozora 234 checkScroll(); 235 $(window).resize(checkScroll); 236 237 // Debounce za automatsko pomeranje 238 $(inner).on('scroll', function () { 239 clearTimeout(isScrolling); 240 isScrolling = setTimeout(() => (isScrolling = false), 1000); 241 }); 242}); 243 244function loadCategoryData() { 245 const showLevel3 = MasterJson?.ShowMenuLevel3; 246 const groupMenu = document.getElementById('group-menu'); 247 248 if (!groupMenu) return; 249 250 const apiUrl = `${MasterJson.ECommerceAPIProductsGetUrl.replace( 251 '/Get', 252 '/GetGroupList' 253 )}?SalesPriceGroupUid=${MasterJson.SalesPriceGroupUid}`; 254 255 $.ajax(apiUrl) 256 .done(function (data) { 257 if (data.length) { 258 const groupHtml = data 259 .map((lvl1) => { 260 const sub = lvl1.Subcategories.length; 261 262 const lvl2Html = lvl1.Subcategories.map((lvl2) => { 263 let lvl3Html = ''; 264 let lvl3Container = ''; 265 const subsub = lvl2.Subcategories.length; 266 267 if (showLevel3) { 268 lvl3Html = lvl2.Subcategories.map((lvl3) => { 269 return ` 270 <div class="level3-panel"> 271 <a href="/g/${lvl1.Name}/${lvl2.Name}/${lvl3.Name}" class="sub-link">${lvl3.Name}</a> 272 </div> 273 `; 274 }).join(''); 275 276 lvl3Container = subsub ? `<div class="level3 sub">${lvl3Html}</div>` : ''; 277 } 278 279 return ` 280 <div class="level2-wrapper"> 281 <div class="level2-panel ${subsub && showLevel3 ? 'has-sub' : ''}"> 282 <a href="/g/${lvl1.Name}/${lvl2.Name}" class="sub-link">${lvl2.Name}</a> 283 </div> 284 ${showLevel3 ? lvl3Container : ''} 285 </div> 286 `; 287 }).join(''); 288 289 const lvl2Container = sub ? `<div class="level2 sub container">${lvl2Html}</div>` : ''; 290 291 return ` 292 <li> 293 <div class="level1 ${sub ? 'has-sub' : ''}"> 294 <a href="/g/${lvl1.Name}" class="sub-link">${lvl1.Name}</a> 295 </div> 296 ${lvl2Container} 297 </li> 298 `; 299 }) 300 .join(''); 301 302 groupMenu.innerHTML = groupHtml; 303 } else { 304 groupMenu.innerHTML = '<li class="error">Nema pronaÄenih kategorija</li>'; 305 } 306 }) 307 .fail(function (err) { 308 console.log(err); 309 groupMenu.innerHTML = '<li class="error">GreÅ¡ka pri uÄitavanju podataka</li>'; 310 }); 311 312 // Logika za otvaranje/skrivanje podgrupa 313 $('#group-menu').on('click', '.sub-link', function (event) { 314 const parent = $(this).parent(); 315 if (parent.hasClass('has-sub')) { 316 event.preventDefault(); 317 parent.toggleClass('open'); 318 parent.next('.sub').slideToggle(); 319 } 320 }); 321} 322 323function renderBasketItems(basketData, basketContainer) { 324 const priceOptions = { 325 style: 'currency', 326 currency: basketData.CurrencyIso, 327 minimumFractionDigits: 2, 328 maximumFractionDigits: 2, 329 }; 330 // const freeShippingTreshold = basketData.FreeShipping; 331 // const difference = freeShippingTreshold - basketData.BasketTotal;
332 // const differenceFormatted = difference.toLocaleString('sr-RS', priceOptions); 333 // let freeShippingHtml = ''; 334 // if (freeShippingTreshold && freeShippingTreshold > 0 && difference > 0) { 335 // freeShippingHtml = ` 336 // <div class="basket-free-shipping"> 337 // Za besplatnu dostavu nedostaje vam ${difference < 500 ? 'samo' : ''} još <strong>${differenceFormatted}</strong> 338 // <progress value="${basketData.BasketTotal}" max="${freeShippingTreshold}"></progress> 339 // </div> 340 // `; 341 // } else if (freeShippingTreshold && freeShippingTreshold > 0 && difference <= 0) { 342 // freeShippingHtml = ` 343 // <div class="basket-free-shipping"> 344 // Imate dovoljan iznos za besplatnu dostavu! 345 // <progress value="${basketData.BasketTotal}" max="${freeShippingTreshold}"></progress> 346 // </div> 347 // `; 348 // } 349 350 const newBasketHtml = basketData.BasketItems.map((item) => { 351 return ` 352 <div class="basket-item"> 353 <div class="image"> 354 ${ 355 item.ImageUrl 356 ? '<img src="' + item.ImageUrl + '" alt="Cart Item">' 357 : '<img src="/Assets/no_image.png" alt="No Image Available">' 358 } 359 </div> 360 <h5 class="name"> 361 ${item.Qty} x ${item.Name} 362 </h5> 363 <span class="item-price-total"> 364 ${ 365 item.SalesType === 1 ? 366 (item.ItemPriceTotal * (1 + item.Vat / 100)).toLocaleString('sr-RS', priceOptions) : (item.ItemPriceTotal).toLocaleString('sr-RS', priceOptions) 367 } 368 </span> 369 <button 370 type="button" 371 class="btn delete-from-basket" 372 onclick="deleteFromBasket('${item.SalesItemUid}');analyticsRemoveFromBasket('${ 373 item.SalesItemUid 374 }', '${item.Name}', '${item.Qty}', '${item.ItemPriceTotal * (1 + item.Vat / 100)}');" 375 >ObriÅ¡i</button> 376 </div> 377 `; 378 }).join(''); 379 380 const totalHtml = ` 381 <div class="basket-total"> 382 <span>Ukupno:</span> 383 <span class="no-wrap"> 384 ${basketData.BasketTotalNoVat.toLocaleString('sr-RS', priceOptions)} 385 </span> 386 </div> 387 `; 388 389 basketContainer.innerHTML = ` 390 <div class="basket-items">${newBasketHtml}</div> 391 <div class="basket-separator"></div> 392 ${totalHtml} 393 <div class="basket-separator"></div> 394 <div class="buttons"> 395 <span class="btn cta close-menu">Zatvori</span> 396 <a href="/korpa.aspx" class="btn text-btn dark proceed">ZavrÅ¡i kupovinu</a> 397 </div> 398 `; 399 400} 401 402async function getBasketData() { 403 const res = await fetch('/Services/EcommerceService.svc/GetBasketItems?B2BMode=false'); 404 if (!res.ok) throw new Error(`request error: ${res.status} - ${res.statusText}`); 405 const data = await res.json(); 406 const basketData = data.d; 407 if (!basketData) throw new Error('no basket data'); 408 return basketData; 409} 410 411// BASKET WIDGET NEW AJAX 412async function loadBasketData() { 413 const loader = document.getElementById('custom-basket-loader'); 414 const basketContainer = document.getElementById('basket-module-container'); 415 416 basketContainer.innerHTML = ''; 417 loader.parentElement.classList.add('loader-shown'); 418 $(loader).fadeIn(200); 419 420 try { 421 const basketData = await getBasketData(); 422 if (!basketData.BasketItems?.length) { 423 basketContainer.innerHTML = ` 424 <div class="text-danger">U korpi trenutno nema proizvoda</div> 425 `; 426 if (typeof applyMinQtyLogic === 'function') applyMinQtyLogic(null); 427 return; 428 } 429 430 renderBasketItems(basketData, basketContainer); 431 if (typeof applyMinQtyLogic === 'function') applyMinQtyLogic(basketData); 432 433 } catch (error) { 434 console.log('getBasketData error', error); 435 basketContainer.innerHTML = ` 436 <div class="text-danger">DoÅ¡lo je do greÅ¡ke</div> 437 `; 438 } finally { 439 loader.parentElement.classList.remove('loader-shown'); 440 $(loader).fadeOut(200); 441 } 442 443} 444 445function deleteFromBasket(uid) { 446 if (confirm('Da li želite da obriÅ¡ete proizvod iz porudžbenice?')) { 447 sessionStorage.removeItem('BasketUI'); 448 449 $.ajax(`/EcommerceService.svc/RemoveFromBasketAjax?SalesItemUid=${uid}`) 450 .done(function () { 451 alert('UspeÅ¡no ste izbacili proizvod iz porudžbenice!'); 452 }) 453 .fail(function (err) { 454 console.log(err); 455 alert('DoÅ¡lo je do greÅ¡ke'); 456 }) 457 .always(function () {
458 BasketBehaivorObj.GetAndRefreshBasket(); 459 loadBasketData(); 460 }); 461 } 462} 463 464function checkScrollWidth() { 465 const outerElement = document.querySelector('.lvl1-inner'); 466 const scrollElement = document.querySelector('.group-menu.horiz'); 467 468 if (outerElement && scrollElement) { 469 const outerPos = outerElement.getBoundingClientRect(); 470 const scrollPos = scrollElement.getBoundingClientRect(); 471 const outerWidth = outerPos.width; 472 const scrollWidth = scrollPos.width; 473 474 if (outerWidth < scrollWidth) { 475 $('.lvl1-scroll').show(); 476 } else { 477 $('.lvl1-scroll').hide(); 478 } 479 } 480} 481 482// * * * * * * * * * * 483// ON READY/LOAD: 484// * * * * * * * * * * 485 486$(function () { 487 window.onpageshow = function (event) { 488 // ako se doÅ¡lo preko Back dugmeta u browseru 489 // USB2C-172 490 if (event.persisted) { 491 BasketBehaivorObj.GetAndRefreshBasket(); 492 loadBasketData(); 493 } 494 }; 495 496 // Check if logged in (TEMP*): 497 // setTimeout(() => { 498 // console.log('Login:'); 499 // console.log(GetDataFromLocalStorage('LoginInfo')?.IsLoggedIn); 500 // if (GetDataFromLocalStorage('LoginInfo')?.IsLoggedIn) { 501 // $('body').addClass('logged-in'); 502 // } 503 // }, 1200); 504 505 loadCategoryData(); 506 507 checkScrollWidth(); 508}); 509 510// * * * * * * * * * * 511// ON RESIZE: 512// * * * * * * * * * * 513window.addEventListener('resize', function () { 514 checkScrollWidth(); 515}); 516 517// * * * * * * * * * * 518// ON ADDTOBASKET: 519// * * * * * * * * * * 520window.addEventListener('AddToBasket', function (res) { 521 $('#advancedfilterresult .btn.cta.loading').removeClass('loading').css('width', 'unset'); 522 523 const opRes = res?.detail?.OperationResult; 524 const errMes = res?.detail?.ErrorMessage; 525 526 // Mapping object for operation results and their corresponding messages 527 const messages = { 528 2: `Proizvoda ${errMes} nema u zahtevanoj koliÄini, probajte sa manjom koliÄinom.`, 529 5: `Uneta koliÄina ne odgovara zahtevanom transportnom pakovanju. Transportno pakovanje je: ${parseFloat(errMes)}.`, 530 6: `Proizvod sadrži varijacije.`, 531 7: `Uneta koliÄina nije validna.`, 532 8: `Uneta koliÄina je manja od zahtevane minimalne koliÄine. ${errMes ? '(' + parseFloat(errMes) + ')' : ''}`, 533 default: `Dodavanje u korpu nije uspelo, pokuÅ¡ajte ponovo.`, 534 }; 535 536 // Handle specific operation results 537 if (opRes === 0) { 538 openBasketMenu(); 539 loadBasketData(); 540 return; 541 } 542 543 // Get the message from the mapping object or use the default 544 const message = messages[opRes] || messages.default; 545 546 // Call customNotify with the appropriate message and type 547 customNotify({ message, type: opRes in messages ? 'notice' : 'error' }); 548 549 // Apply min qty logic (DTMB2C-175): 550 if (typeof applyMinQtyLogic === 'function') applyMinQtyLogic(); 551}); 552 553// setTimeout(function () { 554if ( 555 location.href.includes('/potvrda-registracije.aspx') || 556 location.href.includes('/profil-korisnika.aspx') 557) { 558 $('.verified-info').show(); 559 $('.login__register__menu').hide(); 560} 561// }, 1000); 562 563// product details breadcrumb & title hack: 564if (location.href.includes('/p/')) { 565 if (window.innerWidth < 768) { 566 $('.product__title').insertAfter('.details-indicator'); 567 } else { 568 $('.details-indicator').insertBefore('.product-details .product__title'); 569 } 570} 571 572// detalji proizvoda 573// if($('.var-group-key').val() === ''){ 574// $('.var-group-key').remove(); 575// } 576if ($('.var-group').text().trim() === '') { 577 $('.var-group').remove(); 578} 579 580// linkovi u footeru 581// if ( 582// !location.href.includes('/Nacini-porucivanja.aspx') && 583// !location.href.includes('/Nacini-placanja.aspx') && 584// !location.href.includes('/Reklamacije-i-servis.aspx') && 585// !location.href.includes('/Nacini-isporuke.aspx') && 586// !location.href.includes('/Veze-ka-drugim-web-lokacijama.aspx') && 587// !location.href.includes('/Uslovi-kupovine.aspx') && 588// !location.href.includes('/Upotreba-sadrzaja-sa-sajta.aspx') && 589// !location.href.includes('/Licni-podaci-i-politika-privatnosti.aspx') && 590// !location.href.includes('/Opsti-uslovi.aspx') && 591// !location.href.includes('/Podaci-o-trgovcu.aspx') 592// ) { 593// $('.whole_news-date').show(); 594// $('.whole_news-image').show(); 595// } 596 597if ( 598 location.href.includes('/USLOVI-KORISCENJA') || 599 location.href.includes('/Kodeks-ponasanja') || 600 location.href.includes('/Podaci-o-trgovcu') || 601 location.href.includes('/Prava-potrosaca') || 602 location.href.includes('/Odricanje-od-odgovornosti') || 603 location.href.includes('/Uslovi-online-kupovine') || 604 location.href.includes('/Politika-privatnosti') || 605 location.href.includes('/Nacin-placanja') || 606 location.href.includes('/Nacin-isporuke') || 607 location.href.includes('/Reklamacije') || 608 location.href.includes('/Nacin-isporuke') || 609 location.href.includes('/o-nama') 610) { 611 $('.whole_news-date').hide(); 612 $('.whole_news-image').hide(); 613} else if ( 614 location.href.includes('/O-nama.aspx') || 615 location.href.includes('/Distributeri.aspx') || 616 location.href.includes('/Opremi-kancelariju') 617) { 618 $('.whole_news-date').hide(); 619 $('.whole_news-image').show(); 620} else { 621 $('.whole_news-date').show(); 622 $('.whole_news-image').show(); 623} 624 625// if ( 626// location.href.includes('/O-nama.aspx') || 627// location.href.includes('/Distributeri.aspx') 628// ) { 629// $('.whole_news-date').hide(); 630// $('.whole_news-image').show(); 631// } 632
633// Sklanjanje pretrage na log-in strani (LQ-117) 634if (location.href.includes('/log-in.aspx')) { 635 $('#SearchZone').remove(); 636 637 // nedostaju polja za login/register (HTC-67) 638 $('.tab-pane.active').each(function () { 639 $(this).parent().show(); 640 }); 641} 642 643// Hide basket on /korpa.aspx: 644if (location.href.includes('korpa.aspx')) { 645 $('body').addClass('korpa-aspx'); 646 $('#basket-menu-open').hide(); 647} 648 649// REMOVE CUSTOM LOADER 650if (!location.href.includes('korpa.aspx')) { 651 setTimeout(function () { 652 $('.custom-loader').fadeOut(); 653 }, 1600); 654} 655 656// Current year for copyright 657$('.current-year').html(new Date().getFullYear()); 658 659// (TEMP) prevent click on href="#" 660$(document).on('click', 'a[href="#"]', function (event) { 661 event.preventDefault(); 662}); 663 664// TODO: close other menus too 665// EDIT: Ovo možda i ne treba jer svakako ima overlay pa i ne može da se klikne na otvaranje drugog menija dok je prvi otvoren 666// MeÄutim, trebaÄe ako bude donji fiksni meni koji ne prekriva overlay 667$('#main-menu-open').click(function () { 668 openMainMenu(); 669});
670$('#basket-menu-open').click(function () { 671 openBasketMenu(); 672 loadBasketData(); 673}); 674$('#location-menu-open').click(function () { 675 openLocationsMenu(); 676}); 677$('#user-menu-open').click(function () { 678 openUserMenu(); 679}); 680$('#category-menu-open').click(function () { 681 openCategoryMenu(); 682}); 683$('#search-open').click(function () { 684 openSearchMenu(); 685}); 686$(document).on('click', '.close-menu, .body-overlay', function () { 687 if (typeof clearAutocomplete === 'function') clearAutocomplete(); 688 closeMainMenu(); 689 closeBasketMenu(); 690 closeLocationMenu(); 691 closeUserMenu(); 692 closeCategoryMenu(); 693 closeSearchMenu(); 694}); 695 696function encodeURL(str) { 697 return encodeURIComponent(str) 698 .replace(/!/g, '%21') 699 .replace(/\*/g, '%2A') 700 .replace(/\(/g, '%28') 701 .replace(/\)/g, '%29'); 702} 703 704// *** FILTERI 705$(document).ready(function () { 706 resetFilterView(); // Inicijalno resetuj prikaz filtera na prvih 3 707}); 708 709$('#groupMenuInput').on('keyup', function () { 710 var value = $(this) 711 .val() 712 .toLowerCase() 713 .replaceAll('Ä', 'c') 714 .replaceAll('Ä', 'c') 715 .replaceAll('ž', 'z') 716 .replaceAll('Å¡', 's') 717 .replaceAll('Ä', 'dj'); 718 719 var visibleItems = 0; 720 721 // Prikaži sve li elemente pre filtracije 722 $('#filtersTop .filter-wrapper li').show(); 723 724 // Filtriraj listu 725 $('#filtersTop .filter-wrapper li').each(function () { 726 var match = 727 $(this) 728 .text() 729 .toLowerCase() 730 .replaceAll('Ä', 'c') 731 .replaceAll('Ä', 'c') 732 .replaceAll('ž', 'z') 733 .replaceAll('Å¡', 's') 734 .replaceAll('Ä', 'dj') 735 .indexOf(value) > -1; 736 737 $(this).toggle(match); // Pokaži ili sakrij na osnovu filtera 738 739 if (match) { 740 visibleItems++; 741 } 742 }); 743 744 // Ako je manje ili jednako od 3 vidljivih elemenata, sakrij dugme 'Vidi viÅ¡e' 745 if (value) { 746 $('.see-more-filters').hide(); 747 } else { 748 $('.see-more-filters').show(); 749 } 750 751 // Ako je polje za pretragu prazno, resetuj filtere 752 if (value === '') { 753 sortFilters(); // sortiranje filtera 754 resetFilterView(); 755 } 756}); 757 758// Funkcija za resetovanje filtera na prvih 3 vidljive stavke 759function resetFilterView() { 760 $('#filtersTop .filter-wrapper li').show(); 761 $('#filtersTop .filter-wrapper li').slice(3).hide(); // Sakrij sve osim prvih 3 762 $('.see-more-filters').removeClass('minus').text('Vidi viÅ¡e'); // Resetuj dugme 763 // Osiguraj da prvi li uvek bude vidljiv 764 // $('#filtersTop .filter-wrapper li').first().show(); 765 // console.log($('#filtersTop .filter-wrapper li').first()); 766} 767// *** 768 769function moveGalleryImg(direction) { 770 if (direction == 'right') { 771 if ($('.zoomGalleryActive').next().length) { 772 $('.zoomGalleryActive').next().click(); 773 } 774 } else if (direction == 'left') { 775 if ($('.zoomGalleryActive').prev().length) { 776 $('.zoomGalleryActive').prev().click(); 777 } 778 } 779} 780 781// * * * * * * * * * * * * * * * * 782// * * * * * ANALYTICS * * * * * * 783// * * * * * * * * * * * * * * * * 784 785function analyticsAddToBasket(uid, name, fullPrice, salesPrice, actionPrice, type) { 786 // var actionPriceFloat = parseFloat(actionPrice.replace('.', '')); 787 788 var fullPriceFloat = 0; 789 var salesPriceFloat = 0; 790 791 if (type == 'list') { 792 if (fullPrice) fullPriceFloat = parseFloat(fullPrice.replace(',', '')); 793 if (salesPrice) salesPriceFloat = parseFloat(salesPrice.replace(',', '')); 794 } else { 795 if (fullPrice) fullPriceFloat = parseFloat(fullPrice.replace('.', '').replace(',', '.')); 796 if (salesPrice) salesPriceFloat = parseFloat(salesPrice.replace('.', '').replace(',', '.')); 797 } 798 799 var priceFloat = salesPriceFloat || fullPriceFloat || 0; 800 801 // console.log('analyticsAddToBasket:'); 802 // console.log(MasterJson.GAMeasurementID); 803 804 const qty = type == 'list' ? 1 : parseInt($('.cart-plus-minus-box').val()); 805 const value = qty ? qty * priceFloat : priceFloat; 806 807 // console.table({ uid, name, priceFloat, type, qty }); 808 809 if (MasterJson.GAMeasurementID) { 810 gtag('event', 'add_to_cart', { 811 // send_to: MasterJson.GAMeasurementID, 812 currency: MasterJson.GACurrency || 'RSD', 813 value, 814 items: [ 815 { 816 item_id: uid, 817 item_name: name, 818 price: priceFloat, 819 quantity: qty, 820 }, 821 ], 822 }); 823 } 824 825 if (typeof fbq === 'function') { 826 fbq('track', 'AddToCart', { 827 value, 828 currency: MasterJson.GACurrency || 'RSD', 829 }) 830 } 831} 832function analyticsRemoveFromBasket(uid, name, qty, value) { 833 const quantity = qty ? parseInt(qty) : 1; 834 const valueFloat = parseFloat(value); 835 // console.table({ uid, name, quantity, valueFloat }); 836 837 if (MasterJson.GAMeasurementID) { 838 gtag('event', 'remove_from_cart', { 839 // send_to: MasterJson.GAMeasurementID, 840 value: valueFloat, 841 currency: MasterJson.GACurrency || 'RSD', 842 items: [ 843 { 844 item_id: uid, 845 item_name: name, 846 quantity, 847 }, 848 ], 849 }); 850 } 851} 852 853// LOGIN 854 855function getCookie(cname) { 856 let name = cname + '='; 857 let decodedCookie = decodeURIComponent(document.cookie); 858 let ca = decodedCookie.split(';'); 859 for (let i = 0; i < ca.length; i++) {
860 let c = ca[i]; 861 while (c.charAt(0) == ' ') { 862 c = c.substring(1); 863 } 864 if (c.indexOf(name) == 0) { 865 return c.substring(name.length, c.length); 866 } 867 } 868 return ''; 869} 870 871$.ajax({ 872 url: '/LoginService.svc/GetLoginInfo', 873 method: 'POST', 874 success: function (response) { 875 if (response.d?.IsLoggedIn) { 876 $('.user-menu-wrapper > a').removeAttr('href'); 877 $('.user-menu-wrapper > a.person').addClass('login-green dropdown-toggle'); 878 879 $('#footer-registration').css('display', 'none'); 880 $('#footer-password').css('display', 'none'); 881 $('#footer-wishlist').css('display', 'block'); 882 // $('.buttons-search a.heart').on('click', function (e) { 883 // e.preventDefault(); 884 // window.location.href = '/lista-zelja.aspx'; 885 // }); 886 } else { 887 // $('.buttons-search a.heart').on('click', function (e) { 888 // e.preventDefault(); 889 // alert('Morate biti logovani.'); 890 // }); 891 } 892 }, 893 error: function (error) { 894 console.log(error); 895 }, 896}); 897 898// * * * * * * * * * 899// * * * MODAL * * * 900// * * * * * * * * * 901function showModal(modalId) { 902 $(`#${modalId}`).find('.modal-body').html(` 903 <div class="modal-loader"> 904 <img src="/templates/B2C/skins/main/images/Ripple-1s-200px.svg" /> 905 </div> 906 `); 907 $(`#${modalId}`).css('display', 'flex'); 908} 909function hideModal(modalId) { 910 $(`#${modalId}`).css('display', 'none'); 911 $(`#${modalId}`).find('.modal-body').html(''); 912} 913$('.modal .close').click(function () { 914 $(this).closest('.modal').hide(); 915 $(this).closest('.modal').find('.modal-body').html(''); 916}); 917 918// * * * * * * * * * * * * * * * * * * * * 919// * * * * * * * * filteri - see-more-filters * * * 920// * * * * * * * * * * * * * * * * * * * 921function showMoreFilters(clickTarget) { 922 var parentUl = $(clickTarget).closest('ul'); 923 var liChildren = parentUl.children('li'); 924 925 if ($(clickTarget).hasClass('minus')) { 926 liChildren.slice(3).slideUp(); 927 $(clickTarget).removeClass('minus').text('Vidi više'); 928 } else { 929 liChildren.slice(3).slideDown(); 930 $(clickTarget).addClass('minus').text('Vidi manje'); 931 } 932}
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.