forked from mondayrain/type-mixer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTypeMixer.js
243 lines (209 loc) · 5.39 KB
/
TypeMixer.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
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
/* --- GLOBALS --- */
var BACKGROUND_COLOUR = "rgb(70,130,180)";
var TRANSPARENCY = "0.3";
var LEFT_IS_TRANSPARENT = false;
var RIGHT_IS_TRANSPARENT = false;
var LEFT_TYPE = "";
var RIGHT_TYPE = "";
var TYPE_DICT = {"button-one":"ziggurat",
"button-two":"jenson",
"button-three":"bodoni",
"button-four":"knockout",
"button-five":"futura",
"button-six":"fette"};
var COLOUR_DICT = {"ziggurat":"rgb(246,146,30)",
"jenson":"rgb(198,177,152)",
"bodoni":"rgb(255,29,37)",
"knockout":"rgb(139,159,63)",
"futura":"rgb(105,219,230)",
"fette":"rgb(77,77,77)"};
var MIXED_COLOUR_DICT = {"futura_bodoni":"rgb(158,64,192)",
"knockout_ziggurat":"rgb(182,186,33)",
"fette_jenson":"rgb(117,76,36)"};
var IMAGES_FOLDER = "images/"
$(document).ready(function() {
$("#left-type-img").height(330);
$("#left-type-img").width(460);
$("#right-type-img").height(330);
$("#right-type-img").width(500);
$(".button").click(function()
{
var button = $(this).attr("id");
var typename = TYPE_DICT[button]
var isUsed = change_type(typename);
if (isUsed)
{
var id = $(this).children("img").attr("alt");
var hoverurl = id.concat('-hover.png');
$(this).children("img").attr("src", IMAGES_FOLDER.concat(hoverurl));
}
else
{
var id = $(this).children("img").attr("alt");
var regurl = id.concat('-reg.png');
$(this).children("img").attr("src", IMAGES_FOLDER.concat(regurl));
}
change_background();
});
$(".button").hover(function()
{
if ((LEFT_TYPE == "") || (RIGHT_TYPE == ""))
{
// LIGHT UP BUTTON
var id = $(this).children("img").attr("alt");
if(!is_type_used(TYPE_DICT[id]))
{
var hoverurl = id.concat('-hover.png');
$(this).children("img").attr("src", IMAGES_FOLDER.concat(hoverurl));
}
// SHOW TRANSPARENCY
var typename = TYPE_DICT[id];
if(!is_type_used(typename))
{
if (LEFT_TYPE == "")
{
document.getElementById("left-type-img").style.opacity = TRANSPARENCY;
var source = typename.concat("_left.png");
$("#left-type-img").attr("src", IMAGES_FOLDER.concat(source));
LEFT_IS_TRANSPARENT = true;
}
else
{
document.getElementById("right-type-img").style.opacity = TRANSPARENCY;
var source = typename.concat("_right.png");
$("#right-type-img").attr("src", IMAGES_FOLDER.concat(source));
RIGHT_IS_TRANSPARENT = true;
}
}
}
},
function()
{
if ((LEFT_TYPE == "") || (RIGHT_TYPE == ""))
{
// UNLIGHT BUTTON
var id = $(this).children("img").attr("alt");
if(!is_type_used(TYPE_DICT[id]))
{
var regurl = id.concat('-reg.png');
$(this).children("img").attr("src", IMAGES_FOLDER.concat(regurl));
}
// UNSHOW TRANSPARENCY
var typename = TYPE_DICT[id];
if ((LEFT_TYPE == "") && LEFT_IS_TRANSPARENT)
{
$("#left-type-img").attr("src", "images/left_transparent.png");
LEFT_IS_TRANSPARENT = false;
}
if ((RIGHT_TYPE == "") && RIGHT_IS_TRANSPARENT)
{
$("#right-type-img").attr("src", "images/left_transparent.png");
RIGHT_IS_TRANSPARENT = false;
}
}
});
/* --- CHANGE BACKGROUND COLOUR --- */
var change_background = function()
{
if ((LEFT_TYPE != "") && (RIGHT_TYPE != ""))
{
var possible_type = (LEFT_TYPE.concat("_")).concat(RIGHT_TYPE);
if (possible_type in MIXED_COLOUR_DICT)
{
fade_colour("#wrapper", MIXED_COLOUR_DICT[possible_type]);
return true;
}
var possible_type = (RIGHT_TYPE.concat("_")).concat(LEFT_TYPE);
if (possible_type in MIXED_COLOUR_DICT)
{
fade_colour("#wrapper", MIXED_COLOUR_DICT[possible_type]);
return true;
}
}
else if (LEFT_TYPE)
{
fade_colour("#wrapper", COLOUR_DICT[LEFT_TYPE]);
}
else if (RIGHT_TYPE)
{
fade_colour("#wrapper", COLOUR_DICT[RIGHT_TYPE]);
}
else
{
fade_colour("#wrapper", BACKGROUND_COLOUR);
}
}
var fade_colour = function(element, colour)
{
$(element).animate(
{
backgroundColor: colour
}, 700); //Change this number to change # of milliseconds it takes to fade
}
/* --- CHANGE TYPE --- */
var change_type = function(typename)
{
// If the type is used, just remove it
if (is_type_used(typename))
{
remove_type(typename);
return false;
}
else
{
// If both spaces are taken, don't do anything
if ((LEFT_TYPE != "") && (RIGHT_TYPE != ""))
{
return false;
}
else if (LEFT_TYPE)
{
change_right_type(typename);
return true;
}
else
{
change_left_type(typename);
return true;
}
}
}
var change_left_type = function(typename)
{
var new_src = typename.concat("_left.png");
$("#left-type-img").attr("src", IMAGES_FOLDER.concat(new_src));
document.getElementById("left-type-img").style.opacity = "1.0";
LEFT_TYPE = typename;
}
var change_right_type = function(typename)
{
var new_src = typename.concat("_right.png");
$("#right-type-img").attr("src", IMAGES_FOLDER.concat(new_src));
document.getElementById("right-type-img").style.opacity = "1.0";
RIGHT_TYPE = typename;
}
var remove_type = function(typename)
{
if (typename == LEFT_TYPE)
{
$("#left-type-img").attr("src", "images/left_transparent.png");
LEFT_TYPE = "";
}
else
{
$("#right-type-img").attr("src", "images/left_transparent.png");
RIGHT_TYPE = "";
}
}
var is_type_used = function(typename)
{
if ((typename == LEFT_TYPE) || (typename == RIGHT_TYPE))
{
return true;
}
else
{
return false;
}
}
});