forked from adityab/memecached
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
234 lines (199 loc) · 7.32 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
<!DOCTYPE html>
<html lang="en">
<head>
<title>Memecached - Open Source Meme Generator</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="/nowjs/now.js"></script>
<script src="http://dl.dropbox.com/u/40496552/bootstrap-twipsy.js"></script>
<link rel="stylesheet" type="text/css" href="http://dl.dropbox.com/u/40496552/bootstrap.css"/>
<style>
a:hover { cursor: pointer; }
canvas:hover { cursor: pointer; }
#github {
top: 3px;
right: 10px;
position: absolute;
}
</style>
<script>
currentMeme = "";
width = 240;
height = 240;
availableMemes = {
"bear-grylls.jpg": "Bear Grylls",
"brace-yourselves-x-is-coming.jpg": "Brace yourselves, X is coming",
"courage-wolf.jpg": "Courage Wolf",
"downvoting-roman.jpg": "Downvoting Roman",
"forever-alone.jpg": "Forever Alone",
"foul-bachelor-frog.jpg": "Foul Bachelor Frog",
"insanity-wolf.jpg": "Insanity Wolf",
"high-expectations-asian-father.jpg": "High Expectations Asian Father",
"lame-pun-coon.jpg": "Lame Pun Racoon",
"pedobear.jpg": "Pedo Bear",
"philosoraptor.jpg": "Philosoraptor",
"success-kid.jpg": "Success Kid",
"x-all-the-y.jpg": "X all the Y!",
"the-most-interesting-man-in-the-world.jpg": "The Most Interesting Man in the World",
"y-u-no.jpeg": "Y U NO Guy",
"advice-god.jpg": "Advice God",
"annoying-facebook-girl.jpg": "Annoying Facebook Girl",
"business-cat.jpg": "Business Cat",
"butthurt-dweller.jpg": "Butthurt Dweller",
"depression-dog.jpg": "Depression Dog",
"downvoting-roman.jpg": "Downvoting Roman",
"dwight-schrute.jpg": "Dwight Schrute",
"first-world-problems.jpg": "First World Problems",
"futurama-fry.jpg": "Futurama Fry",
"good-guy-greg.jpg": "Good Guy Greg",
"net-noob.jpg": "Net n00b",
"ordinary-muslim-man.jpg": "Ordinary Muslim Man",
"pickup-line-panda.jpg": "Pick-up Line Panda",
"redditors-wife.jpg": "Redditor's wife",
"scumbag-girl.jpg": "Scumbag Girl",
"scumbag-steve.jpg": "Scumbag Steve",
"sheltering-suburban-mom.jpg": "Sheltering Sub-urban Mom",
"socially-awesome-penguin.jpg": "Socially Awesome Penguine",
"socially-awkward-penguin.jpg": "Socially Awkward Penguine",
"successful-black-man.jpg": "Successful Black Man",
"the-most-interesting-cat-in-the-world.jpg": "The Most Interesting cat in the World"
};
getTemplateLink = function(filename) {
return "http://dl.dropbox.com/u/40496552/memes/" + filename;
}
$(document).ready(function(){
clearMemes = function() {
$("#meme-list").empty();
}
pickMeme = function(name) {
clearMemes();
currentMeme = name;
now.getRecent(name);
if(name) {
$("#current-meme").html(availableMemes[name]);
$("#editor").show();
$("#edit-info").hide();
}
else {
currentMeme = null;
$("#edit-info").show();
$("#editor").hide();
}
}
populateMemePicker = function() {
$("#meme-picker").empty();
for(name in availableMemes) {
var code = "<li> <a rel = 'twipsy' data-original-title = '" + availableMemes[name] + "' onclick = pickMeme('" + name + "')> <img class = 'thumbnail' width = '30' height = '30' src = '" + getTemplateLink(name) + "'></img></a> </li>";
$("#meme-picker").append(code);
}
$(function() {
$("a[rel=twipsy]").twipsy( { live: true } );
});
}
makeCanvas = function(doc) {
return ("<canvas class = 'well' rel = 'twipsy' data-original-title = '" + availableMemes[doc.name] + "' onclick = pickMeme('" + doc.name + "') width = '" + width + "' height = '" + height + "' style='padding: 10px;' id='" + doc._id + "'></canvas>");
$(function() {
$("canvas[rel=twipsy]").twipsy( { live: true } );
});
}
drawText = function(context, pos, text) {
var fontSize = 100;
while(1) {
context.font = "bold " + fontSize + "px Arial";
if( (context.measureText(text).width < (width-15)) && (fontSize < height/10) ) {
break;
}
fontSize-=2;
}
var y;
if(pos == "top")
y = fontSize + 15;
else if(pos == "bottom") {
y = height - 15;
}
context.strokeText(text, width/2, y);
context.fillText(text, width/2, y);
}
updateList = function(doc, where) {
if(where == "top")
$("#meme-list").prepend(makeCanvas(doc));
else {
$("#meme-list").append(makeCanvas(doc));
}
var canvas = document.getElementById(doc._id);
var context = canvas.getContext("2d");
context.textAlign = "center";
context.fillStyle = "#fff";
context.strokeStyle = "#000";
context.lineWidth = 6;
var img = new Image();
img.src = getTemplateLink(doc.name);
img.onload = function() {
context.drawImage(img, 0, 0, canvas.width, canvas.height);
drawText(context, "top", doc.text.line1);
drawText(context, "bottom", doc.text.line2);
};
}
now.getContent = function(docs) {
docs.forEach(updateList);
}
now.receiveMeme = function(doc) {
if(!currentMeme || currentMeme == doc.name)
updateList(doc, "top");
}
$("#showall-button").click(function() {
pickMeme();
});
$("#publish-button").click(function(){
var meme = {
name: currentMeme,
text: {
line1: $("#text-input1").val().toUpperCase(),
line2: $("#text-input2").val().toUpperCase()
}
};
now.publish(meme);
$("#text-input1").val("");
$("#text-input2").val("");
});
$("#edit-info").hide();
$("#editor").hide();
populateMemePicker();
now.ready(function() {
pickMeme();
});
});
</script>
</head>
<body style = "background-color: #FFFAFF;">
<h1 style = "margin-left: 20px;">
<a href = "/" class = "alert-message error"> memecached
<small>because memes must be realtime.</small>
</a>
</h1>
<div id = "github">
<a href = "https://github.com/adityab/memecached" target = "_blank" class = "alert-message warning">fork on <strong>github</strong></a>
</div>
<div class='container-fluid'>
<div class = 'sidebar'>
<div class = "well" style = "height: 300px; overflow: auto;">
<ul class = "media-grid" id = "meme-picker">
</ul>
</div>
<div id = "edit-info" align = "center">
<h2> Click on a meme to start publishing! </h2>
</div>
<div id = "editor" align = "center">
<input type="button" class = "btn success" value="Show All" id="showall-button">
<h2 id = "current-meme"> </h2>
<input type="text" id="text-input1" placeholder = "top line" style="text-transform: uppercase;">
<input type="text" id="text-input2" placeholder = "bottom line" style="text-transform: uppercase;">
<input type="button" class ="btn primary" value="Publish" id="publish-button">
</div>
</div>
<div class = 'content'>
<ul class = "media-grid" id = "meme-list">
</ul>
</div>
</div>
</body>
</html>