-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathstore product detail add to cart button after added callback.html
263 lines (141 loc) · 6.8 KB
/
store product detail add to cart button after added callback.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
<!--
begin store product detail add to cart button after added callback
License : < https://tinyurl.com/s872fb68 >
Version : 0.1.2
SS Versions : 7.1, 7.0
v7.1
Fluid
Engine
Compatible : Not Applicable
Dependencies : twcsl
Note : the code is comprised of two script tags. both are needed
for the full effect to work
this is a base effect meant as a base for other effects.
this code alone shouldn't produce any visible change
this code depends on languages. only a few languages are
currently supported. the code attempts to find the site
language based on the site settings. if the code doesn't
have a language for the language your site is set to
then the code won't work properly. if you need a
language not supported by the code add a post to the
SS forum thread for this code < https://bit.ly/3IaXy4M >
and make a request. no promises that i can add languages
but it doesn't hurt to ask. i need to know the language set
in site settings. please see Language and region settings
< https://bit.ly/3n2THgB >
By : Thomas Creedon < http://www.tomsWeb.consulting/ >
-->
<script>
if ( window.twc == undefined ) window.twc = { };
twc.spdatcbaac = {
/*
callback is a custom function that is called after the atc button
indicates the product has been added to the cart. replace undefined with
the name of your custom function.
your callback must accept a jQuery object which will be the atcb element
that was clicked
*/
callback : undefined
};
</script>
<!-- do not change anything below, there be the borg here -->
<script>
( ( ) => {
const spdatcbaac = ( ) => {
if ( ! twcsl.page.store.detail.is ) return; // bail if not detail
// bail if no mutation observer available
if ( ! ( 'MutationObserver' in window ) ) return;
const options = twc.spdatcbaac;
if ( options.callback == undefined ) return; // bail if no callback
const debugFlag = false;
const getLanguage = language => {
language = languages [ language ];
if ( typeof language == 'string' )
language = languagesRoot [ language ];
return language;
};
const lang = $( 'html' ).attr ( 'lang' );
if ( debugFlag )
console.log ( lang );
const langLanguageMap = {
'de-DE' : 'German (Germany)',
'en-AU' : 'English (Australia)',
'en-CA' : 'English (Canada)',
'en-IN' : 'English (India)',
'en-IE' : 'English (Ireland)',
'en-NZ' : 'English (New Zealand)',
'en-ZA' : 'English (South Africa)',
'en-GB' : 'English (United Kingdom)',
'en-US' : 'English (United States)',
'fr-CA' : 'French (Canada)',
'fr-FR' : 'French (France)',
};
const languages = {
'English (Australia)' : 'English',
'English (Canada)' : 'English',
'English (India)' : 'English',
'English (Ireland)' : 'English',
'English (New Zealand)' : 'English',
'English (South Africa)' : 'English',
'English (United Kingdom)' : 'English',
'English (United States)' : 'English',
'French (Canada)' : 'French',
'French (France)' : 'French',
'German (Germany)' : {
added : 'Hinzugefügt!',
},
};
const languagesRoot = {
'English' : {
added : 'Added!',
},
'French' : {
added : 'Ajout effectué !',
},
};
const observer = new MutationObserver ( function ( mutations ) {
$.each ( mutations, function ( ) {
if ( ! this.addedNodes.length ) return;
let $element = $( this.addedNodes [ 0 ] );
const b = $element.hasClass ( 'status-text' );
if ( ! b ) return true; // continue if no status text
const addedLanguage = siteLanguage.added;
const html = $element.html ( );
if ( debugFlag )
console.log ( html );
if ( html != addedLanguage ) return; // bail if status text not added
$element = $element
.parents ( '.sqs-add-to-cart-button-wrapper' );
options.callback ( $element );
} );
} );
let siteLanguage = langLanguageMap [ lang ];
siteLanguage = getLanguage ( siteLanguage );
// begin listening for changes in specified elements
const selectorPrefixSuffix = '.sqs-add-to-cart-button-inner';
const selector = [
'.ProductItem-details', // simple
// full, half, wrap
'.pdp-layout .pdp-details'
]
.join ( ` ${ selectorPrefixSuffix }, ` )
+
` ${ selectorPrefixSuffix }`;
$( selector ).each ( function ( ) {
observer.observe ( this, {
childList : true
} );
} );
// end listening for changes in specified elements
};
switch ( true ) {
case twcsl.ss.is71 :
$( spdatcbaac );
break;
case twcsl.ss.is70 :
Squarespace.onInitialize ( Y, spdatcbaac );
break;
}
} ) ( );
</script>
<!-- end store product detail add to cart button after added callback -->