1(function() { 2 'use strict'; 3 4 var BasketClass = function(options) { 5 this.init(options); 6 }; 7 8 BasketClass.DEFAULTS = { 9 input: { 10 id: 'a', 11 quantity: 'anzahl' 12 }, 13 selector: { 14 list: { 15 main: '*[data-toggle="basket-add"]', 16 form: 'form.form-basket', 17 quantity: 'input.quantity', 18 submit: '*[type="submit"]', 19 loading: 'io-loading' 20 }, 21 cart: { 22 container: '.cart-icon-dropdown' 23 } 24 } 25 }; 26 27 BasketClass.prototype = { 28 29 constructor: BasketClass, 30 31 init: function(options) { 32 this.options = $.extend({}, BasketClass.DEFAULTS, options); 33 }, 34 35 addToBasket: function($form, data) { 36 var $main = $form; 37 38 if (typeof data === 'undefined') { 39 data = $form.serializeObject(); 40 } 41 42 var productId = parseInt(data[this.options.input.id]); 43 var quantity = parseFloat( 44 data[this.options.input.quantity].replace(',', '.') 45 ); 46 47 if (productId > 0 && quantity > 0) { 48 this.pushToBasket($main, productId, quantity, data); 49 } 50 }, 51 52 pushToBasket: function($main, productId, quantity, data) { 53 var that = this; 54 55 that.toggleState($main, true); 56 57 $.evo.io().call('pushToBasket', [productId, quantity, data], that, function(error, data) { 58 59 that.toggleState($main, false); 60 61 if (error) { 62 return; 63 } 64 65 var response = data.response; 66 67 if (response) { 68 switch (response.nType) { 69 case 0: // error 70 that.error(response); 71 break; 72 case 1: // forwarding 73 that.redirectTo(response); 74 break; 75 case 2: // added to basket 76 that.updateCart(); 77 that.pushedToBasket(response); 78 break; 79 } 80 } 81 }); 82 }, 83 84 toggleState: function($main, loading) { 85 var cls = this.options.selector.list.loading; 86 if (loading) { 87 $main.addClass(cls); 88 } else { 89 $main.removeClass(cls); 90 } 91 }, 92 93 redirectTo: function(response) { 94 window.location.href = response.cLocation; 95 }, 96 97 error: function(response) { 98 var errorlist = '<ul><li>' + response.cHints.join('</li><li>') + '</li></ul>'; 99 $.evo.extended().showNotify({ 100 text: errorlist, 101 title: response.cLabel 102 }); 103 }, 104 105 pushedToBasket: function(response) { 106 $.evo.extended().showNotify({ 107 text: response.cPopup, 108 title: response.cNotification 109 }); 110 }, 111 112 updateCart: function(type) { 113 var that = this, 114 t = parseInt(type); 115 116 if (type === undefined) { 117 t=0; 118 } 119 120 $.evo.io().call('getBasketItems', [t], this, function(error, data) { 121 if (error) { 122 return; 123 } 124 125 var tpl = data.response.cTemplate; 126 127 $(that.options.selector.cart.container) 128 .replaceWith(tpl); 129 }); 130 } 131 }; 132 133 // PLUGIN DEFINITION 134 // ================= 135 136 $.evo.basket = function() { 137 return new BasketClass(); 138 }; 139 140 // PLUGIN DATA-API 141 // =============== 142 $('#main-wrapper').on('submit', '[data-toggle="basket-add"]', function(event) { 143 event.preventDefault(); 144 $.evo.basket().addToBasket($(this)); 145 }).on('show.bs.dropdown', '[data-toggle="basket-items"]', function (event) { 146 $.evo.basket().updateCart(); 147 }); 148})(jQuery);
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.