1site.basket = {}; 2 3site.basket.replace = function(id) { 4 if (id == 'all') { 5 jQuery('a[id^="add_basket_"]').each(function() { 6 $(this).text(i18n.basket_add_button) 7 jQuery('.basket_info_summary').text(i18n.basket_empty); 8 }); 9 } 10 return function(e) { 11 var text, discount, goods_discount_price, goods_discount, item_total_price, item_discount, cart_item, basket, i, item, related_goods, 12 cart_summary = jQuery('.cart_summary'), 13 cart_discount = jQuery('.cart_discount'), 14 goods_discount_price = jQuery('.cart_goods_discount'), 15 rem_item = true, 16 detect_options = {}; 17 18 if (e.summary.amount > 0) { 19 text = e.summary.price.actual; 20 goods_discount = ((typeof e.summary.price.original == 'undefined') ? e.summary.price.actual : e.summary.price.original); 21 discount = ((typeof e.summary.price.discount != 'undefined') ? e.summary.price.discount : '0'); 22 for (i in e.items.item) { 23 item = e.items.item[i]; 24 if (item.id == id) { 25 rem_item = false; 26 item_total_price = item["total-price"].actual; 27 item_discount = ((typeof item.discount != 'undefined') ? item.discount.amount : '0'); 28 } 29 if (item.page.id == id) { 30 if (detect_options.amount) { 31 detect_options.amount = detect_options.amount + item.amount; 32 } 33 else detect_options = {'id':id, 'amount':item.amount}; 34 } 35 } 36 if (detect_options.amount) { 37 var add_basket_button = jQuery('#add_basket_' + detect_options.id); 38 if (add_basket_button[0].tagName.toUpperCase() == 'A' && !site.basket.is_cart) { 39 add_basket_button.text(i18n.basket_add_button + ' (' + detect_options.amount + ')'); 40 } 41 if (add_basket_button[0].tagName.toUpperCase() == 'FORM') { 42 add_basket_button = jQuery('input:submit', add_basket_button); 43 add_basket_button.val(i18n.basket_add_button + ' (' + detect_options.amount + ')'); 44 } 45 else add_basket_button.val(i18n.basket_add_button + ' (' + detect_options.amount + ')'); 46 } 47 if (rem_item) { 48 if (cart_item = jQuery('.cart_item_' + id)) { 49 if(related_goods = jQuery('.cart_item_' + id + ' + tr.related-goods')) { 50 related_goods.remove(); 51 } 52 cart_item.remove(); 53 cart_summary.text(text); 54 cart_discount.text(discount); 55 goods_discount_price.text(goods_discount); 56 jQuery('.basket tr').removeClass('even'); 57 jQuery('tr[class^="cart_item_"]:odd').addClass('even'); 58 jQuery('tr[class^="cart_item_"]:odd + .related-goods').addClass('even'); 59 } 60 } 61 else { 62 jQuery('.cart_item_price_' + id).text(item_total_price); 63 jQuery('.cart_item_discount_' + id).text(item_discount); 64 cart_summary.text(text); 65 cart_discount.text(discount); 66 goods_discount_price.text(goods_discount); 67 } 68 text = e.summary.amount + i18n.basket_items_total + (e.summary.price.prefix||'') + ' ' + text + ' ' + (e.summary.price.suffix||''); 69 } 70 else { 71 text = i18n.basket_empty; 72 if (basket = jQuery('.basket')) { 73 basket.html(i18n.basket_empty_html); 74 } 75 } 76 jQuery('.basket_info_summary').text(text); 77 site.basket.modify.complete = true; 78 }; 79}; 80 81/*site.basket.add = function(id, form, popup) { 82 var e_name, options = {}; 83 if (form) { 84 var elements = jQuery(':radio:checked', form); 85 for (var i = 0; i < elements.length; i++) { 86 e_name = elements[i].name.replace(/^options\[/, '').replace(/\]$/, ''); 87 options[e_name] = elements[i].value; 88 } 89 } 90 basket.putElement(id, options, this.replace(id)); 91 if (popup) { 92 site.message.close(jQuery('#add_options_' + id), jQuery('.overlay')) 93 } 94};*/ 95 96site.basket.list = function(link) { 97 var oneClick = false; 98 var id = (link.id.indexOf('add_basket') != -1) ? link.id.replace(/^add_basket_/, '') : false; 99 if (!id) { 100 oneClick = true; 101 id = (link.id.indexOf('one_click') != -1) ? link.id.replace(/^one_click_/, '') : link; 102 } 103 if (!id) return false; 104 if (jQuery(link).hasClass('options_true')) { 105 var url = '/upage//' + id + '?transform=modules/catalog/popup-add-options.xsl'; 106 if (oneClick) { 107 url = '/upage//' + id + '?transform=modules/catalog/popup-add-options-oneclick.xsl'; 108 } 109 if (jQuery('#add_options_' + id).length == 0) { 110 jQuery.ajax({ 111 url: url, 112 dataType: 'html', 113 success: function (data) { 114 site.message({ 115 id: 'add_options_' + id, 116 header: i18n.basket_options, 117 width: 400, 118 content: data, 119 async: false 120 }); 121 var form = jQuery('form.options'); 122 form.append('<input type="submit" class="button" value="'+ i18n.basket_add_short +'" />'); 123 form.submit(function() {
124 if (!site.basket.is_cart && !oneClick) { 125 site.basket.add(id, this, true); 126 } else if(!site.basket.is_cart && oneClick) { 127 site.basket.oneClick(id, this); 128 site.message.close(jQuery('#add_options_' + id), jQuery('.overlay')) 129 } 130 return false; 131 }); 132 } 133 }); 134 } 135 } 136 else if(!oneClick) { 137 this.add(id); 138 } else { 139 site.basket.oneClick(id); 140 } 141}; 142 143site.basket.modify = function(id, amount_new, amount_old) { 144 if (amount_new.replace(/[\d]+/) == 'undefined' && amount_new != amount_old) { 145 basket.modifyItem(id, {amount:amount_new}, this.replace(id)); 146 var sum=0; 147 $('table input[type="hidden"]').each(function(){ 148 sum += parseFloat($(this).val()); 149 }); 150 $('.amount').html(sum); 151 } 152 else this.modify.complete = true; 153}; 154 155site.basket.modify.complete = true; 156 157site.basket.remove = function(id) { 158 if (id == 'all') basket.removeAll(this.replace(id)); 159 else basket.removeItem(id, this.replace(id)); 160}; 161 162site.basket.oneClick = function(id, form) { 163 var option = $(form).find('input[type="radio"]:checked'); 164 var optional; 165 if (option.length > 0) { 166 optional = '?' + option.attr('name') + '=' + $(form).find('input[type="radio"]:checked').val() 167 } else { 168 optional = ''; 169 } 170 171 var locale = location.pathname; 172 var lang = locale.substring(1,locale.substring(1).indexOf('/')+1); 173 174 jQuery.ajax({ 175 url: '/udata/emarket/createForm/emarket-purchase-oneclick?transform=modules/catalog/one-click.xsl&lang=' + lang, 176 dataType: 'html', 177 success: function (data) { 178 site.message({ 179 id: 'one_click_popup_' + id, 180 header: i18n.oneclick_checkout, 181 width: 400, 182 content: data, 183 async: false 184 }); 185 var form = jQuery('form.buyer_data'); 186 form.attr('action', form.attr('action') + 'element/' + id + '.xml' + optional) 187 form.append('<div><input type="submit" class="button big" value="' + i18n.checkout + '" /></div>'); 188 form.submit(function() { 189 var xml = site.basket.sendForm(form).responseXML; 190 191 form.closest('.content').find('.error').remove(); 192 $(xml).find('error').each( 193 function() { 194 form.closest('div').prepend('<div class="error">' + $(this).text() + '</div>'); 195 } 196 ); 197 198 form.closest('.content').find('.success').remove(); 199 if ($(xml).find('orderId').length > 0) { 200 site.basket.replace('all'); 201 form.closest('div').prepend('<div class="success"><div><p>' + i18n.finish_message_prefix + '<strong>#' + $(xml).find('orderId').eq(0).text() + '</strong>' + i18n.finish_message_postfix + '</p></div><a class="button big close">' + i18n.continue + '</a></div>'); 202 form.remove(); 203 } 204 205 return false; 206 }); 207 } 208 }); 209} 210 211site.basket.sendForm = function(form) { 212 return jQuery.ajax({ 213 url: form.attr('action'), 214 dataType: 'xml', 215 method: form.attr('method'), 216 data: form.serialize(), 217 async: false, 218 success: function (data) { 219 return data; 220 } 221 }); 222} 223 224site.basket.init = function() { 225 this.is_cart = (!!jQuery('.basket table').length); 226 jQuery('.basket_list').click(function(){ 227 if (!site.basket.is_cart || !jQuery(this).hasClass('options_false')) { 228 site.basket.list(this); 229 return false; 230 } 231 }); 232 jQuery('form.options').submit(function(){ 233 var id = (this.id.indexOf('add_basket') != -1) ? this.id.replace(/^add_basket_/, '') : this; 234 site.basket.add(id, this); 235 return false; 236 }); 237 jQuery('div.basket a.del').click(function(){ 238 site.basket.remove(this.id.match(/\d+/).pop()); 239 return false; 240 }); 241 jQuery('div.basket a.basket_remove_all').click(function(){ 242 site.basket.remove('all'); 243 return false; 244 }); 245 jQuery('div.basket input.amount').bind('keyup', function() { 246 if(0 > parseInt(this.value)) 247 this.value = Math.abs(this.value); 248 if (site.basket.modify.complete) { 249 site.basket.modify.complete = false; 250 var amountThis = this; 251 setTimeout(function() { 252 var id = parseInt(amountThis.parentNode.parentNode.className.split('_').pop()), 253 e = jQuery(amountThis).next('input'), 254 old = e.val(); 255 e.val(amountThis.value); 256 site.basket.modify(id, amountThis.value, old); 257 }, 500) 258 } 259 }); 260 jQuery('.change-amount .top').click(function(){ 261 if (site.basket.modify.complete) { 262 site.basket.modify.complete = false;
263 var id = parseInt(this.parentNode.parentNode.parentNode.className.split('_').pop()), 264 e = this.parentNode.previousSibling, 265 old = e.value; 266 e.value = (parseInt(old) + 1); 267 e.previousSibling.value = e.value; 268 site.basket.modify(id, e.value, old); 269 } 270 }); 271 jQuery('.change-amount .bottom').click(function(){ 272 if (site.basket.modify.complete) { 273 site.basket.modify.complete = false; 274 var id = parseInt(this.parentNode.parentNode.parentNode.className.split('_').pop()), 275 e = this.parentNode.previousSibling, 276 old = e.value; 277 e.value = (parseInt(old) - 1); 278 e.previousSibling.value = e.value; 279 site.basket.modify(id, e.value, old); 280 } 281 }); 282}; 283 284jQuery(document).ready(function(){site.basket.init()});
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.