|
1 | | -/** |
2 | | - * Mageplaza |
3 | | - * |
4 | | - * NOTICE OF LICENSE |
5 | | - * |
6 | | - * This source file is subject to the Mageplaza.com license that is |
7 | | - * available through the world-wide-web at this URL: |
8 | | - * https://www.mageplaza.com/LICENSE.txt |
9 | | - * |
10 | | - * DISCLAIMER |
11 | | - * |
12 | | - * Do not edit or add to this file if you wish to upgrade this extension to newer |
13 | | - * version in the future. |
14 | | - * |
15 | | - * @category Mageplaza |
16 | | - * @package Mageplaza_AjaxLayer |
17 | | - * @copyright Copyright (c) Mageplaza (http://www.mageplaza.com/) |
18 | | - * @license https://www.mageplaza.com/LICENSE.txt |
19 | | - */ |
20 | | - |
21 | | -define( |
22 | | - [ |
23 | | - 'jquery', |
24 | | - 'mage/storage', |
25 | | - 'Mageplaza_AjaxLayer/js/model/loader', |
26 | | - 'mage/apply/main' |
27 | | - ], |
28 | | - function ($, storage, loader, mage) { |
29 | | - 'use strict'; |
30 | | - |
31 | | - var productContainer = $('#layer-product-list'), |
32 | | - layerContainer = $('.layered-filter-block-container'), |
33 | | - quickViewContainer = $('#mpquickview-popup'); |
34 | | - |
35 | | - return function (submitUrl, isChangeUrl) { |
36 | | - /** save active state */ |
37 | | - var actives = [], |
38 | | - data; |
39 | | - $('.filter-options-item').each(function (index) { |
40 | | - if ($(this).hasClass('active')) { |
41 | | - actives.push($(this).attr('attribute')); |
42 | | - } |
43 | | - }); |
44 | | - window.layerActiveTabs = actives; |
45 | | - |
46 | | - /** start loader */ |
47 | | - loader.startLoader(); |
48 | | - |
49 | | - /** change browser url */ |
50 | | - if (typeof window.history.pushState === 'function' && (typeof isChangeUrl === 'undefined')) { |
51 | | - window.history.pushState({url: submitUrl}, '', submitUrl); |
52 | | - } |
53 | | - |
54 | | - if (isChangeUrl){ |
55 | | - data = '{}'; |
56 | | - }else{ |
57 | | - data = JSON.stringify({'mp_layer': 1}); |
58 | | - } |
59 | | - |
60 | | - return storage.post(submitUrl, data).done( |
61 | | - function (response) { |
62 | | - if (response.backUrl) { |
63 | | - window.location = response.backUrl; |
64 | | - return; |
65 | | - } |
66 | | - if (response.navigation) { |
67 | | - layerContainer.html(response.navigation); |
68 | | - } |
69 | | - if (response.products) { |
70 | | - productContainer.html(response.products); |
71 | | - } |
72 | | - if (response.quickview) { |
73 | | - quickViewContainer.html(response.quickview); |
74 | | - } |
75 | | - |
76 | | - if (mage) { |
77 | | - mage.apply(); |
78 | | - } |
79 | | - } |
80 | | - ).fail( |
81 | | - function () { |
82 | | - window.location.reload(); |
83 | | - } |
84 | | - ).always( |
85 | | - function () { |
86 | | - loader.stopLoader(); |
87 | | - } |
88 | | - ); |
89 | | - }; |
90 | | - } |
91 | | -); |
| 1 | +/** |
| 2 | + * Mageplaza |
| 3 | + * |
| 4 | + * NOTICE OF LICENSE |
| 5 | + * |
| 6 | + * This source file is subject to the Mageplaza.com license that is |
| 7 | + * available through the world-wide-web at this URL: |
| 8 | + * https://www.mageplaza.com/LICENSE.txt |
| 9 | + * |
| 10 | + * DISCLAIMER |
| 11 | + * |
| 12 | + * Do not edit or add to this file if you wish to upgrade this extension to newer |
| 13 | + * version in the future. |
| 14 | + * |
| 15 | + * @category Mageplaza |
| 16 | + * @package Mageplaza_AjaxLayer |
| 17 | + * @copyright Copyright (c) Mageplaza (http://www.mageplaza.com/) |
| 18 | + * @license https://www.mageplaza.com/LICENSE.txt |
| 19 | + */ |
| 20 | + |
| 21 | +define( |
| 22 | + [ |
| 23 | + 'jquery', |
| 24 | + 'mage/storage', |
| 25 | + 'Mageplaza_AjaxLayer/js/model/loader', |
| 26 | + 'mage/apply/main' |
| 27 | + ], |
| 28 | + function ($, storage, loader, mage) { |
| 29 | + 'use strict'; |
| 30 | + |
| 31 | + var productContainer = $('#layer-product-list'), |
| 32 | + layerContainer = $('.layered-filter-block-container'), |
| 33 | + quickViewContainer = $('#mpquickview-popup'); |
| 34 | + |
| 35 | + return function (submitUrl, isChangeUrl) { |
| 36 | + /** save active state */ |
| 37 | + var actives = [], |
| 38 | + data; |
| 39 | + $('.filter-options-item').each(function (index) { |
| 40 | + if ($(this).hasClass('active')) { |
| 41 | + actives.push($(this).attr('attribute')); |
| 42 | + } |
| 43 | + }); |
| 44 | + window.layerActiveTabs = actives; |
| 45 | + |
| 46 | + /** start loader */ |
| 47 | + loader.startLoader(); |
| 48 | + |
| 49 | + /** change browser url */ |
| 50 | + if (typeof window.history.pushState === 'function' && (typeof isChangeUrl === 'undefined')) { |
| 51 | + window.history.pushState({url: submitUrl}, '', submitUrl); |
| 52 | + } |
| 53 | + |
| 54 | + return storage.get(submitUrl).done( |
| 55 | + function (response) { |
| 56 | + if (response.backUrl) { |
| 57 | + window.location = response.backUrl; |
| 58 | + return; |
| 59 | + } |
| 60 | + if (response.navigation) { |
| 61 | + layerContainer.html(response.navigation); |
| 62 | + } |
| 63 | + if (response.products) { |
| 64 | + productContainer.html(response.products); |
| 65 | + } |
| 66 | + if (response.quickview) { |
| 67 | + quickViewContainer.html(response.quickview); |
| 68 | + } |
| 69 | + |
| 70 | + if (mage) { |
| 71 | + mage.apply(); |
| 72 | + } |
| 73 | + } |
| 74 | + ).fail( |
| 75 | + function () { |
| 76 | + window.location.reload(); |
| 77 | + } |
| 78 | + ).always( |
| 79 | + function () { |
| 80 | + loader.stopLoader(); |
| 81 | + } |
| 82 | + ); |
| 83 | + }; |
| 84 | + } |
| 85 | +); |
0 commit comments