X-Git-Url: http://git.bytex64.net/?a=blobdiff_plain;ds=inline;f=www%2Fjs%2Fblerg.js;h=8cb5bab3d07fbb5854a92eebd016f9aa9df32931;hb=929a369550b4a40b743e7e30746b6cf575760fe3;hp=ba1e39e35464480d366060fe1b19cd6fa722df7f;hpb=e396ecb2bf773e4df131b6edf769ca69868575bd;p=blerg.git
diff --git a/www/js/blerg.js b/www/js/blerg.js
index ba1e39e..8cb5bab 100644
--- a/www/js/blerg.js
+++ b/www/js/blerg.js
@@ -3,7 +3,7 @@
*/
// Config
-var baseURL = '/admin/blerg';
+var baseURL = '';
var recordTemplate = new Template(
'
'
);
@@ -31,6 +31,8 @@ function LoginStatus() {
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;
@@ -51,6 +53,8 @@ LoginStatus.prototype.login = function(username, password) {
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");
@@ -73,6 +77,7 @@ LoginStatus.prototype.logout = function() {
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";
@@ -123,6 +128,19 @@ LoginStatus.prototype.post = function(msg) {
});
}
+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() {
@@ -383,9 +401,28 @@ function mangleRecord(record, template) {
l = l.replace(/&/g, '&').replace(//g, '>');
// Turn HTTP URLs into links
- l = l.replace(/(\s|^)(https?:\/\/[a-zA-Z0-9.-]*[a-zA-Z0-9](\/([^\s"]*[^.!,;?()\s])?)?)/g, '$1$2');
+ l = l.replace(/(\s[()\[\]{}]?|^)(https?:\/\/[a-zA-Z0-9.-]*[a-zA-Z0-9](\/([^\s"]*[^.!,;?()\s])?)?)/g, '$1$2');
// 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$2 ');
+
+ // 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$2 ');
+
+ // 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$2 ');
+
+ // 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$2 ');
+
+ // Regular markdown links
l = l.replace(/(\s|^)\[([^\]]+)\]\((https?:\/\/[a-zA-Z0-9.-]*[a-zA-Z0-9](\/[^)"]*?)?)\)/g, '$1$2');
// Turn *foo* into italics and **foo** into bold
@@ -540,6 +577,7 @@ function Feed(m) {
if (!this.pageStart)
this.pageStart = response.length - 1;
this.itemCount = response.length;
+ loginStatus.requestFeedStatus();
}
this.displayItems();
}.bind(this),
@@ -609,6 +647,36 @@ function signup_cancel() {
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',
@@ -776,6 +844,10 @@ Welcome.prototype.hide = function() {
$('welcome').hide();
}
+Welcome.prototype.updateState = function() {
+ this.show();
+}
+
function ExternalURLPost(m) {
this.title = decodeURIComponent(m[1]).replace(']','').replace('[','');
this.url = decodeURIComponent(m[2]);