1var Store = {}; 2Handlebars.registerHelper("checkedIf", function (condition) { 3 return (condition) ? "checked" : ""; 4}); 5 6(function () { 7 $(function () { 8 Store.isFiredSubmit = false; 9 10 Store.langs = { 11 closeSwal: 'OK' 12 }; 13 14 Store.setLangs = function (langs) { 15 Store.langs = $.extend(Store.langs, langs); 16 } 17 18 Store.submitOrder = function (form) { 19 return $.post('/' + document.locale + '/store/orders/update.json', form.serialize()); 20 }; 21 22 Store.cart = $("#mini-cart-template").length > 0 ? Handlebars.compile($("#mini-cart-template").html()) : false; 23 Store.lineItems = $("#cart-line-items").length > 0 ? Handlebars.compile($("#cart-line-items").html()) : false; 24 Store.totals = $("#cart-totals").length > 0 ? Handlebars.compile($("#cart-totals").html()) : false; 25 Store.points = $("#cart-points").length > 0 ? Handlebars.compile($("#cart-points").html()) : false; 26 Store.deliveryDate = $(".tpl-delivery-date").length > 0 ? Handlebars.compile($(".tpl-delivery-date").html()) : false; 27 Store.deliveryDays = $(".tpl-delivery-days").length > 0 ? Handlebars.compile($(".tpl-delivery-days").html()) : false; 28 Store.orderSubmit = $("#tpl-order-submit").length > 0 ? Handlebars.compile($("#tpl-order-submit").html()) : false; 29 30 function observeInput(el) { 31 if ($(el).val() == '') { 32 $(el).removeClass('not-empty'); 33 } else { 34 $(el).addClass('not-empty'); 35 } 36 } 37 38 // Update cart 39 Store.updateCart = function (data) { 40 if (Shop) { 41 Shop.updateCart(data); 42 } 43 $('body').trigger('updateCart', [data]); 44 if (Store.cart) { 45 var html = Store.cart(data); 46 $('.mini-cart').html(html); 47 } 48 49 if (Store.lineItems) { 50 var html = Store.lineItems(data); 51 $('.cart-line-items').html(html); 52 } 53 54 if (Store.totals) { 55 var html = Store.totals(data); 56 $('.cart-totals').html(html); 57 } 58 59 if (Store.deliveryDate) { 60 var html = Store.deliveryDate(data); 61 $('.tpl-delivery-date').html(html); 62 } 63 64 if (Store.orderSubmit) { 65 var html = Store.orderSubmit(data); 66 $('.tpl-order-submit').html(html); 67 } 68 69 if (Store.points) { 70 var html = Store.points(data); 71 $('.cart-points').html(html); 72 } 73 74 if (Store.deliveryDays) { 75 var html = Store.deliveryDays(data); 76 $('.tpl-delivery-days').html(html); 77 78 if (data.express_delivery) { 79 $("#orders-express-delivery-1").attr('checked', 'checked'); 80 $("#orders-express-delivery-0").attr('checked', false); 81 } else { 82 $("#orders-express-delivery-0").attr('checked', 'checked'); 83 $("#orders-express-delivery-1").attr('checked', false); 84 } 85 } 86 87 if ($('.cart-user-data').length > 0) { 88 $('[cart-error]').removeClass('show'); 89 $('[cart-error]').removeClass('u-show'); 90 $('._checkout-error').removeClass('_checkout-error'); 91 if (!$.isEmptyObject(data.errors) && Store.isFiredSubmit) { 92 var fields_errors = []; 93 $.each(data.errors, function (key, value) { 94 var html = []; 95 var _key = key; 96 $.each(value, function (key, value) { 97 html.push(value); 98 }); 99 100 $('[cart-error="' + _key + '"]').html(html.join(', ')).addClass('show').addClass('u-show'); 101 var field_error = $('[name="Orders[' + key + ']"]'); 102 field_error.addClass('_checkout-error'); 103 fields_errors.push(field_error); 104 }) 105 106 $.scrollTo(fields_errors[0], 800, { 107 offset: { 108 top: -200 109 }, 110 axis: 'y' 111 }); 112 } 113 } 114
115 if (data.has_items) { 116 $('[cart-items-number]') 117 .attr('number', data.line_items.length) 118 .find('small') 119 .html(data.line_items.length) 120 .addClass('active') 121 .attr('number', data.line_items.length); 122 } else if (data && data.line_items) { 123 $('[cart-items-number]') 124 .attr('number', data.line_items.length) 125 .find('small') 126 .html('') 127 .removeClass('active') 128 .attr('number', 0); 129 } 130 } 131 132 if ($("[chart-checkout]").length > 0) { 133 Store.checkout = Handlebars.compile($("[chart-checkout]").html()); 134 } 135 136 Store.updateCartCheckout = function (data) { 137 var html = Store.checkout(data); 138 $("[chart-checkout]").html(html); 139 } 140 141 142 143 // Order same address 144 function changeSameAddress(el) { 145 var $el = $($(el).attr('order-same-address')); 146 147 if ($(el).is(':checked')) { 148 $el.hide(); 149 } else { 150 $el.show(); 151 } 152 } 153 154 changeSameAddress('[order-same-address]'); 155 156 $('body').on('cartError', function (e, data) { 157 if (typeof(Swal) != 'undefined') { 158 Swal.fire({ 159 title: data.error.title, 160 text: data.error.text, 161 icon: 'warning', 162 button: { 163 text: Store.langs.closeSwal, 164 } 165 }) 166 } 167 else if (typeof (swal) != 'undefined') { 168 swal({ 169 title: data.error.title, 170 text: data.error.text, 171 icon: 'error', 172 button: { 173 text: Store.langs.closeSwal, 174 } 175 }) 176 } 177 }); 178 179 // Order same address 180 function changeCreateAccount(el) { 181 var $el = $($(el).attr('order-create-account')); 182 183 if ($(el).is(':checked')) { 184 $el.show(); 185 } else { 186 $el.hide(); 187 } 188 } 189 190 // Points 191 Store.addPoints = function (points) { 192 $.post('/' + document.locale + '/store/orders/addpoints.json', { 193 points: points 194 }) 195 .done(function (data) { 196 Store.updateCart(data.cart); 197 }) 198 } 199 200 $('[order-create-account]').change(function () { 201 changeCreateAccount(this); 202 }); 203 204 changeCreateAccount('[order-create-account]'); 205 206 207 208 // 209 // EVENTOS DE CLICK Y CHANGE 210 // 211 212 // Checkout express change form inputs 213 $('body').delegate("[checkout-express] input:not([type=hidden]):not(.store-item-quantity-input):not([name=order-coupon]):not([no-update]), [checkout-express] select", 'change', function () { 214 var form = $(this).closest("form"); 215 $.post('/' + document.locale + '/store/orders/update.json', form.serialize()) 216 .done(function (data) { 217 Store.updateCart(data.cart); 218 }) 219 }); 220 221 // Add Item 222 $('body').delegate('[data-add-item]', 'click', function () { 223 var _this = $(this); 224 if (_this.attr('disable')) { 225 return; 226 } 227 _this.attr('disable', true); 228 var attributes = []; 229 var values = $('[name^=attributes]').serializeArray(); 230 _this.trigger('loading'); 231 for (i in values) { 232 var name = values[i].name; 233 var group_id = name.replace('attributes[', '').replace(']', ''); 234 attributes.push({ 235 group_id: group_id, 236 attribute_id: values[i].value 237 }); 238 } 239 240 var line_item = {}; 241 var extras = $('[line-item]').serializeArray(); 242 243 for (i in extras) { 244 line_item[extras[i].name] = extras[i].value; 245 } 246 var salt = $(this).data('addItem'); 247 var data = { 248 salt: salt, 249 attributes: attributes, 250 line_item: line_item 251 }; 252 253 if ($('[data-quantity-item=' + $(this).data('addItem') + ']').length > 0) { 254 data.quantity = $('[data-quantity-item=' + $(this).data('addItem') + ']').val(); 255 } 256 257 $.post('/' + document.locale + '/store/orders/additem.json', { 258 product: data 259 }) 260 .done(function (data) { 261 _this.trigger('stoping'); 262 263 if (data.result.errors) { 264 _this.trigger('addItemError'); 265 html = []; 266 for (i in data.result.errors) { 267 if (typeof (swal) != 'undefined' || typeof (Swal) != 'undefined') { 268 html.push(data.result.errors[i]); 269 } else { 270 html.push('<span>' + data.result.errors[i] + '</span>'); 271 } 272 } 273 274 275 console.log(typeof (swal) ); 276 277 if (typeof(Swal) != 'undefined') { 278 Swal.fire({ 279 text: html.join(''), 280 icon: 'warning', 281 button: { 282 text: Store.langs.closeSwal, 283 } 284 }) 285 } else if (typeof (swal) != 'undefined') { 286 swal({ 287 text: html.join(''), 288 icon: 'warning', 289 button: { 290 text: Store.langs.closeSwal, 291 } 292 }) 293 } else {
294 $('[store-add-error="' + salt + '"]').html('<div class="store-add-error">' + html.join('') + '</div>'); 295 } 296 297 } 298 299 if (!data.result.valid) { 300 return; 301 } 302 303 Store.updateCart(data.result.order); 304 305 if (_this.attr('data-add-item-redirect')) { 306 window.location.href = _this.attr('data-add-item-redirect'); 307 } else { 308 var slidebars = $('body').data('slidebars'); 309 if (slidebars && !slidebars.isActiveSlidebar('cart')) { 310 slidebars.open('cart') 311 } 312 _this.trigger('addItemSuccess'); 313 } 314 315 $('body').trigger('storeAddItem', [data.result.item, data.result.order]); 316 }) 317 .fail(function () { 318 _this.trigger('addItemError'); 319 }) 320 .always(function () { 321 _this.removeAttr('disable') 322 }); 323 324 }) 325 326 // Submit cart 327 $('body').delegate('[cart-submit]', 'click', function (e) { 328 e.preventDefault(); 329 var _this = $(this); 330 if (_this.attr('disable')) { 331 return; 332 } 333 _this.attr('disable', true); 334 $(this).trigger('loading'); 335 var form = $('[checkout-express]'); 336 337 $.post('/' + document.locale + '/store/orders/update.json?submit=true', form.serialize()) 338 .done(function (data) { 339 Store.isFiredSubmit = true; 340 341 if (data.cart.is_valid) { 342 window.location.href = _this.attr('href'); 343 } else { 344 Store.updateCart(data.cart); 345 _this.trigger('stoping'); 346 $('.checkout-flash').addClass('active'); 347 setTimeout(function () { 348 $('.checkout-flash').removeClass('active'); 349 }, 2000); 350 351 if (data.redirect) { 352 window.location.href = data.redirect; 353 } 354 355 $('body').trigger('cartError', [data]) 356 } 357 }) 358 .always(function () { 359 _this.removeAttr('disable'); 360 }); 361 362 return false; 363 }); 364 365 // Add / Remove quantity 366 $('body').delegate('[store-item-quantity]', 'click', function (e) { 367 e.preventDefault(); 368 var action = $(this).attr('action'); 369 var id = $(this).attr('store-item-quantity'); 370 371 $.post('/' + document.locale + '/store/orders/quantity.json', { 372 id: id, 373 action: action 374 }) 375 .done(function (data) { 376 if (!data.cart.line_items || (data.cart.line_items && data.cart.line_items.length == 0)) { 377 window.location.reload(); 378 } 379 380 if (data.errors) { 381 var html = []; 382 383 for (i in data.errors) { 384 html.push(data.errors[i]); 385 } 386 387 if (typeof (swal) != 'undefined') { 388 new swal({ 389 text: html.join(''), 390 icon: 'warning', 391 button: { 392 text: Store.langs.closeSwal, 393 } 394 }) 395 } else if (typeof(Swal) != 'undefined') { 396 Swal.fire({ 397 text: html.join(''), 398 icon: 'warning', 399 button: { 400 text: Store.langs.closeSwal, 401 } 402 }) 403 } 404 } 405 406
407 Store.updateCart(data.cart); 408 409 if (action == 'add') { 410 $('body').trigger('storeAddItem', data.item, data.cart); 411 } 412 413 if (action == 'remove') { 414 $('body').trigger('storeDeleteItem', data.item); 415 } 416 }) 417 }); 418 419 // Remove Item 420 $('body').delegate('[store-delete-item]', 'click', function () { 421 $(this).trigger('loading'); 422 $.post('/' + document.locale + '/store/orders/deleteitem.json', { 423 id: $(this).attr('store-delete-item') 424 }) 425 .done(function (data) { 426 $(this).trigger('stoping'); 427 428 if (!data.order.line_items || data.order.line_items.length == 0) { 429 window.location.reload(); 430 } 431 Store.updateCart(data.order); 432 $('body').trigger('storeDeleteItem', data.item); 433 }) 434 }) 435 436 // Refund item 437 $('body').delegate('[refund-item]', 'click', function (e) { 438 e.preventDefault(); 439 var _this = $(this); 440 441 if (typeof(Swal) != 'undefined') { 442 Swal.fire({ 443 text: _this.attr('prompt'), 444 icon: 'warning', 445 showCancelButton: true, 446 cancelButtonText: 'No', 447 button: { 448 text: Store.langs.closeSwal, 449 } 450 }).then(function(value) { 451 if(value.isConfirmed) { 452 _this.trigger('loading'); 453 $.post('/' + document.locale + '/store/orders/refund-line-item.json', { 454 item: _this.attr('refund-item'), 455 quantity: _this.attr('refund-quantity') ? _this.attr('refund-quantity') : 1 456 }) 457 .done(function (data) { 458 if (data.success) { 459 _this.trigger('success'); 460 } else { 461 _this.trigger('error'); 462 } 463 }) 464 } 465 }); 466 } 467 468 }) 469 470 // Change address 471 $('body').delegate('[for=orders-same-address]', 'click', function () { 472 setTimeout(function () { 473 changeSameAddress($('[order-same-address]')); 474 }, 10); 475 $(this).trigger('change'); 476 }); 477 478 $('body').delegate('#orders-same-address', 'click', function () { 479 setTimeout(function () { 480 changeSameAddress($('[order-same-address]')); 481 }, 10); 482 }); 483 484 485 // Change quantity input text 486 $('body').delegate('[store-item-quantity-input]', 'change', function (e) { 487 e.preventDefault(); 488 var salt = $(this).attr('store-item-quantity-input'); 489 490 $.post('/' + document.locale + '/store/orders/quantity.json', { 491 salt: salt, 492 action: 'add', 493 quantity: $(this).val() 494 }) 495 .done(function (data) { 496 Store.updateCart(data.cart); 497 }) 498 }); 499 500 // Remove fav 501 $('body').delegate('[store-remove-fav]', 'click', function (e) { 502 var _this = $(this); 503 e.preventDefault(); 504 var salt = _this.attr('store-remove-fav'); 505 506 $.post('/' + document.locale + '/store/favs/delete.json', { 507 product: salt 508 }) 509 .done(function (data) { 510 if (data.result) { 511 $('#fav_' + salt).remove(); 512 513 if (data.count == 0) { 514 window.location.reload(); 515 } 516 } 517 }) 518 }); 519 520 // Favs
521 $('body').delegate('[store-add-fav]', 'click', function (e) { 522 var _this = $(this); 523 e.preventDefault(); 524 var salt = _this.attr('store-add-fav'); 525 if (!_this.attr('store-remove-added')) { 526 $.post('/' + document.locale + '/store/favs/add.json', { 527 product: salt 528 }) 529 .done(function (data) { 530 if (data.success) { 531 if (!_this.attr('store-add-fav-noadd')) { 532 _this.parent().html(data.success); 533 } 534 535 _this.attr('store-remove-added', true); 536 _this.trigger('storeAddedFav'); 537 $('body').trigger('storeAddedFav', [data]); 538 } 539 if (data.error) { 540 if (!_this.attr('store-add-fav-noadd')) { 541 _this.parent().html(data.error); 542 } 543 } 544 }) 545 } else { 546 $.post('/' + document.locale + '/store/favs/delete.json', { 547 product: salt 548 }) 549 .done(function (data) { 550 if (data.result) { 551 _this.removeAttr('store-remove-added'); 552 _this.trigger('storeRemovedFav'); 553 } 554 }) 555 } 556 557 }); 558 559 // Change country 560 $('body').delegate("[change-country]", 'change', function (e) { 561 var $el = $($(this).attr('change-country')); 562 $.post('/' + document.locale + '/store/orders/states.json', { 563 country_id: $(this).val() 564 }) 565 .done(function (data) { 566 $el.empty(); // remove old options 567 if ($el.attr('empty-label')) { 568 $el.append($("<option></option>") 569 .attr("value", '').text($el.attr('empty-label'))); 570 } 571 $.each(data.states, function (key, value) { 572 $el.append($("<option></option>") 573 .attr("value", value.id).text(value.title)); 574 }); 575 }) 576 }); 577 578 // Coupon 579 $('body').delegate("[store-coupon]", 'click', function (e) { 580 var value = $('[name="order-coupon"]').val(); 581 $.post('/' + document.locale + '/store/orders/coupon.json', { 582 code: value 583 }) 584 .done(function (data) { 585 if (data.error) { 586 $('[store-coupon-message]') 587 .removeClass('u-hide') 588 .text(data.error); 589 } else { 590 Store.updateCart(data.cart); 591 } 592 }) 593 }); 594 595 $('body').delegate("[store-remove-coupon]", 'click', function (e) { 596 $.post('/' + document.locale + '/store/orders/couponremove.json', {}) 597 .done(function (data) { 598 Store.updateCart(data.cart); 599 }) 600 }); 601 }) 602 603})();
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.