1(function ($) { 2 "use strict"; 3 4 if (!$.itThemeExtensions) $.itThemeExtensions = {}; 5 6 function ItTheme() { 7 var self = this; 8 9 // CSS Classes 10 self.classHeaderFixed = "scrolled"; 11 self.classOpen = "open"; 12 self.classDisableScrollbars = "disable-scrollbars"; 13 14 self.env = { 15 mobile: false, 16 smartphone: false, 17 ios: false, 18 android: false, 19 mac: false, 20 }; 21 22 // Page elements 23 self.$window = $(window); 24 self.$document = $(document); 25 self.$html = $("html"); 26 self.$body = $("body"); 27 28 // Header 29 self.$adminBar = $("#wpadminbar"); 30 self.$topBar = $(".topbar"); 31 self.headerScrollTolerance = 56; 32 33 // Menu drawer 34 self.$menuDrawerBtn = $(".menu-button"); 35 self.$menuDrawer = $(".menu-drawer"); 36 37 // Menu drawer list items 38 self.$accordionBtn = $(".btn-accordion"); 39 40 // Search 41 self.$searchBtn = $(".categories-bar .search-button"); 42 self.$searchInput = $(".categories-bar .search-input-field"); 43 self.$searchForm = $(".categories-bar .search-form"); 44 45 // Popup Banner 46 self.$popupBannerBtn = $(".popup-banner .header-wrapper button"); 47 self.$popupBanner = $(".popup-banner"); 48 49 // Mini Cart 50 self.$cartDrawerOpenBtn = $(".it-menu-cart-btn"); 51 self.$minicartDrawer = $(".cart-drawer"); 52 53 self.$loginPopup = $(".it-login-popup-wrap"); 54 self.$loginPopupBtn = $(".account-login"); 55 56 // Categories Swiper 57 self.categoriesSwiper = null; 58 59 // Shop 60 61 // Initialize scripts 62 self.init(); 63 } 64 65 ItTheme.prototype = { 66 /** 67 * Initialize 68 */ 69 init: function () { 70 var self = this; 71 72 // Detect environment 73 self.detectEnv(); 74 75 // Load extension scripts 76 self.loadExtensions(); 77 78 self.bind(); 79 }, 80 81 /** 82 * Extensions: Load scripts 83 */ 84 loadExtensions: function () { 85 var self = this; 86 87 // Comments Script 88 if ($.itThemeExtensions.comments) { 89 $.itThemeExtensions.comments.call(self); 90 } 91 92 // Shop scripts 93 if ($.itThemeExtensions.add_to_cart) { 94 $.itThemeExtensions.add_to_cart.call(self); 95 } 96 97 // Shop: Mini Cart scripts 98 if ($.itThemeExtensions.mini_cart) { 99 $.itThemeExtensions.mini_cart.call(self); 100 } 101 102 // Shop: Cart 103 if ($.itThemeExtensions.cart) { 104 $.itThemeExtensions.cart.call(self); 105 } 106 107 // Shop: Single Product scripts 108 if ($.itThemeExtensions.singleProduct) { 109 $.itThemeExtensions.singleProduct.call(self); 110 } 111 112 // Shop: Checkout 113 if ($.itThemeExtensions.checkout) { 114 $.itThemeExtensions.checkout.call(self); 115 } 116 117 // Global: InfLoad 118 if ($.itThemeExtensions.infload) { 119 $.itThemeExtensions.infload.call(self); 120 } 121 }, 122 123 /** 124 * Bind scripts 125 */ 126 bind: function () { 127 var self = this; 128 129 /* Bind: Window scroll (Fixed header) */ 130 // self.$window.bind("scroll.itheader", function () { 131 // self.headerToggleFixedClass(self); 132 // }); 133 // self.$window.trigger("scroll"); 134 135 // /* Bind: Window click (Close search) */ 136 // self.$window.bind("click", function () { 137 // self.searchFormClose(); 138 // }); 139 140 /* Bind: Menu drawer button */ 141 // self.$menuDrawerBtn.bind("click", function (e) { 142 // e.preventDefault(); 143 144 // self.menuDrawerOpen(); 145 // }); 146 147 /* Bind: Menu drawer - Toggle sub-menu */ 148 // self.$accordionBtn.bind("click", function () { 149 // $(this).closest("li").toggleClass(self.classOpen); 150 // }); 151 152 /* Bind: Page overlay */ 153 $(".overlay").bind("click", function () { 154 self.menuDrawerClose(); 155 self.cartDrawerClose(); 156 }); 157 158 /* Bind: Search Input */ 159 // self.$searchInput.bind("click", function (e) { 160 // // stop the event from bubbling up to the body and trigger searchFormClose event 161 // e.stopPropagation(); 162 // }); 163 164 /* Bind: Search */ 165 // self.$searchBtn.bind("click", function (e) { 166 // // stop the event from bubbling up to the body and trigger searchFormClose event 167 // e.stopPropagation(); 168 169 // if (!self.$searchForm.hasClass(self.classOpen)) { 170 // // open the search form 171 // e.preventDefault(); 172 // self.$searchForm.addClass(self.classOpen); 173 // self.$searchInput.focus(); 174 // } else {
175 // var validSearch = self.searchValidateInput(self.$searchInput.val()); 176 // if (!validSearch) { 177 // e.preventDefault(); 178 // self.searchFormClose(); 179 // } 180 // } 181 // }); 182 183 /* Bind: Popup Banner */ 184 self.$popupBannerBtn.bind("click", function () { 185 self.$popupBanner.addClass("hidden"); 186 }); 187 188 /* Bind: Cart Drawer */ 189 self.cartDrawerBind(); 190 191 /* Bind: Login popup */ 192 if (self.$loginPopup.length) { 193 self.$loginPopupBtn.bind("click", function (e) { 194 e.preventDefault(); 195 self.loginCouponShowForm("#it-login-popup-wrap", "it-login-popup"); 196 }); 197 } 198 199 /* Bind: Category Swiper Input */ 200 // self.categoriesSwiper = new Swiper(".categories-swiper-container", { 201 // navigation: { 202 // nextEl: ".arrow-next", 203 // prevEl: ".arrow-prev", 204 // disabledClass: "hidden", 205 // }, 206 // a11y: false, 207 // slidesPerView: "auto", 208 // freeMode: true, 209 // watchOverflow: true, 210 // }); 211 // // Slide to the current category 212 // if (typeof activeCat !== "undefined" && activeCat !== null) { 213 // self.categoriesSwiper.slideTo(activeCat, 500, false); 214 // } 215 216 // self.cartDrawerOpen(); 217 }, 218 219 /** 220 * Login/Coupon: Show popup form 221 */ 222 loginCouponShowForm: function ($formContainer, containerClass) { 223 $.magnificPopup.open({ 224 mainClass: containerClass + " it-mfp-fade-in", 225 alignTop: true, 226 closeMarkup: 227 '<a class="mfp-close it-font it-font-close2 login-popup-close">X</a>', 228 removalDelay: 180, 229 items: { 230 src: $formContainer, 231 type: "inline", 232 }, 233 }); 234 }, 235 236 /** 237 * Detect environment 238 */ 239 detectEnv: function () { 240 var self = this; 241 242 var userAgent = navigator.userAgent || navigator.vendor || window.opera; 243 244 if ( 245 /iPad|iPhone|iPod|Android|iemobile/.test(userAgent) && 246 !window.MSStream 247 ) { 248 self.env.mobile = true; 249 $("html").addClass("touch"); 250 } else { 251 $("html").addClass("no-touch"); 252 } 253 254 if (/iPhone|iPod|Android|iemobile/.test(userAgent) && !window.MSStream) { 255 self.env.smartphone = true; 256 } 257 258 if (/iPad|iPhone|iPod/.test(userAgent) && !window.MSStream) { 259 self.env.ios = true; 260 $("html").addClass("ios"); 261 } 262 263 if (/android/i.test(userAgent) && !window.MSStream) { 264 self.env.android = true; 265 $("html").addClass("android"); 266 } 267 268 if (/mac os/i.test(userAgent)) { 269 self.env.mac = true; 270 $("html").addClass("mac"); 271 } 272 }, 273 274 /** 275 * Shop: Replace fragments 276 */ 277 shopReplaceFragments: function (fragments) { 278 // console.log(fragments); 279 var $fragment; 280 $.each(fragments, function (selector, fragment) { 281 // console.log('selector: ', selector, 'fragment: ', fragment); 282 $fragment = $(fragment); 283 if ($fragment.length) { 284 $(selector).replaceWith($fragment); 285 } 286 }); 287 }, 288 289 /** 290 * Cart drawer: Bind 291 */ 292 cartDrawerBind: function () { 293 var self = this; 294 295 /* Bind: "Cart" buttons */ 296 self.$cartDrawerOpenBtn.bind("click", function (e) { 297 e.preventDefault(); 298 299 // // Close the mobile menu first 300 // if (self.$body.hasClass(self.classMobileMenuOpen)) { 301 // var $this = $(this); 302 // self.$pageOverlay.trigger('click'); 303 // setTimeout(function() { 304 // $this.trigger('click'); // Trigger this function again 305 // }, self.panelsAnimSpeed); 306 // } else { 307 // self.cartDrawerOpen(); 308 // } 309 310 self.cartDrawerOpen(); 311 }); 312 313 /* Bind: "Close" button */ 314 $(".cart-drawer .close").bind("click", function (e) { 315 e.preventDefault(); 316 317 self.cartDrawerClose(); 318 }); 319 320 // /* Bind: "Continue shopping" button */ 321 // self.$widgetPanel.on('click.nmCartPanelClose', '#it-cart-panel-continue', function(e) { 322 // e.preventDefault(); 323 // $('#it-widget-panel-overlay').trigger('click'); 324 // }); 325 326 self.$body.on("adding_to_cart", function (event, $button, data) { 327 // console.log('EVENT: adding_to_cart'); 328 self.cartDrawerOpen(true); 329 }); 330 331 self.$body.on("added_to_cart", function (event, fragments, cartHash) { 332 // console.log('EVENT: added_to_cart'); 333 self.widgetPanelCartHideLoader(); 334 }); 335 336 self.$document.on("wc_fragments_refreshed", function () { 337 // clearTimeout( cart_timeout ); 338 // cart_timeout = setTimeout( refresh_cart_fragment, day_in_ms ); 339 // console.log('EVENT: wc_fragments_refreshed'); 340 // self.cartDrawerOpen(); 341 }); 342 }, 343 344 /** 345 * Cart drawer: Open 346 */ 347 cartDrawerOpen: function (showLoader) { 348 var self = this; 349 350 if (showLoader) { 351 self.widgetPanelCartShowLoader(); 352 } 353 354 if (!self.$body.hasClass(self.classDisableScrollbars)) { 355 self.$body.addClass(self.classDisableScrollbars); 356 } 357 358 // self.$body.addClass('widget-panel-opening '+self.classWidgetPanelOpen); 359 if (!self.$minicartDrawer.hasClass(self.classOpen)) { 360 self.$minicartDrawer.addClass(self.classOpen); 361 } 362 }, 363 364 /** 365 * Cart drawer: Hide 366 */ 367 cartDrawerClose: function () { 368 var self = this; 369 // console.log('cartDrawerClose') 370 371 if (self.$body.hasClass(self.classDisableScrollbars)) { 372 self.$body.removeClass(self.classDisableScrollbars); 373 } 374 375 if (self.$minicartDrawer.hasClass(self.classOpen)) { 376 self.$minicartDrawer.removeClass(self.classOpen); 377 } 378 }, 379 380 /** 381 * Widget panel: Cart - Show loader 382 */ 383 widgetPanelCartShowLoader: function () { 384 $("#it-cart-panel-loader").addClass("show"); 385 }, 386 387 /** 388 * Widget panel: Cart - Hide loader 389 */ 390 widgetPanelCartHideLoader: function () { 391 var self = this; 392 393 $("#it-cart-panel-loader").addClass("fade-out"); 394 setTimeout(function () { 395 $("#it-cart-panel-loader").removeClass("fade-out show"); 396 }, 200); 397 }, 398 399 /** 400 * Quantity inputs: Bind buttons 401 */
402 quantityInputsBindButtons: function ($container) { 403 var self = this; 404 405 /* 406 * Bind buttons click event 407 */ 408 $container 409 .off("click.itQty") 410 .on("click.itQty", ".it-qty-plus, .it-qty-minus", function () { 411 // Get elements and values 412 var $this = $(this), 413 $qty = $this.closest(".quantity").find(".qty"), 414 currentVal = parseFloat($qty.val()), 415 max = parseFloat($qty.attr("max")), 416 min = parseFloat($qty.attr("min")), 417 step = $qty.attr("step"); 418 419 // console.log('qty: ', $qty); 420 421 // Format values 422 if (!currentVal || currentVal === "" || currentVal === "NaN") 423 currentVal = 0; 424 if (max === "" || max === "NaN") max = ""; 425 if (min === "" || min === "NaN") min = 0; 426 if ( 427 step === "any" || 428 step === "" || 429 step === undefined || 430 parseFloat(step) === "NaN" 431 ) 432 step = 1; 433 434 // Change the value 435 if ($this.hasClass("it-qty-plus")) { 436 if (max && (max == currentVal || currentVal > max)) { 437 $qty.val(max); 438 } else { 439 $qty.val(currentVal + parseFloat(step)); 440 self.quantityInputsTriggerEvents($qty); 441 } 442 } else { 443 if (min && (min == currentVal || currentVal < min)) { 444 $qty.val(min); 445 } else if (currentVal > 0) { 446 $qty.val(currentVal - parseFloat(step)); 447 self.quantityInputsTriggerEvents($qty); 448 } 449 } 450 }); 451 }, 452 453 /** 454 * Quantity inputs: Trigger events 455 */ 456 quantityInputsTriggerEvents: function ($qty) { 457 var self = this; 458 459 // Trigger quantity input "change" event 460 $qty.trigger("change"); 461 462 // Trigger custom event 463 self.$document.trigger("it_qty_change", $qty); 464 }, 465 466 /** 467 * Header: Toggle fixed class 468 */ 469 headerToggleFixedClass: function (self) { 470 if (self.$document.scrollTop() > self.headerScrollTolerance) { 471 if (!self.$topBar.hasClass(self.classHeaderFixed)) { 472 self.$topBar.addClass(self.classHeaderFixed); 473 self.$adminBar.fadeOut(300); 474 } 475 } else { 476 if (self.$topBar.hasClass(self.classHeaderFixed)) { 477 self.$topBar.removeClass(self.classHeaderFixed); 478 self.$adminBar.fadeIn(1); 479 } 480 } 481 }, 482 483 /** 484 * Menu drawer: Open 485 */ 486 menuDrawerOpen: function () { 487 var self = this; 488 489 if (!self.$menuDrawer.hasClass(self.classOpen)) { 490 self.$menuDrawer.addClass(self.classOpen); 491 } 492 }, 493 494 /** 495 * Menu drawer: Close 496 */ 497 menuDrawerClose: function () { 498 var self = this; 499 500 if (self.$menuDrawer.hasClass(self.classOpen)) { 501 self.$menuDrawer.removeClass(self.classOpen); 502 } 503 }, 504 505 /** 506 * Header: Close Search Form 507 */ 508 searchFormClose: function () { 509 var self = this; 510 511 // Empty input value 512 self.$searchInput.val(""); 513 514 self.$searchForm.removeClass(self.classOpen); 515 }, 516 517 /** 518 * Search: Validate input string 519 */ 520 searchValidateInput: function (s) { 521 // Make sure the search string has at least one character (not just whitespace) and minimum allowed characters are entered 522 if (/\S/.test(s) && s.length > 2) { 523 return true; 524 } else { 525 return false; 526 } 527 }, 528 }; 529 530 // Add core script to $.itTheme so it can be extended 531 $.itTheme = ItTheme.prototype; 532 533 $(document).ready(function () { 534 // Initialize script 535 new ItTheme(); 536 }); 537})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.