|
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 | | - |
87 | | - var colorAttr = $('.filter-options .filter-options-item .color .swatch-option-link-layered .swatch-option'); |
88 | | - |
89 | | - colorAttr.each(function(){ |
90 | | - var el = $(this), |
91 | | - hex = el.attr('data-option-tooltip-value'); |
92 | | - if(typeof hex != "undefined"){ |
93 | | - if (hex.charAt(0) === '#') { |
94 | | - hex = hex.substr(1); |
95 | | - } |
96 | | - if ((hex.length < 2) || (hex.length > 6)) { |
97 | | - el.attr('style','background: '+el.attr('data-option-label')+';'); |
98 | | - } |
99 | | - var values = hex.split(''), |
100 | | - r, |
101 | | - g, |
102 | | - b; |
103 | | - |
104 | | - if (hex.length === 2) { |
105 | | - r = parseInt(values[0].toString() + values[1].toString(), 16); |
106 | | - g = r; |
107 | | - b = r; |
108 | | - } else if (hex.length === 3) { |
109 | | - r = parseInt(values[0].toString() + values[0].toString(), 16); |
110 | | - g = parseInt(values[1].toString() + values[1].toString(), 16); |
111 | | - b = parseInt(values[2].toString() + values[2].toString(), 16); |
112 | | - } else if (hex.length === 6) { |
113 | | - r = parseInt(values[0].toString() + values[1].toString(), 16); |
114 | | - g = parseInt(values[2].toString() + values[3].toString(), 16); |
115 | | - b = parseInt(values[4].toString() + values[5].toString(), 16); |
116 | | - } else { |
117 | | - el.attr('style','background: '+el.attr('data-option-label')+';'); |
118 | | - } |
119 | | - |
120 | | - el.attr('style','background: center center no-repeat rgb('+[r, g, b]+');'); |
121 | | - } |
122 | | - |
123 | | - }); |
124 | | - |
125 | | - //selected |
126 | | - |
127 | | - var filterCurrent = $('.layered-filter-block-container .filter-current .items .item .filter-value'); |
128 | | - |
129 | | - filterCurrent.each(function(){ |
130 | | - var el = $(this), |
131 | | - colorLabel = el.html(), |
132 | | - colorAttr = $('.filter-options .filter-options-item .color .swatch-option-link-layered .swatch-option'); |
133 | | - |
134 | | - colorAttr.each(function(){ |
135 | | - var elA = $(this); |
136 | | - if(elA.attr('data-option-label') === colorLabel && !elA.hasClass('selected')){ |
137 | | - elA.addClass('selected'); |
138 | | - } |
139 | | - }); |
140 | | - }); |
141 | | - |
142 | | - loader.stopLoader(); |
143 | | - } |
144 | | - ); |
145 | | - }; |
146 | | - } |
147 | | -); |
| 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 | + |
| 81 | + var colorAttr = $('.filter-options .filter-options-item .color .swatch-option-link-layered .swatch-option'); |
| 82 | + |
| 83 | + colorAttr.each(function(){ |
| 84 | + var el = $(this), |
| 85 | + hex = el.attr('data-option-tooltip-value'); |
| 86 | + if(typeof hex != "undefined"){ |
| 87 | + if (hex.charAt(0) === '#') { |
| 88 | + hex = hex.substr(1); |
| 89 | + } |
| 90 | + if ((hex.length < 2) || (hex.length > 6)) { |
| 91 | + el.attr('style','background: '+el.attr('data-option-label')+';'); |
| 92 | + } |
| 93 | + var values = hex.split(''), |
| 94 | + r, |
| 95 | + g, |
| 96 | + b; |
| 97 | + |
| 98 | + if (hex.length === 2) { |
| 99 | + r = parseInt(values[0].toString() + values[1].toString(), 16); |
| 100 | + g = r; |
| 101 | + b = r; |
| 102 | + } else if (hex.length === 3) { |
| 103 | + r = parseInt(values[0].toString() + values[0].toString(), 16); |
| 104 | + g = parseInt(values[1].toString() + values[1].toString(), 16); |
| 105 | + b = parseInt(values[2].toString() + values[2].toString(), 16); |
| 106 | + } else if (hex.length === 6) { |
| 107 | + r = parseInt(values[0].toString() + values[1].toString(), 16); |
| 108 | + g = parseInt(values[2].toString() + values[3].toString(), 16); |
| 109 | + b = parseInt(values[4].toString() + values[5].toString(), 16); |
| 110 | + } else { |
| 111 | + el.attr('style','background: '+el.attr('data-option-label')+';'); |
| 112 | + } |
| 113 | + |
| 114 | + el.attr('style','background: center center no-repeat rgb('+[r, g, b]+');'); |
| 115 | + } |
| 116 | + |
| 117 | + }); |
| 118 | + |
| 119 | + //selected |
| 120 | + |
| 121 | + var filterCurrent = $('.layered-filter-block-container .filter-current .items .item .filter-value'); |
| 122 | + |
| 123 | + filterCurrent.each(function(){ |
| 124 | + var el = $(this), |
| 125 | + colorLabel = el.html(), |
| 126 | + colorAttr = $('.filter-options .filter-options-item .color .swatch-option-link-layered .swatch-option'); |
| 127 | + |
| 128 | + colorAttr.each(function(){ |
| 129 | + var elA = $(this); |
| 130 | + if(elA.attr('data-option-label') === colorLabel && !elA.hasClass('selected')){ |
| 131 | + elA.addClass('selected'); |
| 132 | + } |
| 133 | + }); |
| 134 | + }); |
| 135 | + |
| 136 | + loader.stopLoader(); |
| 137 | + } |
| 138 | + ); |
| 139 | + }; |
| 140 | + } |
| 141 | +); |
0 commit comments