/
page-store.twig
365 lines (350 loc) · 18.5 KB
/
page-store.twig
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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
{% extends "base.twig" %}
{% macro variants_modal(prompt,allow_multiple,id,name,variants) %}
{% set variants_json = [] %}
{% for variant in variants %}
{% set variants_json = variants_json|merge([{ 'option': variant.title, 'id': variant.id }]) %}
{% endfor %}
{% if variants|length > 1 %}
<div id="product_modal_{{ id }}" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">{{ prompt|default('Please select your preferred option.') }}</h4>
</div>
<div class="modal-body">
<div data-bind="visible: store_view() == 'downloads'">
<label><input type="checkbox" data-bind="checked: remember_format" /> Make this format my default.</label>
</div>
{% for variant in variants %}
<button class="option" onclick='addToCart({{ id }},"{{ name|escape('js') }}",{{ variant.price|number_format }},{{ variants_json|json_encode() }},{{ variant.id }},{{ allow_multiple }})' id="product{{ id }}_{{ variant.title }}">{{ variant.title }}</button>
{% endfor %}
<div class="clearfix"></div>
</div>
</div>
</div>
</div>
{% else %}
<script>
function add_{{ id }}_to_cart() {
addToCart({{ id }},"{{ name }}",{{ variants[0].price|number_format }},{{ variants_json|json_encode() }},{{ variants[0].id }},{{ allow_multiple }});
}
</script>
{% endif %}
{% endmacro %}
{% import _self as macros %}
{% block second_header %}
<nav id="nav-store">
<div class="container">
<ul>
{% for category in store %}
{% if not loop.first %}<div class="menu_slash">/</div>{% endif %}
<li class="menu-item" data-bind="css: { 'current-menu-item': store_view() == '{{ category.html_name }}' }">
<a onclick="store_nav('{{ category.html_name }}')">{{ category.name }}</a>
</li>
{% endfor %}
<div class="cart_link" data-toggle="modal" data-target="#cart_modal">
<span class="cart_image" data-bind="css: { cart_full: cart().length > 0}, text: pos_cart_number"></span>
<span class="cart_text">CART</span>
</div>
</ul>
</div>
</nav>
{% endblock %}
{% block content %}
<div class="container" style="display: none; padding-bottom: 60px;" data-bind="fadeVisible: knockout_loaded">
{% if store|length < 1 %}
<p>The store is temporarily offline.</p>
{% endif %}
{% for category in store %}
{% set allow_multiple = 'true' %}
{% if category.shopify_type == 'Music download' or category.shopify_type == 'Karaoke' %}
{% set allow_multiple = 'false' %}
{% endif %}
<div data-bind="visible: store_view() == '{{ category.html_name }}'">
{% if category.shopify_type == 'Music download' %}
{% for album in category.products %}
<a class="anchor" id="album{{ album.collection.id }}"></a>
<div class="col-xs-12 col-sm-4">
{% if album.collection.image.src %}
<div class="album_square" style="background-image: url('{{ album.collection.image.src }}')"></div>
{% endif %}
{% for track in album.products %}
{% if track.metafields.track_number == 0 %}
<a data-bind="visible: !in_cart({ product_id: {{ track.id }} })" onclick="option_modal({{ track.id }})" class="no_underline">
<div class="add_to_cart_box_blue">
Add album to cart
<img src="{{ theme.link }}/images/add_to_cart_white.svg" class="track_icon_img" />
</div>
</a>
<div data-bind="visible: in_cart({ product_id: {{ track.id }} })" class="add_to_cart_box_blue">
Album in cart
<img src="{{ theme.link }}/images/checked_white.svg" class="track_icon_img" />
</div>
{% endif %}
{% endfor %}
</div>
<div class="col-xs-12 col-sm-8">
<h3 class="album_title">{{ album.collection.title }}</h3>
<span class="album_year">{{ album.collection.body_html }}</span>
{% for track in album.products %}
<div class="track_row {% if track.metafields.track_number == 0 %}album_row{% endif %}" data-bind="css: { play_row: current_song() == {{ track.id }} }">
<span class="track_icon_left">{% if track.metafields.track_number > 0 %}{{ track.metafields.track_number }}{% endif %}</span>
<span class="track_icon_left">{% if track.metafields.track_number > 0 %}
<span data-bind="visible: player_ready">
<span data-bind="visible: current_song() != {{ track.id }} || !playing()">
<a onclick="playSound({{ track.id }})"><img src="{{ theme.link }}/images/play_black.svg" class="track_play_img"></a>
</span>
<span data-bind="visible: current_song() == {{ track.id }} && playing">
<a onclick="pauseSound()"><img src="{{ theme.link }}/images/pause_black.svg" class="track_play_img"></a>
</span>
</span>
{% endif %}</span>
<div class="track_title" style="z-index: 0">{{ track.title }}</div>
<div class="track_icon_right_group">
<span class="track_icon_right">
<a data-bind="visible: !in_cart({ product_id: {{ track.id }} })" onclick="option_modal({{ track.id }})">
<img src="{{ theme.link }}/images/add_to_cart_blue.svg" class="track_icon_img">
</a>
<span data-bind="visible: in_cart({ product_id: {{ track.id }} })">
<img src="{{ theme.link }}/images/checked_blue.svg" class="track_icon_img">
</span>
</span>
<span class="track_icon_right">${{ track.variants[0].price|number_format }}</span>
<span class="track_icon_right">
<a href="{{ track.metafields.wiki_link }}" class="track_info_icon {% if track.metafields.track_number == 0 %}album_info_icon{% endif %}"></a>
</span>
</div>
</div>
{{ macros.variants_modal('Please select a file format for your download.',allow_multiple,track.id,track.title,track.variants) }}
{% endfor %}
<div style="height: 50px;"></div>
</div>
<div class="clearfix"></div>
{% endfor %}
{% else %}
{% for product in category.products %}
<div class="col-sm-3 product">
<div class="album_square" style="background-image: url('{{ product.image.src }}')"></div>
<a onclick="option_modal('{{ product.id }}')" class="no_underline">
<div class="add_to_cart_box_blue" style="margin: 0 0 20px;">
<span data-bind="visible: !in_cart({ product_id: {{ product.id }} })">
${{ product.variants[0].price|number_format }} | Add to cart
<img src="{{ theme.link }}/images/add_to_cart_white.svg" class="track_icon_img" />
</span>
<span data-bind="visible: in_cart({ product_id: {{ product.id }} })">
${{ product.variants[0].price|number_format }} | Add another
<img src="{{ theme.link }}/images/checked_white.svg" class="track_icon_img" />
</span>
</div>
</a>
<div class="product_title">{{ product.title }}</div>
<div class="product_description">{{ product.body_html }}</div>
</div>
{{ macros.variants_modal('',allow_multiple,product.id,product.title,product.variants) }}
{% endfor %}
<div class="clearfix"></div>
{% endif %}
</div>
{% endfor %}
</div>
<!-- MODALS -->
<div id="cart_modal" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Your cart!</h4>
</div>
<div class="modal-body">
<div class="cart_row cart_headers">
<span>Item</span>
<span class="cart_icon_right">Remove</span>
<span class="cart_icon_right">Price</span>
<span class="cart_icon_right">Option</span>
<span class="cart_icon_right">Duplicate item</span>
</div>
<div data-bind="foreach: cart">
<div class="cart_row">
<div data-bind="text: product_name" class="cart_title"></div>
<span class="cart_icon_right"><a data-bind="click: $root.remove_product">✕</a></span>
<span class="cart_icon_right">$<span data-bind="text: calculated_cost"></span></span>
<span class="cart_icon_right"><select data-bind="options: variants, value: variant, optionsText: 'option', visible: variants().length > 1"></select></span>
<span class="cart_icon_right"><a data-bind="click: duplicate_item, visible: allow_multiple">+</a></span>
</div>
</div>
<div class="subtotal_box">
<div class="subtotal_line">
Subtotal <span style="float: right;">$<span data-bind="text: total_cost"></span></span>
</div>
<div class="subtotal_fineprint">(Shipping and tax calculated at checkout.)</div>
</div>
<div class="clearfix"></div>
<div style="float: left;">
<a onclick="$('#cart_modal').modal('hide')" class="no_underline">
<div class="gray_arrow_left">Keep shopping</div>
</a>
</div>
<div style="float: right;">
<a data-bind="attr: { href: checkout_link }, visible: cart().length > 0" class="no_underline">
<div class="blue_arrow_right" style="width: 200px;">Checkout</div>
</a>
<div class="gray_arrow_right" data-bind="visible: cart().length < 1">Checkout</div>
</div>
<div class="clearfix"></div>
</div>
</div>
</div>
</div>
<div id="cart_confirm_modal" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">
Item added to cart!
<br />
<img src="{{ theme.link }}/images/checked_white.svg">
</h4>
</div>
<div class="modal-body">
<span id="cart_confirm_product_name"></span> has been added to your shopping cart!
<div class="" style="margin: 30px auto;">
<div class="col-xs-6">
<button class="option centered" onclick="$('#cart_confirm_modal').modal('hide')">Keep shopping</button>
</div>
<div class="col-xs-6">
<!-- The setTimeout function prevents weird scrolling behavior from Bootstrap -->
<button class="option centered" onclick="$('#cart_confirm_modal').modal('hide'); setTimeout('$(\'#cart_modal\').modal(\'show\')',400);">Checkout</button>
</div>
<div class="clearfix"></div>
</div>
</div>
</div>
</div>
</div>
<div id="purchase_confirm_modal" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Item added to cart!</h4>
</div>
<div class="modal-body">
Thank you for your order from jonathancoulton.com!<br />
<br />
You are awesome.<br />
<br />
<a onclick="$('#purchase_confirm_modal').modal('hide')"><div class="blue_arrow_left">Back</div></a>
</div>
</div>
</div>
</div>
<script type="application/javascript">
//var store_section = '{{ get_vars.store_section|default('downloads') }}';
var store_section = 'downloads';
var scrollto = '';
var hash = window.location.hash.split('#')[1];
if (hash) {
var parts = hash.split('-'); // This means anchor IDs can't have dashes in them
store_section = parts[0];
scrollto = parts[1];
}
{% if get_vars.return_from_shopify %}
window.onload = function() {
myViewModel.cart([]);
sessionStorage.setItem('cart',ko.toJSON([]));
$('#purchase_confirm_modal').modal('show');
};
{% endif %}
var playlist = [
{% for category in store %}
{% if category.shopify_type == 'Music download' %}
{% for album in category.products %}
{% for track in album.products %}
{% if track.metafields.music_link %}
{ id: {{ track.id }}, url: '{{ track.metafields.music_link }}', title: '{{ track.title|e }}' },
{% endif %}
{% endfor %}
{% endfor %}
{% endif %}
{% endfor %}
];
soundManager.setup({
url: '/path/to/swf-files/',
flashVersion: 9, // optional: shiny features (default = 8)
// optional: ignore Flash where possible, use 100% HTML5 mode
preferFlash: false,
debugMode: false,
onready: function() {
myViewModel.player_ready(true);
}
});
function playControl() {
if (myViewModel.current_song() == 0) {
playSound(playlist[0].id);
} else {
playSound(myViewModel.current_song())
}
}
function nextControl() {
var current_song = myViewModel.current_song();
if (current_song != 0) {
for (var i = 0; i < playlist.length; i++) {
if (playlist[i].id == current_song) {
var next_id = i == playlist.length-1 ? playlist[0].id : playlist[i+1].id;
playSound(next_id);
}
}
}
}
function backControl() {
var current_song = myViewModel.current_song();
if (current_song != 0) {
for (var i = 0; i < playlist.length; i++) {
if (playlist[i].id == current_song) {
var next_id = i == 0 ? playlist[playlist.length-1].id : playlist[i-1].id;
playSound(next_id);
}
}
}
}
function playSound(song_id) {
myViewModel.playing(true);
if (myViewModel.current_song() == song_id) {
soundManager.resume(song_id);
} else {
stopSound();
myViewModel.current_song(song_id);
for (var i = 0; i < playlist.length; i++) {
if (playlist[i].id == song_id) {
myViewModel.current_song_title($('<textarea />').html(playlist[i].title).text()); // the jquery removes html entities
var next_id = i == playlist.length - 1 ? playlist[0].id : playlist[i + 1].id;
soundManager.createSound({
id: song_id,
url: playlist[i].url,
autoLoad: true,
autoPlay: true,
onfinish: function () {
playSound(next_id);
}
});
}
}
}
}
function pauseSound() {
myViewModel.playing(false);
soundManager.pause(myViewModel.current_song());
}
function stopSound() {
var song = soundManager.getSoundById(myViewModel.current_song());
if (song) {
myViewModel.current_song(0);
song.stop();
song.destruct();
}
}
</script>
<script type="application/javascript" src="{{ theme.link }}/js/store.js"></script>
{% endblock %}