X-Git-Url: http://git.euphorik.ch/?p=euphorik.git;a=blobdiff_plain;f=js%2FpageMinichat%2FpageMinichat.js;fp=js%2FpageMinichat%2FpageMinichat.js;h=1213cab224324a0a0a817ac151cb3b13225741b9;hp=0000000000000000000000000000000000000000;hb=904f2d76c25b7fd04b1f90dfa095c7bf0f8c7ce5;hpb=c4669f8724bdf389a3541b113b0c1e20a70cc879
diff --git a/js/pageMinichat/pageMinichat.js b/js/pageMinichat/pageMinichat.js
new file mode 100755
index 0000000..1213cab
--- /dev/null
+++ b/js/pageMinichat/pageMinichat.js
@@ -0,0 +1,284 @@
+// coding: utf-8
+// Copyright 2008 Grégory Burri
+//
+// This file is part of Euphorik.
+//
+// Euphorik is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Euphorik is distributed in the hope that it will be useful,
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Euphorik. If not, see .
+
+function PageMinichat(client, formateur, util)
+{
+ this.nom = "minichat"
+
+ this.client = client
+ this.formateur = formateur
+ this.util = util
+
+ // permet d'éviter d'envoyer plusieurs messages simultanément en pressant
+ // rapidement sur "enter" par exemple
+ this.envoieMessageEnCours = false
+
+ this.regexMessageTagMatch = /\{.*?\}>/g
+ this.regexMessageTagReplace = /^(.*?\{.*?\}>)*/
+}
+
+PageMinichat.prototype.contenu = function()
+{
+ // le fait que tout soit collé est fait exprès, permet d'éviter d'avoir des espaces supplémentaires entre les spans'
+ var formulaireXHTML = '
'
+ var trollXHTML = 'Troll de la semaine :
'
+ //var titreXHTML = '
'
+ //var messagesXHTML = '
'
+ var conversationXHTML = ''
+
+ if (this.client.chatOrder == "reverse")
+ return trollXHTML + formulaireXHTML + conversationXHTML
+ else
+ return trollXHTML + conversationXHTML + formulaireXHTML
+}
+
+PageMinichat.prototype.classes = function()
+{
+ return this.client.chatOrder == "reverse" ? "orderReverse" : "orderChrono"
+}
+
+PageMinichat.prototype.charger = function()
+{
+ thisPage = this
+
+ $("form input.pseudo").val(this.client.pseudo)
+
+ // cet appel ne doit pas être fait avant l'appel à 'charger'
+ this.conversations = new Conversations(this.client, this.formateur, this.util)
+
+ this.conversations.rafraichirMessages(true)
+
+ this.util.setCaretToEnd($("form input.message")[0])
+
+ // les outils de bannissement (uniquement pour les ekMaster)
+ if (this.client.ekMaster)
+ {
+ this.util.outilsBan = $(
+ '' +
+ '' +
+ '' +
+ '' +
+ '' +
+ '' +
+ ''
+ )
+
+ this.util.infoBulle("Slap", $("#slap", this.util.outilsBan))
+ this.util.infoBulle("Kick (" + euphorik.conf.tempsKick + "min)", $("#kick", this.util.outilsBan))
+ this.util.infoBulle("Ban (" + euphorik.conf.tempsBan / 24 / 60 + " jours)", $("#ban", this.util.outilsBan))
+ this.util.infoBulle("La raison", $("input", this.util.outilsBan))
+ }
+
+ this.util.infoBulle("Ouvrir la conversation liée au troll de la semaine", $("#trollCourant .troll"))
+
+ this.util.infoBulle("Cliquer sur les messages pour les enlevers de la liste",
+ $("form#posterMessage #repondA").hover(
+ function() { thisPage.util.afficherBoite($(".messages", this), $(this), positionTypeX.centre, positionTypeY.bas) },
+ function() { $(".messages", this).hide() }
+ ).click(
+ function(e)
+ {
+ if ($(e.target).is(".nb"))
+ thisPage.conversations.enleverMessagesRepond()
+ }
+ ),
+ euphorik.Util.positionBulleType.droite
+ )
+
+ //
+ $("body").append('')
+ // affichage des smiles
+ $("#smiles").append(this.formateur.getSmilesHTML()).children().each(
+ function(i)
+ {
+ var opacityBase = $(this).css("opacity")
+ $(this).click(
+ function()
+ {
+ thisPage.util.replaceSelection($("form#posterMessage input.message")[0], thisPage.formateur.smiles[$(this).attr("class")][0].source.replace(/\\/g, ""))
+ }
+ ).hover(
+ function() { $(this).animate({opacity: 1}, 200) },
+ function() { $(this).animate({opacity: opacityBase}, 200) }
+ )
+ }
+ )
+ $("form button.smiles").hover(
+ // affichage de la boite présentant les smiles
+ function(e){ thisPage.util.afficherBoite($("#smiles"), $(e.target), positionTypeX.centre, positionTypeY.basRecouvrement) },
+ function(){}
+ )
+ $("#smiles").hover(
+ function(){},
+ function()
+ {
+ $("#smiles").hide()
+ }
+ )
+ //
+
+ // événements
+ var nouveauMessage =
+ function()
+ {
+ // captcha anti bot
+ if ($("form input.captcha").val() != "") return
+
+ thisPage.envoyerMessage(
+ $("form input.pseudo").val(),
+ $("form input.message").val()
+ )
+
+ $("form input.message").focus()
+ }
+
+ $("form").keypress(
+ function(e)
+ {
+ if (e.which == 13) // return
+ nouveauMessage()
+ }
+ )
+
+ $("form button.return").click(nouveauMessage)
+
+ // interdiction de submiter le formulaire
+ $("form").submit(function(){ return false})
+
+ $("input.pseudo").click(
+ function()
+ {
+ var input = $("input.pseudo")[0]
+ if (input.value == euphorik.conf.pseudoDefaut)
+ input.value = ""
+ }
+ )
+}
+
+PageMinichat.prototype.decharger = function()
+{
+ this.conversations.pageEvent.stopAttenteCourante()
+
+ $("body #smiles").remove()
+}
+
+PageMinichat.prototype.getJSONMessage = function(pseudo, message)
+{
+ var repondA = []
+ for (var id in this.conversations.messagesRepond)
+ repondA.push(parseInt(id)) // FIXME : une propriété ne peut pas être de type int ?
+
+ return {
+ "header" : { "action" : "put_message", "version" : euphorik.conf.versionProtocole },
+ "cookie" : this.client.cookie,
+ "nick" : pseudo,
+ "content" : message,
+ "answer_to" : repondA
+ }
+}
+
+PageMinichat.prototype.envoyerMessage = function(pseudo, message)
+{
+ var thisPageMinichat = this
+
+ // (un pseudo vide est autorisé)
+ pseudo = this.formateur.filtrerInputPseudo(pseudo)
+
+ if (pseudo == euphorik.conf.nickDefaut)
+ {
+ this.util.messageDialogue("Le pseudo ne peut pas être " + euphorik.conf.nickDefaut)
+ return
+ }
+
+ message = message.trim()
+ if (message == "")
+ {
+ this.util.messageDialogue("Le message est vide")
+ return
+ }
+
+ if (!this.client.authentifie())
+ if (!this.client.enregistrement())
+ {
+ this.util.messageDialogue("login impossible")
+ return
+ }
+
+ this.client.pseudo = pseudo
+
+ // évite le double post
+ if (this.envoieMessageEnCours)
+ {
+ this.util.messageDialogue("Message en cours d'envoie...")
+ return
+ }
+ this.envoieMessageEnCours = true
+
+ jQuery.ajax(
+ {
+ url : "request",
+ type: "POST",
+ data : this.util.jsonVersAction(this.getJSONMessage(pseudo, message)),
+ dataType : "json",
+ beforeSend : function(xmlHttpRequest)
+ {
+ // TODO : ça marche ça ??
+ xmlHttpRequest.setRequestHeader("X-Requested-With", "")
+ },
+ success : function(data, textStatus)
+ {
+ if(data["reply"] == "ok")
+ {
+ // met à jour la classe des messages auquel repond celui ci (c'est un peu de la triche) TODO : ya mieux ?
+ for (var messId in thisPageMinichat.conversations.messagesRepond)
+ {
+ for (var j = 0; j < thisPageMinichat.conversations.conversations.length; j++)
+ {
+ var mess = thisPageMinichat.conversations.conversations[j].messagesParId[messId]
+ if (mess != undefined)
+ mess.clientARepondu = true
+ }
+ // TODO : ca sert à qque chose ?
+ //$("#conversations div#" + thisPageMinichat.conversations.messagesRepond[messId].getId()).addClass("repondu")
+ }
+
+ $("form input.message").val("")
+ thisPageMinichat.conversations.enleverMessagesRepond()
+ }
+ else if (data["reply"] == "error")
+ {
+ thisPageMinichat.util.messageDialogue(data["error_message"])
+ }
+ thisPageMinichat.envoieMessageEnCours = false
+ },
+ error : function()
+ {
+ thisPageMinichat.envoieMessageEnCours = false
+ }
+ }
+ )
+}