1MstBase.Shop = newClass(null, { 2 templateName : "basket", 3 4 constructor : function(options) 5 { 6 options = options || {}; 7 $.extend(this, options); 8 }, 9 10 AddToBasket : function(ob, elemId, priceCode) 11 { 12 if (!priceCode) priceCode = "RETAIL"; 13 $.ajax({ 14 context: this, 15 type: "POST", 16 dataType: "html", 17 url: "/bitrix/mst/ajax.php", 18 data: {"comp": "mst:catalog.cart.small", "action" : "addtobasket", "template" : this.templateName, "elementId" : elemId, "price" : priceCode}, 19 complete :function() { window.Mst.Functions && Mst.Functions.Loader(false); }, 20 beforeSend:function() { window.Mst.Functions && Mst.Functions.Loader(true); }, 21 success: function(data) 22 { 23 this.OnBasketAddSuccess(data, {object: ob}); 24 } 25 }); 26 }, 27 28 OnBasketAddSuccess : function(data, params) {}, 29 30 UpdateBasket : function(ob, elemId, quantity) 31 { 32 $.ajax({ 33 context: this, 34 type: "POST", 35 dataType: "html", 36 url: "/bitrix/mst/ajax.php", 37 data: {"comp": "mst:catalog.cart.small", "action" : "change", "quantity" : quantity, "template" : this.templateName, "elementId" : elemId}, 38 complete :function() { Mst.Functions.Loader(false); }, 39 beforeSend:function() { Mst.Functions.Loader(true); }, 40 success: function(data) 41 { 42 this.OnBasketUpdateSuccess(data); 43 } 44 }); 45 }, 46 47 OnBasketUpdateSuccess : function(data, params) {}, 48 49 DeleteFromBasket : function(ob, elemId) 50 { 51 $.ajax({ 52 context: this, 53 type: "POST", 54 dataType: "html", 55 url: "/bitrix/mst/ajax.php", 56 data: {"comp": "mst:catalog.cart.small", "action" : "delete", "template" : this.templateName, "elementId" : elemId}, 57 complete :function() { Mst.Functions.Loader(false); }, 58 beforeSend:function() { Mst.Functions.Loader(true); }, 59 success: function(data) 60 { 61 this.OnBasketDeleteSuccess(data, {object: ob}); 62 } 63 }); 64 }, 65 66 OnBasketDeleteSuccess : function(data, params) {}, 67 68 ChangeQuantity : function(ob, elemId){ 69 var curVal = parseInt($(ob).val()); 70 if (curVal != 0) 71 { 72 if (isNaN(curVal) || curVal < 1) 73 { 74 curVal = 1; 75 } 76 $(ob).val(curVal); 77 78 this.UpdateBasket(ob, elemId, curVal); 79 } 80 else 81 { 82 this.DeleteFromBasket(ob, elemId); 83 } 84 }, 85 86 ShowBasket : function() { 87 $.ajax({ 88 context: this, 89 type: "POST", 90 dataType: "html", 91 url: "/bitrix/mst/ajax.php", 92 data: {"comp": "mst:catalog.cart.small", "action" : "none", "template" : this.templateName}, 93 complete :function() { Mst.Functions.Loader(false); }, 94 beforeSend:function() { Mst.Functions.Loader(true); }, 95 success: function(data) 96 { 97 obShop.ShowCartPopup(data); 98 99 100 } 101 }); 102 }, 103 104 ShowCartPopup : function(data) { 105 var options = { 106 templateID: "messageTemplate", 107 needCover: true, 108 timeOut : false, 109 posX: "center", 110 posY: "center", 111 popupId : "basketPopup", 112 data: {content: data, specialClass: "basketPopup"} 113 }; 114 115 popupWindow = new Mst.Popup(options); 116 popupWindow.show(); 117 }, 118 119 ShowPreOrderPopup : function(data) { 120 var options = { 121 templateID: "messageTemplate", 122 needCover: true, 123 timeOut : false, 124 posX: "center", 125 posY: "center", 126 popupId : "basketPopup", 127 data: {content: data, specialClass: "preOrder"} 128 }; 129 130 popupWindow = new Mst.Popup(options); 131 popupWindow.show(); 132 }, 133 134 AddToWishList : function(ob, elemId, priceCode, reload) 135 { 136 if (!priceCode) priceCode = "RETAIL"; 137 $.ajax({ 138 context: this, 139 type: "GET", 140 dataType: "html", 141 url: "/bitrix/mst/ajax.php", 142 data: {"comp": "mst:catalog.cart.small", "action" : "addtowishlist", "elementId" : elemId, "template" : "wishlist", price : priceCode}, 143 complete :function() { Mst.Functions.Loader(false); }, 144 beforeSend:function() { Mst.Functions.Loader(true); }, 145 success: function(data) 146 { 147 this.ReplaceSmallWishlist(data); 148 this.ReplaceWishListButtonText(ob); 149 } 150 }); 151 }, 152 153 ReplaceSmallWishlist : function(data) {}, 154 ReplaceWishListButtonText : function(ob) {}, 155 156 ShowWishlistEmpty : function() { 157 var options = { 158 //afterHideHandler : function() {window.location = "/";} 159 templateID: "messageTemplate", 160 needCover: true, 161 timeOut : false, 162 posX: "center", 163 posY: "center", 164 data: {content: $( "#popupWishListEmpty" ).tmpl().html()} 165 }; 166 167 popupWindow = new Mst.Popup(options); 168 popupWindow.show(); 169 } 170}); 171 172Mst.Shop = newClass(MstBase.Shop, { 173 WishData : null, 174 basket : null, 175 176 addToCartSelector : ".add2cart", //ÑелекÑÐ¾Ñ ÐºÐ¾Ð½ÑÑола Ð´Ð¾Ð±Ð°Ð²Ð»ÐµÐ½Ð¸Ñ Ð² коÑзин
176Ñ 177 canBuyClass : "allow-buy", //клаÑÑ, коÑоÑÑй пÑиÑÑÑÑÑвÑÐµÑ Ð² кнопки добавлениÑ, ÑигнализиÑÑÑÑий о Ñом, ÑÑо ÑооÑв. ÑÐ¾Ð²Ð°Ñ Ð¼Ð¾Ð¶Ð½Ð¾ кÑпиÑÑ 178 itemParentWithIdSelector : ".ui_element_id", //ÑелекÑоÑ, коÑоÑÑй ÑодеÑÐ¶Ð¸Ñ id, ÑооÑвеÑÑÑвÑÑÑее иденÑеÑикаÑоÑÑ ÑоваÑа 179 idPrefLen : 2, //длинна пÑеÑикÑа Ñ id, поÑле коÑоÑого ÑледÑÐµÑ Ð¸Ð´ÐµÐ½ÑеÑикаÑÐ¾Ñ ÑоваÑа (веÑÑ Ð¿ÑеÑÐ¸ÐºÑ Ð¸Ð³Ð½Ð¾ÑиÑÑеÑÑÑ) 180 181 removeFromCartSelector : ".removeItem", //ÑелекÑÐ¾Ñ ÐºÐ¾Ð½ÑÑола ÑÐ´Ð°Ð»ÐµÐ½Ð¸Ñ ÑлеменÑа из коÑÐ·Ð¸Ð½Ñ 182 smallCartSelector : "#smallCart", //ÑелекÑÐ¾Ñ Ð¼Ð°Ð»ÐµÐ½Ñкой коÑÐ·Ð¸Ð½Ñ 183 smallWishListSelector : "#smallWish", //ÑелекÑÐ¾Ñ Ð¼Ð°Ð»ÐµÐ½Ñкого WishList-а 184 newWishListBtnSelector : "#newWishListBtn",//ÑелекÑÐ¾Ñ ÑлеменÑа, коÑоÑÑй ÑодеÑÐ¶Ð¸Ñ Ð½Ð¾Ð²Ñй ÑекÑÑ ÐºÐ½Ð¾Ð¿ÐºÐ¸ "ÐобавиÑÑ Ð² избÑанное" 185 popupCartContentSelector : ".buy_product", 186 187 showCartSelector : ".ui_showCart", //ÑелекÑÐ¾Ñ ÐºÐ½Ð¾Ð¿ÐºÐ¸ оÑобÑÐ°Ð¶ÐµÐ½Ð¸Ñ ÐºÐ¾ÑÐ·Ð¸Ð½Ñ 188 189 lastValidQuantity : null,//иÑполÑзÑеÑÑÑ Ð´Ð»Ñ Ð·Ð°Ð¿Ð¾Ð¼Ð¸Ð½Ð°Ð½Ð¸Ñ Ð¿Ð¾Ñледнего коÑÑеÑного колиÑеÑÑва пÑи обÑабоÑке оÑибок ввода 190 parent : null,//ÑÑÑлка на ÑодиÑелÑÑкий клаÑÑ 191 192 constructor : function(options) 193 { 194 parentConstructor(this, options); 195 this.parent = this.constructor.prototype; 196 }, 197 198 ShowCartPopup : function(data) { 199 this.parent.ShowCartPopup.call(this, data); 200 this.lastValidQuantity = $(".cartItemCount").find("input").val(); 201 }, 202 203 204 205 Init : function() 206 { 207 208 var localObj = this; 209 210 $(this.addToCartSelector + "." + this.canBuyClass).live("click", function(event){ 211 event.preventDefault(); 212 var parent = localObj.getParentForElem(this); 213 var elID = localObj.getIdForElement(this); 214 var priceCode = parent.find(".hiddenPriceCode").val(); 215 if (elID){ 216 localObj.AddToBasket(this, elID, priceCode); 217 } 218 }); 219 220 $(this.removeFromCartSelector).live("click", function(event){ 221 event.preventDefault(); 222 var elID = parseInt($(this).parent().attr("id")); 223 if (elID){ 224 localObj.DeleteFromBasket(this, elID); 225 } 226 }); 227 228 $(".add2wish").live("click", function(event){ 229 event.preventDefault(); 230 var parent = localObj.getParentForElem(this); 231 var elID = localObj.getIdForElement(this); 232 233 // var parent = $(this).closest(".ui_element_id"); 234 // var elID = parseInt(parent.attr("id").substring(2)); 235 236 var priceCode = parent.find(".hiddenPriceCode").val(); 237 if (elID){ 238 localObj.AddToWishList(this, elID, priceCode); 239 } 240 }); 241 242 /* $(".add2wish.reload").live("click", function(event){ 243 event.preventDefault(); 244 var parent = $(this).closest(".ui_element_id"); 245 var elID = parseInt(parent.attr("id").substring(2)); 246 var priceCode = parent.find(".hiddenPriceCode").val(); 247 if (elID){ 248 localObj.AddToWishList(this, elID, priceCode, true); 249 } 250 }); */ 251 252 $(".cartItemCount").find("input").live("blur", function(event){ 253 event.preventDefault(); 254 if (this.value.match(/^[^1-9]/)) 255 { 256 if (localObj.lastValidQuantity) 257 { 258 this.value = localObj.lastValidQuantity; 259 } 260 return; 261 } 262 var elID = parseInt($(this).parent().attr("id")); 263 if (elID){ 264 localObj.ChangeQuantity(this, elID); 265 } 266 localObj.lastValidQuantity = this.value 267 }); 268 269 $(".closeBtn").live("click", function(){ 270 popupWindow.hide(); 271 }) 272 $('.popupCover').live('click', function() { 273 popupWindow.hide(); 274 }); 275 276 $(".showCart").live("click", function(event){ 277 event.preventDefault(); 278 localObj.ShowBasket(); 279 }); 280 281 $(this.showCartSelector).live("click", function(e) { 282 e.preventDefault(); 283 localObj.ShowBasket(); 284 }); 285 }, 286 287 getIdForElement : function (elem) 288 { 289 return this.getParentForElem(elem).attr("id").substr(this.idPrefLen); 290 }, 291 292 getParentForElem : function(elem) 293 { 294 return $(elem).closest(this.itemParentWithIdSelector); 295 }, 296 297 OnBasketAddSuccess : function(data, params) { 298 $(params.object).text(obMessage.InCart); 299 obShop.ShowCartPopup(data); 300 301 this.ReplaceSmallBasket($("#cartReplacement").html()); 302 }, 303 304 OnBasketUpdateSuccess : function(data, params) { 305 $("#jsPopup").find(this.popupCartContentSelector).html(data); 306 this.ReplaceSmallBasket($("#cartReplacement").html()); 307 }, 308 309 OnBasketDeleteSuccess : function(data, params) { 310 var btn = $("#id" + parseInt($(params.object).attr("id")) ).find(".add2cart"); 311 if (btn.length) { 312 btn.text(obMessage.Buy); 313 } 314 $("#jsPopup").find(this.popupCartContentSelector).html(data); 315 this.ReplaceSmallBasket($("#cartReplacement").html()); 316 }, 317 318 ReplaceSmallBasket : function(data) 319 { 320 $(this.smallCartSelector).html(data); 321 }, 322 323 ReplaceSmallWishlist : function(data) 324 { 325 $(this.smallWishListSelector).replaceWith(data); 326 }, 327 328 ReplaceWishListButtonText : function(ob) 329 { 330 $(ob).text($(this.newWishListBtnSelector).text()); 331 $(this.newWishListBtnSelector).empty(); 332 } 333 334}); 335 336/** Так как некоÑоÑÑе клаÑÑÑ Ð½Ðµ иÑпоÑзÑÑÑ Ð¾Ð¿Ñии (не ÑÑебÑÑÑ Ð¿Ð¾Ð²ÑоÑной иниÑиализаÑии), Ñоздаем Ð¸Ñ Ð³Ð»Ð¾Ð±Ð°Ð
336»Ñно */ 337var obShop = new Mst.Shop(); 338 339Mst.CompareList = { 340 341 elementClass : "ui_element_id", //DOM-ÑÐ»ÐµÐ¼ÐµÐ½Ñ ÑÑого клаÑÑа должен ÑодеÑжаÑÑ Ð°ÑÑÑибÑÑ id, ÑооÑвеÑÑÑвÑÑÑий иденÑеÑикаÑоÑÑ ÑлеменÑа каÑалога 342 btnClass : "ui_compare-btn", //клаÑÑ DOM-ÑлеменÑа, на коÑоÑÑй веÑаеÑÑÑ Ð¾Ð±ÑабоÑÑик по добавлениÑ/ÑÐ´Ð°Ð»ÐµÐ½Ð¸Ñ Ð¸Ð· ÑпиÑка Ð´Ð»Ñ ÑÑÐ°Ð²Ð½ÐµÐ½Ð¸Ñ 343 btnRemoveClass : "ui_compare-remove", //клаÑÑ, коÑоÑÑй ÑодеÑжиÑÑÑ Ñ ÐºÐ½Ð¾Ð¿ÐºÐ¸ ÑÐ´Ð°Ð»ÐµÐ½Ð¸Ñ Ð¸Ð· ÑпиÑка ÑÑÐ°Ð²Ð½ÐµÐ½Ð¸Ñ 344 compareBlockId : "ui_compare-small", // id DOM-ÑлеменÑа, коÑоÑÑй ÑодеÑÐ¶Ð¸Ñ ÑпиÑок ÑлеменÑов в ÑÑавнении 345 newBtnContainerId : "new-btn", // в оÑвеÑе на AJAX запÑÐ¾Ñ ÑдалениÑ/Ð´Ð¾Ð±Ð°Ð²Ð»ÐµÐ½Ð¸Ñ Ð±ÑÐ´ÐµÑ Ð¸ÑкаÑÑÑ ÑÐ»ÐµÐ¼ÐµÐ½Ñ Ñ Ð·Ð°Ð´Ð°Ð½Ð½Ñм аÑÑибÑÑом, его ÑодеÑжимÑм бÑÐ´ÐµÑ Ð·Ð°Ð¼ÐµÐ½ÐµÐ½Ð° кнопка, по коÑоÑой бÑл оÑпÑавлен запÑÐ¾Ñ Ð½Ð° добавление/Ñдаление 346 compareMsgClass : "compare-btn-msg", //клаÑÑ DOM-ÑлеменÑа, ÑодеÑжаÑий ÑекÑÑ ÑообÑÐµÐ½Ð¸Ñ Ð¾Ð± ÑÑпеÑном Ñдалении/добавлении 347 348 349 addToListHandler : function(eventSender) 350 { 351 //@todo обÑабоÑÐºÑ Ð¾Ñибок, когда id не найдено 352 id = parseInt($(eventSender).closest("." + this.elementClass).attr("id").substring(2)) 353 354 /** еÑли кнопка Ð¸Ð¼ÐµÐµÑ ÐºÐ»Ð°ÑÑ, оÑвеÑаÑÑей кнопке ÑдалениÑ, оÑпÑавлÑем запÑÐ¾Ñ Ð½Ð° Ñдаление, инаÑе - на добавление */ 355 action = $(eventSender).hasClass(this.btnRemoveClass) ? "RemoveFromList" : "AddToList"; 356 thisOb = this 357 $.ajax({ 358 context : this, 359 type: "GET", 360 url: "/bitrix/mst/ajax.php", 361 data: {"comp": "mst:catalog.compare", "template" : "small", "action" : action, "id": id}, 362 complete :function() { Mst.Functions.Loader(false); }, 363 beforeSend:function() { Mst.Functions.Loader(true); }, 364 success: function(data){ 365 /** оÑиÑаем ÑÑаÑÑе ÑообÑение об ÑÑпеÑном Ñдалении/добавлении */ 366 $("." + this.compareMsgClass).empty() 367 /** вÑÑавлÑем новÑй код блока Ñ ÐºÑаÑким ÑпиÑком */ 368 $("#" + this.compareBlockId).replaceWith(data) 369 /** полÑÑаем новÑй код кнопки добавлениÑ/ÑÐ´Ð°Ð»ÐµÐ½Ð¸Ñ */ 370 newBtnHtml = $("#new-btn").html() 371 /** кнопка, вÑзвавÑÐ°Ñ ÑÑÐ¾Ñ Ð¾Ð±ÑабоÑÑик заменÑеÑÑÑ Ð½Ð° новÑй полÑÑеннÑй код кнопки */ 372 $("#id"+id+" ."+this.btnClass).replaceWith(newBtnHtml) 373 /** ÑлеменÑ, ÑодеÑжаÑий код новой кнопки ÑдалÑеÑÑÑ */ 374 $("#" + this.newBtnContainerId).empty() 375 } 376 }); 377 }, 378 379 Init : function() 380 { 381 $("." + Mst.CompareList.btnClass).live("click", function(e) 382 { 383 e.preventDefault(); 384 Mst.CompareList.addToListHandler(this) 385 }) 386 } 387} 388 389Mst.CurrencySelector = { 390 391 selectorId : "currency-select", 392 393 changeCurrencyHandler : function() 394 { 395 var newCurr = $("#" + this.selectorId).val() 396 $.ajax({ 397 type: "GET", 398 url: "/bitrix/mst/ajax.php", 399 data: {"comp": "mst:currency.selector", "template" : ".default", "newCurr": newCurr}, 400 complete :function() { Mst.Functions.Loader(false); }, 401 beforeSend:function() { Mst.Functions.Loader(true); }, 402 success: function(data){ 403 location.reload() 404 } 405 }); 406 407 }, 408 409 Init : function() 410 { 411 var thisOb = this 412 $("#" + this.selectorId).live("change", function(){thisOb.changeCurrencyHandler()}) 413 } 414 415} 416 417 418$(document).ready(function(){ 419 obShop.Init(); 420 Mst.CompareList.Init() 421 Mst.CurrencySelector.Init() 422});
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.