summaryrefslogtreecommitdiff
path: root/templates
diff options
context:
space:
mode:
authorMichael Save <savetheinternet@tinyboard.org>2012-03-31 19:25:36 +1100
committerMichael Save <savetheinternet@tinyboard.org>2012-03-31 19:25:36 +1100
commitad657916a03fd01e2bb92ab72bc2f440f4e436d3 (patch)
tree85e15bfd6d25ff8f6fa96501ef99b8fd7738ed4c /templates
parentd9b2b3f7a19ae12019c8c4583f77db7708cf5004 (diff)
Javascript cleanup
Diffstat (limited to 'templates')
-rw-r--r--templates/main.js59
1 files changed, 27 insertions, 32 deletions
diff --git a/templates/main.js b/templates/main.js
index 71180259..0b514a80 100644
--- a/templates/main.js
+++ b/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 + '=([^;]*)(;|$)');
if(results)
return (unescape(results[2]));
@@ -7,9 +15,8 @@
return null;
}
-function highlightReply(id)
-{
- if(window.event !== undefined && event.which == 2) {
+function highlightReply(id) {
+ if(typeof window.event != "undefined" && event.which == 2) {
// don't highlight on middle click
return true;
}
@@ -21,23 +28,18 @@ function highlightReply(id)
divs[i].className = divs[i].className.replace(/highlighted/, '');
}
if (id) {
- post = document.getElementById('reply_'+id);
+ var post = document.getElementById('reply_'+id);
if(post)
post.className += ' highlighted';
}
}
-function focusId(id)
-{
- document.getElementById(id).focus();
- init();
-}
function generatePassword() {
- pass = '';
- chars = '{% endraw %}{{ config.genpassword_chars }}{% raw %}';
- for(i=0;i<8;i++) {
- rnd = Math.floor(Math.random() * chars.length);
- pass += chars.substring(rnd,rnd + 1);
+ var pass = '';
+ var chars = '{% endraw %}{{ config.genpassword_chars }}{% raw %}';
+ for(var i = 0; i < 8; i++) {
+ var rnd = Math.floor(Math.random() * chars.length);
+ pass += chars.substring(rnd, rnd + 1);
}
return pass;
}
@@ -56,17 +58,17 @@ function dopost(form) {
return form.elements['body'].value != "" || form.elements['file'].value != "";
}
function citeReply(id) {
- body = document.getElementById('body');
+ var body = document.getElementById('body');
if (document.selection) {
// IE
body.focus();
- sel = document.selection.createRange();
+ var sel = document.selection.createRange();
sel.text = '>>' + id + '\n';
} else if (body.selectionStart || body.selectionStart == '0') {
// Mozilla
- start = body.selectionStart;
- end = body.selectionEnd;
+ var start = body.selectionStart;
+ var end = body.selectionEnd;
body.value = body.value.substring(0, start) + '>>' + id + '\n' + body.value.substring(end, body.value.length);
} 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) {
localStorage.stylesheet = styles[x][1];
document.getElementById('stylesheet').href = styles[x][1];
@@ -88,7 +83,7 @@ function changeStyle(x) {
}
if(localStorage.stylesheet) {
- for(x=0;x<styles.length;x++) {
+ for(var x = 0; x < styles.length ; x++) {
if(styles[x][1] == localStorage.stylesheet) {
changeStyle(x);
break;
@@ -113,10 +108,10 @@ function rememberStuff() {
citeReply(window.location.hash.substring(2));
if(sessionStorage.body) {
- saved = JSON.parse(sessionStorage.body);
+ var saved = JSON.parse(sessionStorage.body);
if(get_cookie('{% endraw %}{{ config.cookies.js }}{% raw %}')) {
// 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) {
saved[url] = null;
}
@@ -137,11 +132,11 @@ function rememberStuff() {
}
function init() {
- newElement = document.createElement('div');
+ var newElement = document.createElement('div');
newElement.className = 'styles';
for(x=0;x<styles.length;x++) {
- style = document.createElement('a');
+ var style = document.createElement('a');
style.innerHTML = '[' + styles[x][0] + ']';
style.href = 'javascript:changeStyle(' + x + ');';
if(selectedstyle == styles[x][0])