From 062241ce702944bbbfd06d6413aa3373f8bb2cc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Tue, 13 Dec 2011 21:52:32 +0100 Subject: [PATCH] Moved submit into an own method --- file/js/TimWolla.WCF.Chat.js | 51 ++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/file/js/TimWolla.WCF.Chat.js b/file/js/TimWolla.WCF.Chat.js index c3043ee..ee3629b 100644 --- a/file/js/TimWolla.WCF.Chat.js +++ b/file/js/TimWolla.WCF.Chat.js @@ -54,33 +54,8 @@ if (typeof TimWolla.WCF == 'undefined') TimWolla.WCF = {}; }, this)); $('#chatForm').submit($.proxy(function (event) { - // break if input contains only whitespace - if ($('#chatInput').val().trim().length === 0) return false; - event.preventDefault(); - submitButton = $(event.target).find('input[type=image]'); - - $.ajax('index.php/Chat/Send/', { - dataType: 'json', - data: { - text: $('#chatInput').val() - }, - type: 'POST', - beforeSend: $.proxy(function (jqXHR) { - submitButton.attr('src', WCF.Icon.get('wcf.icon.loading')); - }), - success: $.proxy(function (data, textStatus, jqXHR) { - this.getMessages(); - $('#chatInput').val('').focus(); - }, this), - error: function() { - // TODO: find a nicer solution. - alert('Error while sending message'); - }, - complete: function() { - submitButton.attr('src', WCF.Icon.get('wcf.icon.toRight1')); - } - }); + this.submit($(event.target)); }, this)); }, /** @@ -180,6 +155,30 @@ if (typeof TimWolla.WCF == 'undefined') TimWolla.WCF = {}; if (options.submit) $('#chatForm').submit(); else $('#chatInput').focus(); }, + submit: function (target) { + // break if input contains only whitespace + if ($('#chatInput').val().trim().length === 0) return false; + + submitButton = target.find('input[type=image]'); + + $.ajax($('#chatForm').attr('action'), { + dataType: 'json', + data: { + text: $('#chatInput').val() + }, + type: 'POST', + beforeSend: $.proxy(function (jqXHR) { + submitButton.attr('src', WCF.Icon.get('wcf.icon.loading')); + }), + success: $.proxy(function (data, textStatus, jqXHR) { + this.getMessages(); + $('#chatInput').val('').focus(); + }, this), + complete: function() { + submitButton.attr('src', WCF.Icon.get('wcf.icon.toRight1')); + } + }); + } toggleUserMenu: function (target) { liUserID = '#' + target.parent().parent().attr('id'); if ($(liUserID).hasClass('activeMenuItem')) {