Browse Source

Javascript cleanup

pull/40/head
Michael Save 12 years ago
parent
commit
ad657916a0
  1. 59
      templates/main.js

59
templates/main.js

@ -1,5 +1,13 @@
{% raw %}function get_cookie(cookie_name) {% raw %}
{
var selectedstyle = '{% endraw %}{{ config.default_stylesheet.0 }}{% raw %}';
var styles = [
{% endraw %}{% for stylesheet in stylesheets %}{% raw %}['{% endraw %}{{ stylesheet.name }}{% raw %}', '{% endraw %}{{ stylesheet.uri }}{% raw %}']{% endraw %}{% if not loop.last %}{% raw %},
{% endraw %}{% endif %}{% endfor %}{% raw %}
];
var saved = {};
function get_cookie(cookie_name) {
var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)'); var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)');
if(results) if(results)
return (unescape(results[2])); return (unescape(results[2]));
@ -7,9 +15,8 @@
return null; return null;
} }
function highlightReply(id) function highlightReply(id) {
{ if(typeof window.event != "undefined" && event.which == 2) {
if(window.event !== undefined && event.which == 2) {
// don't highlight on middle click // don't highlight on middle click
return true; return true;
} }
@ -21,23 +28,18 @@ function highlightReply(id)
divs[i].className = divs[i].className.replace(/highlighted/, ''); divs[i].className = divs[i].className.replace(/highlighted/, '');
} }
if (id) { if (id) {
post = document.getElementById('reply_'+id); var post = document.getElementById('reply_'+id);
if(post) if(post)
post.className += ' highlighted'; post.className += ' highlighted';
} }
} }
function focusId(id)
{
document.getElementById(id).focus();
init();
}
function generatePassword() { function generatePassword() {
pass = ''; var pass = '';
chars = '{% endraw %}{{ config.genpassword_chars }}{% raw %}'; var chars = '{% endraw %}{{ config.genpassword_chars }}{% raw %}';
for(i=0;i<8;i++) { for(var i = 0; i < 8; i++) {
rnd = Math.floor(Math.random() * chars.length); var rnd = Math.floor(Math.random() * chars.length);
pass += chars.substring(rnd,rnd + 1); pass += chars.substring(rnd, rnd + 1);
} }
return pass; return pass;
} }
@ -56,17 +58,17 @@ function dopost(form) {
return form.elements['body'].value != "" || form.elements['file'].value != ""; return form.elements['body'].value != "" || form.elements['file'].value != "";
} }
function citeReply(id) { function citeReply(id) {
body = document.getElementById('body'); var body = document.getElementById('body');
if (document.selection) { if (document.selection) {
// IE // IE
body.focus(); body.focus();
sel = document.selection.createRange(); var sel = document.selection.createRange();
sel.text = '>>' + id + '\n'; sel.text = '>>' + id + '\n';
} else if (body.selectionStart || body.selectionStart == '0') { } else if (body.selectionStart || body.selectionStart == '0') {
// Mozilla // Mozilla
start = body.selectionStart; var start = body.selectionStart;
end = body.selectionEnd; var end = body.selectionEnd;
body.value = body.value.substring(0, start) + '>>' + id + '\n' + body.value.substring(end, body.value.length); body.value = body.value.substring(0, start) + '>>' + id + '\n' + body.value.substring(end, body.value.length);
} else { } else {
// ??? // ???
@ -74,13 +76,6 @@ function citeReply(id) {
} }
} }
var selectedstyle = '{% endraw %}{{ config.default_stylesheet.0 }}{% raw %}';
var styles = [
{% endraw %}{% for stylesheet in stylesheets %}{% raw %}['{% endraw %}{{ stylesheet.name }}{% raw %}', '{% endraw %}{{ stylesheet.uri }}{% raw %}']{% endraw %}{% if not loop.last %}{% raw %},
{% endraw %}{% endif %}{% endfor %}{% raw %}
];
var saved = {};
function changeStyle(x) { function changeStyle(x) {
localStorage.stylesheet = styles[x][1]; localStorage.stylesheet = styles[x][1];
document.getElementById('stylesheet').href = styles[x][1]; document.getElementById('stylesheet').href = styles[x][1];
@ -88,7 +83,7 @@ function changeStyle(x) {
} }
if(localStorage.stylesheet) { if(localStorage.stylesheet) {
for(x=0;x<styles.length;x++) { for(var x = 0; x < styles.length ; x++) {
if(styles[x][1] == localStorage.stylesheet) { if(styles[x][1] == localStorage.stylesheet) {
changeStyle(x); changeStyle(x);
break; break;
@ -113,10 +108,10 @@ function rememberStuff() {
citeReply(window.location.hash.substring(2)); citeReply(window.location.hash.substring(2));
if(sessionStorage.body) { if(sessionStorage.body) {
saved = JSON.parse(sessionStorage.body); var saved = JSON.parse(sessionStorage.body);
if(get_cookie('{% endraw %}{{ config.cookies.js }}{% raw %}')) { if(get_cookie('{% endraw %}{{ config.cookies.js }}{% raw %}')) {
// Remove successful posts // Remove successful posts
successful = JSON.parse(get_cookie('{% endraw %}{{ config.cookies.js }}{% raw %}')); var successful = JSON.parse(get_cookie('{% endraw %}{{ config.cookies.js }}{% raw %}'));
for (var url in successful) { for (var url in successful) {
saved[url] = null; saved[url] = null;
} }
@ -137,11 +132,11 @@ function rememberStuff() {
} }
function init() { function init() {
newElement = document.createElement('div'); var newElement = document.createElement('div');
newElement.className = 'styles'; newElement.className = 'styles';
for(x=0;x<styles.length;x++) { for(x=0;x<styles.length;x++) {
style = document.createElement('a'); var style = document.createElement('a');
style.innerHTML = '[' + styles[x][0] + ']'; style.innerHTML = '[' + styles[x][0] + ']';
style.href = 'javascript:changeStyle(' + x + ');'; style.href = 'javascript:changeStyle(' + x + ');';
if(selectedstyle == styles[x][0]) if(selectedstyle == styles[x][0])

Loading…
Cancel
Save