*/
// Config
-var baseURL = '/admin/blerg';
+var baseURL = '';
var recordTemplate = new Template(
'<div class="record">#{data}<div class="info">Posted #{date}. <a href="' + baseURL + '/\##{author}/#{record}" onclick="return qlink()">[permalink]</a> <a href="#" onclick="postPopup(\'@#{author}/#{record}: \'); return false">[reply]</a></div></div>'
);
if (cookies.auth && cookies.username) {
this.loggedIn = true;
this.username = cookies.username;
+ this.requestFeedStatus();
+ this.feedStatusUpdateInterval = setInterval(this.requestFeedStatus.bind(this), 900000);
} else {
this.loggedIn = false;
this.username = null;
this.username = username;
document.cookie = "username=" + username;
$('login.password').value = '';
+ this.requestFeedStatus();
+ this.feedStatusUpdateInterval = setInterval(this.requestFeedStatus.bind(this), 900000);
this.update();
} else {
alert("Could not log in");
this.loggedIn = false;
document.cookie = "auth=; expires=1-Jan-1970 00:00:00 GMT";
this.update();
+ clearInterval(this.feedStatusUpdateInterval);
}.bind(this)
});
document.cookie = "username=; expires=1-Jan-1970 00:00:00 GMT";
});
}
+LoginStatus.prototype.requestFeedStatus = function() {
+ new Ajax.Request('/feedinfo', {
+ parameters: { username: this.username },
+ onSuccess: function(r) {
+ var j = r.responseText.evalJSON();
+ if (j['new'] > 0) {
+ $('newFeedMessages').update('(' + j['new'] + ' new)');
+ } else {
+ $('newFeedMessages').update('');
+ }
+ }
+ });
+}
// Base object for paged data
function Pager() {
l = l.replace(/(\s|^)(https?:\/\/[a-zA-Z0-9.-]*[a-zA-Z0-9](\/([^\s"]*[^.!,;?()\s])?)?)/g, '$1<a href="$2">$2</a>');
// Turn markdown links into links
+ var re;
+
+ // Craft a regex that finds URLs that end in the extensions specified by BlergMedia.audioExtensions.
+ re = new RegExp('(\\s|^)\\[([^\\]]+)\\]\\((https?:\\/\\/[a-zA-Z0-9.-]*[a-zA-Z0-9]\\/[^)"]*?\\.(' + BlergMedia.audioExtensions.join('|') + '))\\)', 'g');
+ l = l.replace(re, '$1<a href="$3">$2</a> <a href="$3" onclick="play_audio(); return false"><img src="/images/play.png"></a>');
+
+ // Ditto, but use the extended markdown link syntax to specify the format
+ re = new RegExp('(\\s|^)\\[([^\\]]+)\\]\\((https?:\\/\\/[a-zA-Z0-9.-]*[a-zA-Z0-9](\\/[^)"]*?)?)\\s+audio:(' + BlergMedia.audioExtensions.join('|') + ')\\)', 'g');
+ l = l.replace(re, '$1<a href="$3">$2</a> <a href="$3" onclick="play_audio(); return false"><img src="/images/play.png"></a>');
+
+ // Craft a regex that finds URLs that end in the extensions specified by BlergMedia.videoExtensions.
+ re = new RegExp('(\\s|^)\\[([^\\]]+)\\]\\((https?:\\/\\/[a-zA-Z0-9.-]*[a-zA-Z0-9]\\/[^)"]*?\\.(' + BlergMedia.videoExtensions.join('|') + '))\\)', 'g');
+ l = l.replace(re, '$1<a href="$3">$2</a> <a href="$3" onclick="play_video(); return false"><img src="/images/play.png"></a>');
+
+ // Ditto, but use the extended markdown link syntax to specify the format
+ re = new RegExp('(\\s|^)\\[([^\\]]+)\\]\\((https?:\\/\\/[a-zA-Z0-9.-]*[a-zA-Z0-9](\\/[^)"]*?)?)\\s+video:(' + BlergMedia.videoExtensions.join('|') + ')\\)', 'g');
+ l = l.replace(re, '$1<a href="$3">$2</a> <a href="$3" onclick="play_video(); return false"><img src="/images/play.png"></a>');
+
+ // Regular markdown links
l = l.replace(/(\s|^)\[([^\]]+)\]\((https?:\/\/[a-zA-Z0-9.-]*[a-zA-Z0-9](\/[^)"]*?)?)\)/g, '$1<a href="$3">$2</a>');
// Turn *foo* into italics and **foo** into bold
if (!this.pageStart)
this.pageStart = response.length - 1;
this.itemCount = response.length;
+ loginStatus.requestFeedStatus();
}
this.displayItems();
}.bind(this),
urlSwitch();
}
+function passwd() {
+ var old_password = $('passwd.old_password').value;
+ var new_password = $('passwd.new_password').value;
+
+ new Ajax.Request(baseURL + '/passwd', {
+ parameters: {
+ username: loginStatus.username,
+ password: old_password,
+ new_password: new_password
+ },
+ onSuccess: function(r) {
+ if (r.responseJSON.status == 'success') {
+ alert('Password changed');
+ passwd_cancel();
+ } else {
+ alert('Password change failed. Your password has NOT been changed.');
+ }
+ },
+ onFailure: function(r) {
+ alert('Password change error');
+ }
+ });
+}
+
+function passwd_cancel() {
+ $('passwd').hide();
+ $('navigation').show();
+ urlSwitch();
+}
+
function subscribe() {
new Ajax.Request(baseURL + '/subscribe/' + currentPager.username, {
method: 'post',
return false;
}
-function Welcome() {
- loadLatest();
-}
-
-Welcome.prototype.show = function() {
- $$('[name=section]').each(function(v) { v.update('Welcome') });
- $('welcome').show();
-}
-
-Welcome.prototype.hide = function() {
- stopTicker();
- $('welcome').hide();
-}
-
function ExternalURLPost(m) {
this.title = decodeURIComponent(m[1]).replace(']','').replace('[','');
this.url = decodeURIComponent(m[2]);
$('post.content').value = '[' + this.title + '](' + this.url + ')';
$('post').show();
}
-
-var urlmap = [
- ['search', /^\?post\/([^/]+)\/(.+)/, ExternalURLPost],
- ['hash', /^#\/(ref|tag)\/([A-Za-z0-9_-]+)(?:\/p(\d+))?$/, Tag],
- ['hash', /^#\/feed(?:\/p(\d+))?$/, Feed],
- ['hash', /^#([A-Za-z0-9_-]+)(?:\/(p)?(\d+))?$/, User]
-];
-
-function urlSwitch() {
- var m;
- var pageconstructor;
-
- for (var i = 0; i < urlmap.length; i++) {
- if (m = location[urlmap[i][0]].match(urlmap[i][1])) {
- pageconstructor = urlmap[i][2];
- break;
- }
- }
- if (i == urlmap.length)
- pageconstructor = Welcome;
-
- if (currentPager && currentPager instanceof pageconstructor) {
- // updateState returns true if the state has been successfully updated.
- // Otherwise, we continue and create a new instance.
- if (currentPager.updateState(m))
- return;
- }
-
- if (currentPager && currentPager.hide)
- currentPager.hide();
-
- currentPager = new pageconstructor(m);
- if (currentPager.show)
- currentPager.show();
-}
-
-var lastHash;
-function hashCheck() {
- if (location.hash != lastHash) {
- lastHash = location.hash;
- urlSwitch();
- }
-}
-
-function init() {
- items = $('items');
- loginStatus = new LoginStatus();
-
- lastHash = location.hash;
- urlSwitch();
-
- setInterval(hashCheck, 250);
-
- document.body.observe('keyup', function(event) {
- if (event.shiftKey && event.keyCode == 32) {
- postPopup();
- event.stop();
- }
- });
- $('post.content').addEventListener('keyup', function(event) {
- event.stopPropagation();
- }, true);
-}