forked from heiswayi/random-name-picker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
274 lines (242 loc) · 8.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
<!DOCTYPE html>
<!--[if IE 8]> <html class="no-js lt-ie9" lang="en"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]-->
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>Random Name Picker</title>
<link rel="stylesheet" href="css/normalize.css" />
<link rel="stylesheet" href="css/foundation.css" />
<script src="js/vendor/custom.modernizr.js"></script>
<script src="js/jquery-latest.min.js"></script>
<style>
#values { position:relative;font-size:400%;text-align:center;margin: 0 auto;z-index:0; }
.name { overflow:hidden;display:block; }
#names { display:none;padding:5px; }
#namesbox { min-height:400px;font-size:32px;color:#333;resize:none;border:1px solid #F39C12; }
.extra { font-size:16px;margin-top:20px; }
#result1 { background:#000;color:#fbe34b;padding:20px;z-index:10;margin-top:-150px; }
body { background:#F1C40F url(img/bg-noise-orange.png); }
#varnote { font-size:40px;text-align:center;padding:30px; }
.copyright { font-size:11px;font-family:Tahoma;color:#9B59B6; }
</style>
</head>
<body onload="reset();">
<div class="full-head" style="width:100%;background:#111 url(img/header-bg.png) repeat-x center top;border-bottom:1px solid #D35400;">
<div class="row">
<div class="large-12 columns" style="padding-top:50px;background:#111 url(img/header-bg.png) repeat-x center top;z-index:20;">
<ul class="button-group even-4">
<li><a href="index.html" class="alert button" id="reset">Reset</a></li>
<li><button class="button" id="list" onclick="namelist();">Name List</button></li>
<li><button class="button" id="save" onclick="save();">Save & Update</button></li>
<li><button class="success button" id="go" onclick="go();">GO!</button></li>
</ul>
</div>
</div>
</div>
<div class="row">
<div class="large-12 columns">
<h3 style="text-align:center;margin-top:30px;" id="headline">Let's see who is The Lucky One?</h3>
<div id="varnote"><img src="img/logo.png"><div class="copyright">© Coded by <strong>Heiswayi Nrird</strong>, June 2013</div></div>
<div id="popdown">
<div id="names" class="inbox"><textarea name="namesbox" id="namesbox"></textarea></div>
</div>
<div id="values"></div>
</div>
</div>
<script>
document.write('<script src=' +
('__proto__' in {} ? 'js/vendor/zepto' : 'js/vendor/jquery') +
'.js><\/script>')
</script>
<script src="js/foundation.min.js"></script>
<script>$(document).foundation();</script>
<script src="data/raffleFeed.jsonp"></script>
<script>
String.prototype.setCharAt = function(index, char) {
return this.substr(0, index) + char + this.substr(index + 1);
}
function randomXToY(minVal, maxVal)
{
var randVal = minVal + (Math.random() * (maxVal - minVal));
return Math.round(randVal);
}
function maskString(str) {
var strLen = str.length;
var numToMask = Math.min(strLen * 3 / 5, strLen - 2);
for (var i = 0; i < numToMask;) {
var pos = randomXToY(1, strLen - 2);
if (str.charAt(pos) != '*') {
str = str.setCharAt(pos, '*');
i++;
}
}
return str;
}
function maskEmail(email) {
var atIndex = email.indexOf('@');
var namePart = email.substr(0, atIndex);
var domainIndex = email.lastIndexOf('.');
var providerPart = email.substr(atIndex + 1, domainIndex - atIndex - 1);
return maskString(namePart) + '@' + maskString(providerPart) + email.substr(domainIndex);
}
var text;
var namesFeed = [];
var participantsLength = participants.length;
for(var i = 0; i < participantsLength; i++) {
namesFeed.push(participants[i].name + ' (' + maskEmail(participants[i].email) + ')');
}
var names = Array.from(namesFeed);
function reset(){
// re-enable go button
setTimeout("$('#go').removeAttr('disabled')",11005);
var namesbreak = "";
if(gup('names') != "") {
var names = gup('names');
namesbreak = names.replace(/101/g,'\n');
namesbreak = namesbreak.replace(/%20/g,' ');
} else {
var names = Array.from(namesFeed);
}
for(var i in names) {
name = names[i];
if (name == "" || typeof(name) == undefined) {
} else {
namesbreak = namesbreak + name + "\n";
}
}
$("#namesbox").val(namesbreak);
}
function gup(para)
{
para = para.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+para+"=([^&#]*)";
var regex = new RegExp( regexS );
var results = regex.exec( window.location.href );
if( results == null )
return "";
else
return results[1];
}
function randOrd(){
return (Math.round(Math.random())-0.5);
}
function save(){
$("#varnote").hide();
$("#popdown").show();
$("#values").hide();
$("div").remove("#result1");
savenames = $("#namesbox").val();
savenames = savenames.replace(/\n\r?/g, '101');
$('#headline').fadeOut();
$('#headline').text('The name list is saved and updated.').fadeIn();
$("#names").show();
$('#namesbox').attr('disabled','disabled');
}
function namelist(){
$("#varnote").hide();
$('#namesbox').removeAttr('disabled','disabled');
$('#headline').text('Configure name list');
$("#popdown").show();
$("#values").hide();
$("#names").show();
$('body').css({"overflow-y": "visible"});
}
// does the actual animation
function go(){
$("#varnote").hide();
$('body').css({"overflow-y": "hidden"});
$('#go').attr('disabled','disabled');
$('#list').attr('disabled','disabled');
$('#save').attr('disabled','disabled');
$('#headline').slideUp();
$('#namesbox').slideDown();
var count = 1;
count = 1;
$("div").remove("#result1");
names = $("#namesbox").val();
if(document.all) { // IE
names=names.split("\n");
}
else { //Mozilla
names=names.split("\n");
}
$("#values").show();
$(".name").show();
$("#popdown").hide();
$("div").remove(".name");
$("div").remove(".extra");
$("#playback").html("");
newtop = names.length * 200 * -1;
//$('#values').css({top: -300});
$('#values').css({top: + newtop});
names.sort( randOrd );
var fruits = new Array ( "apple", "pear", "orange", "banana" );
//console.log(fruits);
//console.log(names);
//alert(newtop);
for(var i in names){
if (names[i] == "" || typeof(names[i]) == undefined){
count = count-1;
} else {
name = names[i];
//console.log(name);
$('#values').append('<div id=result'+count+' class=name>'+name+'</div>');
}
count = count+1;
}
for(var i in names){
if (names[i] == "" || typeof(names[i]) == undefined){}else{
name = names[i];
$('#values').append('<div class=name>'+name+'</div>');
}
count = count+1;
}
for(var i in names){
if (names[i] == "" || typeof(names[i]) == undefined){}else{
name = names[i];
$('#values').append('<div class=name>'+name+'</div>');
}
count = count+1;
}
text = $('#result1').text()
$('#values').animate({top: '+176'},5000);
// make it stand out
setTimeout("standout(text)",5000);
//setTimeout("$('#playback').hide('slow')",11005);
}
function standout(text){
$('#result1').removeClass('name');
$('.name').animate({opacity: .25});
$('#result1').animate({height: '+=60px'});
$('#result1').append('<div class="extra"><a class="small alert button" href="#" onClick="removevictim();">Remove name from list</a></div>');
$('#go').removeAttr('disabled','disabled');
$('#list').removeAttr('disabled','disabled');
$('#save').removeAttr('disabled','disabled');
$('#headline').text('Found the Winner!');
$('#headline').slideDown();
}
function removevictim(){
// Removing victim from array and UI
// names = names.filter(function(){ return true});
// Rewriting namesbox contents
var nameupdated = "";
for(var i in names){
name = names[i];
if (name == "" || name == text || typeof(name) == undefined){}else{
nameupdated = nameupdated + "\n" + name;
}
}
$('#namesbox').val("");
$('#namesbox').val(nameupdated);
$('#result1').html("Removed");
$('#result1').fadeOut(1000, function(){
$("div").remove("#result1");
});
$("div").remove(".name");
$("div").remove(".extra");
$('#headline').text('OK, done! Let\'s see who is next? Just click "GO!" button for next roll.');
}
</script>
</body>
</html>