From f4b3a2eb3a5093d58e6f6be1f95c9487a2d7c78f Mon Sep 17 00:00:00 2001 From: danielvincent Date: Tue, 24 Aug 2010 20:49:32 -0700 Subject: [PATCH] more cleaning up of comment box. javascript stuff. --- app/views/comments/_new_comment.html.haml | 6 +++--- public/javascripts/view.js | 21 +++++++++++++++++++++ public/stylesheets/application.css | 4 ++++ public/stylesheets/sass/application.sass | 6 ++++++ 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/app/views/comments/_new_comment.html.haml b/app/views/comments/_new_comment.html.haml index 897e1e43c..bd117f7a0 100644 --- a/app/views/comments/_new_comment.html.haml +++ b/app/views/comments/_new_comment.html.haml @@ -1,7 +1,7 @@ = form_for Comment.new, :remote => true do |f| %p %label{:for => "comment_text_on_#{post.id}"} Comment - = f.text_area :text, :rows => 2, :id => "comment_text_on_#{post.id}" + = f.text_area :text, :rows => 1, :id => "comment_text_on_#{post.id}", :class => "comment_box" = f.hidden_field :post_id, :value => post.id - %p - = f.submit "Comment" + %p{:style => "text-align:right;"} + = f.submit "Comment", :class => "comment_submit" diff --git a/public/javascripts/view.js b/public/javascripts/view.js index 1d52e84bc..5f70b8f4b 100644 --- a/public/javascripts/view.js +++ b/public/javascripts/view.js @@ -61,6 +61,27 @@ $(document).ready(function(){ speed: 3000 }); + + //comments///// + + $(".comment_box").live('focus', function(evt){ + var $this = $(this); + $this.attr("rows", 2); + $this.parents("p").parents("form").children("p").children(".comment_submit").fadeIn(200); + }); + + $(".comment_box").live('blur', function(evt){ + var $this = $(this); + if( $this.val() == '' ) { + $this.parents("p").parents("form").children("p").children(".comment_submit").fadeOut(0); + $this.attr("rows", 1); + } + }); + + $(".comment_submit").live('click', function(evt){ + $this.parents("p").parents("form").children("p").children(".comment_box").attr("rows", 1); + }); + //buttons////// diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index e23d78229..ad56fe4b5 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -201,6 +201,10 @@ form { padding: 0; padding-left: 65px; } +input.comment_submit { + display: none; + margin-right: -10px; } + ul.comment_set { margin: 0; margin-top: 1em; diff --git a/public/stylesheets/sass/application.sass b/public/stylesheets/sass/application.sass index 5096a9884..b68e35d79 100644 --- a/public/stylesheets/sass/application.sass +++ b/public/stylesheets/sass/application.sass @@ -248,6 +248,12 @@ form :padding 0 :left 65px +input.comment_submit + :display none + :margin + :right -10px + + ul.comment_set :margin 0 :top 1em