diff options
| author | Savetheinternet <savetheinternet@n0v4.com> | 2011-04-22 18:16:12 +1000 |
|---|---|---|
| committer | Savetheinternet <savetheinternet@n0v4.com> | 2011-04-22 18:16:12 +1000 |
| commit | c4913ab883b30cd3eb2b4d6bb7854563e59bb482 (patch) | |
| tree | 93de0bd2b4d5ac59f1ca246e506508c9d48acd06 | |
| parent | 25e77ae425e49fa90ebf94d9e7074d5da58d0530 (diff) | |
more efficient javascript remembering system
| -rw-r--r-- | main.js | 65 | ||||
| -rw-r--r-- | templates/index.html | 5 | ||||
| -rw-r--r-- | templates/main.js | 63 | ||||
| -rw-r--r-- | templates/thread.html | 5 |
4 files changed, 79 insertions, 59 deletions
@@ -51,7 +51,7 @@ function citeReply(id) { document.getElementById('body').value += '>>' + id + '\n';
}
-var selectedstyle = 'Yotsuba';
+var selectedstyle = 'Yotsuba B';
var styles = [
['Yotsuba B', '/board/default.css'],
['Yotsuba', '/board/yotsuba.css']
@@ -73,6 +73,41 @@ if(localStorage.stylesheet) { }
}
+function rememberStuff() {
+ if(document.forms.post) {
+ if(!localStorage.password)
+ localStorage.password = generatePassword();
+ document.forms.post.password.value = localStorage.password;
+
+ if(localStorage.name)
+ document.forms.post.name.value = localStorage.name;
+ if(localStorage.email)
+ document.forms.post.email.value = localStorage.email;
+
+ if(sessionStorage.body) {
+ saved = JSON.parse(sessionStorage.body);
+ if(get_cookie('serv')) {
+ // Remove successful posts
+ successful = JSON.parse(get_cookie('serv'));
+ for (var url in successful) {
+ saved[url] = null;
+ }
+ sessionStorage.body = JSON.stringify(saved);
+
+ document.cookie = 'serv={};expires=0;path=/;';
+ }
+ if(saved[document.location]) {
+ document.getElementsByTagName('form')[0].body.value = saved[document.location];
+ }
+ }
+
+ if(localStorage.body) {
+ document.getElementsByTagName('form')[0].body.value = localStorage.body;
+ localStorage.body = '';
+ }
+ }
+}
+
function init()
{
newElement = document.createElement('div');
@@ -89,8 +124,6 @@ function init() document.getElementsByTagName('body')[0].insertBefore(newElement, document.getElementsByTagName('body')[0].lastChild)
- if(!localStorage.password)
- localStorage.password = generatePassword();
if(document.forms.delete) {
document.forms.delete.password.value = localStorage.password;
}
@@ -99,33 +132,7 @@ function init() citeReply(window.location.hash.substring(2));
else if (window.location.hash.substring(1))
highlightReply(window.location.hash.substring(1));
- if(localStorage.name)
- document.getElementsByTagName('form')[0].name.value = localStorage.name;
- if(localStorage.email)
- document.getElementsByTagName('form')[0].email.value = localStorage.email;
-
- if(sessionStorage.body) {
- saved = JSON.parse(sessionStorage.body);
- if(get_cookie('serv')) {
- // Remove successful posts
- successful = JSON.parse(get_cookie('serv'));
- for (var url in successful) {
- saved[url] = null;
- }
- sessionStorage.body = JSON.stringify(saved);
-
- document.cookie = 'serv={};expires=0;path=/;';
- }
- if(saved[document.location]) {
- document.getElementsByTagName('form')[0].body.value = saved[document.location];
- }
- }
-
- if(localStorage.body) {
- document.getElementsByTagName('form')[0].body.value = localStorage.body;
- localStorage.body = '';
- }
link = document.getElementsByTagName('a');
for ( i in link ) {
if(typeof link[i] == "object" && link[i].childNodes[0].src) {
diff --git a/templates/index.html b/templates/index.html index 4573431d..7ba56828 100644 --- a/templates/index.html +++ b/templates/index.html @@ -18,7 +18,7 @@ <div class="title">{board[title]?{board[title]}}<p>{mod?<a href="?/">Return to dashboard</a>}</p></div>
- <form onsubmit="return dopost(this);" enctype="multipart/form-data" action="{config[post_url]}" method="post">
+ <form name="post" onsubmit="return dopost(this);" enctype="multipart/form-data" action="{config[post_url]}" method="post">
{hidden_inputs}
<input type="hidden" name="board" value="{board[uri]}" />
{mod?<input type="hidden" name="mod" value="1" />}
@@ -96,6 +96,9 @@ </tr>
</table>
</form>
+ <script type="text/javascript">
+ rememberStuff();
+ </script>
<hr/>
<form name="delete" action="{post_url}" method="post">
<input type="hidden" name="board" value="{board[uri]}" />
diff --git a/templates/main.js b/templates/main.js index bf880036..83de6485 100644 --- a/templates/main.js +++ b/templates/main.js @@ -73,6 +73,41 @@ if(localStorage.stylesheet) { }
}
+function rememberStuff() {
+ if(document.forms.post) {
+ if(!localStorage.password)
+ localStorage.password = generatePassword();
+ document.forms.post.password.value = localStorage.password;
+
+ if(localStorage.name)
+ document.forms.post.name.value = localStorage.name;
+ if(localStorage.email)
+ document.forms.post.email.value = localStorage.email;
+
+ if(sessionStorage.body) {
+ saved = JSON.parse(sessionStorage.body);
+ if(get_cookie('{config[cookies][js]}')) {
+ // Remove successful posts
+ successful = JSON.parse(get_cookie('{config[cookies][js]}'));
+ for (var url in successful) {
+ saved[url] = null;
+ }
+ sessionStorage.body = JSON.stringify(saved);
+
+ document.cookie = '{config[cookies][js]}={};expires=0;path=/;';
+ }
+ if(saved[document.location]) {
+ document.getElementsByTagName('form')[0].body.value = saved[document.location];
+ }
+ }
+
+ if(localStorage.body) {
+ document.getElementsByTagName('form')[0].body.value = localStorage.body;
+ localStorage.body = '';
+ }
+ }
+}
+
function init()
{
newElement = document.createElement('div');
@@ -89,8 +124,6 @@ function init() document.getElementsByTagName('body')[0].insertBefore(newElement, document.getElementsByTagName('body')[0].lastChild)
- if(!localStorage.password)
- localStorage.password = generatePassword();
if(document.forms.delete) {
document.forms.delete.password.value = localStorage.password;
}
@@ -99,33 +132,7 @@ function init() citeReply(window.location.hash.substring(2));
else if (window.location.hash.substring(1))
highlightReply(window.location.hash.substring(1));
- if(localStorage.name)
- document.getElementsByTagName('form')[0].name.value = localStorage.name;
- if(localStorage.email)
- document.getElementsByTagName('form')[0].email.value = localStorage.email;
-
- if(sessionStorage.body) {
- saved = JSON.parse(sessionStorage.body);
- if(get_cookie('{config[cookies][js]}')) {
- // Remove successful posts
- successful = JSON.parse(get_cookie('{config[cookies][js]}'));
- for (var url in successful) {
- saved[url] = null;
- }
- sessionStorage.body = JSON.stringify(saved);
-
- document.cookie = '{config[cookies][js]}={};expires=0;path=/;';
- }
- if(saved[document.location]) {
- document.getElementsByTagName('form')[0].body.value = saved[document.location];
- }
- }
-
- if(localStorage.body) {
- document.getElementsByTagName('form')[0].body.value = localStorage.body;
- localStorage.body = '';
- }
link = document.getElementsByTagName('a');
for ( i in link ) {
if(typeof link[i] == "object" && link[i].childNodes[0].src) {
diff --git a/templates/thread.html b/templates/thread.html index f857923f..28130dd4 100644 --- a/templates/thread.html +++ b/templates/thread.html @@ -17,7 +17,7 @@ <div class="title">{board[title]?{board[title]}}<p>{mod?<a href="?/">Return to dashboard</a>}</p></div>
<div class="banner">Posting mode: Reply <a class="unimportant" href="{return}">[Return.]</a></div>
- <form onsubmit="return dopost(this);" enctype="multipart/form-data" action="{config[post_url]}" method="post">{hidden_inputs}
+ <form name="post" onsubmit="return dopost(this);" enctype="multipart/form-data" action="{config[post_url]}" method="post">{hidden_inputs}
<input type="hidden" name="thread" value="{id}" />
<input type="hidden" name="board" value="{board[uri]}" />
{mod?<input type="hidden" name="mod" value="1" />}
@@ -87,6 +87,9 @@ </tr>
</table>
</form>
+ <script type="text/javascript">
+ rememberStuff();
+ </script>
<hr/>
<form name="delete" action="{config[post_url]}" method="post">
<input type="hidden" name="board" value="{board[uri]}" />
|
