Escape @ and #, as well; fix username in User.reload()
[blerg.git] / www / js / blerg.js
1 /* Blerg is (C) 2011 The Dominion of Awesome, and is distributed under a
2  * BSD-style license.  Please see the COPYING file for details.
3  */
4
5 // Config
6 var baseURL = '';
7 var recordTemplate = new Template(
8     '<div class="record">#{data}<div class="info">Posted #{date}. <a href="/\##{author}/#{record}">[permalink]</a></div></div>'
9 );
10 var tagRecordTemplate = new Template(
11     '<div class="record">#{data}<div class="info">Posted by <a class="author ref" href="/\##{author}" onclick="return qlink()">@#{author}</a> on #{date}. <a href="/\##{author}/#{record}">[permalink]</a></div></div>'
12 );
13 var latestRecordsTemplate = new Template(
14     '<div class="record"><a class="author ref" href="/\##{author}" onclick="return qlink()">@#{author}</a> #{data}</div>'
15 );
16
17 // Page elements
18 var items;
19
20 // Other globals
21 var currentPager;
22 var loginStatus;
23
24 // Object to keep track of login status
25 function LoginStatus() {
26     var cookies = {};
27     document.cookie.split(/;\s+/).each(function(v) {
28         kv = v.split('=');
29         cookies[kv[0]] = kv[1];
30     });
31     if (cookies.auth && cookies.username) {
32         this.loggedIn = true;
33         this.username = cookies.username;
34     } else {
35         this.loggedIn = false;
36         this.username = null;
37     }
38     this.update();
39 }
40
41 LoginStatus.prototype.login = function(username, password) {
42     new Ajax.Request(baseURL + '/login', {
43         parameters: {
44             username: username,
45             password: password
46         },
47         onSuccess: function(r) {
48             var j = r.responseText.evalJSON();
49             if (j && j.status == 'success') {
50                 this.loggedIn = true;
51                 this.username = username;
52                 document.cookie = "username=" + username;
53                 $('login.password').value = '';
54                 this.update();
55             } else {
56                 alert("Could not log in");
57                 $('login.username').focus();
58             }
59         }.bind(this),
60         onFailure: function(r) {
61             alert("Could not log in");
62             $('login.username').focus();
63         }
64     });
65 }
66
67 LoginStatus.prototype.logout = function() {
68     new Ajax.Request(baseURL + '/logout', {
69         parameters: {
70             username: this.username
71         },
72         onSuccess: function(r) {
73             this.loggedIn = false;
74             document.cookie = "auth=; expires=1-Jan-1970 00:00:00 GMT";
75             this.update();
76         }.bind(this)
77     });
78     document.cookie = "username=; expires=1-Jan-1970 00:00:00 GMT";
79 }
80
81 LoginStatus.prototype.update = function() {
82     if (this.loggedIn) {
83         $('userlink').href = '/#' + this.username;
84         $('userlink').update('@' + this.username);
85         $('reflink').href = '/#/ref/' + this.username;
86         $('login').hide();
87         $('logout').show();
88     } else {
89         $('post').hide();
90         $('login').show();
91         $('logout').hide();
92     }
93 }
94
95 LoginStatus.prototype.post = function(msg) {
96     if (!this.loggedIn) {
97         alert("You are not logged in!");
98         return;
99     }
100
101     new Ajax.Request(baseURL + '/put', {
102         parameters: {
103             username: this.username,
104             data: msg
105         },
106         onSuccess: function(r) {
107             var j = r.responseText.evalJSON();
108             if (j && j.status == 'success') {
109                 $('post.content').value = '';
110                 if (location.hash != '#' + this.username) {
111                     qlink(this.username);
112                 } else {
113                     currentPager.itemCount++;
114                     currentPager.reload();
115                 }
116             } else {
117                 alert('Post failed!');
118             }
119         }.bind(this),
120         onFailure: function(r) {
121             alert('Post failed!');
122         }
123     });
124 }
125
126
127 // Base object for paged data
128 function Pager() {
129     this.itemsPerPage = 10;
130 }
131
132 Pager.prototype.initPager = function() {
133     this.itemCache = new Hash();
134     this.pageStart = null;
135 }
136
137 Pager.prototype.olderPage = function() {
138     if (this.pageStart >= this.itemsPerPage) {
139         qlink(this.baseFrag + '/p' + (this.pageStart - this.itemsPerPage));
140     }
141 }
142
143 Pager.prototype.newerPage = function() {
144     if (this.pageStart + this.itemsPerPage < this.itemCount) {
145         qlink(this.baseFrag + '/p' + (this.pageStart + this.itemsPerPage));
146     }
147 }
148
149 Pager.prototype.addItems = function(items) {
150     items.each(function(v) {
151         if (!this.itemCache[v.id])
152             this.itemCache[v.id] = v;
153     }.bind(this));
154 }
155
156 Pager.prototype.displayItems = function() {
157     if (this.pageStart == undefined)
158         this.pageStart == this.itemCount - 1;
159     items.update();
160
161     if (this.pageStart != undefined && this.itemCache[this.pageStart]) {
162         var end = (this.pageStart >= this.itemsPerPage ? this.pageStart - this.itemsPerPage + 1 : 0);
163         for (var i = this.pageStart; i >= end; i--) {
164             items.insert(this.itemCache[i].html);
165         }
166     } else {
167         items.insert("There doesn't seem to be anything here!");
168     }
169
170     if (this.pageStart < this.itemCount - 1) {
171         $('newer_link').href = '/#' + this.baseFrag + '/p' + (this.pageStart + this.itemsPerPage);
172         $('newer_link').show();
173     } else {
174         $('newer_link').hide();
175     }
176
177     if (this.pageStart >= 10) {
178         $('older_link').href = '/#' + this.baseFrag + '/p' + (this.pageStart - this.itemsPerPage);
179         $('older_link').show();
180     } else {
181         $('older_link').hide();
182     }
183
184     document.body.scrollTo();
185 }
186
187 Pager.prototype.reload = function() {
188     this.pageStart = null;
189     this.loadItems(null, null, Pager.prototype.showPageAt.bind(this, this.itemCount - 1));
190 }
191
192 Pager.prototype.showPageAt = function(r) {
193     var end = (r - 9 > 0 ? r - 9 : 0);
194     if (this.itemCache[r] && this.itemCache[end]) {
195         this.pageStart = r;
196         this.displayItems();
197     } else {
198         this.loadItems((r >= 49 ? r - 49 : 0), r, Pager.prototype.showPageAt.bind(this, r));
199     }
200 }
201
202 Pager.prototype.showRecord = function(r) {
203     if (this.itemCache[r]) {
204         $('older_link').hide();
205         $('newer_link').hide();
206         items.update(this.itemCache[r].html);
207     } else {
208         this.loadItems(r, r, Pager.prototype.showRecord.bind(this, r));
209     }
210 }
211
212 Pager.prototype.loadItems = function(from, to, continuation) { }
213
214
215 // Object to render user pages
216 function User(username) {
217     this.initPager();
218     this.username = username;
219     this.baseFrag = username;
220 }
221 User.prototype = new Pager();
222 User.prototype.constructor = User;
223
224 User.prototype.show = function() {
225     $$('[name=section]').each(function(v) { v.update(' @' + this.username) }.bind(this));
226     $('welcome').hide();
227     items.show();
228     $('rss').show();
229     $('rsslink').href = '/rss/' + this.username;
230     $$('[name=user.reflink]').each(function(e) {
231         e.href = '/#/ref/' + this.username;
232     }.bind(this));
233     $('usercontrols').show();
234 }
235
236 User.prototype.reload = function() {
237     this.pageStart = null;
238
239     $$('[name=user.subscribelink]').each(Element.hide);
240     $$('[name=user.unsubscribelink]').each(Element.hide);
241
242     if (loginStatus.loggedIn) {
243         new Ajax.Request(baseURL + '/feedinfo/' + this.username, {
244             method: 'post',
245             parameters: {
246                 username: loginStatus.username
247             },
248             onSuccess: function(r) {
249                 var json = r.responseText.evalJSON();
250                 if (json.subscribed) {
251                     $$('[name=user.subscribelink]').each(Element.hide);
252                     $$('[name=user.unsubscribelink]').each(Element.show);
253                 } else {
254                     $$('[name=user.subscribelink]').each(Element.show);
255                     $$('[name=user.unsubscribelink]').each(Element.hide);
256                 }
257             }
258         });
259     }
260
261     new Ajax.Request(baseURL + '/info/' + this.username, {
262         method: 'get',
263         onSuccess: function(r) {
264             var j = r.responseText.evalJSON();
265             if (j) {
266                 this.itemCount = parseInt(j.record_count);
267                 if (!this.pageStart)
268                     this.showPageAt(this.itemCount - 1);
269             }
270         }.bind(this)
271     });
272 }
273
274 User.prototype.loadItems = function(from, to, continuation) {
275     var url;
276     if (from != undefined && to != undefined) {
277         url = baseURL + '/get/' + this.username + '/' + from + '-' + to;
278         this.pageStart = to;
279     } else {
280         url = baseURL + '/get/' + this.username;
281     }
282
283     new Ajax.Request(url, {
284         method: 'get',
285         onSuccess: function(r) {
286             var records = r.responseText.evalJSON();
287             if (records && records.length > 0) {
288                 records.each(function(v) {
289                     v.id = v.record;
290                     v.author = this.username;
291                     mangleRecord(v, recordTemplate);
292                 }.bind(this));
293                 this.addItems(records);
294                 if (!this.pageStart)
295                     this.pageStart = records[0].recInt;
296             }
297             continuation();
298         }.bind(this),
299         onFailure: function(r) {
300             this.displayItems();
301         }.bind(this),
302         on404: function(r) {
303             displayError('User not found');
304         }
305     });
306 }
307
308 function mangleRecord(record, template) {
309     record.recInt = parseInt(record.record);
310
311     var lines = record.data.split(/\r?\n/);
312     if (lines[lines.length - 1] == '')
313         lines.pop();
314
315     var out = ['<p>'];
316     var endpush = null;
317     var listMode = false;
318     lines.each(function(l) {
319         if (l == '') {
320             if (out[out.length - 1] == '<br>') {
321                 out[out.length - 1] = '<p>';
322             }
323             if (out[out.length - 1] == '</li>') {
324                 out.push('</ul>');
325                 out.push('<p>');
326                 listMode = false;
327             }
328             return;
329         }
330
331         // Put quoted material into a special paragraph
332         if (l[0] == '>') {
333             var pi = out.lastIndexOf('<p>');
334             if (pi != -1) {
335                 out[pi] = '<p class="quote">';
336                 l = l.replace(/^>\s*/, '');
337             }
338         }
339
340         // Sanitize HTML input
341         l = l.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
342
343         // Turn HTTP URLs into links
344         l = l.replace(/(\s|^)(https?:\/\/[a-zA-Z0-9.-]*[a-zA-Z0-9](\/([^\s"]*[^.!,;?()\s])?)?)/g, '$1<a href="$2">$2</a>');
345
346         // Turn markdown links into links
347         l = l.replace(/(\s|^)\[([^\]]+)\]\((https?:\/\/[a-zA-Z0-9.-]*[a-zA-Z0-9](\/[^)"]*?)?)\)/g, '$1<a href="$3">$2</a>');
348
349         // Turn *foo* into italics and **foo** into bold
350         l = l.replace(/([^\w\\]|^)\*\*(\w[^*]*)\*\*(\W|$)/g, '$1<b>$2</b>$3');
351         l = l.replace(/([^\w\\]|^)\*(\w[^*]*)\*(\W|$)/g, '$1<i>$2</i>$3');
352
353         // Turn refs and tags into links
354         l = l.replace(/(\s|^)#([A-Za-z0-9_-]+)/g, '$1<a href="#/tag/$2" class="ref" onclick="return qlink()">#$2</a>');
355         l = l.replace(/(\s|^)@([A-Za-z0-9_-]+)/g, '$1<a href="#$2" class="ref" onclick="return qlink()">@$2</a>');
356
357         // Create lists when lines begin with *
358         if (l[0] == '*') {
359             if (!listMode) {
360                 var pi = out.lastIndexOf('<p>');
361                 out[pi] = '<ul>';
362                 listMode = true;
363             }
364             l = l.replace(/^\*\s*/, '');
365             out.push('<li>');
366             endpush = '</li>';
367         }
368
369         // Create headers when lines begin with = or #
370         if (l[0] == '=' || l[0] == '#') {
371             var m = l.match(/^([=#]+)/);
372             var depth = m[1].length;
373             if (depth <= 5) {
374                 l = l.replace(/^[=#]+\s*/, '').replace(/\s*[=#]+$/, '');
375                 out.push('<h' + depth + '>');
376                 endpush = '</h' + depth + '>';
377             }
378         }
379
380         // Remove backslashes from escaped metachars
381         l = l.replace(/\\([*\[\]@#])/g, '$1');
382
383         out.push(l);
384         if (endpush) {
385             out.push(endpush);
386             endpush = null;
387         } else {
388             out.push('<br>');
389         }
390     });
391     while (out[out.length - 1] == '<br>' || out[out.length - 1] == '<p>')
392         out.pop();
393     if (listMode)
394         out.push('</ul>');
395
396     record.data = out.join('');
397     record.date = (new Date(record.timestamp * 1000)).toString();
398     record.html = template.evaluate(record);
399 }
400
401 function displayError(msg) {
402     items.innerText = msg;
403 }
404
405
406 // Object for browsing tags
407 function Tag(type, tag) {
408     this.initPager();
409     this.type = type;
410     this.tag = tag;
411
412     var url = baseURL + "/tag/";
413     switch(type) {
414     case 'tag':
415         //url += '%23';
416         url += 'H';  // apache is eating the hash, even encoded.  Probably a security feature.
417         this.baseFrag = '/tag/' + tag;
418         break;
419     case 'ref':
420         url += '%40';
421         this.baseFrag = '/ref/' + tag;
422         break;
423     default:
424         alert('Invalid tag type: ' + type);
425         return;
426     }
427     url += tag;
428
429     new Ajax.Request(url, {
430         method: 'get',
431         onSuccess: function(r) {
432             var j = r.responseText.evalJSON();
433             if (j) {
434                 var maxid = j.length - 1;
435                 j.each(function(v, i) {
436                     v.id = maxid - i;
437                     mangleRecord(v, tagRecordTemplate)
438                 });
439                 this.addItems(j);
440                 this.pageStart = j.length - 1;
441                 this.itemCount = j.length;
442             }
443             this.displayItems();
444         }.bind(this),
445         onFailure: function(r) {
446             this.displayItems();
447         }.bind(this)
448     });
449
450 }
451 Tag.prototype = new Pager();
452 Tag.prototype.constructor = Tag;
453
454 Tag.prototype.show = function() {
455     var ctype = {ref: '@', tag: '#'}[this.type];
456
457     $$('[name=section]').each(function(v) {
458         v.update(' about ' + ctype + this.tag);
459     }.bind(this));
460     $('welcome').hide();
461     $('post').hide();
462     $('older_link').hide();
463     $('newer_link').hide();
464     $('rss').hide();
465     items.show();
466     $('usercontrols').hide();
467 }
468
469
470 // Pager for browsing subscription feeds
471 function Feed() {
472     this.initPager();
473     this.username = loginStatus.username;
474     this.baseFrag = '/feed';
475
476     new Ajax.Request(baseURL + '/feed', {
477         method: 'post',
478         parameters: {
479             username: loginStatus.username
480         },
481         onSuccess: function(r) {
482             var response = r.responseText.evalJSON();
483             if (response) {
484                 var maxid = response.length - 1;
485                 response.each(function(v, i) {
486                     v.id = maxid - i;
487                     mangleRecord(v, tagRecordTemplate)
488                 });
489                 this.addItems(response);
490                 this.pageStart = response.length - 1;
491                 this.itemCount = response.length;
492             }
493             this.displayItems();
494         }.bind(this),
495         onFailure: function(r) {
496             this.displayItems();
497         }.bind(this)
498     });
499 }
500 Feed.prototype = new Pager();
501 Feed.prototype.constructor = Feed;
502
503 Feed.prototype.show = function() {
504     $$('[name=section]').each(function(v) {
505         v.update(' ' + loginStatus.username + "'s spycam");
506     }.bind(this));
507     $('welcome').hide();
508     $('post').hide();
509     $('older_link').hide();
510     $('newer_link').hide();
511     $('rss').hide();
512     items.show();
513     $('usercontrols').hide();
514 }
515
516
517 function postPopup() {
518     if (loginStatus.loggedIn) {
519         var post = $('post');
520         if (post.visible()) {
521             post.hide();
522         } else {
523             post.show();
524             if (currentPager.username && currentPager.username != loginStatus.username && !$('post.content').value) {
525                 $('post.content').value = '@' + currentPager.username + ': ';
526             }
527             $('post.content').focus();
528         }
529     }
530 }
531
532 function signup() {
533     var username = $('signup.username').value;
534     var password = $('signup.password').value;
535
536     new Ajax.Request(baseURL + '/create', {
537         parameters: {
538             username: username,
539             password: password
540         },
541         onSuccess: function(r) {
542             $('signup').hide();
543             qlink(username);
544
545             loginStatus.login(username, password);
546         },
547         onFailure: function(r) {
548             alert("Failed to create user");
549         }
550     });
551 }
552
553 function signup_cancel() {
554     $('signup').hide();
555     hashSwitch();
556 }
557
558 function subscribe() {
559     new Ajax.Request(baseURL + '/subscribe/' + currentPager.username, {
560         method: 'post',
561         parameters: {
562             username: loginStatus.username
563         },
564         onSuccess: function(r) {
565             var response = r.responseText.evalJSON();
566             if (response.status == 'success') {
567                 alert("You call " + currentPager.username + " and begin breathing heavily into the handset.");
568                 $$('[name=user.subscribelink]').each(Element.hide);
569                 $$('[name=user.unsubscribelink]').each(Element.show);
570             } else {
571                 alert('Failed to subscribe. This is probably for the best');
572             }
573         },
574         onFailure: function(r) {
575             alert('Failed to subscribe. This is probably for the best');
576         }
577     });
578 }
579
580 function unsubscribe() {
581     new Ajax.Request(baseURL + '/unsubscribe/' + currentPager.username, {
582         method: 'post',
583         parameters: {
584             username: loginStatus.username
585         },
586         onSuccess: function(r) {
587             var response = r.responseText.evalJSON();
588             if (response.status == 'success') {
589                 alert("You come to your senses.");
590                 $$('[name=user.subscribelink]').each(Element.show);
591                 $$('[name=user.unsubscribelink]').each(Element.hide);
592             } else {
593                 alert('You are unable to tear yourself away (because something failed on the server)');
594             }
595         },
596         onFailure: function(r) {
597             alert('You are unable to tear yourself away (because something failed on the server)');
598         }
599     });
600 }
601
602 var resizePostContentTimeout = null;
603 function resizePostContent() {
604     if (resizePostContentTimeout)
605         clearTimeout(resizePostContentTimeout);
606     resizePostContentTimeout = setTimeout(function() {
607         var c = $('post.content');
608         var lines = Math.floor(c.value.length / (100 * (c.clientWidth / 1000))) + 1;
609         var m = c.value.match(/\r?\n/g);
610         if (m)
611             lines += m.length;
612         if (lines <= 3) {
613             c.style.height = "";
614         } else {
615             c.style.height = (lines * 17) + "pt";
616         }
617         resizePostContentTimeout = null;
618     }, 150);
619 }
620
621 var tickerTimer = null;
622 var tickerHead, tickerTail;
623
624 function tickerFader(a, b, p) {
625     var p2 = 1 - p;
626
627     a.style.opacity = p;
628     a.style.lineHeight = (100 * p) + '%';
629
630     b.style.opacity = p2;
631     b.style.lineHeight = (100 * p2) + '%';
632     if (p == 1.0)
633         b.hide();
634 }
635
636 function ticker() {
637     tickerHead.show();
638     Bytex64.FX.run(tickerFader.curry(tickerHead, tickerTail), 0.5);
639     tickerHead = tickerHead.nextSibling;
640     tickerTail = tickerTail.nextSibling;
641     if (tickerHead == null) {
642         stopTicker();
643         loadLatest.delay(10);
644     }
645 }
646
647 function startTicker() {
648     stopTicker();
649     for (var elem = $('latest-posts').firstChild; elem != null; elem = elem.nextSibling) {
650         elem.hide();
651     }
652
653     // Show the first five
654     tickerHead = $('latest-posts').firstChild;
655     for (var i = 0; i < 10 && tickerHead; i++) {
656         tickerHead.show();
657         tickerHead = tickerHead.nextSibling;
658     }
659     tickerTail = $('latest-posts').firstChild;
660     tickerTimer = setInterval(ticker, 5000);
661 }
662
663 function stopTicker() {
664     if (tickerTimer)
665         clearInterval(tickerTimer);
666     tickerTimer = null;
667 }
668
669 function loadLatest() {
670     new Ajax.Request(baseURL + '/latest.json', {
671         onSuccess: function(r) {
672             var j = r.responseText.evalJSON();
673
674             $('latest-tags').update();
675             j.tags.each(function(v) {
676                 var a = new Element('a', {href: '/#/tag/' + v});
677                 a.insert('#' + v);
678                 a.onclick = "return qlink()";
679                 a.className = 'ref';
680                 $('latest-tags').insert(a);
681                 $('latest-tags').appendChild(document.createTextNode(' '));
682             });
683
684             $('latest-posts').update();
685             j.records.each(function(v) {
686                 v.data = v.data.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
687                 v.date = (new Date(v.timestamp * 1000)).toString();
688                 var html = latestRecordsTemplate.evaluate(v);
689                 $('latest-posts').insert(html);
690             });
691             startTicker();
692         }
693     });
694 }
695
696 function qlink(loc) {
697     if (loc) {
698         location.hash = loc;
699     } else if (event && event.target) {
700         location.href = event.target.href;
701     } else {
702         // Bogus qlink
703         return;
704     }
705     hashSwitch();
706     return false;
707 }
708
709 function hashSwitch() {
710     var m;
711     stopTicker();
712     if (m = location.search.match(/^\?post\/([^/]+)\/(.+)/)) {
713         $('post').show();
714         $('post.content').value = '[' + decodeURIComponent(m[1]).replace(']','').replace('[','') + '](' + decodeURIComponent(m[2]) + ')';
715     } else if (m = location.hash.match(/^#\/(ref|tag)\/([A-Za-z0-9_-]+)(?:\/p(\d+))?$/)) {
716         if (!currentPager || !(currentPager instanceof Tag) || currentPager.type != m[1] || currentPager.tag != m[2])
717             currentPager = new Tag(m[1], m[2]);
718         currentPager.show();
719
720         if (m[3]) {
721             var r = parseInt(m[3]);
722             currentPager.showPageAt(r);
723         } else {
724             currentPager.showPageAt(currentPager.itemCount - 1);
725         }
726     } else if (m = location.hash.match(/^#\/feed(?:\/p(\d+))?$/)) {
727         if (loginStatus.loggedIn) {
728             if (!currentPager || !(currentPager instanceof Feed) || currentPager.username != loginStatus.username)
729                 currentPager = new Feed();
730             currentPager.show();
731             if (m[3]) {
732                 var r = parseInt(m[3]);
733                 currentPager.showPageAt(r);
734             } else {
735                 currentPager.showPageAt(currentPager.itemCount - 1);
736             }
737         } else {
738             location.href = baseURL;
739         }
740     } else if (m = location.hash.match(/^#([A-Za-z0-9_-]+)(?:\/(p)?(\d+))?$/)) {
741         if (!currentPager || !(currentPager instanceof User) || currentPager.username != m[1])
742             currentPager = new User(m[1]);
743         currentPager.show();
744         loginStatus.update();
745
746         if (m[3]) {
747             var r = parseInt(m[3]);
748             if (m[2] == 'p') {
749                 currentPager.showPageAt(r);
750             } else {
751                 currentPager.showRecord(r);
752             }
753         } else {
754             currentPager.reload();
755         }
756     } else {
757         $$('[name=section]').each(function(v) { v.update('Welcome') });
758         $('signup').hide();
759         items.update();
760         items.hide();
761         $('newer_link').hide();
762         $('older_link').hide();
763         $('welcome').show();
764         $('rss').hide();
765         $('usercontrols').hide();
766         loadLatest();
767     }
768 }
769
770 var lastHash;
771 function hashCheck() {
772     if (location.hash != lastHash) {
773         lastHash = location.hash;
774         hashSwitch();
775     }
776 }
777
778 function init() {
779     items = $('items');
780     loginStatus = new LoginStatus();
781
782     lastHash = location.hash;
783     hashSwitch();
784
785     setInterval(hashCheck, 250);
786
787     document.body.observe('keyup', function(event) {
788         if (event.shiftKey && event.keyCode == 32) {
789             postPopup();
790             event.stop();
791         }
792     });
793     $('post.content').addEventListener('keyup', function(event) {
794         event.stopPropagation();
795     }, true);
796 }