X-Git-Url: http://git.bytex64.net/?a=blobdiff_plain;f=www%2Fjs%2Fblerg.js;h=9f92594ba51b22777d5855bf0390d4854d0bb3b9;hb=f4bf2d2efc566e9f165b97bda72cd5a27e0d2b19;hp=96f6cb2d7a15569b5ab635d970cca8cf48e4220e;hpb=b4f3c5710795c0792e7e21659571002079acd133;p=blerg.git diff --git a/www/js/blerg.js b/www/js/blerg.js index 96f6cb2..9f92594 100644 --- a/www/js/blerg.js +++ b/www/js/blerg.js @@ -8,10 +8,10 @@ var recordTemplate = new Template( '
'];
+ var endpush = null;
+ var listMode = false;
+ lines.each(function(l) {
+ if (l == '') {
+ if (out[out.length - 1] == '
') {
+ out[out.length - 1] = '
'; + } + if (out[out.length - 1] == '') { + out.push(''); + out.push('
'); + listMode = false; + } + return; + } - // Turn HTTP URLs into links - record.data = record.data.replace(/(\s|^)(https?:\/\/[a-zA-Z0-9.-]*[a-zA-Z0-9](\/([^\s"]*[^.!,;?()\s])?)?)/g, '$1$2'); + if (l[0] == '>') { + var pi = out.lastIndexOf('
'); + if (pi != -1) { + out[pi] = '
'; + l = l.replace(/^>\s*/, ''); + } + } + if (l[0] == '*') { + if (!listMode) { + var pi = out.lastIndexOf('
'); + out[pi] = '
").replace(/\r?\n/g, "
");
+ // Turn refs and tags into links
+ l = l.replace(/(\s|^)#([A-Za-z0-9_-]+)/g, '$1#$2');
+ l = l.replace(/(\s|^)@([A-Za-z0-9_-]+)/g, '$1@$2');
+ out.push(l);
+ if (endpush) {
+ out.push(endpush);
+ endpush = null;
+ } else {
+ out.push('
');
+ }
+ });
+ while (out[out.length - 1] == '
' || out[out.length - 1] == '
') + out.pop(); + + record.data = out.join(''); record.date = (new Date(record.timestamp * 1000)).toString(); record.html = template.evaluate(record); } @@ -332,6 +414,7 @@ Tag.prototype.show = function() { $('newer_link').hide(); $('rss').hide(); items.show(); + $('usercontrols').hide(); } function postPopup() { @@ -386,6 +469,50 @@ function older_page() { currentPager.olderPage(); } +function obsess() { + new Ajax.Request(baseURL + '/subscribe/' + currentPager.username, { + method: 'post', + parameters: { + username: loginStatus.username + }, + onSuccess: function(r) { + var response = r.responseText.evalJSON(); + if (response.status == 'success') { + alert("You call " + currentPager.username + " and begin breathing heavily into the handset."); + $$('[name=user.obsesslink]').each(Element.hide); + $$('[name=user.unobsesslink]').each(Element.show); + } else { + alert('Failed to obsess. This is probably for the best'); + } + }, + onFailure: function(r) { + alert('Failed to obsess. This is probably for the best'); + } + }); +} + +function unobsess() { + new Ajax.Request(baseURL + '/unsubscribe/' + currentPager.username, { + method: 'post', + parameters: { + username: loginStatus.username + }, + onSuccess: function(r) { + var response = r.responseText.evalJSON(); + if (response.status == 'success') { + alert("You come to your senses."); + $$('[name=user.obsesslink]').each(Element.show); + $$('[name=user.unobsesslink]').each(Element.hide); + } else { + alert('You are unable to tear yourself away (because something failed on the server)'); + } + }, + onFailure: function(r) { + alert('You are unable to tear yourself away (because something failed on the server)'); + } + }); +} + var resizePostContentTimeout = null; function resizePostContent() { if (resizePostContentTimeout) @@ -420,9 +547,6 @@ function tickerFader(a, b, p) { b.hide(); } -function fadeOut(p) { -} - function ticker() { tickerHead.show(); Bytex64.FX.run(tickerFader.curry(tickerHead, tickerTail), 0.5); @@ -442,7 +566,7 @@ function startTicker() { // Show the first five tickerHead = $('latest-posts').firstChild; - for (var i = 0; i < 5 && tickerHead; i++) { + for (var i = 0; i < 10 && tickerHead; i++) { tickerHead.show(); tickerHead = tickerHead.nextSibling; } @@ -465,6 +589,7 @@ function loadLatest() { j.tags.each(function(v) { var a = new Element('a', {href: '/#tag/' + v}); a.insert('#' + v); + a.className = 'ref'; $('latest-tags').insert(a); $('latest-tags').appendChild(document.createTextNode(' ')); }); @@ -499,7 +624,7 @@ function hashSwitch() { if (m[3]) { var r = parseInt(m[3]); currentPager.showRecord = r; - if (currentPager.recordCache[r]) { + if (currentPager.itemCache[r]) { currentPager.displayItems(); } else { currentPager.loadItems((r >= 49 ? r - 49 : 0), r); @@ -517,6 +642,7 @@ function hashSwitch() { $('older_link').hide(); $('welcome').show(); $('rss').hide(); + $('usercontrols').hide(); loadLatest(); } }