From 9d2849d8518e9aa86e3a5f728321b4c805d57e86 Mon Sep 17 00:00:00 2001 From: Raphael Sofaer Date: Sun, 8 May 2011 20:40:35 -0700 Subject: [PATCH] Move publisher ajax stuff into publisher.js --- public/javascripts/publisher.js | 26 ++++++++++++++++++++++++++ public/javascripts/stream.js | 23 ----------------------- 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/public/javascripts/publisher.js b/public/javascripts/publisher.js index 621935201..29176218f 100644 --- a/public/javascripts/publisher.js +++ b/public/javascripts/publisher.js @@ -338,6 +338,31 @@ var Publisher = { } }); }, + onSubmit: function(data, json, xhr){ + $("#photodropzone").find('li').remove(); + $("#publisher textarea").removeClass("with_attachments").css('paddingBottom', ''); + }, + onFailure: function(data, json, xhr){ + json = $.parseJSON(html.responseText); + if(json.errors.length !== 0){ + Diaspora.widgets.alert.alert(json.errors); + }else{ + Diaspora.widgets.alert.alert('Failed to post message!'); + } + }, + onSuccess: function(data, json, xhr){ + ContentUpdater.addPostToStream(json.html); + //collapse publisher + Publisher.close(); + Publisher.clear(); + //Stream.setUpImageLinks(); + Stream.setUpAudioLinks(); + }, + bindAjax: function(){ + Publisher.form().bind('ajax:loading', Publisher.onSubmit); + Publisher.form().bind('ajax:failure', Publisher.onFailure); + Publisher.form().bind('ajax:success', Publisher.onSuccess); + }, initialize: function() { Publisher.cachedForm = Publisher.cachedSubmit = Publisher.cachedInput = Publisher.cachedHiddenInput = false; @@ -354,6 +379,7 @@ var Publisher = { Publisher.hiddenInput().val(Publisher.input().val()); Publisher.input().keydown(Publisher.autocompletion.keyDownHandler); Publisher.input().keyup(Publisher.autocompletion.keyUpHandler); + Publisher.bindAjax(); Publisher.form().find("textarea").bind("focus", function(evt) { Publisher.open(); }); diff --git a/public/javascripts/stream.js b/public/javascripts/stream.js index b361ed9ee..03d6df209 100644 --- a/public/javascripts/stream.js +++ b/public/javascripts/stream.js @@ -66,29 +66,6 @@ var Stream = { } }); - $(".new_status_message").live('ajax:loading', function(data, json, xhr) { - $("#photodropzone").find('li').remove(); - $("#publisher textarea").removeClass("with_attachments").css('paddingBottom', ''); - }); - - $(".new_status_message").live('ajax:success', function(data, json, xhr) { - ContentUpdater.addPostToStream(json.html); - //collapse publisher - Publisher.close(); - Publisher.clear(); - //Stream.setUpImageLinks(); - Stream.setUpAudioLinks(); - }); - - $(".new_status_message").live('ajax:failure', function(data, html , xhr) { - json = $.parseJSON(html.responseText); - if(json.errors.length !== 0){ - Diaspora.widgets.alert.alert(json.errors); - }else{ - Diaspora.widgets.alert.alert('Failed to post message!'); - } - }); - $(stream_string + ".new_comment").live('ajax:failure', function(data, html, xhr) { Diaspora.widgets.alert.alert('Failed to post message!'); });