1// JavaScript Document 2mw.require('forms.js'); 3 4 5mw.cart = { 6 7 add_and_checkout: function (content_id, price, c) { 8 if (typeof(c) == 'undefined') { 9 var c = function () { 10 window.location.href = mw.settings.api_url + 'shop/redirect_to_checkout'; 11 } 12 } 13 return mw.cart.add_item(content_id, price, c); 14 }, 15 16 add_item: function (content_id, price, c) { 17 var data = {}; 18 if (content_id == undefined) { 19 return; 20 } 21 22 data.content_id = content_id; 23 24 if (price != undefined && data != undefined) { 25 data.price = price; 26 } 27 28 $.post(mw.settings.api_url + 'update_cart', data, 29 function (data) { 30 31 // mw.cart.after_modify(data); 32 33 34 if (typeof c === 'function') { 35 c.call(data); 36 } 37 mw.cart.after_modify(data,['mw.cart.add']); 38 39 // mw.trigger('mw.cart.add', [data]); 40 }); 41 }, 42 43 add: function (selector, price, c) { 44 var data = mw.form.serialize(selector); 45 46 47 var is_form_valid = true; 48 mw.$('[required],.required', selector).each(function () { 49 50 if (!this.validity.valid) { 51 is_form_valid = false 52 53 var is_form_valid_check_all_fields_tip = mw.tooltip({ 54 id: 'mw-cart-add-invalid-form-tooltip-show', 55 content: 'This field is required', 56 close_on_click_outside: true, 57 group: 'mw-cart-add-invalid-tooltip', 58 skin: 'warning', 59 element: this 60 }); 61 62 63 return false; 64 } 65 }); 66 67 if (!is_form_valid) { 68 return; 69 } 70 71 72 if (price != undefined && data != undefined) { 73 data.price = price; 74 } 75 if (data.price == null) { 76 data.price = 0; 77 } 78 $.post(mw.settings.api_url + 'update_cart', data, 79 function (data) { 80 81 // mw.trigger('mw.cart.add', [data]); 82 83 if (typeof c === 'function') { 84 c.call(data); 85 } 86 mw.cart.after_modify(data,['mw.cart.add']); 87 88 89 90 }); 91 }, 92 93 remove: function ($id) { 94 var data = {} 95 data.id = $id; 96 97 $.post(mw.settings.api_url + 'remove_cart_item', data, 98 function (data) { 99 var parent = mw.$('.mw-cart-item-' + $id).parent(); 100 mw.$('.mw-cart-item-' + $id).fadeOut(function () { 101 mw.$(this).remove(); 102 if (parent.find(".mw-cart-item").length == 0) { 103 104 } 105 }); 106 //mw.cart.after_modify(); 107 // mw.reload_module('shop/cart'); 108 // mw.reload_module('shop/shipping'); 109 // mw.trigger('mw.cart.remove', [data]); 110 mw.cart.after_modify(data,['mw.cart.remove']); 111 112 }); 113 }, 114 115 qty: function ($id, $qty) { 116 var data = {} 117 data.id = $id; 118 data.qty = $qty; 119 $.post(mw.settings.api_url + 'update_cart_item_qty', data, 120 function (data) { 121 // mw.reload_module('shop/cart'); 122 // mw.reload_module('shop/shipping'); 123 // mw.trigger('mw.cart.qty', [data]); 124 125 mw.cart.after_modify(data,['mw.cart.qty']); 126 127 128 129 }); 130 131 }, 132 133 after_modify: function (data, events_to_trigger) { 134 135 136 137 var modules = ["shop/cart", "shop/shipping", "shop/payments"].filter(function(module){ 138 return !!document.querySelector('[data-type="'+ module +'"'); 139 }); 140 141 var events = ['mw.cart.modify']; 142 143 if(!!events_to_trigger) { 144 var events = events.concat(events_to_trigger); 145 } 146 147 148 149 if(modules.length) { 150 mw.reload_modules(modules, function (data) { 151 events.forEach(function(item){ 152 mw.trigger(item, [data]); 153 }) 154 }, true); 155 } else {
156 events.forEach(function(item){ 157 mw.trigger(item, [data]); 158 }) 159 } 160 161 162 // mw.reload_module('shop/cart'); 163 // mw.reload_module('shop/shipping'); 164 // mw.reload_module('shop/payments'); 165 166 167 168 if((typeof data == 'object') && typeof data.cart_items_quantity !== 'undefined'){ 169 $('.js-shopping-cart-quantity').html(data.cart_items_quantity); 170 } 171 172 173 mw.trigger('mw.cart.after_modify', data); 174 175 176 177 178 179 }, 180 181 checkout: function (selector, callback) { 182 var form = mw.$(selector); 183 184 185 var state = form.dataset("loading"); 186 if (state == 'true') return false; 187 form.dataset("loading", 'true'); 188 form.find('.mw-checkout-btn').attr('disabled', 'disabled'); 189 form.find('.mw-checkout-btn').hide(); 190 var obj = mw.form.serialize(selector); 191 $.ajax({ 192 type: "POST", 193 url: mw.settings.api_url + 'checkout', 194 data: obj 195 }) 196 .done(function (data) { 197 mw.trigger('checkoutDone', data); 198 199 200 var data2 = data; 201 202 if (data != undefined) { 203 mw.$(selector + ' .mw-cart-data-btn').removeAttr('disabled'); 204 mw.$('[data-type="shop/cart"]').removeAttr('hide-cart'); 205 206 207 if (typeof(data2.error) != 'undefined') { 208 mw.$(selector + ' .mw-cart-data-holder').show(); 209 mw.response(selector, data2); 210 } else if (typeof(data2.success) != 'undefined') { 211 212 213 if (typeof callback === 'function') { 214 callback.call(data2.success); 215 216 } else if (typeof window[callback] === 'function') { 217 window[callback](selector, data2.success); 218 } else { 219 220 mw.$('[data-type="shop/cart"]').attr('hide-cart', 'completed'); 221 mw.reload_module('shop/cart'); 222 mw.$(selector + ' .mw-cart-data-holder').hide(); 223 mw.response(selector, data2); 224 } 225 226 227 mw.trigger('mw.cart.checkout.success', data2); 228 229 230 if (typeof(data2.redirect) != 'undefined') { 231 232 setTimeout(function () { 233 window.location.href = data2.redirect; 234 }, 10) 235 236 } 237 238 239 } else if (parseInt(data) > 0) { 240 mw.$('[data-type="shop/checkout"]').attr('view', 'completed'); 241 mw.reload_module('shop/checkout'); 242 } else { 243 if (obj.payment_gw != undefined) { 244 var callback_func = obj.payment_gw + '_checkout'; 245 if (typeof window[callback_func] === 'function') { 246 window[callback_func](data, selector); 247 } 248 var callback_func = 'checkout_callback'; 249 if (typeof window[callback_func] === 'function') { 250 window[callback_func](data, selector); 251 } 252 } 253 } 254 255 } 256 form.dataset("loading", 'false'); 257 form.find('.mw-checkout-btn').removeAttr('disabled'); 258 form.find('.mw-checkout-btn').show(); 259 mw.trigger('mw.cart.checkout', [data]); 260 }); 261 } 262} 263 264 265 266mw.cart.modal = {} 267 268mw.cart.modal.init = function (root_node) { 269 270 271 mw.cart.modal.bindStepButtons(root_node); 272 273 274 var inner_cart_module = $(root_node).find('[parent-module-id="js-ajax-cart-checkout-process"]')[0]; 275 var inner_cart_module = $(root_node).find('[id="cart_checkout_js-ajax-cart-checkout-process"]')[0]; 276 277 if(inner_cart_module ){ 278 // mw.log(inner_cart_module.innerHTML); 279 var check = $(document).find('[id="'+inner_cart_module.id+'"]').length 280 281 282 //mw.log(check); 283 284 mw.on.moduleReload(inner_cart_module.id, function () { 285 //alert('Module was reloaded') 286 }); 287 } 288 289 290 291 292 293 294 // 295 // mw.on('mw.cart.after_modify', function () { 296 // 297 // }); 298 299 300 // var inner_cart_module = $(root_node).find('[data-type="shop/cart"]');
301 // if(inner_cart_module.length > 0){ 302 // if(!inner_cart_module.hasClass('cart-modal-module-events-binded')){ 303 // var inner_cart_module_id = inner_cart_module.attr('id') 304 // 305 // inner_cart_module.addClass('cart-modal-module-events-binded') 306 // 307 // 308 // 309 // mw.on.moduleReload($('[data-type="shop/cart"]')[0], function () { 310 // alert('Module was reloaded') 311 // }); 312 // 313 // } 314 // 315 // } 316 317 318 319} 320 321mw.cart.modal.bindStepButtons = function (root_node) { 322 323 $( root_node).off( "click",'.js-show-step'); 324 $( root_node).on( "click",'.js-show-step', function( event ) { 325 326 327 328 329 var has_error = false; 330 var step = mw.$(this).data('step'); 331 var holder = mw.tools.firstParentWithClass(this, 'js-step-content'); 332 333 334 335 336 337 if (step == 'checkout-complete') { 338 return; 339 } 340 341 342 343 344 345 346 mw.$('input,textarea,select', holder).each(function () { 347 if (!this.checkValidity()) { 348 mw.$(this).addClass('is-invalid'); 349 // mw.$(this).addClass('error'); 350 has_error = 1; 351 } else { 352 mw.$(this).removeClass('is-invalid'); 353 // mw.$(this).removeClass('error'); 354 } 355 356 }); 357 358 359 360 361 362 if (step == 'payment-method' || step == 'preview') { 363 if (has_error) { 364 step = 'delivery-address' 365 } 366 } 367 368 369 370 371 mw.$('.js-show-step').removeClass('active'); 372 373 mw.$('[data-step]').removeClass('active'); 374 mw.$('[data-step="' + step + '"]').addClass('active').parent().removeClass('muted'); 375 mw.$(this).addClass('active'); 376 step1 = '.js-' + step; 377 mw.$('.js-step-content').hide(); 378 mw.$(step1).show(); 379 380 if (!has_error) { 381 382 } 383 384 if (has_error) { 385 mw.notification.warning('Please fill the required fields'); 386 } 387 388 }); 389 390 391 /* 392 mw.$('.js-show-step').off('click'); 393 mw.$('.js-show-step').on('click', function () { 394 395 396 397 });*/ 398 399 400}
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.