-
Notifications
You must be signed in to change notification settings - Fork 2
/
picker.rb
56 lines (55 loc) · 1.42 KB
/
picker.rb
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
header =<<-EOD
<html>
<head>
<style type="text/css">
.gifHolder {
height: 200px;
width: 200px;
border: 5px solid #AAB0BE;
float: left;
margin-left: 20px;
margin-bottom: 20px;
background-size: 100%;
overflow: hidden;
}
.gifChosen {
border-color: red;
}
</style>
<script>
currentGif = false
function setGif(gifId) {
gifDiv = document.getElementById(gifId)
if(currentGif) {
currentGif.className = "gifHolder"
}
gifUrl = gifDiv.getAttribute('data-gif-url')
gifDiv.className = "gifHolder gifChosen"
currentGif = gifDiv
document.cookie = gifUrl;
}
function init() {
divs = document.body.getElementsByClassName("gifHolder")
for(i in divs) {
gifDiv = divs[i]
gifUrl = gifDiv.getAttribute('data-gif-url')
gifDiv.onclick = Function("setGif(" + gifDiv.id + ")")
gifDiv.style.background = "url('" + gifUrl + "')"
}
}
window.onload = Function("init()");
</script>
</head>
<body>
EOD
i = 0
gifs = File.open("gifs.txt", "r").read.split("\n")
divs = gifs.collect do |gifUrl|
i += 1
"<div id='#{i}' class='gifHolder' data-gif-url='#{gifUrl}'> </div>"
end.compact.join("\n")
footer = <<-EOD
<body>
</html>
EOD
File.open("picker.html", "w").write([header,divs,footer].join("\n"))