1/** 2 * @version 3.x 3 * @package DJ-Catalog2 4 * @copyright Copyright (C) DJ-Extensions.com, All rights reserved. 5 * @license DJ-Extensions.com Proprietary Use License 6 * @author url: http://dj-extensions.com 7 * @author email [email protected] 8 * 9 */ 10 11var DJC2ScrollOffset = (typeof window.DJC2ScrollOffset !== 'undefined') ? window.DJC2ScrollOffset : 0; 12 13function DJCatMatchModules(className, setLineHeight, reset) { 14 var maxHeight = 0; 15 var divs = null; 16 if (typeof(className) == 'string') { 17 divs = jQuery(document.body).find(className); 18 } else { 19 divs = className; 20 } 21 if (divs.length > 1) { 22 jQuery(divs).each(function(index, element) { 23 if (reset == true) { 24 jQuery(element).css('height', ''); 25 } 26 maxHeight = Math.max(maxHeight, parseInt(jQuery(element).outerHeight())); 27 }); 28 29 jQuery(divs).css('height', maxHeight + 'px'); 30 31 if (setLineHeight) { 32 jQuery(divs).css('line-height', maxHeight + 'px'); 33 } 34 } 35} 36 37this.DJCatImageSwitcher = function (){ 38 jQuery('.djc_image_switcher').each(function(){ 39 var wrapper = jQuery(this); 40 41 var mainimagelink = wrapper.find('[data-target="main-image-link"]'); 42 var mainimage = mainimagelink.find('img'); 43 var thumbs = wrapper.find('[data-toggle="image-thumbs"]').find('img'); 44 var thumblinks = wrapper.find('[data-toggle="image-thumbs"]').find('a'); 45 46 if(mainimagelink.length > 0 && mainimage.length > 0) { 47 jQuery(mainimagelink).unbind('click'); 48 jQuery(mainimagelink).click(function(event) { 49 event.preventDefault(); 50 var rel = jQuery(mainimagelink).attr('data-thumb'); 51 thumblinks.filter('[data-thumb="'+rel+'"]').trigger('click'); 52 return false; 53 }); 54 } 55 56 if (!mainimage.length || !mainimagelink.length || !thumblinks.length || !thumbs.length) return false; 57 58 mainimagelink = jQuery(mainimagelink.first()); 59 mainimage = jQuery(mainimage.first()); 60 jQuery(thumblinks).each(function(index, thumblink){ 61 jQuery(thumblink).find('img').click(function(event){ 62 event.stopPropagation(); 63 var img = new Image(); 64 img.onload = (function() { 65 mainimage.fadeIn(300); 66 }); 67 mainimage.fadeOut({ 68 duration: 300, 69 start: function() { 70 mainimagelink.attr('href', jQuery(thumblink).attr('href')); 71 mainimagelink.attr('title', jQuery(thumblink).attr('title')); 72 mainimagelink.attr('data-thumb', index); 73 74 img.src = jQuery(thumblink).attr('data-large'); 75 76 mainimage.attr('alt', jQuery(thumblink).attr('title')); 77 }, 78 complete: function(){ 79 mainimage.attr('src', img.src); 80 if (jQuery(window).width() <= 979) { 81 jQuery('html, body').animate({ 82 scrollTop: mainimagelink.offset().top - DJC2ScrollOffset 83 }, 10); 84 } 85 } 86 }); 87 return false; 88 }); 89 }); 90 }); 91}; 92 93(function($){ 94 window.DJCatOrderSummary = function(deliveries, payments, shipping_days) { 95 this.delivery_id = 0; 96 this.payment_id = 0; 97 this.shipping_days = shipping_days; 98 99 if (deliveries.length) { 100 for (var i = 0; i < deliveries.length; i++) { 101 if (deliveries[i].checked) { 102 this.delivery_id = deliveries[i].value; 103 } 104 } 105 } 106 if (payments.length) { 107 for (var i = 0; i < payments.length; i++) { 108 if (payments[i].checked) { 109 this.payment_id = payments[i].value; 110 } 111 } 112 } 113 114 this.djc_delivery_extra = $("div.djc_delivery_details"); 115 this.djc_payment_extra = $("div.djc_payment_details"); 116 117 var self = this; 118 119 if (self.djc_delivery_extra.length) { 120 self.djc_delivery_extra.each(function(){ 121 var element = $(this); 122 if (element.attr('data-id') == self.delivery_id) { 123 element.css('display', ''); 124 } else { 125 element.css('display', 'none'); 126 } 127 }); 128 } 129 if (self.djc_payment_extra.length) { 130 self.djc_payment_extra.each(function(){ 131 var element = $(this); 132 if (element.attr('data-id') == self.payment_id) { 133 element.css('display', ''); 134 } else { 135 element.css('display', 'none'); 136 } 137 }); 138 } 139 140 $('#djc_ordersummary').css('opacity', 0.3); 141 $('#djcDeliveryForm').html(''); 142 143 $.ajax({ 144 url : 'index.php?option=com_djcatalog2&task=cart.getSummary&ts=' + Date.now(), 145 data: 'payment=' + self.payment_id + '&' + 'delivery=' + this.delivery_id + ((!isNaN(this.shipping_days) ? '&shipping_days=' + this.shipping_days : '')) 146 }).done(function(data){ 147 try { 148 var response = $.parseJSON(data); 149 150 if (response.data) { 151 if (response.error == 0) { 152 var prices = response.data; 153 $('#djc_summary_gross').html(prices.products); 154 $('#djc_summary_delivery').html(prices.delivery); 155 $('#djc_summary_payment').html(prices.payment); 156 $('#djc_summary_components').html(prices.components); 157 $('#djc_summary_total').html(prices.total); 158 159 if(response.delivery) { 160 $(document).trigger('checkout:reloadDelivery:' + response.delivery); 161 } 162 163 } else if (response.error_message) { 164 alert(response.error_message); 165 if (deliveries.length) { 166 deliveries.each(function(){ 167 $(this).removeAttr('checked'); 168 }); 169 } 170 if (payments.length) { 171 payments.each(function(){ 172 $(this).removeAttr('checked'); 173 }); 174 } 175 } 176 } 177 } catch (e) { 178 179 } 180 }).always(function(){ 181 $('#djc_ordersummary').css('opacity', 1); 182 }); 183 }; 184})(jQuery); 185 186this.DJCatContactForm = function(){ 187 // contact form handler 188 var contactform = jQuery('#contactform'); 189 var makesure = jQuery('#djc_contact_form'); 190 var contactformButton = jQuery('#djc_contact_form_button'); 191 var contactformButtonClose = jQuery('#djc_contact_form_button_close'); 192 193 if (contactform.length && makesure.length) { 194 195 if (window.location.hash == 'contactform' || window.location.hash == '#contactform') { 196 contactform.slideDown(200, function(){ 197 jQuery('html, body').animate({ 198 scrollTop: jQuery('#contactform').offset().top - DJC2ScrollOffset 199 }, 200); 200 }); 201 } else if (contactformButton.length) { 202 contactform.hide(); 203 } 204 if (contactformButton.length) { 205 contactformButton.click(function(event) { 206 event.preventDefault(); 207 contactform.slideDown(); 208 209 if (contactform.is(':hidden') == false) { 210 jQuery('html, body').animate({ 211 scrollTop: jQuery('#contactform').offset().top - DJC2ScrollOffset 212 }, 200); 213 } 214 }); 215 } 216 if (contactformButtonClose.length > 0) { 217 contactformButtonClose.click(function(event){ 218 event.preventDefault(); 219 220 var isIframe = false;
221 try { 222 isIframe = window.self !== window.top; 223 } catch (e) { 224 isIframe = true; 225 } 226 227 if (isIframe) { 228 jQuery(window.parent.document).find('button.mfp-close').trigger('click'); 229 } else { 230 contactform.slideUp(200, function(){ 231 jQuery('html, body').animate({ 232 scrollTop: jQuery('#djcatalog').offset().top - DJC2ScrollOffset 233 }, 200); 234 }); 235 } 236 }); 237 } 238 } 239}; 240 241this.DJCatAdvSearch = function() { 242 var advSearchToggle = jQuery('.djc_adv_search_toggle'); 243 var advSearchWrapper = jQuery('#djc_additional_filters'); 244 if (advSearchToggle.length > 0) { 245 if (!advSearchWrapper) { 246 advSearchToggle.css('display', 'none'); 247 } else { 248 var cookieVal = document.cookie.match('(^|;) ?' + 'djcAdvSearch' + '=([^;]*)(;|$)'); 249 var visible = cookieVal ? cookieVal[2] : null; 250 251 if (visible != 1) { 252 advSearchWrapper.hide(); 253 } 254 255 advSearchToggle.click(function(event){ 256 advSearchWrapper.toggle(); 257 258 setTimeout(function(){ 259 var expires = new Date(); 260 expires.setTime(expires.getTime() + (1 * 24 * 60 * 60 * 1000)); 261 262 if (advSearchWrapper.is(':hidden') == false) { 263 document.cookie = 'djcAdvSearch' + '=' + '1' + ';expires=' + expires.toUTCString(); 264 jQuery('html, body').animate({ 265 scrollTop: advSearchWrapper.offset().top - DJC2ScrollOffset 266 }, 200); 267 } else { 268 document.cookie = 'djcAdvSearch' + '=' + '0' + ';expires=' + expires.toUTCString(); 269 } 270 }, 200); 271 }); 272 } 273 } 274}; 275 276var DJCatMatchBackgrounds = function(){ 277 278 //DJCatMatchModules('.djc_subcategory_bg', false, true); 279 DJCatMatchModules('.djc_thumbnail', true, true); 280 281 if (jQuery('.djc_subcategory_row').length > 0) { 282 jQuery('.djc_subcategory_row').each(function(){ 283 var row = jQuery(this); 284 var elements = row.find('.djc_subcategory_bg'); 285 if (elements.length > 0) { 286 DJCatMatchModules(elements, false, true); 287 } 288 }); 289 } 290 291 if (jQuery('.djc_item_row').length > 0) { 292 jQuery('.djc_item_row').each(function(){ 293 var row = jQuery(this); 294 var elements = row.find('.djc_item_bg'); 295 if (elements.length > 0) { 296 DJCatMatchModules(elements, false, true); 297 } 298 }); 299 } 300}; 301 302function DJCatSelectCustomerUser(input) { 303 var id =jQuery(input).val(); 304 if (id.length) { 305 window.location.href= window.DJC2BaseUrl + '/index.php?option=com_djcatalog2&task=cart.selectCheckoutUser&user_id=' + id; 306 } 307} 308 309function DJCatUpdateDeliveryMethods(state) { 310 var deliveryMethods = jQuery('input.djc_delivery_method'); 311 var countryId = (state == 1) ? jQuery('.djc_country.billing').val() : jQuery('.djc_country.delivery').val(); 312 var postCode = (state == 1) ? jQuery('.djc_postcode.billing').val() : jQuery('.djc_postcode.delivery').val().trim(); 313 314 deliveryMethods.each(function(){ 315 var attrs = JSON.parse(jQuery(this).attr('data-options')); 316 var validCountry = false; 317 var validPostcode = false 318 319 if (attrs.countries.length > 0) { 320 if (countryId) { 321 jQuery.each(attrs.countries, function(i, dCountryId){ 322 if (dCountryId == countryId) { 323 validCountry = true; 324 } 325 }); 326 } else { 327 validCountry = false; 328 } 329 } else { 330 validCountry = true; 331 } 332 333 if (attrs.postcodes.length > 0) { 334 if (postCode) { 335 if (attrs.postcodes.length == 1) { 336 if (attrs.postcodes[0] == postCode) { 337 validPostcode = true; 338 } 339 } else { 340 if (postCode >= attrs.postcodes[0] && postCode <= attrs.postcodes[1]) { 341 validPostcode = true; 342 } else { 343 validPostcode = false; 344 } 345 } 346 } else { 347 validPostcode = false; 348 } 349 } else { 350 validPostcode =true; 351 } 352 353 if (!validCountry || !validPostcode) { 354 jQuery(this).removeAttr('checked').hide(); 355 jQuery('label[for="'+this.id+'"]').hide(); 356 jQuery('input.djc_payment_method').removeAttr('checked'); 357 jQuery('input.djc_payment_method').trigger('change'); 358 } else { 359 jQuery(this).show(); 360 jQuery('label[for="'+this.id+'"]').show(); 361 } 362 }); 363} 364 365function DJCatUpdatePaymentMethods(state) { 366 var paymentMethods = jQuery('input.djc_payment_method'); 367 var countryId = (state == 1) ? jQuery('.djc_country.billing').val() : jQuery('.djc_country.delivery').val(); 368 var postCode = (state == 1) ? jQuery('.djc_postcode.billing').val() : jQuery('.djc_postcode.delivery').val().trim(); 369 370 paymentMethods.each(function(){ 371 var attrs = JSON.parse(jQuery(this).attr('data-options'));
372 var validCountry = false; 373 var validPostcode = false 374 375 if (attrs.countries.length > 0) { 376 if (countryId) { 377 jQuery.each(attrs.countries, function(i, dCountryId){ 378 if (dCountryId == countryId) { 379 validCountry = true; 380 } 381 }); 382 } else { 383 validCountry = false; 384 } 385 } else { 386 validCountry = true; 387 } 388 389 if (attrs.postcodes.length > 0) { 390 if (postCode) { 391 if (attrs.postcodes.length == 1) { 392 if (attrs.postcodes[0] == postCode) { 393 validPostcode = true; 394 } 395 } else { 396 if (postCode >= attrs.postcodes[0] && postCode <= attrs.postcodes[1]) { 397 validPostcode = true; 398 } else { 399 validPostcode = false; 400 } 401 } 402 } else { 403 validPostcode = false; 404 } 405 } else { 406 validPostcode =true; 407 } 408 409 if (!validCountry || !validPostcode) { 410 jQuery(this).removeAttr('checked').hide(); 411 jQuery('label[for="'+this.id+'"]').hide(); 412 } else { 413 var delivery_id = 0; 414 415 jQuery('input[name="jform[djcatalog2orderdetails][delivery_method_id]"]').each(function(){ 416 if (jQuery(this).is(':checked')) { 417 delivery_id = jQuery(this).val(); 418 } 419 }); 420 421 var xref = jQuery(this).attr("data-delivery"); 422 var validMethod = false; 423 424 if (xref.length == 0) { 425 validMethod = true; 426 } else { 427 xref = xref.split(','); 428 for (var i=0; i< xref.length; i++) { 429 if (xref[i] == delivery_id) { 430 validMethod = true; 431 } 432 } 433 } 434 435 if (validMethod) { 436 jQuery(this).show(); 437 jQuery('label[for="'+this.id+'"]').show(); 438 } else { 439 jQuery(this).removeAttr('checked').hide(); 440 jQuery('label[for="'+this.id+'"]').hide(); 441 } 442 } 443 }); 444} 445 446 447(function($){ 448 $(document).ready(function(){ 449 // image switcher, contact form, advanced search module 450 DJCatImageSwitcher(); 451 DJCatContactForm(); 452 DJCatAdvSearch(); 453 454 var DJCatQty = { 455 initWrapper: function(element) { 456 var input = $(element); 457 if (input.prop('hasQtyBtns')) return; 458 459 var type = input.attr('data-type') == 'flo' ? 'flo' : 'int'; 460 var minVal = input.attr('data-min') ? input.attr('data-min') : 1; 461 var maxVal = input.attr('data-max') ? input.attr('data-max') : 0; 462 463 if (type == 'int') { 464 minVal = parseInt(minVal); 465 maxVal = parseInt(maxVal); 466 } else { 467 minVal = parseFloat(minVal); 468 maxVal = parseFloat(maxVal); 469 } 470 471 var allowEmpty = (input.attr('data-allowempty') == '1'); 472 var step = (typeof input.attr('data-step') != 'undefined') ? input.attr('data-step') : 1; 473 var precision = (typeof input.attr('data-precision') != 'undefined') ? input.attr('data-precision') : 0; 474 var unit = (typeof input.attr('data-unit') != 'undefined') ? input.attr('data-unit') : ''; 475 476 input.prop('qtyCfg', { 477 type: type, 478 minVal: minVal, 479 maxVal: maxVal, 480 allowEmpty: allowEmpty, 481 step: type == 'int' ? parseInt(step) : parseFloat(step), 482 precision: precision, 483 unit: unit 484 }); 485 486 input.prop('hasQtyBtns', true); 487 488 //this.setMarkup(input); 489 this.bindEvents(input); 490 }, 491 492 setMarkup: function(input) { 493 var props = input.prop('qtyCfg'); 494 495 var html1 = '<span data-toggle="dec" class="btn djc_qty_btn djc_qty_dec">-</span>'; 496 var html2 = '<span data-toggle="inc" class="btn djc_qty_btn djc_qty_inc">+</span>'; 497 498 input.wrap('<div class="djc_qty input-append input-prepend"></div>'); 499 input.parent().append('<span class="add-on">'+props.unit+'</span>'); 500 input.parents('.djc_qty').prepend($(html1)).append($(html2)); 501 }, 502 503 bindEvents: function(input) { 504 var self = this; 505 input.on('keyup', function(){ 506 self.validate(input, false); 507 }); 508 input.on('change click', function(){ 509 self.validate(input, true); 510 }); 511 512 var btns = input.parents('.djc_qty').find('.djc_qty_btn'); 513 514 btns.on('qty:click', function(event, extra){ 515 var props = input.prop('qtyCfg'); 516 517 var current = props.type=='int' ? parseInt(input.val()) : parseFloat(input.val()); 518 519 if (isNaN(current) /*|| current == 0*/) { 520 if (props.allowEmpty) { 521 input.val(''); 522 } else { 523 input.val(props.minVal); 524 } 525 return; 526 } 527 528 var action = $(this).attr('data-toggle'); 529 if (action != 'inc' && action != 'dec') { 530 return false;
531 } 532 533 if (action == 'inc') { 534 if (props.maxVal > 0) { 535 if ( current == props.maxVal || current+props.step > props.maxVal ) { 536 current = props.maxVal; 537 } else { 538 current = parseFloat( (current + props.step).toFixed(props.precision) ); 539 } 540 } else { 541 current = parseFloat((current + props.step).toFixed(props.precision)); 542 } 543 } else { 544 if ( current == props.minVal || current-props.step < props.minVal ) { 545 current = props.minVal; 546 } else { 547 current = parseFloat( (current - props.step).toFixed(props.precision) ); 548 } 549 }; 550 input.val(current); 551 //self.validate(input, true); 552 input.trigger('change', extra); 553 }); 554 555 btns.on('keypress', function(evt){ 556 var key = evt.which; 557 if (key == 13) { 558 $(this).trigger('qty:click', 'keypress'); 559 return false; 560 } 561 }); 562 563 var interval = null; 564 btns.on('mousedown touchstart', function(event){ 565 event.preventDefault(); 566 event.stopPropagation(); 567 var btn = $(this); 568 btn.trigger('qty:click', 'mouseclick'); 569 interval = setInterval(function(){ 570 btn.trigger('qty:click', 'mouseclick'); 571 }, 600); 572 }).on('mouseup mouseleave touchend', function(event){ 573 clearInterval(interval); 574 }); 575 }, 576 577 validate: function(input, full) { 578 full = (typeof full != 'undefined' && full) ? true : false; 579 var props = input.prop('qtyCfg'); 580 //var value = (props.type == 'int') ? parseInt(input.val()) : parseFloat(input.val()); 581 var value = input.val(); 582 var numVal = (props.type == 'int') ? parseInt(value) : parseFloat(value); 583 584 if (props.type == 'int') { 585 var validNo = new RegExp(/^\d$/); 586 var restricted = new RegExp(/[^\d+]/g); 587 if (validNo.test(value) == false) { 588 value = value.replace(restricted, ''); 589 } 590 numVal = parseInt(value); 591 } else { 592 var validNo = new RegExp(/^(\d+|\d+\.\d+)$/); 593 var semiValidNo = new RegExp(/^\d+|\.$/); 594 var wrongDec = new RegExp(/\,/g); 595 var restricted = new RegExp(/[^\d+\.]/g); 596 597 value = value.replace(wrongDec, "."); 598 599 if (validNo.test(value) == false) { 600 if (full || semiValidNo.test(value) == false) { 601 value = value.replace(restricted, ''); 602 } 603 } 604 numVal = parseFloat(value); 605 } 606 607 if (full) { 608 if (numVal < props.minVal) { 609 value = props.minVal; 610 } else if (props.maxVal > 0 && props.maxVal < numVal) { 611 value = props.maxVal; 612 } 613 614 numVal = parseFloat(value); 615 if (props.step > 0.0000) { 616 var stepQty = parseFloat(props.minVal.toFixed(props.precision)); 617 var tmp = stepQty; 618 while ( tmp < numVal) { 619 stepQty += props.step; 620 tmp = parseFloat(stepQty.toFixed(props.precision)); 621 } 622 value = stepQty; 623 } 624 625 value = (props.type == 'int') ? parseInt(value) : parseFloat(value).toFixed(props.precision); 626 } 627 628 input.val(value); 629 } 630 }; 631 632 // producer modals 633 $(document).ready(function(){ 634 $('#djcatalog').on('ajaxFilter:loadItems', function(){ 635 $(this).find('a[data-toggle="modal"]').each(function(){ 636 var link = $(this); 637 $(link.attr('data-target')).on('show.bs.modal', function() { 638 $('body').addClass('modal-open'); 639 var modalBody = $(this).find('.modal-body'); 640 modalBody.find('iframe').remove(); 641 modalBody.prepend('<iframe class="iframe" src="'+link.attr('data-href')+'" name="'+link.attr('data-modaltitle')+'" height="600px"></iframe>'); 642 }).on('shown.bs.modal', function() { 643 var modalHeight = $('div.modal:visible').outerHeight(true), 644 modalHeaderHeight = $('div.modal-header:visible').outerHeight(true), 645 modalBodyHeightOuter = $('div.modal-body:visible').outerHeight(true), 646 modalBodyHeight = $('div.modal-body:visible').height(), 647 modalFooterHeight = $('div.modal-footer:visible').outerHeight(true), 648 padding = this.offsetTop, 649 maxModalHeight = ($(window).height()-(padding*2)), 650 modalBodyPadding = (modalBodyHeightOuter-modalBodyHeight),
651 maxModalBodyHeight = maxModalHeight-(modalHeaderHeight+modalFooterHeight+modalBodyPadding); 652 var iframeHeight = $('.iframe').height(); 653 if (iframeHeight > maxModalBodyHeight){ 654 $('.modal-body').css({'max-height': maxModalBodyHeight, 'overflow-y': 'auto'}); 655 $('.iframe').css('max-height', maxModalBodyHeight-modalBodyPadding); 656 } 657 }).on('hide.bs.modal', function () { 658 $('body').removeClass('modal-open'); 659 $('.modal-body').css({'max-height': 'initial', 'overflow-y': 'initial'}); 660 $('.modalTooltip').tooltip('destroy'); 661 }); 662 }); 663 }); 664 }); 665 666 // product compare 667 $([document, $('#djcatalog')]).on('ready ajaxFilter:loadItems', function(){ 668 var compare_forms = $('form.djc_form_compare'); 669 if (compare_forms.length > 0) { 670 var items = []; 671 672 $.ajax({ 673 url: window.DJC2BaseUrl + '/index.php?option=com_djcatalog2&task=item.getProductsToCompare', 674 type: 'get' 675 }).done(function(data){ 676 var contents; 677 try { 678 contents = JSON.parse(data); 679 } catch(e){ 680 // do nothing 681 return; 682 } 683 for (var i in contents) { 684 if (contents.hasOwnProperty(i)) { 685 items.push(contents[i]); 686 } 687 } 688 689 var checkboxes = $('input[name="item_id_chk"]'); 690 checkboxes.each(function(){ 691 var val = parseInt($(this).val()); 692 693 if ( items.indexOf(val) >= 0 ) { 694 $(this).attr('checked', 'checked'); 695 } else { 696 $(this).removeAttr('checked'); 697 } 698 }); 699 700 if (items.length > 1) { 701 //$('a.djc_compare_btn').css('display', ''); 702 $('a.djc_compare_btn').removeAttr('disabled'); 703 } 704 }); 705 706 compare_forms.each(function(pos) { 707 var el = $(this); 708 709 var checkboxes = el.find('input[name="item_id_chk"]'); 710 checkboxes.change(function(){ 711 var new_value = $(this).is(':checked') ? 'item.addToCompare' : 'item.removeFromCompare'; 712 713 el.find('input[name="task"]').first().val(new_value); 714 el.trigger('submit'); 715 }); 716 717 el.on('submit', function(evt){ 718 719 var post_url = el.attr('action'); 720 if (post_url.indexOf('?') == -1) { 721 post_url = post_url + '?ajax=1'; 722 } else { 723 post_url = post_url + '&ajax=1'; 724 } 725 $.ajax({ 726 url: post_url, 727 type: 'post', 728 data: el.serialize() 729 }).done(function(data){ 730 731 var response = JSON.parse(data); 732 733 if (typeof response.error == 'undefined') { 734 return; 735 } 736
737 var alertContainer = $('<div />', {'class': 'alert djc_alert djc_compare_alert', html: response.message}); 738 739 if (response.error) { 740 var checkBox = el.find('input[name="item_id_chk"]').first(); 741 if (checkBox.is(':checked')) { 742 checkBox.removeAttr('checked'); 743 } else { 744 checkBox.attr('checked', 'checked'); 745 } 746 alertContainer.addClass('alert-error'); 747 748 $(document.body).append(alertContainer); 749 setTimeout(function(){alertContainer.remove();}, 3000); 750 } else { 751 alertContainer.addClass('alert-success'); 752 if ( Object.keys(response.items).length > 1) { 753 //$('a.djc_compare_btn').css('display', ''); 754 $('a.djc_compare_btn').removeAttr('disabled'); 755 } else { 756 //$('a.djc_compare_btn').css('display', 'none'); 757 $('a.djc_compare_btn').attr('disabled', 'disabled'); 758 } 759 } 760 761 }).always(function(){ 762 }); 763 764 return false; 765 }); 766 }); 767 768 compare_forms.css('display', ''); 769 } 770 }); 771 772 // cart pop-up 773 $(document).ready(function(){ 774 var cart_popup = $('<div id="djc_cart_popup" class="modal hide fade">' 775 + '<div class="modal-dialog"><div class="modal-content">' 776 + '<div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-label="close" aria-hidden="true">×</button></div>' 777 + '<div class="modal-body djc_cart_popup">' 778 + '<div></div></div></div>'); 779 var cart_loader = $('<div id="djc_cart_popup_loader" style="display: none"><span></span></div>'); 780 781 $(document.body).append(cart_loader); 782 $(document.body).append(cart_popup); 783 }); 784 785 // cart quantity change events 786 $(document).ready(function(){ 787 var cartUpdateTimeout; 788 789 $('.djc_cart_table input.djc_qty_input').on('keydown', function(evt){ 790 if (evt.which == 9) { 791 clearTimeout(cartUpdateTimeout); 792 } 793 }); 794 795 $('.djc_cart_table input.djc_qty_input').on('change', function(evt, extra){ 796 clearTimeout(cartUpdateTimeout); 797 var input = $(this); 798 var time = evt.type == 'keyup' ? 4500 : 1500; 799 800 if ((evt.type == 'change' && typeof evt.isTrigger == 'undefined') || extra == 'keypress') { 801 return; 802 } 803 804 if (input.val() != '') { 805 cartUpdateTimeout = setTimeout(function(){ 806 input.parents('form').css('opacity', 0.3); 807 input.parents('form').trigger('submit'); 808 }, time); 809 } 810 }); 811 812 $('.djc_cart_table .btn.djc_update_quantity').on('click', function(evt){ 813 evt.preventDefault(); 814 var input = $(this); 815 cartUpdateTimeout = setTimeout(function(){ 816 input.parents('form').css('opacity', 0.3); 817 input.parents('form').trigger('submit'); 818 }, 10); 819 }); 820 }); 821 822 // checkout page, payments and deliveries 823 $(document).ready(function(){ 824 var djc_deliveries = $("input.djc_delivery_method"); 825 var djc_delivery_toggle = $('#jform_djcatalog2delivery_delivery_to_billing'); 826 var djc_delivery_wrapper = $('#djc_delivery_wrapper'); 827 var djc_delivery_fields = $('#djc_delivery_fields'); 828 var djc_delivery_toggle_state = 1; 829 var djc_payments = $("input.djc_payment_method"); 830 var djc_payment_labels = $("label.djc_payment_method"); 831 var shipping_days = jQuery('form#djc_checkout_form #shipping-days'); 832 833 if (djc_delivery_toggle.length > 0){ 834 djc_delivery_toggle_state = djc_delivery_toggle.value; 835 } 836 837 if (djc_deliveries.length > 0) { 838 djc_deliveries.on("change", function(evt){ 839 var delivery_id = this.value; 840 var use_delivery = $(this).attr('data-shippment'); 841 842 if (djc_payments.length > 0) { 843 djc_payments.each(function(position){ 844 var element = $(this); 845 var label = $(djc_payment_labels[position]); 846 var xref = element.attr("data-delivery"); 847 var valid = false; 848 if (xref.length == 0) { 849 valid = true; 850 } else { 851 xref = xref.split(','); 852 for (var i=0; i<xref.length; i++) { 853 if (xref[i] == delivery_id) { 854 valid = true; 855 } 856 } 857 } 858 859 if (valid) { 860 element.css('display', ''); 861 label.css('display', ''); 862 } else { 863 console.log('remove : ' + label.text()); 864 element.removeAttr("checked"); 865 element.css('display', 'none'); 866 label.css('display', 'none'); 867 } 868 }); 869 } 870 871 setTimeout(function(){ 872 DJCatOrderSummary(djc_deliveries, djc_payments, shipping_days.val()); 873 }, 200); 874 875 if (djc_delivery_wrapper.length > 0 && djc_delivery_toggle.length > 0) { 876 if (use_delivery == 1) { 877 if (djc_delivery_toggle_state == 1) { 878 djc_delivery_toggle.value = 1; 879 } else { 880 djc_delivery_toggle.value = 0; 881 } 882 djc_delivery_wrapper.css('display', ''); 883 } else { 884 djc_delivery_toggle.value = 1; 885 djc_delivery_toggle.trigger('change', djc_delivery_toggle); 886 djc_delivery_wrapper.css('display', 'none'); 887 } 888 } 889 }); 890 } 891 892 if (djc_payments.length) { 893 djc_payments.on("change", function(evt){ 894 DJCatOrderSummary(djc_deliveries, djc_payments, shipping_days.val()); 895 }); 896 } 897 898 if (djc_delivery_toggle.length && djc_delivery_fields.length) { 899 djc_delivery_toggle.on('change', function(evt){ 900 if (this.value == 1) { 901 djc_delivery_toggle_state = 1; 902 djc_delivery_fields.css('display', 'none'); 903 djc_delivery_fields.find('input, select, textarea').each(function(){ 904 $(this).attr('disabled', 'disabled'); 905 }); 906 } else { 907 djc_delivery_toggle_state = 0; 908 djc_delivery_fields.css('display', ''); 909 djc_delivery_fields.find('input, select, textarea').each(function(){ 910 $(this).removeAttr('disabled'); 911 }); 912 } 913 914 DJCatUpdateDeliveryMethods(djc_delivery_toggle_state); 915 DJCatUpdatePaymentMethods(djc_delivery_toggle_state); 916 }); 917 } 918 919 if (djc_delivery_toggle.length) { 920 djc_delivery_toggle.trigger('change', djc_delivery_toggle); 921 } 922 923 if (djc_deliveries.length) { 924 djc_deliveries.each(function(){ 925 if (this.checked) { 926 $(this).trigger('change', this); 927 } 928 }); 929 } else if (djc_payments.length) { 930 djc_payments.each(function(){ 931 if (this.checked) { 932 $(this).trigger('change', this); 933 } 934 }); 935 } 936 937 shipping_days.bind('change', function (e) { 938 DJCatOrderSummary(djc_deliveries, djc_payments, shipping_days.val()); 939 }); 940 941 $('#djc_checkout_form').find('.djc_country, .djc_postcode').on('keyup change', function(event){ 942 DJCatUpdateDeliveryMethods(djc_delivery_toggle_state); 943 DJCatUpdatePaymentMethods(djc_delivery_toggle_state); 944 }); 945 }); 946 947 //$(document).ready(function(){ 948 $([document, $('#djcatalog')]).on('ready ajaxFilter:loadItems', function(event){ 949 950 $('input.djc_qty_input').each(function(){ 951 DJCatQty.initWrapper(this); 952 }); 953 954 // add to cart form handler 955 var cart_forms = $('form.djc_form_addtocart'); 956 var cart_popup = $('#djc_cart_popup'); 957 var cart_loader = $('#djc_cart_popup_loader'); 958 959 $('#djc_cart_popup').on('show.bs.modal', function () { 960 var tmpModal = $(this); 961 tmpModal.addClass('show').removeClass('hide').css('display', 'block'); 962 tmpModal.find('[data-dismiss="modal"]').click(function(){ 963 tmpModal.modal('hide'); 964 tmpModal.removeClass('show').removeClass('in').addClass('hide').css('display', 'none'); 965 $('.modal-backdrop').removeClass('show').removeClass('in').remove(); 966 try { 967 tmpModal.modal('dispose'); 968 } catch (e) { 969 // do noting, exception for BS4+ 970 } 971 }); 972 }); 973 974 $('#djc_cart_popup').on('shown.bs.modal', function () {
975 var modalHeight = $('div.modal:visible').outerHeight(true); 976 var padding = document.getElementById('djc_cart_popup').offsetTop; 977 var offset = ($(window).height()-modalHeight) / 2; 978 979 $('#djc_cart_popup').css('top', offset+'px'); 980 $('#djc_cart_popup a').first().focus(); 981 }); 982 983 if (cart_forms.length > 0) { 984 cart_forms.each(function(pos) { 985 var el = $(this); 986 987 if (el.attr('data-noajax') == '1') { 988 return; 989 } else if (el.hasClass('djc_multi_addtocart')) { 990 var submitter = $('form.djc_addtocart_submitter'); 991 if (submitter.length < 1) { 992 return; 993 } 994 var itemId = el.find('input[name="item_id"]').val(); 995 el.find('input.djc_qty_input').change(function(){ 996 var targetInput = submitter.find('input[name="quantity['+itemId+']"]'); 997 var val = $(this).val(); 998 if (val != '' && (parseFloat(val) > 0.0000 || parseInt(val) > 0)) { 999 if (targetInput.length > 0) { 1000 targetInput.val($(this).val()); 1001 } else { 1002 submitter.append($('<input type="hidden" name="quantity['+itemId+']" value="'+$(this).val()+'" />')); 1003 } 1004 } else if (targetInput.length) { 1005 targetInput.remove(); 1006 } 1007 1008 if (submitter.find('input[name^="quantity"]').length > 0) { 1009 submitter.find('[type="submit"]').removeAttr('disabled'); 1010 } else { 1011 submitter.find('[type="submit"]').attr('disabled', 'disabled'); 1012 } 1013 }); 1014 } 1015 1016 if (event.type == 'ajaxFilter:loadItems') { 1017 el.unbind('submit'); 1018 } 1019 el.on('submit', function(evt){ 1020 1021 var valid = true; 1022 1023 if (typeof comboSelector != 'undefined') { 1024 1025 var required_fields = jQuery("[djc-required]"); 1026 1027 1028 required_fields.each(function (index, item) { 1029 1030 var type = jQuery(item).prop("type"); 1031 1032 // Search radio in fieldset 1033 if (type == 'fieldset') { 1034 var radios = jQuery(type).find('input[type=radio]:checked'); 1035 if (radios.length === 0) { 1036 jQuery(item).addClass('djc-invalid'); 1037 valid = false; 1038 } 1039 } else { 1040 if (jQuery(item).val() === '') { 1041 jQuery(item).addClass('djc-invalid'); 1042 valid = false; 1043 } 1044 1045 } 1046 }); 1047 } 1048 1049 if(!valid) { 1050 var invalidCartMsg = Joomla.JText._('COM_DJCATALOG2_ADD_TO_CART_ERROR_COMBINATION_PARAMS_INVALID'); 1051 cart_popup.find('.modal-body > div').first().html(invalidCartMsg); 1052 cart_popup.modal('show'); 1053 return false; 1054 } 1055 1056 cart_loader.css('display', 'block'); 1057 1058 var post_url = el.attr('action'); 1059 if (post_url.indexOf('?') == -1) { 1060 post_url = post_url + '?ajax=1'; 1061 } else { 1062 post_url = post_url + '&ajax=1'; 1063 } 1064 $.ajax({ 1065 url: post_url, 1066 type: 'post', 1067 data: el.serialize() 1068 }).done(function(data){ 1069 //var response = $.parseJSON(data); 1070 var response = JSON.parse(data); 1071 1072 cart_popup.find('.modal-body > div').first().html(response.message); 1073 //cart_popup.css('display', '').removeClass('hide'); 1074 cart_popup.modal('show'); 1075 //cart_popup.addClass('show'); 1076 1077 if (typeof response.basket_count != 'undefined') { 1078 $('strong.djc_mod_cart_items_count').each(function(){ 1079 $(this).html(response.basket_count); 1080 }); 1081 var basket_items = $('.mod_djc2_cart_contents'); 1082 var basket_is_empty = $('.mod_djc2cart_is_empty'); 1083 1084 if (basket_items) { 1085 if (response.basket_count > 0) { 1086 basket_items.css('display', 'block'); 1087 el.trigger('Ajax:itemAdded', response); 1088 } else { 1089 basket_items.css('display', 'none'); 1090 el.trigger('Ajax:itemAdded', response); 1091 } 1092 } 1093 1094 if (basket_is_empty) { 1095 if (response.basket_count > 0) { 1096 basket_is_empty.css('display', 'none'); 1097 } else { 1098 basket_is_empty.css('display', 'block'); 1099 } 1100 } 1101 } 1102 1103 }).always(function(){ 1104 cart_loader.css('display', 'none'); 1105 }); 1106 1107 return false; 1108 }); 1109 1110 }); 1111 } 1112 1113 /*$('#djc_cart_table').parents('form').on('submit', function(event){ 1114 event.preventDefault(); 1115 1116 cart_loader.css('display', 'block'); 1117 1118 var post_url = $(this).attr('action'); 1119 if (post_url.indexOf('?') == -1) { 1120 post_url = post_url + '?ajax=1'; 1121 } else { 1122 post_url = post_url + '&ajax=1'; 1123 } 1124 $.ajax({ 1125 url: post_url, 1126 type: 'post', 1127 data: $(this).serialize(), 1128 dataType: 'html' 1129 }).done(function(data){ 1130 $('#djc_cart_table').replaceWith($(data).find('#djc_cart_table')); 1131 1132 $('input.djc_qty_input').each(function(){ 1133 DJCatQty.initWrapper(this); 1134 }); 1135 1136 var cartUpdateTimeout; 1137 1138 $('.djc_cart_table input.djc_qty_input').on('change keyup', function(evt){
1139 clearTimeout(cartUpdateTimeout); 1140 var input = $(this); 1141 var time = evt.type == 'keyup' ? 4500 : 1500; 1142 if (input.val() != '') { 1143 cartUpdateTimeout = setTimeout(function(){ 1144 //input.parents('form').css('opacity', 0.3); 1145 input.parents('form').trigger('submit'); 1146 }, time); 1147 } 1148 }); 1149 1150 }).always(function(){ 1151 cart_loader.css('display', 'none'); 1152 }); 1153 1154 return false; 1155 });*/ 1156 }); 1157 1158 $([document, $('#djcatalog')]).on('ready ajaxFilter:loadItems', function(){ 1159 if (typeof window.DJCatalog2InitGooglePlaces != 'undefined') { 1160 window.DJCatalog2InitGooglePlaces(); 1161 } 1162 }); 1163 1164 $([document, $('#djcatalog')]).on('ajaxFilter:loadItems', function(){ 1165 DJCatAdvSearch(); 1166 }); 1167 1168 // Wishlist 1169 $([document, $('#djcatalog')]).on('ready ajaxFilter:loadItems', function(){ 1170 var wishlist_btns = $('.djc_addtowishlist_btn[item-id]'); 1171 1172 if(wishlist_btns) { 1173 $.ajax({ 1174 url: window.DJC2BaseUrl + '/index.php?option=com_djcatalog2&task=wish.getWishList', 1175 type: 'get' 1176 }).done(function(data){ 1177 var response = JSON.parse(data); 1178 wishlist_btns.each(function () { 1179 var wish_btn = jQuery(this); // Set pointer 1180 1181 var item_id = wish_btn.attr('item-id'); 1182 1183 if(jQuery.inArray(item_id, response) == -1) 1184 wish_btn.removeClass('disabled'); 1185 }) 1186 }); 1187 } 1188 }); 1189 1190 1191 1192 $('.djc_addtowishlist_btn[item-id]').on('click', function (e) { 1193 e.preventDefault(); 1194 if(!$(this).hasClass('disabled')) { 1195 var item_id = $(this).attr('item-id'); 1196 var wishlist_btn = $(this); 1197 var cart_popup = $('#djc_cart_popup'); 1198 1199 if(item_id) { 1200 $.ajax({ 1201 url: window.DJC2BaseUrl + '/index.php?option=com_djcatalog2&task=wish.add&item_id=' + item_id, 1202 type: 'get' 1203 }).done(function(data){ 1204 var response = JSON.parse(data); 1205 if(response.status) 1206 wishlist_btn.toggleClass('disabled'); 1207 cart_popup.find('.modal-body > div').first().html(response.message); 1208 cart_popup.modal('show'); 1209 }); 1210 } 1211 } 1212 1213 return false; 1214 }) 1215 }); 1216})(jQuery); 1217 1218jQuery(window).on('load', function(){ 1219 DJCatMatchBackgrounds(); 1220 1221 var tabHash = window.location.hash; 1222 1223 var tabTogglers = jQuery('.djc_tabs li.nav-toggler'); 1224 var tabPanels = jQuery('.djc_tabs .tab-pane'); 1225 1226 if (tabTogglers.length) { 1227 1228 tabTogglers.each(function(index){ 1229 var tab = jQuery(this); 1230 tab.on('click', 'a', function(e){ 1231 e.preventDefault(); 1232 tab.siblings().removeClass('active'); 1233 tab.addClass('active'); 1234 jQuery(tabPanels[index]).siblings().removeClass('active'); 1235 jQuery(tabPanels[index]).addClass('active'); 1236 }); 1237 1238 // open tab from url hash 1239 if (this.id && ('#' + this.id) == decodeURIComponent(tabHash)) { 1240 tab.find('a').trigger('click'); 1241 } 1242 }); 1243 } 1244 1245 var accTogglers = jQuery('.djc_tabs .accordion-toggle'); 1246 1247 if (accTogglers.length) { 1248 1249 accTogglers.each(function(index){ 1250 var acc = jQuery(this); 1251 acc.on('click', function(e){ 1252 //e.preventDefault(); 1253 accTogglers.removeClass('active'); 1254 acc.addClass('active'); 1255 }); 1256 1257 if (acc.attr('data-collapseid') && ('#' + acc.attr('data-collapseid')) == decodeURIComponent(tabHash)) { 1258 acc.trigger('click'); 1259 } 1260 }); 1261 } 1262 1263 var filterModules = jQuery('.mod_djc2filters'); 1264 if (filterModules.length > 0) { 1265 filterModules.each(function(){ 1266 var togglers = jQuery(this).find('.djc_tab_toggler'); 1267 var contents = jQuery(this).find('.djc_tab_content'); 1268 1269 if (togglers.length) { 1270 1271 togglers.each(function(index){ 1272 var toggler = jQuery(this); 1273 toggler.on('click', function(e){ 1274 if(toggler.hasClass('active')) return false;
1275 togglers.removeClass('active'); 1276 toggler.addClass('active'); 1277 contents.slideUp(); 1278 jQuery(contents[index]).slideDown(); 1279 }); 1280 if(index == 0) { 1281 toggler.addClass('active'); 1282 } else { 1283 jQuery(contents[index]).hide(); 1284 } 1285 }); 1286 } 1287 }); 1288 } 1289}); 1290 1291jQuery(window).on('resize', function(){ 1292 DJCatMatchBackgrounds(); 1293}); 1294
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.