-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
225 lines (193 loc) · 7.34 KB
/
index.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
<!doctype HTML>
<html>
<head>
<meta charset='utf-8'>
<title>PixelSquid Atlas - Basic Loading</title>
<script src='../src/externals/jquery-1.12.3.min.js'></script>
<style>
.atlas-container {
position: relative;
}
.cancel {
font-size: 16px;
background-color: #da4b3a;
color: white;
margin-bottom: 5px;
}
.download {
font-size: 16px;
background-color: #da4b3a;
color: white;
display: none;
margin-bottom: 5px;
}
#download_iframe {
display: none;
}
.atlas-viewer {
display: none;
}
.atlas-signature-image {
width: 600px;
height: 600px;
}
</style>
</head>
<body>
<button type='button' class='cancel'>Cancel</button>
<div class='progress'>Loading Progress: 0%</div>
<button type='button' class='download'>Download</button>
<div class='atlas-container'>
<div class='atlas-events'>
<div class='atlas-control-area atlas-viewer'>
</div>
<div class='atlas-signature-image'>
<img id='atlas_signature_image' src=''/>
</div>
</div>
</div>
<iframe id='download_iframe'></iframe>
<script>
var productIds = [
'1117422901537019360', // full spinner, reduced bitmap, clipped
'1110610592596498081', // half spinner, reduced bitmap, blank lines at bottom
'1025400099527726189', // half spinner, reduced bitmap, clipped
]
var productId = productIds[0]
window.player = null;
///***
///Loading Progress with jQuery
///***
$(document).on('atlas-load-start', '.atlas-events', function() {
$('.progress').show();
$('.download').hide();
$('.progress').html('Loading Progress: 0%');
});
$(document).on('atlas-load-progress', '.atlas-events', function(element, data) {
$('.progress').html('Loading Progress: ' + (data.progress * 100.0) + '%');
});
$(document).on('atlas-load-complete', '.atlas-events', function(element, data) {
$('.progress').hide();
$('.download').show();
$('.atlas-signature-image').hide();
$('.atlas-viewer').show();
});
$(document).on('atlas-image-changed', '.atlas-events', function(element, data) {
//console.log(data);
});
$(document).on('atlas-load-error', '.atlas-events', function(element, error) {
console.log(error);
});
///***
///Loading Progress without jQuery
///***
var element = document.querySelectorAll('.atlas-events');
if (element && element.length) {
element[0].addEventListener('atlas-load-start', function() {
var cancel = document.querySelectorAll('.cancel');
var progress = document.querySelectorAll('.progress');
var download = document.querySelectorAll('.download');
cancel && cancel.length, cancel[0].style.display = 'block';
progress && progress.length, progress[0].innerHTML = 'Loading Progress: 0%';
progress && progress.length, progress[0].style.display = 'block';
download && download.length, download[0].style.display = 'none';
});
element[0].addEventListener('atlas-load-progress', function(e) {
var progress = document.querySelectorAll('.progress');
progress && progress.length, progress[0].innerHTML = 'Loading Progress: ' + (e.detail.progress * 100.0) + '%';
});
element[0].addEventListener('atlas-load-complete', function(e) {
var cancel = document.querySelectorAll('.cancel');
var progress = document.querySelectorAll('.progress');
var download = document.querySelectorAll('.download');
var signatureImage = document.querySelectorAll('.atlas-signature-image');
var viewer = document.querySelectorAll('.atlas-viewer');
cancel && cancel.length, cancel[0].style.display = 'none';
progress && progress.length, progress[0].style.display = 'none';
signatureImage && signatureImage.length, signatureImage[0].style.display = 'none';
download && download.length, download[0].style.display = 'block';
viewer && viewer.length, viewer[0].style.display = 'block';
});
element[0].addEventListener('atlas-image-changed', function(e) {
//console.log(e.detail);
});
element[0].addEventListener('atlas-load-error', function(e) {
console.log(e.detail);
});
}
$(document).on('click', '.cancel', function() {
window.player.cancelLoading();
});
///***
///Download Hi-Res Image
///***
$(document).on('click', '.download', function() {
var params = {
data: {
type: 'download_link',
attributes: {
angle: window.player.getCurrentImageIndex(),
resolution: '2k',
image_format: 'png',
client_ip: '127.0.0.1',
session_id: 'SESSION',
attachment: true
}
}
};
//the replacement of the hostname is just needed for this example since it is running through a "proxy"
var url = 'http://' + window.location.hostname + ':8081/api/products/' + productId + '/download_links';
$.ajax({
type: 'POST',
url: url,
data: JSON.stringify(params),
dataType: 'json',
contentType: 'application/json; charset=utf-8',
headers: {
'Authorization': 'Basic REVWRUxPUEVSX1BBQ0s6cGl4ZWxzcXVpZHNhbXBsZQ==',
'Accept': 'application/vnd.api+json; com.pixelsquid.api.version=1',
'X-Client-External-User-ID': 'SAMPLEUSER'
}
}).done(function(data) {
$('#download_iframe').attr('src', data.data.attributes.url);
});
});
///***
///Initialize the player and begin loading
///***
$(function() {
var productIndex = window.location.href.match(/(productIndex=\d)/)
if (productIndex) {
productId = productIds[productIndex[0].split('=')[1]]
}
//the replacement of the hostname is just needed for this example since it is running through a "proxy"
$.ajax({
url: 'http://' + window.location.hostname + ':8081/api/products/' + productId + '?include=spinner,product_collections',
headers: {
'Authorization': 'Basic REVWRUxPUEVSX1BBQ0s6cGl4ZWxzcXVpZHNhbXBsZQ==',
'Accept': 'application/vnd.api+json; com.pixelsquid.api.version=1',
'X-Client-External-User-ID': 'SAMPLEUSER'
}
}).done(function(data) {
var adapter = new PixelSquid.AtlasAPIAdapter();
adapter.parseResponse(data);
//show a static image while loading
var asset = adapter.getAsset();
$('#atlas_signature_image').attr('src', asset.signature_image);
var preferredImageSize = 600;
//use smaller resolution images for mobile
if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
preferredImageSize = 300;
}
var useCanvas = true;
if (window.location.href.match(/nocanvas/)) {
useCanvas = false;
}
window.player = new PixelSquid.AtlasSpriteSheetPlayer({ preferredImageSize: preferredImageSize, jquery: $, applyStyles: true, useCanvas: useCanvas });
window.player.load({ asset: asset, attachImage: true });
});
});
</script>
<script src='../dist/pixelsquid-atlas.js'></script>
</body>
</html>