diff --git a/public/src/app.js b/public/src/app.js index de5d57235c..d5404d66ab 100644 --- a/public/src/app.js +++ b/public/src/app.js @@ -143,6 +143,40 @@ var socket, } } + // If there was a saved draft, populate the post content with it now + if (localStorage) { + var draft = localStorage.getItem(post_mode + '_' + id + '_draft'); + if (draft && draft.length > 0) { + post_content.value = draft; + localStorage.removeItem(post_mode + '_' + id + '_draft'); + } + } + + // Override post window behaviour if user is not logged in + if (document.getElementById('user_label') === null) { + submit_post_btn.innerHTML = ' Save & Login'; + submit_post_btn.onclick = function() { + // Save the post content in localStorage and send the user to registration page + if (localStorage && post_content.value.length > 0) { + localStorage.setItem(post_mode + '_' + id + '_draft', post_content.value); + + jQuery(post_window).slideUp(250); + $(document.body).removeClass('composing'); + post_title.value = ''; + reply_title.value = ''; + post_content.value = ''; + + app.alert({ + title: 'Post Saved', + message: 'We've saved your post as a draft. It will be available again when you log in and post again.', + type: 'notify', + timeout: 5000 + }); + + ajaxify.go('login'); + } + } + } }; diff --git a/public/templates/header.tpl b/public/templates/header.tpl index c69e2eb4c9..e79cd49f47 100644 --- a/public/templates/header.tpl +++ b/public/templates/header.tpl @@ -65,7 +65,7 @@