1
0
mirror of https://github.com/wbbaddons/Tims-Chat.git synced 2025-01-09 00:20:08 +00:00

Implemented the send-event.

This commit is contained in:
max-m 2011-12-13 21:40:39 +01:00
parent 311c519a9d
commit 0165b0c1ac

View File

@ -16,14 +16,18 @@ if (typeof TimWolla.WCF == 'undefined') TimWolla.WCF = {};
messageTemplate: null, messageTemplate: null,
init: function(roomID, messageID) { init: function(roomID, messageID) {
this.bindEvents(); this.bindEvents();
$('#chatBox').css('background-color', $('div.main').css('background-color')); //calculate the width for the chatRoomContent, 'cause the styles width isn't fixed.
$('#chatRoomContent').width($('#chatBox').width() - 400); $('#chatRoomContent').width($('#chatBox').width() - 400);
//add toRight1.svg to WCF.Icon-storage
WCF.Icon.add('wcf.icon.toRight1', $('#chatForm .inputImage').attr('src'));
$('#chatInput').focus();
}, },
bindEvents: function () { bindEvents: function () {
$('.smiley').click($.proxy(function (event) { $('.smiley').click($.proxy(function (event) {
this.insertText($(event.target).attr('alt')); this.insertText($(event.target).attr('alt'));
}, this)); }, this));
//recalculate the width of chatRoomContent on resize
var chatRoomContent = $('#chatRoomContent'); var chatRoomContent = $('#chatRoomContent');
var chatBox = $('#chatBox'); var chatBox = $('#chatBox');
$(window).resize(function() { $(window).resize(function() {
@ -45,9 +49,36 @@ if (typeof TimWolla.WCF == 'undefined') TimWolla.WCF = {};
event.preventDefault(); event.preventDefault();
this.toggleUserMenu($(event.target)); this.toggleUserMenu($(event.target));
}, this)); }, this));
$('#chatForm').submit($.proxy(function (event) { $('#chatForm').submit($.proxy(function (event) {
//check the input, if not empty send it.
if ($('#chatInput').val().trim().length === 0) return false;
event.preventDefault(); event.preventDefault();
$(event.target).find('input[type=image]').attr('src', WCF.Icon.get('wcf.icon.loading')); textInput = $(event.target).find('#chatInput');
submitButton = $(event.target).find('input[type=image]');
$.ajax('index.php/Chat/Send/', {
dataType: 'json',
data: { ajax: 1,
text: textInput.val()
},
type: 'POST',
beforeSend: $.proxy(function (jqXHR) {
submitButton.attr('src', WCF.Icon.get('wcf.icon.loading'));
}),
success: $.proxy(function (data, textStatus, jqXHR) {
this.getMessages();
textInput.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)); }, this));
}, },
changeRoom: function (target) { changeRoom: function (target) {
@ -99,6 +130,9 @@ if (typeof TimWolla.WCF == 'undefined') TimWolla.WCF = {};
target.parent().addClass('ajaxLoad'); target.parent().addClass('ajaxLoad');
}, this) }, this)
}); });
},
getMessages: function (id) {
}, },
handleMessages: function (messages) { handleMessages: function (messages) {
for (message in messages) { for (message in messages) {