forked from joshuawalcher/writtenkitten-original
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
295 lines (278 loc) · 9.14 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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
<!doctype html>
<html lang="en">
<head>
<title>Written? Bears!</title>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<link href="http://fonts.googleapis.com/css?family=Indie+Flower" rel="stylesheet" type="text/css" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script>
<style type="text/css">
body { background: url(kittenbg.gif) repeat #6AAFDA }
::-moz-selection {
background: #6AAFDA;
color: #fff;
}
::selection {
background: #6AAFDA;
color: #fff;
}
.wrapper {
margin: 50px auto;
background-color: #fff;
width: 1000px;
padding: 1em 2em 2em 2em;
border: 1px solid #5896bc;
-webkit-border-radius: 20px;
-moz-border-radius: 20px;
border-radius: 20px;
-webkit-box-shadow: 0px 0px 5px 2px #5896bc;
-moz-box-shadow: 0px 0px 5px 2px #5896bc;
box-shadow: 0px 0px 5px 2px #5896bc;
}
img {
border: 0;
-ms-interpolation-mode: bicubic;
vertical-align: middle;
max-width: 100%;
}
textarea {
width: 580px;
height: 400px;
overflow: auto;
vertical-align: top;
resize: vertical;
}
h1 {
font-size: 3em;
margin: 0;
}
h2 {
font-size: 1.7em;
margin: 0;
}
a, a:visited {
color: #5896bc;
text-decoration: none;
cursor: pointer;
}
a:hover { color: #305c78 }
a:focus { outline: thin dotted; }
a:hover, a:active { outline: 0; }
p { font-size: .9em }
h1, .controls, h2, .hide {
font-family: 'Indie Flower', cursive;
font-weight: normal;
}
.hide {
font-size: 1.2em;
cursor: pointer;
}
.warning {
background-color: #f7f8c3;
border: 1px solid #f7ce6d;
padding: 1em 1em 0 1em;
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
}
.warning h2 { font-size: 2em }
.warning a {
font-size: 1.5em;
color: #000;
cursor: pointer;
}
.hidelink {
text-align: right;
padding-right: 1em;
}
#displayWords, #about, #kittenCredit, .warning {
font-family: "Helvetica Neue", sans-serif;
font-weight: 200;
}
.meta { padding-left: 2em }
#kittenFrame {
float: right;
height: 400px;
width: 400px;
background-position: center;
background-repeat: no-repeat;
}
#nextKitten { display: none }
#kittenCredit {
color: #999;
width: 100%;
font-size: .8em;
margin-top: 420px;
text-align: right;
}
#about { margin: 0 2em }
</style>
<!--[if IE ]>
<style type="text/css">
textarea { width:500px }
</style>
<![endif]-->
<script>
var current_word_count = 0;
var words_for_reward = 100;
var kittens_earned = 0;
var kittens_shown = 0;
var warning_shown = true;
var warning;
if (typeof localStorage == "undefined") warning = "#warning-no-ls"
else warning = "#warning-ls";
var next_kitten = {
img_url: '',
page_url: '',
alt: ''
};
function word_count(text, wc) {
if (typeof localStorage != "undefined") localStorage.text = text;
if (current_word_count >= 10 && warning_shown == false) {
show_warning();
}
text = text.replace(/^\s*|\s*$/g,''); //removes whitespace from front and end
text = text.replace(/\s+/g,' '); // collapse multiple consecutive spaces
var words = text.split(" ");
wc.value = words.length;
current_word_count = wc.value = words.length;
$("#displayWords").html(wc.value);
kittens_earned = current_word_count / words_for_reward;
if (kittens_earned >= kittens_shown+1) {
show_kitten();
}
}
function show_warning() {
$(warning).fadeIn("slow");
}
function hide_warning(immediate) {
if (immediate == true) {
$(warning).hide();
} else {
$(warning).fadeOut("slow");
}
warning_shown = true;
}
function show_kitten() {
// console.log("show");
hide_warning(true);
kittens_shown++;
$("#kittenFrame").css("background-image", "url(" + next_kitten.img_url + ")");
$("#kittenCredit").html("<a href='" + next_kitten.page_url + "'>" + next_kitten.alt + "</a>");
fetch_next_kitten();
}
function fetch_next_kitten() {
if (tmp = getParameterByName("search")) {
search = tmp;
$("#titleKitten").html("<strike>Bears!</strike>");
$("#titleSearch").html(" " + search + "!");
} else {
search = "bear,cute";
}
var flickr_url = "http://api.flickr.com/services/rest/?format=json&sort=interestingness-desc&method=flickr.photos.search&license=4&extras=owner_name&tags=" + search + "&tag_mode=all&api_key=5dfc80756edad8d0566cf40f0909324e&jsoncallback=?";
$.getJSON(flickr_url, function(data) {
if (data.stat == "ok") {
var i = Math.ceil(Math.random() * 100);
var photo = data.photos.photo[i];
next_kitten.img_url = "http://farm" + photo.farm + ".static.flickr.com/" + photo.server + "/" + photo.id + "_" + photo.secret + "_z.jpg";
next_kitten.page_url = "http://www.flickr.com/photos/" + photo.owner + "/" + photo.id;
next_kitten.alt = photo.title + " by " + photo.ownername + " (under CC-BY)";
$("#nextKitten").attr("src", next_kitten.img_url);
}
});
}
function change_reward(howmany) {
// console.log("rewarding every " + howmany);
words_for_reward = howmany;
kittens_earned = current_word_count / howmany;
kittens_shown = parseInt(kittens_earned);
// console.log("kittens_earned = " + kittens_earned);
// console.log("kittens_shown = " + kittens_shown);
}
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regexS = "[\\?&]" + name + "=([^&#]*)";
var regex = new RegExp(regexS);
var results = regex.exec(window.location.href);
if (results == null)
return "";
else
return decodeURIComponent(results[1].replace(/\+/g, " "));
}
function restore_text() {
if (typeof localStorage != "undefined") $("#writearea").attr("value", localStorage.text).keyup();
}
</script>
</head>
<body onLoad="fetch_next_kitten(); restore_text()">
<div class="wrapper">
<a name="top"></a>
<h1>Written? <span id="titleKitten">Bears!</span><span id="titleSearch"></span></h1>
<div id="kittenFrame">
<div id="warning-no-ls" class="warning" style="display:none">
<h2>Warning!</h2>
<p>We don't save your work for you! You'll need to regularly copy
and paste your text into a word processor or other application to save it permanently.</p>
<p>If you want your work saved even if you close your browser,
upgrade to a recent version of <a href="https://www.google.com/chrome/">Chrome</a>,
<a href="http://www.mozilla.org/firefox/">Firefox</a>, <a href="http://www.apple.com/safari/">Safari</a>
or <a href="http://www.opera.com/">Opera</a>.</p>
<p class="hidelink"><a href="#" class="hide" onClick="hide_warning()">OK, got it!</a></p>
</div>
<div id="warning-ls" class="warning" style="display:none">
<h2>Hey!</h2>
<p>Looks like your browser supports local storage. That's great!
Your writing will be saved even if you close this page.</p>
<p>We can't take responsibility for things going wrong, though, so you might want to
copy and paste your work to an external document every so often, just in case.</p>
<p class="hidelink"><a href="#" class="hide" onClick="hide_warning()">OK, got it!</a></p>
</div>
<div id="kittenCredit"></div>
</div>
<form>
<input type="hidden" name="hidden_count" value="" disabled />
<textarea id="writearea" cols="80" rows="30" onKeyUp="word_count(this.value, hidden_count)"></textarea>
</form>
<form class="controls">
<span class="meta">
Fresh bears every <select id="howmany" onChange="change_reward(this.value)">
<option value="100">100</option>
<option value="200">200</option>
<option value="500">500</option>
<option value="1000">1000</option>
</select> words
</span>
<span class="meta">
Current word count: <span id="displayWords">0</span>
</span>
<span class="meta">
<a href="#" onClick="$('#about').slideDown()">About</a>
</span>
</form>
<div id="about" style="display:none">
<h2>About</h2>
<p>
Written Bears is based off of Written Kitten. Written was created by <a href="http://twitter.com/Skud" rel="author">Skud</a>, <a href="http://twitter.com/aquaprofundanet" rel="author">Emily</a> and <a href="https://github.com/Skud/writtenkitten/contributors" rel="author">contributors</a>. Written Kitten was adapted to Written Bears for my friend Celine. The basically 2 lines of modification were done by <a href="http://anthonykosednar.com/">Anthony Kosednar</a>. We like positive reinforcement, so we decided to make something a bit like <a href="http://writeordie.com">writeordie</a> but
cuter and fuzzier.
Images are randomly selected from Flickr's “most interesting” photos matching the tags “bear”cute“.
Enjoy!
</p>
<p><a href="#" class="hide" onClick="$('#about').slideUp()">Hide</a></p>
<img src="" id="nextKitten"/>
</div>
<script>
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-26983491-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<!--[if lt IE 7 ]>
<script src="//ajax.googleapis.com/ajax/libs/chrome-frame/1.0.3/CFInstall.min.js"></script>
<script>window.attachEvent('onload',function(){CFInstall.check({mode:'overlay'})})</script>
<![endif]-->
</body>
</html>