textareas auto expand

This commit is contained in:
danielvincent 2010-12-11 22:16:18 -08:00
parent 3b5ee72ed8
commit 52a3996ad0
6 changed files with 33 additions and 11 deletions

View file

@ -5,7 +5,7 @@
= form_tag( comments_path, :id => "new_comment_on_#{post_id}", :class => 'new_comment', :remote => true) do = form_tag( comments_path, :id => "new_comment_on_#{post_id}", :class => 'new_comment', :remote => true) do
%p %p
= label_tag "comment_text_on_#{post_id}", t('.comment') = label_tag "comment_text_on_#{post_id}", t('.comment')
= text_area_tag :text, nil, :rows => 1, :class => "comment_box",:id => "comment_text_on_#{post_id}" = text_area_tag :text, nil, :rows => 2, :class => "comment_box",:id => "comment_text_on_#{post_id}"
= hidden_field_tag :post_id, post_id, :id => "post_id_on_#{post_id}" = hidden_field_tag :post_id, post_id, :id => "post_id_on_#{post_id}"
= submit_tag t('.comment'), :id => "comment_submit_#{post_id}", :class => "comment_submit button", :disable_with => t('.commenting') = submit_tag t('.comment'), :id => "comment_submit_#{post_id}", :class => "comment_submit button", :disable_with => t('.commenting')

View file

@ -9,6 +9,7 @@ javascripts:
- public/javascripts/vendor/jquery.infieldlabel.js - public/javascripts/vendor/jquery.infieldlabel.js
- public/javascripts/vendor/jquery.tipsy.js - public/javascripts/vendor/jquery.tipsy.js
- public/javascripts/vendor/jquery.hotkeys.js - public/javascripts/vendor/jquery.hotkeys.js
- public/javascripts/vendor/jquery.autoresize.min.js
- public/javascripts/vendor/fancybox/jquery.fancybox-1.3.1.pack.js - public/javascripts/vendor/fancybox/jquery.fancybox-1.3.1.pack.js
- public/javascripts/vendor/fileuploader.js - public/javascripts/vendor/fileuploader.js
- public/javascripts/view.js - public/javascripts/view.js

View file

@ -10,6 +10,11 @@ var Stream = {
$stream.not(".show").delegate("a.show_post_comments", "click", Stream.toggleComments); $stream.not(".show").delegate("a.show_post_comments", "click", Stream.toggleComments);
// publisher textarea reset
$publisher.find("textarea").bind("blur", function(){
$(this).css('height','42px');
});
// comment submit action // comment submit action
$stream.delegate("a.comment_submit", "click", function(evt) { $stream.delegate("a.comment_submit", "click", function(evt) {
$(this).closest("form").children(".comment_box").attr("rows", 1); $(this).closest("form").children(".comment_box").attr("rows", 1);
@ -23,14 +28,16 @@ var Stream = {
$stream.delegate("textarea.comment_box", "focus", function(evt) { $stream.delegate("textarea.comment_box", "focus", function(evt) {
var commentBox = $(this); var commentBox = $(this);
commentBox.attr("rows", 2) commentBox
.closest("form").find(".comment_submit").fadeIn(200); .closest("form").find(".comment_submit").fadeIn(200);
}); });
$stream.delegate("textarea.comment_box", "blur", function(evt) { $stream.delegate("textarea.comment_box", "blur", function(evt) {
var commentBox = $(this); var commentBox = $(this);
if (!commentBox.val()) { if (!commentBox.val()) {
commentBox.attr("rows", 1) commentBox
.attr('rows',2)
.css('height','2.4em')
.closest("form").find(".comment_submit").hide(); .closest("form").find(".comment_submit").hide();
} }
}); });

View file

@ -0,0 +1,7 @@
/*
* jQuery autoResize (textarea auto-resizer)
* @copyright James Padolsey http://james.padolsey.com
* @version 1.04
*/
(function(a){a.fn.autoResize=function(j){var b=a.extend({onResize:function(){},animate:true,animateDuration:150,animateCallback:function(){},extraSpace:20,limit:1000},j);this.filter('textarea').each(function(){var c=a(this).css({resize:'none','overflow-y':'hidden'}),k=c.height(),f=(function(){var l=['height','width','lineHeight','textDecoration','letterSpacing'],h={};a.each(l,function(d,e){h[e]=c.css(e)});return c.clone().removeAttr('id').removeAttr('name').css({position:'absolute',top:0,left:-9999}).css(h).attr('tabIndex','-1').insertBefore(c)})(),i=null,g=function(){f.height(0).val(a(this).val()).scrollTop(10000);var d=Math.max(f.scrollTop(),k)+b.extraSpace,e=a(this).add(f);if(i===d){return}i=d;if(d>=b.limit){a(this).css('overflow-y','');return}b.onResize.call(this);b.animate&&c.css('display')==='block'?e.stop().animate({height:d},b.animateDuration,b.animateCallback):e.height(d)};c.unbind('.dynSiz').bind('keyup.dynSiz',g).bind('keydown.dynSiz',g).bind('change.dynSiz',g)});return this}})(jQuery);

View file

@ -15,7 +15,7 @@ var View = {
/* In field labels */ /* In field labels */
$("label").inFieldLabels(); $("label").inFieldLabels();
/* Focus aspect name on fancybox */ /* Focus aspect name on fancybox */
$(this.addAspectButton.selector) $(this.addAspectButton.selector)
.click(this.addAspectButton.click); .click(this.addAspectButton.click);
@ -40,7 +40,7 @@ var View = {
/* User menu */ /* User menu */
$(this.userMenu.selector) $(this.userMenu.selector)
.click(this.userMenu.click); .click(this.userMenu.click);
/* Sending a request message */ /* Sending a request message */
$(this.newRequest.selector) $(this.newRequest.selector)
.live("submit", this.newRequest.submit); .live("submit", this.newRequest.submit);
@ -52,6 +52,13 @@ var View = {
'hideOnOverlayClick' : false 'hideOnOverlayClick' : false
}); });
/* Autoexpand textareas */
$('textarea')
.autoResize({
'animate': false,
'extraSpace': 0
});
/* Webfinger form ajaxy loading */ /* Webfinger form ajaxy loading */
$(this.webFingerForm.selector) $(this.webFingerForm.selector)
.submit(this.webFingerForm.submit); .submit(this.webFingerForm.submit);

View file

@ -524,6 +524,7 @@ ul.comments
textarea textarea
:width 100% :width 100%
:height 2.4em
li.comment li.comment
:list :list
@ -710,9 +711,9 @@ textarea
:border 1px solid #ccc :border 1px solid #ccc
:height auto :height auto
:-webkit-border-radius 5px :-webkit-border-radius 4px
:-moz-border-radius 5px :-moz-border-radius 4px
:border-radius 5px :border-radius 4px
input[type='checkbox'] input[type='checkbox']
:width auto :width auto
@ -795,13 +796,12 @@ label
img img
:border-radius 5px :border-radius 5px
textarea
:height 42px
input[type='text'], input[type='text'],
textarea textarea
:width 460px :width 460px
:margin 0 :margin 0
textarea
:height 42px
label label
:font :font
:size 14px :size 14px