-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbehavior.js
109 lines (89 loc) · 2.96 KB
/
behavior.js
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
var assigned = false,
physical = false,
emotional = false,
expression = false,
identity = false;
var cssPrefix = (Array.prototype.slice
.call(window.getComputedStyle(document.documentElement, ''))
.join('')
.match(/-(moz|webkit|ms)-/) || (styles.OLink === '' && ['', 'o'])
)[1];
function share() {
var store = serialize();
document.location.hash = store;
setTimeout(function() {
$('#share-modal input').val(document.location.href).focus();
$('#share-modal input').val(document.location.href).select();
}, 100);
}
function changeIdentity() {
identity = true;
$('.unicorn img.thought').addClass('show');
}
function changeExpression() {
expression = true;
var deg = 360 * $('section.expression input#expression-feminine').val() / 100
- 360 * $('section.expression input#expression-masculine').val() / 100
+ 360 * $('section.expression input#expression-other').val() / 100;
deg = Math.floor(deg);
deg %= 360;
$('.unicorn img.expression').addClass('show');
$('.unicorn img.plain')[0].setAttribute('style', 'filter: hue-rotate(' + deg + 'deg)');
$('.unicorn img.assigned')[0].setAttribute('style', 'filter: hue-rotate(' + deg + 'deg)');
if (cssPrefix == 'webkit') {
$('.unicorn img.plain')[0].setAttribute('style', '-' + cssPrefix + '-filter: hue-rotate(' + deg + 'deg)');
$('.unicorn img.assigned')[0].setAttribute('style', '-' + cssPrefix + '-filter: hue-rotate(' + deg + 'deg)');
}
}
function changeAssigned() {
assigned = true;
$('.unicorn img.assigned').addClass('show');
}
function changePhysical() {
physical = true;
$('.unicorn img.physical').addClass('show');
}
function changeEmotional() {
emotional = true;
$('.unicorn img.emotional').addClass('show');
}
$('section.identity input').change(changeIdentity);
$('section.expression input').change(changeExpression);
$('section.assigned input').change(changeAssigned);
$('section.physical input').change(changePhysical);
$('section.emotional input').change(changeEmotional);
$(document).scroll(function() {
$('.unicorn').css({
marginTop: $(document).scrollTop()
});
});
$('button').click(share);
function serialize() {
var data = [];
$('input[type=range]').each(function() {
data.push(this.value);
});
$('input[type=radio]').each(function() {
data.push(this.checked - 0);
});
return data.join(',');
}
function unserialize(store) {
var data = store.split(',');
$('input[type=range]').each(function() {
this.value = data.shift();
});
$('input[type=radio]').each(function() {
this.checked = data.shift() == '1'? true: false;
});
}
if (document.location.hash.length > 1) {
unserialize(document.location.hash.replace(/#/, ''));
setTimeout(function() {
changeIdentity();
changeAssigned();
changePhysical();
changeEmotional();
changeExpression();
}, 50);
}