From 20a70fc1818d9a4a369c53a7b4ba02519e7b98a6 Mon Sep 17 00:00:00 2001 From: Greg Burri Date: Sun, 5 Oct 2008 10:02:43 +0000 Subject: [PATCH] FIX #74 --- js/fragment.js | 3 +-- js/pageMinichat/conversation.js | 43 ++++++++++++++++++++++++-------- js/pageMinichat/conversations.js | 6 ++--- js/pageMinichat/pageMinichat.js | 15 ++--------- js/util.js | 5 ++-- 5 files changed, 41 insertions(+), 31 deletions(-) diff --git a/js/fragment.js b/js/fragment.js index 23f22d0..4ffbf8f 100644 --- a/js/fragment.js +++ b/js/fragment.js @@ -25,7 +25,7 @@ Fragment = function() { var replaceHtmlCode = function(str) { return str.replace(/%(\d\d)/g, function(text, code) { return String.fromCharCode(parseInt(code, 16)); - }) + }); }; this.fragments = {}; if (!window.location.hash) { @@ -38,7 +38,6 @@ Fragment = function() { thisFragment.fragments[tuple[0]] = JSON.parse(tuple[1]); }); } catch(error) { - alert(error) ;; console.log(error); } }; diff --git a/js/pageMinichat/conversation.js b/js/pageMinichat/conversation.js index 2810b1b..4d590b6 100644 --- a/js/pageMinichat/conversation.js +++ b/js/pageMinichat/conversation.js @@ -244,15 +244,22 @@ euphorik.Conversation.prototype.flush = function() { var messagePair = (this.idDernierMessageAffiche === 0 ? true : ($("#" + this.getId() + " .messages div:" + (reverse ? "first" : "last")).attr("class").search("messagePair") === -1) - ); + ); + + // permet d'itérer sur les nouveaux messages à afficher + var pourChaqueNouveauMessage = function(f) { + thisConversation.messages.each(function(i, mess) { + if (mess.id > thisConversation.idDernierMessageAffiche) { + f(mess); + } + }); + }; // construction de l'XHTML des messages - var XHTML = ""; - this.messages.each(function(i, mess) { - if (mess.id > thisConversation.idDernierMessageAffiche) { - XHTML += mess.XHTML(messagePair, thisConversation.getId()); - messagePair = !messagePair; - } + var XHTML = ""; + pourChaqueNouveauMessage(function(mess) { + XHTML += mess.XHTML(messagePair, thisConversation.getId()); + messagePair = !messagePair; }); var DOM = $(XHTML); @@ -274,11 +281,25 @@ euphorik.Conversation.prototype.flush = function() { } else { $("#" + this.getId() + " .messages .message").slice(0, nbMessagesAffiche - this.nbMessageMax).remove(); } - } + } + + // met à jour la classe des messages auquels repondent les nouveaux messages + // dans le cas où ce message appartient au client courant (c'est un peu de la triche) TODO : ya mieux ? + pourChaqueNouveauMessage(function(mess) { + if (mess.client === thisConversation.client) { + objectEach(mess.repondA, function(messId) { + var mess = thisConversation.messagesParId[messId]; + if (mess) { + mess.clientARepondu = true; + $("#conversations #" + mess.getId(thisConversation.getId())).addClass("repondu") + } + }); + } + }); if (this.messages.length > 0) { this.idDernierMessageAffiche = this.messages[this.messages.length-1].id; - } + } // met à jour la racine de la conversation this.majRacine(); @@ -326,7 +347,7 @@ euphorik.Conversation.prototype.attacherEventsSurMessage = function(element) { // donne le focus à la ligne de saisie $("form input.message").focus(); }).hover(function() { // affiche les outils liées au message - var top = $(this).offset().top + var top = $(this).offset().top; var left = $(this).offset().left + $(this).outerWidth() - thisConversation.util.outilsMessage.outerWidth(); $(".extraire", thisConversation.util.outilsMessage).unbind(); $(".extraireCompletement", thisConversation.util.outilsMessage).unbind(); @@ -336,7 +357,7 @@ euphorik.Conversation.prototype.attacherEventsSurMessage = function(element) { thisConversation.util.infoBulle("Extraction de la conversation complète", $(".extraireCompletement", thisConversation.util.outilsMessage)); thisConversation.util.outilsMessage.css("top", top).css("left", left).prependTo(this).show(); }, function() { - thisConversation.util.outilsMessage.hide() + thisConversation.util.outilsMessage.hide(); }); // mise en évidence de la conversation diff --git a/js/pageMinichat/conversations.js b/js/pageMinichat/conversations.js index b99e092..94236c1 100644 --- a/js/pageMinichat/conversations.js +++ b/js/pageMinichat/conversations.js @@ -63,11 +63,11 @@ euphorik.Conversations.prototype.toggleMessageRepond = function(mess) { euphorik.Conversations.prototype.mettreAJourFragment = function() { conv = []; for(var i = 1; i < this.conversations.length; i++) { - conv.push(this.conversations[i].racine.id) + conv.push(this.conversations[i].racine.id); } this.fragment.setVal("conv", conv); this.fragment.write(); -} +}; /** * Enlève tous les messages auquel l'utilisateur souhaite répondre. @@ -195,7 +195,7 @@ euphorik.Conversations.prototype.getJSONrafraichirMessages = function() { }; euphorik.Conversations.prototype.getJSONConversations = function() { - var thisConversations = this + var thisConversations = this; var clientConv = []; this.client.conversations.each(function(i, conv) { diff --git a/js/pageMinichat/pageMinichat.js b/js/pageMinichat/pageMinichat.js index 6a2706f..b71efea 100755 --- a/js/pageMinichat/pageMinichat.js +++ b/js/pageMinichat/pageMinichat.js @@ -213,14 +213,14 @@ euphorik.PageMinichat.prototype.chargerConversationsFragment = function() { } catch(e) { ;; console.log(e) } -} +}; euphorik.PageMinichat.prototype.decharger = function() { this.conversations.comet.stopAttenteCourante(); $("body #smiles").remove(); - this.fragment.delVal("conv") + this.fragment.delVal("conv"); }; /** @@ -265,17 +265,6 @@ euphorik.PageMinichat.prototype.envoyerMessage = function(message) { "put_message", this.getJSONMessage(pseudo, message), function() { - // TODO : revoir cette partie - // met à jour la classe des messages auquel repond celui ci (c'est un peu de la triche) TODO : ya mieux ? - objectEach(thisPageMinichat.conversations.messagesRepond, function(messId) { - thisPageMinichat.conversations.conversations.each(function(i, conv) { - var mess = conv.messagesParId[messId]; - if (mess) { - mess.clientARepondu = true; - $("#conversations #" + mess.getId(conv.getId())).addClass("repondu") - } - }); - }); $("form#posterMessage input.message").val(""); thisPageMinichat.conversations.enleverMessagesRepond(); thisPageMinichat.envoieMessageEnCours = false; diff --git a/js/util.js b/js/util.js index fe36b47..86c4e79 100644 --- a/js/util.js +++ b/js/util.js @@ -75,8 +75,9 @@ euphorik.Util.prototype.messageDialogue = function(message, type, boutons, forma }); $("#info").slideDown(200); - if (temps !== -1) - this.timeoutMessageDialogue = setTimeout(fermer, temps || euphorik.conf.tempsAffichageMessageDialogue); + if (temps !== -1) { + this.timeoutMessageDialogue = setTimeout(fermer, temps || euphorik.conf.tempsAffichageMessageDialogue); + } }; euphorik.Util.positionTypeX = {gauche: 0, gaucheRecouvrement: 1, centre: 2, droiteRecouvrement: 3, droite: 4}; -- 2.43.0