Add ReplyNew Thread

 Post Autosaver, Jcink
Black
 Posted: December 21st, 2013, 02:18 PM
Quote
Finally finished.
Posts:290Group:AdministratorJoined:July 14th, 2013
Send Message


Description: Automatically saves the contents of a new topic or reply via the browser's local storage, and continues to do so at regular intervals(every 30 seconds by default). Saved posts are unique to the forum and topic they are being made in; there will be no overlap between different forums. This script does not save posts being edited or previewed. Saved posts are saved locally, and are not globally shared between different internet browsers or computers.
Requires: jQuery
Target Platform: Jcink
Demonstration: This script is being used here on Code.
Installation Instructions:
Step 1: Add this script to your board header.

Code (Click to highlight)
<script>
// Post Autosaver by Black
// http://code.jfbs.net/?showtopic=81
$(document).ready(function() {
if(window.location.href.indexOf("act=Post") !== -1 && window.location.href.indexOf("&f=") !== -1 && window.location.href.indexOf("&CODE=08") == -1) {
var forumParameters = (function(url) {
var result = {};
for (var i=0; i<url.length; i++) {
var parameter = url[i].split('=');
if (parameter.length != 2) continue;
result[parameter[0]] = decodeURIComponent(parameter[1].replace(/\+/g, " "));
}
return result;
})(window.location.search.substr(1).split('&'));
var subDomain = location.hostname.split('.').shift();
function savePost() {
if(forumParameters["t"]) {
localStorage[subDomain + forumParameters["f"] + forumParameters["t"]] = $("textarea[name='Post']").val();
}
else {
localStorage[subDomain + forumParameters["f"]] = $("textarea[name='Post']").val();
}
}
function loadPost() {
if(forumParameters["t"]) {
if(forumParameters["p"]) {
return false;
}
$("textarea[name='Post']").val(localStorage[subDomain + forumParameters["f"] + forumParameters["t"]]);
}
else {
$("textarea[name='Post']").val(localStorage[subDomain + forumParameters["f"]]);
}
}
function savePostRepeat() {
setTimeout(function() {
savePost();
savePostRepeat();
}, 30000);
}
$(window).unload(function() {
savePost();
});
$("form[name='REPLIER']").on("submit", function() {
if(forumParameters["t"]) {
localStorage.removeItem(subDomain + forumParameters["f"] + forumParameters["t"]);
}
else {
localStorage.removeItem(subDomain + forumParameters["f"]);
}
});
loadPost();
savePostRepeat();
}
});
</script>


This post has been edited by Black: January 4th, 2014, 09:06 AM
PANSY PARKINSON
 Posted: December 22nd, 2013, 05:25 PM
Quote
Advanced Member
Posts:40Group:MemberJoined:October 28th, 2013
Send Message


This is so perfect! Thank you!!
EmailWebsite
MAX ROCKATANSKY
 Posted: December 24th, 2013, 03:39 AM
Quote
Advanced Member
Posts:65Group:MemberJoined:November 19th, 2013
Send Message


Black you beautiful soul this is fab.
Pierrot
 Posted: January 4th, 2014, 06:44 AM
Quote
you are not your skin.
Posts:499Group:StaffJoined:August 28th, 2013
Send Message


Works great except it doesn't seem to like it when I quote threads.
Email
Black
 Posted: January 4th, 2014, 09:06 AM
Quote
Finally finished.
Posts:290Group:AdministratorJoined:July 14th, 2013
Send Message


This was a really quick fix, so it's been included. Thanks for pointing it out, Pierrot!

If there are any threads here on Code where quoting still yields a blank post, clear your browser's data and it should start cooperating.
shobby
 Posted: February 6th, 2014, 08:00 AM
Quote
Newbie
Posts:1Group:New MemberJoined:February 6th, 2014
Send Message


Hey black!

First off, I want to thank you for all your amazing coding. I'm new to skinning and find them all so very helpful!

My question is: which header do I put this under and how can I tell if it is working? Does it go in the board wrapper section (that is where I have it at the moment) or in the style sheet? I apologise if this seems like such a silly question - I am extremely new to all this coding and trying to learn! I have a member on my board that only has a nook and it likes to play up on her and she loses her posts on a regular basis - trying to add this for her because she is so wonderful and doesn't deserve to keep losing her posts!

Also, is there any chance someone can explain jQuery to me? Or point me in the direction of a tutorial or something? I truly appreciate any help!

Cheers
Black
 Posted: February 6th, 2014, 08:44 AM
Quote
Finally finished.
Posts:290Group:AdministratorJoined:July 14th, 2013
Send Message


All JavaScript stuff goes in the board wrappers, typically between the <head> and </head> tags. A reference to jQuery is included in Jcink's <% JAVASCRIPT %> wrapper tag by default, but when I last checked it was outdated by a few versions. It shouldn't pose a compatibility problem here, though.

As a warning, this script uses a relatively new feature of HTML5 that may not be available on her Nook, unfortunately. If you could direct her to http://html5test.com/#head-storage and "Local Storage" does not have a green check mark beside it this script won't do anything for her, I'm afraid.

jQuery is a library written in JavaScript that makes doing certain things(animation and event handling, mostly) a complete breeze. Looking at it, however, this script is a poor example and could be rewritten without being dependent on jQuery at all- I guess I've developed a bad habit of relying on jQuery too often. A full explanation on jQuery will have to wait, since I need to go get ready for work. Send me a PM sometime and I'll take a crack at it, though!
Pierrot
 Posted: February 6th, 2014, 02:10 PM
Quote
you are not your skin.
Posts:499Group:StaffJoined:August 28th, 2013
Send Message


Here is an introduction to how jQuery works.
Email
MAX ROCKATANSKY
 Posted: April 20th, 2014, 12:05 AM
Quote
Advanced Member
Posts:65Group:MemberJoined:November 19th, 2013
Send Message


this doesn't work when i reply to threads on my site now? it saves when i post new threads, but if i click reply, nothing.
Jenny!
 Posted: August 19th, 2014, 03:54 PM
Quote
Newbie
Posts:9Group:New MemberJoined:August 17th, 2014
Send Message


Okay, I love this. But, one quick question. Say I'm makin' a new reply, and I hit the button, my previous post is there. Is that supposed to happen?

Topic Options Add ReplyNew Thread


 


 

   Chatbox
's reputation