-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
464 lines (410 loc) · 14.2 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
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
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
<!doctype html>
<html>
<head>
<title>JoyStation Static</title>
<meta charset="utf-8">
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" name="viewport">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<link rel="shortcut icon" type="image/png" href="favicon.png">
<link rel="apple-touch-icon" href="favicon.png">
<script src="https://unpkg.com/[email protected]/dist/vue.min.js"></script>
<script src="https://unpkg.com/[email protected]/dist/vue-ls.min.js"></script>
<script src="https://unpkg.com/[email protected]/vec2.min.js"></script>
<script>
// Analytics
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
</script>
<link href="https://fonts.googleapis.com/css?family=Berkshire+Swash" rel="stylesheet">
<!-- <script src="https://github.com/hsluv/hsluv/releases/download/v0.0.1/hsluv.min.js"></script> -->
<style>
*{
box-sizing: border-box;
}
html{
font-size:8vmin;
background-color:#fff07e;
}
body{
margin:0;
}
#app{
display:flex;
flex-direction:row;
height:100vh;
}
.cushion-sides{
padding: 0 0.5rem;
}
.cushion{
padding: 0.5rem;
}
.prompt {
font-family: 'Berkshire Swash', cursive;
text-align:center;
}
.face{
fill:#1c4355;
stroke:#1c4355;
stroke-width:25px;
/* fill:white;
stroke:red; */
/* marker-start: url(#head); */
/* stroke-width:1px; */
stroke-linecap:round;
stroke-linejoin:round;
}
.range-wrapper {
border-radius: 1rem;
overflow:hidden;
background-color:red;
height:2rem;
}
.mood-range {
-webkit-appearance: none;
margin:0;
width: 100%;
}
.mood-range:focus {
outline: none;
}
.mood-range::-webkit-slider-runnable-track {
width: 100%;
height: 2rem;
padding:0.1rem;
border-radius: 1rem;
border: none;
cursor: pointer;
background: #b6df9b;
background: linear-gradient(to right,#fc3f05 0%,#ae96ac 50%,#00b7b9 100%);
}
.mood-range::-webkit-slider-thumb {
height: 1.8rem;
width: 1.8rem;
border: none;
border-radius: 0.9rem;
background: white;
cursor: pointer;
-webkit-appearance: none;
}
.mood-range:focus::-webkit-slider-runnable-track {
background: linear-gradient(to right, #1e5799 0%,#7db9e8 100%);
}
.admin{
background-color:white;
font-family: Helvetica;
}
.admin *{
font-size: 18px;
}
.admin form{
display:flex;
flex-direction: column;
overflow-x:scroll;
}
.admin label{
margin-bottom:1em;
}
.admin input[type="text"],
.admin input[type="number"],
.admin select
{
background-color:bisque;
border:solid 1px rgb(223, 183, 134);
padding: 0.1em 0.2em;
border-radius: 0.2em;
}
.admin small{
font-size:0.8em;
font-style: italic;
}
.thanks{
/* display:flex;
flex-direction:column; */
font-size:2rem;
font-family: 'Berkshire Swash', cursive;
/* text-align: center; */
align-content: space-evenly;
height:100%;
margin:0 auto;
}
button{
width:100%;
font-size:1.5rem;
border:0;
border-radius: 0.45rem;
padding: 0.1rem 0.2rem;
background-color:rgb(79, 145, 243);
color:white;
font-weight:800;
}
</style>
</head>
<body>
<div id="app">
<div v-if="adminMode" class="admin cushion-sides">
<h1>Settings</h1>
<form>
<label>
<div>Prompt</div>
<input type="text" v-model="settings.action" placeholder="That meeting was" size="20" maxlength="21" pattern="[\d| |?]">
</label>
<label>
<div>Category</div>
<!-- <input type="text" v-model="category" placeholder="staff" size="10"> -->
<select v-model="settings.category">
<option>customers</option>
<option>staff</option>
</select>
</label>
<label>
<div>Location</div>
<input type="text" v-model="settings.label" placeholder="main" size="10">
</label>
<label>
<div>Start Joy With</div>
<input type="number" v-model="settings.joyDefault" pattern="\d*" size="10" min="-200" max="200" placeholder="100">
<input type="range" v-model="settings.joyDefault" min="-200" max="200">
</label>
<label>
<div>Thanks & Wait (seconds)</div>
<input type="number" v-model="settings.thanksDelay" pattern="\d*" size="10" min="5" max="30" placeholder="10">
<input type="range" v-model="settings.thanksDelay" min="5" max="30">
</label>
<label>
<div>Analytics Key</div>
<input type="text" v-model="settings.analyticsKey">
<br>
<small>Without a key, JoyStation runs in Demo Mode</small>
</label>
<label>
<div>Force Demo Mode</div>
<input type="checkbox" v-model="settings.debug">
</label>
</form>
<button @click="saveSettings" @touchstart="saveSettings">Save</button>
<button onclick="location.reload(true)" ontouchend="location.reload(true)">Reset</button>
</div>
<div v-if="answerMode">
<p class="prompt">{{settings.action}}</p>
<svg width="768" height="500" viewBox="0 -50 400 300" @mousedown="down" @mousemove="move" @mouseup="up" @touchstart="down" @touchmove="move" @touchend="up">
<defs>
<marker id='head' orient='auto' markerWidth='4' markerHeight='4' refX='0' refY='2'>
<path d='M0,0 V4 L4,2 Z' />
</marker>
<path id="negative2" d="
M 95 -10 A 40,15,15 1 0 96,-10
M 300 -10 A 40,15,345 1 0 301,-10
M 60,180 C 90,50 310,50 340,180 310,160 90,160 60,180 z"/>
<path id="negative1" d="
M 120 0 A 20,30,0 1 0 121,0
M 280 0 A 20,30,360 1 0 281,0
M 60,160 C 90,90 310,90 340,160 310,100 90,100 60,160 z"/>
<path id="positive1" d="
M 120 -10 A 20,30,15 1 0 121,-10
M 280 -10 A 20,30,355 1 0 281,-10
M 60,110 C 90,190 310,190 340,110 310,210 90,210 60,110 z"/>
<path id="positive2" d="
M 120 -30 A 20,40,5 1 0 121,-30
M 280 -30 A 20,40,355 1 0 281,-30
M 60,115 C 90,105 310,105 340,115 310,255 90,255 60,115 z"/>
</defs>
<path class="face"
id="mouth"
:d="mouthData"/>
</svg>
<div class="cushion-sides">
<div class="range-wrapper">
<input class="mood-range" type="range" min="-200" max="200" v-model="joySwap" @mouseup="activated=true" @touchstart="activated=true">
</div>
</div>
<div class="cushion">
<button v-if="activated" @touchstart="done" @mouseup="done">Send</button>
</div>
</div>
<div v-else class="thanks">
<p>Thanks!</p>
<img src="logo-color.svg">
</div>
</div>
<script>
/* JoyStation Logic pseudo-code walkthrough
Compare screen dimensions to viewport dimensions
If they don't match up, prompt admin settings
If in admin mode show admin panel
allow changing of the question, location, context, delay, etc
allow changing of google analytics tracking code
If in regular mode
if in prompt mode
allow vertical swiping on face to change joy value
allow horizontal slider to change joy value
if joy value has been changed
show submit button
if button is pressed
switch to thanks mode
If in thanks mode
display "thanks"
switch back to prompt mode after the delay completes.
*/
var svgDataPattern = /(-|\d)+|\w/g;
var negative2 = document.querySelector('#negative2').getAttributeNS(null,'d').match(svgDataPattern);
var negative1 = document.querySelector('#negative1').getAttributeNS(null,'d').match(svgDataPattern);
var positive1 = document.querySelector('#positive1').getAttributeNS(null,'d').match(svgDataPattern);
var positive2 = document.querySelector('#positive2').getAttributeNS(null,'d').match(svgDataPattern);
function lerp(v0, v1, t) {
return v0*(1-t)+v1*t
}
function lerpArray(value1, value2, t, out) {
if (typeof value1 === 'number'
&& typeof value2 === 'number') {
return lerp(value1, value2, t)
} else { //assume array
var len = Math.min(value1.length, value2.length)
out = out||new Array(len)
for (var i=0; i<len; i++) {
// console.log( Number(value1[i]), Number(value2[i]));
if (!isNaN(value1[i])
&& !isNaN(value2[i]))
out[i] = lerp(value1[i], value2[i], t)
else
out[i] = value1[i]
}
return out
}
}
var pressed = false;
var rebootOnTilt = false;
var thisPoint = Vec2(150,165);
////// Vue
Vue.use(VueLocalStorage)
var app = new Vue({
el: '#app',
data:{
joySwap: 0,
adminMode: false,
answerMode: true,
activated: false,
settings: {
debug: false,
analyticsKey:'',
action:'Question',
category: 'customers',
label:'main',
thanksDelay: 20.0,
joyDefault: 100
}
},
created() {
this.toggleAdmin();
// retrieve settings from local storage
var keys = Object.keys(this.settings);
for(i in keys) {
var key = keys[i];
console.log('building retrieve for', key);
this.settings[key] = Vue.ls.get(key, this.settings[key]);
var self = this;
Vue.ls.on(key, function(val) {
self.settings[key] = val;
});
}
this.joySwap = this.settings.joyDefault;
if(this.settings.analyticsKey !== '' && !this.settings.debug) {
ga('create', this.settings.analyticsKey, 'auto', 'user');
ga('user.send', 'pageview');
}
},
computed: {
joy() {
return this.adminMode ? this.settings.joyDefault : this.joySwap;
},
mouthData() {
var A = '';
var B = '';
var t=0;
if(this.joy >= -200 && this.joy <= -100){
A = negative2;
B = negative1;
t = (Number(this.joy) + 200) / 100
}
if(this.joy > -100 && this.joy <= 100){
A = negative1;
B = positive1;
t = (Number(this.joy) + 100) / 200
}
if(this.joy > 100 && this.joy <= 200){
A = positive1;
B = positive2;
t = (Number(this.joy) - 100) / 100
}
return lerpArray(A, B, t).join(' ');
}
},
methods: {
down(e){
e.preventDefault();
pressed = true;
this.activated = true;
this.move(e);
},
move(e){
if(pressed){
// console.log(e);
thisPoint = Vec2(e.pageX, e.pageY);
// this.x = thisPoint.x;
this.joy = (thisPoint.y-200) / 500 * 400 - 200;
this.joy = Math.min(200, this.joy)
this.joy = Math.max(-200, this.joy)
}
},
up(e){
pressed = false;
},
done(e) {
e.preventDefault();
if(this.settings.analyticsKey !== '' && !this.settings.debug) {
ga('create', this.settings.analyticsKey, 'auto', 'user');
ga('user.send','event',this.settings.category, this.settings.action, this.settings.label, this.joy, {test: 123, anotherTest: "pineapple"})
}
this.activated = false;
this.answerMode = false;
var self = this;
setTimeout(function(){
self.answerMode = true;
self.joySwap = self.settings.joyDefault;
}, this.settings.thanksDelay * 1000);
console.log('Answer submitted. Waiting', this.settings.thanksDelay, 'seconds')
},
toggleAdmin() {
var orientation = ( window.screen.orientation !== undefined ) ?
window.screen.orientation.angle : window.orientation;
console.log('orientation',orientation)
if( (orientation === 90) || (orientation === -90) ) {
this.adminMode = true;
}else if(rebootOnTilt){
location.reload(true);
}
},
reset() {
console.log('reset');
},
saveSettings() {
var keys = Object.keys(this.settings);
for(i in keys) {
var key = keys[i];
Vue.ls.set(key, this.settings[key]);
}
this.joySwap = this.settings.joyDefault;
this.toggleAdmin();
rebootOnTilt = true;
}
}
});
window.addEventListener("orientationchange", function() {
app.toggleAdmin();
});
</script>
</body>
</html>