From c11ffe93c0a88a7b96d39124fbff855c7ca9a58c Mon Sep 17 00:00:00 2001 From: Raphael Sofaer Date: Tue, 8 Feb 2011 19:15:47 -0800 Subject: [PATCH] Actually close the publisher on and with Publisher.close() --- app/views/shared/_publisher.html.haml | 2 +- public/javascripts/publisher.js | 13 +++++++++++-- public/javascripts/rails.js | 2 +- public/javascripts/stream.js | 5 ++--- spec/javascripts/rails-spec.js | 16 +++++++++++++--- 5 files changed, 28 insertions(+), 10 deletions(-) diff --git a/app/views/shared/_publisher.html.haml b/app/views/shared/_publisher.html.haml index 35bc9ce8d..f2291fac9 100644 --- a/app/views/shared/_publisher.html.haml +++ b/app/views/shared/_publisher.html.haml @@ -28,7 +28,7 @@ #publisher_textarea_wrapper %ul#photodropzone = status.text_area :fake_message, :rows => 2, :value => h(params[:prefill]) - = status.hidden_field :message, :value => '' + = status.hidden_field :message, :value => '', :class => 'clear_on_submit' - for aspect_id in @aspect_ids = hidden_field_tag 'aspect_ids[]', aspect_id.to_s diff --git a/public/javascripts/publisher.js b/public/javascripts/publisher.js index 1c8262c8b..1b3f30a04 100644 --- a/public/javascripts/publisher.js +++ b/public/javascripts/publisher.js @@ -8,10 +8,12 @@ var Publisher = { close: function(){ Publisher.form().addClass('closed'); Publisher.form().find(".options_and_submit").hide(); - }, + Publisher.form().find("textarea").css('min-height', ''); + }, open: function(){ Publisher.form().removeClass('closed'); Publisher.form().find(".options_and_submit").show(); + Publisher.form().find("textarea").css('min-height', '42px'); }, cachedForm : false, form: function(){ @@ -133,6 +135,9 @@ var Publisher = { } } }, + clear: function(){ + this.mentions = []; + }, destroyMentionAt : function(effectiveCursorIndex){ var mentionIndex = this.mentionAt(effectiveCursorIndex); @@ -245,6 +250,11 @@ var Publisher = { Publisher.oldInputContent = Publisher.input().val(); } }, + clear: function(){ + this.autocompletion.mentionList.clear(); + $("#photodropzone").find('li').remove(); + $("#publisher textarea").removeClass("with_attachments"); + }, initialize: function() { Publisher.cachedForm = false; Publisher.cachedInput = false; @@ -266,7 +276,6 @@ var Publisher = { Publisher.input().keyup(Publisher.autocompletion.keyUpHandler); Publisher.form().find("textarea").bind("focus", function(evt) { Publisher.open(); - $(this).css('min-height', '42px'); }); } }; diff --git a/public/javascripts/rails.js b/public/javascripts/rails.js index 9c8fef0ba..1fc425caf 100644 --- a/public/javascripts/rails.js +++ b/public/javascripts/rails.js @@ -4,7 +4,7 @@ $.fn.clearForm = function() { if ($(this).is('form')) { return $(':input', this).clearForm(); } - if ($(this).is(':text') || $(this).is(':password') || $(this).is('textarea')) { + if ($(this).hasClass('clear_on_submit') || $(this).is(':text') || $(this).is(':password') || $(this).is('textarea')) { $(this).val(''); } else if ($(this).is(':checkbox') || $(this).is(':radio')) { $(this).attr('checked', false); diff --git a/public/javascripts/stream.js b/public/javascripts/stream.js index 8b0a2e34d..fae271794 100644 --- a/public/javascripts/stream.js +++ b/public/javascripts/stream.js @@ -73,9 +73,8 @@ var Stream = { json = $.parseJSON(json); WebSocketReceiver.addPostToStream(json.post_id, json.html); //collapse publisher - $("#publisher").addClass("closed"); - $("#photodropzone").find('li').remove(); - $("#publisher textarea").removeClass("with_attachments"); + Publisher.close(); + Publisher.clear(); }); $(".new_status_message").bind('ajax:failure', function(data, html, xhr) { diff --git a/spec/javascripts/rails-spec.js b/spec/javascripts/rails-spec.js index c79917319..6d1911f7a 100644 --- a/spec/javascripts/rails-spec.js +++ b/spec/javascripts/rails-spec.js @@ -5,6 +5,8 @@ describe("rails", function() { '
' + '' + '' + + '' + + '' + '
' ); }); @@ -14,9 +16,17 @@ describe("rails", function() { }); it("should clear form on ajax:success", function() { $('#form').trigger('ajax:success'); - + expect($('#status_message_message').val()).toEqual(""); - + }); + it('should not clear normal hidden fields', function(){ + $('#form').trigger('ajax:success'); + expect($('#standard_hidden').val()).toEqual("keep this value"); + }) + it('should clear hidden fields marked clear_on_submit', function(){ + $('#form').trigger('ajax:success'); + expect($('#clearable_hidden').val()).toEqual(""); + }) }); -}); \ No newline at end of file +});