1BX.namespace("BX.Sale"); 2BX.Sale.GiftMainProductsClass = (function () { 3 var GiftMainProductsClass = function (parameters) { 4 this.ajaxUrl = "/bitrix/components/bitrix/sale.gift.main.products/ajax.php"; 5 this.contextAjaxData = parameters.contextAjaxData || {}; 6 this.mainProductState = parameters.mainProductState || null; 7 this.injectId = parameters.injectId || null; 8 this.isGift = !!parameters.isGift; 9 this.productId = parameters.productId; 10 this.offerId = parameters.offerId; 11 this.offers = parameters.offers || []; 12 13 this.setEvents(); 14 15 //detect #as_gift 16 if (document.location.hash.match(/as_gift/g)) { 17 if (this.isGift) { 18 this.enableGift(); 19 } else { 20 this.raiseNonGiftEvent(); 21 } 22 } 23 BX.bindDelegate( 24 BX(this.injectId), 25 "click", 26 { tagName: "a" }, 27 BX.proxy(this.clickNavLink, this) 28 ); 29 }; 30 31 GiftMainProductsClass.prototype.clickNavLink = function (e) { 32 if (this.onPageNavigationByLink(BX.proxy_context)) { 33 return BX.PreventDefault(e); 34 } 35 }; 36 37 GiftMainProductsClass.prototype.setEvents = function () { 38 BX.addCustomEvent( 39 "onCatalogStoreProductChange", 40 BX.proxy(this.onCatalogStoreProductChange, this) 41 ); 42 BX.addCustomEvent( 43 "onAddToBasketMainProduct", 44 BX.proxy(this.onAddToBasketMainProduct, this) 45 ); 46 }; 47 48 GiftMainProductsClass.prototype.unsubscribeEvents = function () { 49 BX.removeCustomEvent( 50 "onCatalogStoreProductChange", 51 BX.proxy(this.onCatalogStoreProductChange, this) 52 ); 53 }; 54 55 GiftMainProductsClass.prototype.onAddToBasketMainProduct = function ( 56 productObject 57 ) { 58 this.enableGift(); 59 }; 60 61 GiftMainProductsClass.prototype.onCatalogStoreProductChange = function ( 62 offerId 63 ) { 64 if (offerId == this.offerId) { 65 return; 66 } 67 if ($(this.injectId).length) { 68 BX.ajax({ 69 url: this.ajaxUrl, 70 method: "POST", 71 data: BX.merge(this.contextAjaxData, { 72 offerId: offerId, 73 mainProductState: this.mainProductState, 74 SITE_ID: BX.message("SITE_ID"), 75 }), 76 dataType: "html", 77 processData: false, 78 start: true, 79 onsuccess: BX.delegate(function (html) { 80 this.offerId = offerId; 81 var ob = BX.processHTML(html); 82 if (!ob.HTML) { 83 if (document.location.hash.match(/as_gift/g)) { 84 //raise event from previous state. It's trick. 85 if (this.isGift) { 86 this.raiseGiftEvent(); 87 } else { 88 this.raiseNonGiftEvent(); 89 } 90 } 91 92 return; 93 } 94 this.unsubscribeEvents(); 95 96 BX(this.injectId).innerHTML = ob.HTML; 97 BX.ajax.processScripts(ob.SCRIPT); 98 }, this), 99 }); 100 } 101 }; 102 103 GiftMainProductsClass.prototype.onPageNavigationByLink = function (link) { 104 var isValidNavigationLink = BX.delegate(function (link) { 105 if (!BX.type.isElementNode(link) || !link.href) { 106 return false; 107 } 108 if (link.href.indexOf(this.ajaxUrl) >= 0) { 109 return true; 110 } 111 return link.href.indexOf("PAGEN_") !== -1; 112 }, this); 113 114 if (!isValidNavigationLink(link)) { 115 return false; 116 } 117 118 BX.ajax({ 119 url: link.href, 120 method: "POST", 121 data: BX.merge(this.contextAjaxData, { SITE_ID: BX.message("SITE_ID") }), 122 dataType: "html", 123 processData: false, 124 start: true, 125 onsuccess: BX.delegate(function (html) { 126 var ob = BX.processHTML(html); 127 if (!ob.HTML) { 128 return; 129 } 130 this.unsubscribeEvents(); 131 132 BX(this.injectId).innerHTML = ob.HTML; 133 BX.ajax.processScripts(ob.SCRIPT); 134 }, this), 135 }); 136 137 return true; 138 }; 139 140 GiftMainProductsClass.prototype.enableGift = function () { 141 this.isGift = true; 142 this.raiseGiftEvent(); 143 }; 144 145 GiftMainProductsClass.prototype.raiseGiftEvent = function () { 146 BX.onCustomEvent("onSaleProductIsGift", [this.productId, this.offerId]); 147 }; 148 149 GiftMainProductsClass.prototype.raiseNonGiftEvent = function () { 150 BX.onCustomEvent("onSaleProductIsNotGift", [this.productId, this.offerId]); 151 }; 152 153 return GiftMainProductsClass; 154})();
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.