Actually close the publisher on and with Publisher.close()

This commit is contained in:
Raphael Sofaer 2011-02-08 19:15:47 -08:00
parent cb67c14a51
commit c11ffe93c0
5 changed files with 28 additions and 10 deletions

View file

@ -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

View file

@ -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');
});
}
};

View file

@ -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);

View file

@ -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) {

View file

@ -5,6 +5,8 @@ describe("rails", function() {
'<form accept-charset="UTF-8" id="form" action="/status_messages" data-remote="true" method="post">' +
'<textarea id="status_message_message" name="status_message[message]">Some status message</textarea>' +
'<input type="submit">' +
'<input id="standard_hidden" type="hidden" value="keep this value">' +
'<input id="clearable_hidden" type="hidden" class="clear_on_submit" value="clear this value">' +
'</form>'
);
});
@ -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("");
})
});
});
});