Permalink
Browse files

Alpha auto-save functionality (doesnt support duplicating posts yet)

  • Loading branch information...
natew committed Mar 30, 2012
1 parent c547806 commit 4c14269b256c5fb19b948ed38e048a30a886cad2
@@ -49,4 +49,13 @@ function validateTitle() {
} else {
return true;
}
+}
+
+function savePost() {
+ var form = $('.edit_post'),
+ action = form.attr('action');
+
+ $.post(action, form.serialize(), function() {
+ $('#save-button').val('Saved').addClass('saved');
+ });
}
@@ -3,11 +3,12 @@ $(function() {
var title = document.getElementById('text-title'),
content = document.getElementById('text-content');
-
$('.post').fitVids();
// If we're on the edit page
if (title) {
+ var changed = false;
+
// Hide bar
$('#publish-bar').delay(1000).animate({
bottom: '-100px'
@@ -42,14 +43,22 @@ $(function() {
$('#post_content').css('min-height', $(window).height() - $('#post_title').height() - 130);
// Autosave
- // setInterval(function(){
- // var form = $('.edit_post'),
- // action = form.attr('action');
+ $('#post_content,#post_title').bind('keyup', function(){
+ changed = true;
+ $('#save-button').val('Save').removeClass('saved');
+ });
- // $.post(action, form.serialize(), function(data){
- // $('body').prepend('<span>Saved!</span>');
- // });
- // },10000);
+ setInterval(function(){
+ if (changed) {
+ changed = false;
+ savePost();
+ }
+ },5000);
+
+ // Ajax save-button
+ $('#save-button').click(function(){
+ savePost();
+ });
// Preview pops open new window
var $form = $('form:first'),
@@ -351,6 +351,14 @@ label {
margin: 0 auto;
position: relative;
+ #save-button.saved {
+ color: #999;
+
+ &:hover {
+ cursor: normal;
+ }
+ }
+
#drafts {
float: left;
border: 4px solid #000;
@@ -9,6 +9,7 @@
<body class="admin">
<div id="admin">
+ <div id="save"></div>
<% if notice %><span class="notice"><%= notice %></span><% end %>
<%= yield %>
</div>
@@ -0,0 +1,5 @@
+class AddParentToPosts < ActiveRecord::Migration
+ def change
+ add_column :posts, :parent, :integer
+ end
+end
View
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20120327204225) do
+ActiveRecord::Schema.define(:version => 20120330144129) do
create_table "posts", :force => true do |t|
t.string "title"
@@ -22,6 +22,7 @@
t.datetime "updated_at", :null => false
t.boolean "aside", :default => false
t.string "url"
+ t.integer "parent"
end
create_table "sessions", :force => true do |t|

0 comments on commit 4c14269

Please sign in to comment.