X-Git-Url: http://git.bytex64.net/?a=blobdiff_plain;ds=inline;f=www%2Fjs%2Fblerg.js;h=0d114cb22f70ef8d0f3e21a490aac81f14741241;hb=6d460ea60252c7bb6b567b06e4428e3e7986885e;hp=bae782ed96bbed815679760c1ae24e6e8d367e3a;hpb=54789cc8538714fc3622646721f6f2ecceae94ac;p=blerg.git diff --git a/www/js/blerg.js b/www/js/blerg.js index bae782e..0d114cb 100644 --- a/www/js/blerg.js +++ b/www/js/blerg.js @@ -2,96 +2,10 @@ * BSD-style license. Please see the COPYING file for details. */ -// Config -var baseURL = ''; -var recordTemplate = new Template( - '
").replace(/\r?\n/g, "
");
-
- record.date = (new Date(record.timestamp * 1000)).toString();
- record.html = template.evaluate(record);
-}
-
-function displayError(msg) {
- items.innerText = msg;
-}
-
-
-// Object for browsing tags
-function Tag(type, tag) {
- this.initPager();
- this.type = type;
- this.tag = tag;
-
- var url = baseURL + "/tag/";
- switch(type) {
- case 'tag':
- //url += '%23';
- url += 'H'; // apache is eating the hash, even encoded. Probably a security feature.
- break;
- case 'ref':
- url += '%40';
- break;
- default:
- alert('Invalid tag type: ' + type);
- return;
- }
- url += tag;
-
- new Ajax.Request(url, {
- method: 'get',
- onSuccess: function(r) {
- var j = r.responseText.evalJSON();
- if (j) {
- var maxid = j.length - 1;
- j.each(function(v, i) {
- v.id = maxid - i;
- mangleRecord(v, tagRecordTemplate)
- });
- this.addItems(j);
- this.pageStart = j.length - 1;
- }
- this.displayItems();
- }.bind(this),
- onFailure: function(r) {
- this.displayItems();
- }.bind(this)
- });
-
-}
-Tag.prototype = new Pager();
-Tag.prototype.constructor = Tag;
-
-Tag.prototype.show = function() {
- var ctype = {ref: '@', tag: '#'}[this.type];
-
- $$('[name=section]').each(function(v) {
- v.update(' about ' + ctype + this.tag);
- }.bind(this));
- $('welcome').hide();
- $('post').hide();
- $('older_link').hide();
- $('newer_link').hide();
- $('rss').hide();
- items.show();
-}
-
-function postPopup() {
- if (loginStatus.loggedIn) {
- var post = $('post');
- if (post.visible()) {
- post.hide();
- } else {
- post.show();
- if (currentPager.username && currentPager.username != loginStatus.username && !$('post.content').value) {
- $('post.content').value = '@' + currentPager.username + ': ';
- }
- $('post.content').focus();
- }
- }
-}
-
-function signup() {
- var username = $('signup.username').value;
- var password = $('signup.password').value;
-
- new Ajax.Request(baseURL + '/create', {
+ new Ajax.Request(baseURL + '/passwd', {
parameters: {
- username: username,
- password: password,
+ username: loginStatus.username,
+ password: old_password,
+ new_password: new_password
},
onSuccess: function(r) {
- $('signup').hide();
- location.hash = username;
- hashSwitch();
-
- loginStatus.login(username, password);
+ 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("Failed to create user");
+ alert('Password change error');
}
});
}
-function signup_cancel() {
- $('signup').hide();
- hashSwitch();
-}
-
-function newer_page() {
- if (currentPager)
- currentPager.newerPage();
-}
-
-function older_page() {
- if (currentPager)
- currentPager.olderPage();
-}
-
-var resizePostContentTimeout = null;
-function resizePostContent() {
- if (resizePostContentTimeout)
- clearTimeout(resizePostContentTimeout);
- resizePostContentTimeout = setTimeout(function() {
- var c = $('post.content');
- var lines = Math.floor(c.value.length / (100 * (c.clientWidth / 1000))) + 1;
- var m = c.value.match(/\r?\n/g);
- if (m)
- lines += m.length;
- if (lines <= 3) {
- c.style.height = "";
- } else {
- c.style.height = (lines * 17) + "pt";
- }
- resizePostContentTimeout = null;
- }, 150);
-}
-
-function hashSwitch() {
- var m = location.hash.match(/^#((ref|tag)\/)?(\w+)(:(\d+))?/);
- if (m) {
- if (m[1]) {
- currentPager = new Tag(m[2], m[3]);
- currentPager.show();
- } else {
- if (!currentPager || currentPager.username != m[3])
- currentPager = new User(m[3]);
- currentPager.show();
- loginStatus.update();
-
- if (m[5]) {
- var r = parseInt(m[5]);
- currentPager.showRecord = r;
- if (currentPager.recordCache[r]) {
- currentPager.displayItems();
- } else {
- currentPager.loadItems((r >= 49 ? r - 49 : 0), r);
- }
- } else {
- currentPager.pageStart = currentPager.itemCount - 1;
- currentPager.loadItems();
- }
- }
- } else {
- $$('[name=section]').each(function(v) { v.update('Welcome') });
- $('signup').hide();
- items.update();
- items.hide();
- $('newer_link').hide();
- $('older_link').hide();
- $('welcome').show();
- $('rss').hide();
- }
-}
-
-var lastHash;
-function hashCheck() {
- if (location.hash != lastHash) {
- lastHash = location.hash;
- hashSwitch();
- }
-}
-
-function init() {
- items = $('items');
- loginStatus = new LoginStatus();
-
- lastHash = location.hash;
- hashSwitch();
-
- setInterval(hashCheck, 250);
-
- document.body.observe('keyup', function(event) {
- if (event.shiftKey && event.keyCode == '32') {
- postPopup();
- event.stop();
- }
- });
+function passwd_cancel() {
+ $('passwd').hide();
+ $('navigation').show();
+ urlSwitch();
}