Total Complexity | 4 |
Complexity/F | 1 |
Lines of Code | 40 |
Function Count | 4 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | define([ |
||
2 | 'jquery' |
||
3 | ], function ($) { |
||
4 | 'use strict'; |
||
5 | |||
6 | return { |
||
7 | addToCartUrl: 'checkout/cart/add', |
||
8 | buyNowCartUrl: 'buynow/cart/add', |
||
9 | buyNowBtnListSelector: '.mageprince-buynow-btn-list', |
||
10 | |||
11 | /** |
||
12 | * Replace add to cart url |
||
13 | * |
||
14 | * @param {string} baseUrl |
||
15 | * @returns {String} |
||
16 | */ |
||
17 | replaceBuyNowUrl: function (baseUrl) { |
||
18 | return baseUrl.replace(this.addToCartUrl, this.buyNowCartUrl); |
||
19 | }, |
||
20 | |||
21 | /** |
||
22 | * Init buy now button click event for list page |
||
23 | */ |
||
24 | initListBuyNowBtnSelector: function (e) { |
||
25 | var self = this; |
||
26 | $(this.buyNowBtnListSelector).click(function (e) { |
||
27 | e.stopImmediatePropagation(); |
||
28 | e.preventDefault(); |
||
29 | $(this).attr('disabled', true); |
||
30 | var form = $(this).closest('form'), |
||
31 | baseUrl = form.attr('action'), |
||
32 | buyNowUrl = self.replaceBuyNowUrl(baseUrl); |
||
33 | form.attr('action', buyNowUrl); |
||
34 | form.trigger('submit'); |
||
35 | form.attr('action', baseUrl); |
||
36 | return false; |
||
37 | }); |
||
38 | } |
||
39 | } |
||
40 | }); |
||
41 |