1// JavaScript Document 2mw.require('forms.js'); 3 4mw.product = { 5 quick_view: function(product_id, dialog_title) { 6 $.get(mw.settings.api_url + 'product/quick-view', {id:product_id}, 7 function (html) { 8 mw.dialog({ 9 title: dialog_title, 10 width: 960, 11 content: html, 12 onremove: function () { 13 14 }, 15 name: 'product-quick-view' 16 }); 17 } 18 ); 19 } 20}; 21 22mw.cart = { 23 24 add_and_checkout: function (content_id, price, c) { 25 if (typeof(c) == 'undefined') { 26 var c = function () { 27 window.location.href = mw.settings.api_url + 'shop/redirect_to_checkout'; 28 } 29 } 30 return mw.cart.add_item(content_id, price, c); 31 }, 32 33 add_item: function (content_id, price, c) { 34 var data = {}; 35 if (content_id == undefined) { 36 return; 37 } 38 39 data.content_id = content_id; 40 41 if (price != undefined && data != undefined) { 42 data.price = price; 43 } 44 45 $.post(mw.settings.api_url + 'update_cart', data, 46 function (data) { 47 48 // mw.cart.after_modify(data); 49 50 51 if (typeof c === 'function') { 52 c.call(data); 53 } 54 mw.cart.after_modify(data, ['mw.cart.add']); 55 mw.trigger('cartAddItem', data); 56 57 // mw.trigger('mw.cart.add', [data]); 58 }); 59 }, 60 61 add: function (selector, price, c) { 62 var data = mw.form.serialize(selector); 63 64 65 var is_form_valid = true; 66 mw.$('[required],.required', selector).each(function () { 67 68 if (!this.validity.valid) { 69 is_form_valid = false 70 71 var is_form_valid_check_all_fields_tip = mw.tooltip({ 72 id: 'mw-cart-add-invalid-form-tooltip-show', 73 content: 'This field is required', 74 close_on_click_outside: true, 75 group: 'mw-cart-add-invalid-tooltip', 76 skin: 'warning', 77 element: this 78 }); 79 80 81 return false; 82 } 83 }); 84 85 if (!is_form_valid) { 86 return; 87 } 88 89 90 if (price != undefined && data != undefined) { 91 data.price = price; 92 } 93 if (data.price == null) { 94 data.price = 0; 95 } 96 $.post(mw.settings.api_url + 'update_cart', data, 97 function (data) { 98 99 // mw.trigger('mw.cart.add', [data]); 100 101 if (typeof c === 'function') { 102 c.call(data); 103 } 104 mw.cart.after_modify(data, ['mw.cart.add']); 105 mw.trigger('cartAddItem', data); 106 107 108 }); 109 }, 110 111 remove: function ($id) { 112 var data = {} 113 data.id = $id; 114 115 $.post(mw.settings.api_url + 'remove_cart_item', data, 116 function (data) { 117 var parent = mw.$('.mw-cart-item-' + $id).parent(); 118 mw.$('.mw-cart-item-' + $id).fadeOut(function () { 119 mw.$(this).remove(); 120 if (parent.find(".mw-cart-item").length == 0) { 121 122 } 123 }); 124 //mw.cart.after_modify(); 125 // mw.reload_module('shop/cart'); 126 // mw.reload_module('shop/shipping'); 127 // mw.trigger('mw.cart.remove', [data]); 128 mw.cart.after_modify(data, ['mw.cart.remove']); 129 mw.trigger('cartRemoveItem', data); 130 131 }); 132 }, 133 134 qty: function ($id, $qty) { 135 var data = {} 136 data.id = $id; 137 data.qty = $qty; 138 $.post(mw.settings.api_url + 'update_cart_item_qty', data, 139 function (data) { 140 // mw.reload_module('shop/cart'); 141 // mw.reload_module('shop/shipping'); 142 // mw.trigger('mw.cart.qty', [data]); 143 144 if(data && typeof(data.error) !== 'undefined'){ 145 if(typeof(data.message) !== 'undefined'){ 146 mw.notification.warning(data.message); 147 } 148 } 149 150 mw.cart.after_modify(data, ['mw.cart.qty']); 151 mw.trigger('cartModify', data); 152 153 154 }); 155 156 }, 157 158 after_modify: function (data, events_to_trigger) { 159 160 161 var modules = ["shop/cart", "shop/shipping", "shop/payments"].filter(function (module) { 162 return !!document.querySelector('[data-type="' + module + '"'); 163 }); 164 165 var events = ['mw.cart.modify']; 166 167 if (!!events_to_trigger) { 168 var events = events.concat(events_to_trigger); 169 } 170 171 172 if (modules.length) { 173 mw.reload_modules(modules, function (data) {
174 events.forEach(function (item) { 175 mw.trigger(item, [data]); 176 }) 177 }, true); 178 } else { 179 events.forEach(function (item) { 180 mw.trigger(item, [data]); 181 }) 182 } 183 184 185 // mw.reload_module('shop/cart'); 186 // mw.reload_module('shop/shipping'); 187 // mw.reload_module('shop/payments'); 188 189 190 if ((typeof data == 'object') && typeof data.cart_items_quantity !== 'undefined') { 191 $('.js-shopping-cart-quantity').html(data.cart_items_quantity); 192 } 193 194 195 mw.trigger('mw.cart.after_modify', data); 196 mw.trigger('cartModify', data); 197 198 199 }, 200 201 checkout: function (selector, callback, beforeRedirect) { 202 203 if (!beforeRedirect) { 204 beforeRedirect = function () { 205 return new Promise(function (){ 206 resolve(); 207 }); 208 }; 209 } 210 211 var form = mw.$(selector); 212 $(document).trigger("checkoutBeforeProcess", form); 213 214 215 var state = form.dataset("loading"); 216 if (state == 'true') return false; 217 form.dataset("loading", 'true'); 218 form.find('.mw-checkout-btn').attr('disabled', 'disabled'); 219 form.find('.mw-checkout-btn').hide(); 220 221 setTimeout(function () { 222 223 var form = mw.$(selector); 224 var obj = mw.form.serialize(form); 225 226 227 $.ajax({ 228 type: "POST", 229 url: mw.settings.api_url + 'checkout', 230 data: obj, 231 error: function (xhr, ajaxOptions, thrownError) { 232 mw.errorsHandle(JSON.parse(xhr.responseText)) 233 form.dataset("loading", 'false'); 234 form.find('.mw-checkout-btn').removeAttr('disabled'); 235 form.find('.mw-checkout-btn').show(); 236 237 } 238 }) 239 .done(function (data) { 240 mw.trigger('checkoutDone', data); 241 242 var data2 = data; 243 244 if (data != undefined) { 245 mw.$(selector + ' .mw-cart-data-btn').removeAttr('disabled'); 246 mw.$('[data-type="shop/cart"]').removeAttr('hide-cart'); 247 248 249 if (typeof(data2.error) != 'undefined') { 250 mw.$(selector + ' .mw-cart-data-holder').show(); 251 if (typeof(data2.error.address_error) != 'undefined') { 252 var form_with_err = form; 253 var isModalForm = $(form_with_err).attr('is-modal-form') 254 255 if (isModalForm) { 256 mw.cart.modal.showStep(form_with_err, 'delivery-address'); 257 } 258 mw.notification.error('Please fill your address details'); 259 260 } 261 262 mw.response(selector, data2); 263 } else if (typeof(data2.success) != 'undefined') { 264 265 266 if (typeof callback === 'function') { 267 callback.call(data2.success); 268 269 } else if (typeof window[callback] === 'function') { 270 window[callback](selector, data2.success); 271 } else { 272 273 mw.$('[data-type="shop/cart"]').attr('hide-cart', 'completed'); 274 mw.reload_module('shop/cart'); 275 mw.$(selector + ' .mw-cart-data-holder').hide(); 276 mw.response(selector, data2); 277 } 278 279 280 281 282 283 if (typeof(data2.redirect) != 'undefined') { 284 285 setTimeout(function () { 286 beforeRedirect().then(function (){ 287 window.location.href = data2.redirect; 288 }); 289 }, 100); 290 return; 291 } else { 292 mw.trigger('mw.cart.checkout.success', data2); 293 mw.trigger('checkoutSuccess', [data]); 294 295 } 296 297 298 } else if (parseInt(data) > 0) { 299 mw.$('[data-type="shop/checkout"]').attr('view', 'completed'); 300 mw.reload_module('shop/checkout'); 301 } else { 302 if (obj.payment_gw != undefined) { 303 var callback_func = obj.payment_gw + '_checkout'; 304 if (typeof window[callback_func] === 'function') { 305 window[callback_func](data, selector); 306 } 307 var callback_func = 'checkout_callback'; 308 if (typeof window[callback_func] === 'function') { 309 window[callback_func](data, selector); 310 } 311 } 312 } 313 314 } 315 form.dataset("loading", 'false'); 316 form.find('.mw-checkout-btn').removeAttr('disabled'); 317 form.find('.mw-checkout-btn').show();
318 mw.trigger('checkoutResponse', data); 319 }); 320 321 }, 1500); 322 } 323} 324 325if (typeof(mw.cart.modal) == 'undefined') { 326 mw.cart.modal = {}; 327} 328if (typeof(mw.cart.modal.init) == 'undefined') { 329 mw.cart.modal.init = function (root_node) { 330 mw.cart.modal.bindStepButtons(root_node); 331 332 /* 333 var inner_cart_module = $(root_node).find('[parent-module-id="js-ajax-cart-checkout-process"]')[0]; 334 */ 335 var inner_cart_module = $(root_node).find('[id="cart_checkout_js-ajax-cart-checkout-process"]')[0]; 336 if (inner_cart_module) { 337 var check = $(document).find('[id="' + inner_cart_module.id + '"]').length 338 mw.on.moduleReload(inner_cart_module.id); 339 } 340 }; 341} 342if (typeof(mw.cart.modal.bindStepButtons) == 'undefined') { 343 344 mw.cart.modal.bindStepButtons = function (root_node) { 345 if (typeof root_node === 'string') { 346 root_node = mw.$(root_node); 347 } 348 349 if (root_node[0]._bindStepButtons) { 350 return; 351 } 352 root_node[0]._bindStepButtons = true; 353 354 var checkout_form = $(root_node).find('form').first(); 355 356 357 $('body').on("mousedown touchstart", '.js-show-step', function () { 358 var step = $(this).attr('data-step'); 359 360 mw.cart.modal.showStep(checkout_form, step); 361 362 363 }); 364 }; 365 366 mw.cart.modal.showStep = function (form, step) { 367 368 369 var prevStep = mw.$('.js-show-step.active', form).data('step'); 370 371 if (prevStep === step) return; 372 373 var prevHolder = $(form).find('.js-' + prevStep).first(); 374 375 $(form).attr('is-modal-form', true); 376 377 if (step === 'checkout-complete') { 378 return; 379 } 380 381 var validate = function (callback) { 382 var hasError = false; 383 mw.$('input,textarea,select', prevHolder).each(function () { 384 if (!this.checkValidity()) { 385 mw.$(this).addClass('is-invalid'); 386 hasError = true; 387 } else { 388 mw.$(this).removeClass('is-invalid'); 389 } 390 }); 391 if (step === 'payment-method' || step === 'preview') { 392 if (hasError) { 393 step = 'delivery-address'; 394 callback.call(undefined, hasError, undefined, step); 395 } 396 } 397 if (step === 'payment-method') { 398 $.post(mw.settings.api_url + 'checkout/validate', mw.serializeFields(prevHolder), function (data) { 399 if (!data.valid) { 400 step = 'delivery-address'; 401 } 402 callback.call(undefined, !data.valid, undefined, step); 403 404 }).fail(function (data) { 405 mw.errorsHandle(data) 406 }); 407 } else { 408 callback.call(undefined, hasError, undefined, step); 409 } 410 }; 411 412 validate(function (hasError, message, step) { 413 if (hasError) { 414 message = message || mw.lang('Please fill properly the required fields'); 415 mw.notification.warning(message); 416 } 417 418 mw.$('.js-show-step').removeClass('active'); 419 mw.$('[data-step]').removeClass('active'); 420 mw.$('[data-step="' + step + '"]').addClass('active').parent().removeClass('muted'); 421 mw.$(this).addClass('active'); 422 var step1 = '.js-' + step; 423 mw.$('.js-step-content').hide(); 424 mw.$(step1).show(); 425 426 }); 427 428 429 }; 430} 431 432mw.cart.modal.bindStepButtons__old = function (root_node) { 433 if (typeof root_node === 'string') { 434 root_node = mw.$(root_node); 435 } 436 437 if (root_node[0]._bindStepButtons) { 438 return; 439 } 440 root_node[0]._bindStepButtons = true; 441 442 root_node.find('.js-show-step').on("mousedown touchstart", function () { 443 444 var has_error = false; 445 446 var form = mw.tools.firstParentWithTag(this, 'form'); 447 var prevStep = mw.$('.js-show-step.active', form).data('step'); 448 var step = this.dataset.step; 449 450 if (prevStep === step) return; 451 452 453 var prevHolder = form.querySelector('.js-' + prevStep); 454 455 456 if (step === 'checkout-complete') { 457 return; 458 } 459 mw.$('input,textarea,select', prevHolder).each(function () { 460 if (!this.checkValidity()) { 461 mw.$(this).addClass('is-invalid'); 462 has_error = 1; 463 } else { 464 mw.$(this).removeClass('is-invalid'); 465 } 466 }); 467 if (step === 'payment-method' || step === 'preview') { 468 if (has_error) { 469 step = 'delivery-address'; 470 } 471 }
472 mw.$('.js-show-step').removeClass('active'); 473 mw.$('[data-step]').removeClass('active'); 474 mw.$('[data-step="' + step + '"]').addClass('active').parent().removeClass('muted'); 475 mw.$(this).addClass('active'); 476 var step1 = '.js-' + step; 477 mw.$('.js-step-content').hide(); 478 mw.$(step1).show(); 479 if (has_error) { 480 mw.notification.warning('Please fill the required fields'); 481 } 482 }); 483 484}
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.