2 // Copyright 2008 Grégory Burri
4 // This file is part of Euphorik.
6 // Euphorik is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation, either version 3 of the License, or
9 // (at your option) any later version.
11 // Euphorik is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with Euphorik. If not, see <http://www.gnu.org/licenses/>.
20 * Contient la base javascript pour le site euphorik.ch.
21 * Chaque page possède son propre fichier js nommé "page<nom de la page>.js".
29 * Normalement 'const' à la place de 'var' mais non supporté par IE7.
32 nbMessageAffiche : 40, // (par page)
33 pseudoDefaut : "<nick>",
34 tempsAffichageMessageDialogue : 4000, // en ms
35 tempsKick : 15, // en minute
36 tempsBan : 60 * 24 * 3, // en minutes (3jours)
38 "smile" : [/:\)/g, /:-\)/g],
39 "bigsmile" : [/:D/g, /:-D/g],
40 "clin" : [/;\)/g, /;-\)/g],
41 "cool" : [/8\)/g, /8-\)/g],
42 "eheheh" : [/:P/g, /:-P/g],
43 "lol" : [/\[-lol\]/g],
44 "spliff" : [/\[-spliff\]/g],
45 "oh" : [/:o/g, /:O/g],
46 "heink" : [/\[-heink\]/g],
47 "hum" : [/\[-hum\]/g],
48 "boh" : [/\[-boh\]/g],
49 "sniff" : [/:\(/g, /:-\(/g],
50 "triste" : [/\[-triste\]/g],
51 "pascontent" : [/>\(/g, />\(/g],
52 "argn" : [/\[-argn\]/g],
53 "redface" : [/\[-redface\]/g],
54 "bunny" : [/\[-lapin\]/g],
55 "chat" : [/\[-chat\]/g],
56 "renne" : [/\[-renne\]/g],
57 "star" : [/\[-star\]/g],
58 "kirby" : [/\[-kirby\]/g],
59 "slurp" : [/\[-slurp\]/g],
60 "agreed" : [/\[-agreed\]/g],
61 "dodo" : [/\[-dodo\]/g],
66 ///////////////////////////////////////////////////////////////////////////////////////////////////
68 String
.prototype.trim = function()
70 return jQuery
.trim(this) // anciennement : this.replace(/^\s+|\s+$/g, "");
73 String
.prototype.ltrim = function()
75 return this.replace(/^\s+/, "");
78 String
.prototype.rtrim = function()
80 return this.replace(/\s+$/, "");
83 ///////////////////////////////////////////////////////////////////////////////////////////////////
86 * Cette classe regroupe des fonctions utilitaires (helpers).
87 * @formateur est permet de formater les messages affichés à l'aide de messageDialogue (facultatif)
89 function Util(formateur
)
91 $("#info .fermer").click(function(){
92 $("#info").slideUp(50)
95 $("body").append('<div id="flecheBulle"></div>').append('<div id="messageBulle"><p></p></div>')
97 this.formateur
= formateur
98 this.bulleActive
= true
101 var messageType
= {informatif: 0, question: 1, erreur: 2}
104 * Affiche une boite de dialogue avec un message à l'intérieur.
105 * @param message le message (string)
106 * @param type voir 'messageType'. par défaut messageType.informatif
107 * @param les boutons sous la forme d'un objet ou les clefs sont les labels des boutons
108 * et les valeurs les fonctions executées lorsqu'un bouton est activé.
109 * @param formate faut-il formaté le message ? true par défaut
111 Util
.prototype.messageDialogue = function(message
, type
, boutons
, formate
)
115 if (type
== undefined)
116 type
= messageType
.informatif
118 if (formate
== undefined)
121 if (this.timeoutMessageDialogue
!= undefined)
122 clearTimeout(this.timeoutMessageDialogue
)
124 var fermer = function(){$("#info").slideUp(100)}
127 $("#info .message").html(thisUtil
.formateur
== undefined || !formate
? message : thisUtil
.formateur
.traitementComplet(message
))
130 case messageType
.informatif : $("#info #icone").attr("class", "information"); break
131 case messageType
.question : $("#info #icone").attr("class", "interrogation"); break
132 case messageType
.erreur : $("#info #icone").attr("class", "exclamation"); break
134 $("#info .boutons").html("")
135 for (var b
in boutons
)
136 $("#info .boutons").append("<div>" + b
+ "</div>").find("div:last").click(boutons
[b
]).click(fermer
)
138 $("#info").slideDown(200)
139 this.timeoutMessageDialogue
= setTimeout(fermer
, conf
.tempsAffichageMessageDialogue
)
143 * Affiche un info bulle lorsque le curseur survole l'élément donné.
144 * FIXME : le width de element ne tient pas compte du padding !?
146 Util
.prototype.infoBulle = function(message
, element
)
150 var cacherBulle = function()
152 $("#flecheBulle").hide()
153 $("#messageBulle").hide()
159 if (!thisUtil
.bulleActive
)
162 var m
= $("#messageBulle")
163 var f
= $("#flecheBulle")
165 $("p", m
).html(message
)
167 var positionFleche
= {
168 left : element
.offset().left
+ element
.width() / 2 - f
.width() / 2,
169 top : element
.offset().top
- f
.height()
171 var positionMessage
= {
172 left : element
.offset().left
+ element
.width() / 2 - m
.width() / 2,
173 top : element
.offset().top
- f
.height() - m
.height()
175 var depassementDroit
= (positionMessage
.left
+ m
.width()) - $("body").width()
176 if (depassementDroit
> 0)
177 positionMessage
.left
-= depassementDroit
180 if (positionMessage
.left
< 0)
181 positionMessage
.left
= 0
184 m
.css("top", positionMessage
.top
).css("left", positionMessage
.left
).show()
185 f
.css("top", positionFleche
.top
).css("left", positionFleche
.left
).show()
192 * Utilisé pour l'envoie de donnée avec la méthode ajax de jQuery.
194 Util
.prototype.jsonVersAction = function(json
)
196 return {action : JSON
.stringify(json
) }
199 Util
.prototype.md5 = function(chaine
)
201 return hex_md5(chaine
)
204 // pompé de http://www.faqts.com/knowledge_base/view.phtml/aid/13562/fid/130
205 Util
.prototype.setSelectionRange = function(input
, selectionStart
, selectionEnd
)
207 if (input
.setSelectionRange
)
210 input
.setSelectionRange(selectionStart
, selectionEnd
)
212 else if (input
.createTextRange
)
214 var range
= input
.createTextRange()
216 range
.moveEnd('character', selectionEnd
)
217 range
.moveStart('character', selectionStart
)
222 Util
.prototype.setCaretToEnd = function(input
)
224 this.setSelectionRange(input
, input
.value
.length
, input
.value
.length
)
226 Util
.prototype.setCaretToBegin = function(input
)
228 this.setSelectionRange(input
, 0, 0)
230 Util
.prototype.setCaretToPos = function(input
, pos
)
232 this.setSelectionRange(input
, pos
, pos
)
234 Util
.prototype.selectString = function(input
, string
)
236 var match
= new RegExp(string
, "i").exec(input
.value
)
239 this.setSelectionRange (input
, match
.index
, match
.index
+ match
[0].length
)
242 Util
.prototype.replaceSelection = function(input
, replaceString
) {
243 if (input
.setSelectionRange
)
245 var selectionStart
= input
.selectionStart
246 var selectionEnd
= input
.selectionEnd
247 input
.value
= input
.value
.substring(0, selectionStart
) + replaceString
+ input
.value
.substring(selectionEnd
)
249 if (selectionStart
!= selectionEnd
) // has there been a selection
250 this.setSelectionRange(input
, selectionStart
, selectionStart
+ replaceString
.length
)
252 this.setCaretToPos(input
, selectionStart
+ replaceString
.length
)
254 else if (document
.selection
)
256 var range
= document
.selection
.createRange();
257 if (range
.parentElement() == input
)
259 var isCollapsed
= range
.text
== ''
260 range
.text
= replaceString
263 // there has been a selection
264 // it appears range.select() should select the newly
265 // inserted text but that fails with IE
266 range
.moveStart('character', -replaceString
.length
);
273 Util
.prototype.rot13 = function(chaine
)
275 var ACode
= 'A'.charCodeAt(0)
276 var aCode
= 'a'.charCodeAt(0)
277 var MCode
= 'M'.charCodeAt(0)
278 var mCode
= 'm'.charCodeAt(0)
279 var ZCode
= 'Z'.charCodeAt(0)
280 var zCode
= 'z'.charCodeAt(0)
282 var f = function(ch
, pos
) {
283 if (pos
== ch
.length
)
286 var c
= ch
.charCodeAt(pos
);
287 return String
.fromCharCode(
289 (c
>= ACode
&& c
<= MCode
|| c
>= aCode
&& c
<= mCode
? 13 :
290 (c
> MCode
&& c
<= ZCode
|| c
> mCode
&& c
<= zCode
? -13 : 0))
296 ///////////////////////////////////////////////////////////////////////////////////////////////////
300 this.pageCourante
= null
304 Pages
.prototype.ajouterPage = function(page
)
306 page
.pages
= this // la magie des langages dynamiques : le foutoire
307 this.pages
[page
.nom
] = page
310 Pages
.prototype.afficherPage = function(nomPage
, forcerChargement
)
312 if (forcerChargement
== undefined) forcerChargement
= false
314 var page
= this.pages
[nomPage
]
315 if (page
== undefined || (!forcerChargement
&& page
== this.pageCourante
)) return
317 if (this.pageCourante
!= null && this.pageCourante
.decharger
)
318 this.pageCourante
.decharger()
320 $("#menu li").removeClass("courante")
321 $("#menu li." + nomPage
).addClass("courante")
323 this.pageCourante
= page
324 $("#page").html(this.pageCourante
.contenu()).removeClass().addClass(this.pageCourante
.nom
)
326 if (this.pageCourante
.charger
)
327 this.pageCourante
.charger()
330 ///////////////////////////////////////////////////////////////////////////////////////////////////
333 * Classe permettant de formater du texte par exemple pour la substitution des liens dans les
334 * message par "[url]".
335 * TODO : améliorer l'efficacité des méthods notamment lié au smiles.
339 this.smiles
= conf
.smiles
340 this.protocoles
= "http|https|ed2k"
342 this.regexUrl
= new RegExp("(?:(?:" + this.protocoles
+ ")://|www\\.)[^ ]*", "gi")
343 this.regexImg
= new RegExp("^.*?\\.(gif|jpg|png|jpeg|bmp|tiff)$", "i")
344 this.regexDomaine
= new RegExp("^(?:(?:" + this.protocoles
+ ")://|www\\.).*?([^/.]+\\.[^/.]+)(?:$|/).*$", "i")
345 this.regexTestProtocoleExiste
= new RegExp("^(?:" + this.protocoles
+ ")://.*$", "i")
346 this.regexNomProtocole
= new RegExp("^(.*?)://")
350 * Formate un pseudo saise par l'utilisateur.
351 * @param pseudo le pseudo brut
352 * @return le pseudo filtré
354 Formateur
.prototype.filtrerInputPseudo = function(pseudo
)
356 return pseudo
.replace(/{|}/g, "").trim()
359 Formateur
.prototype.getSmilesHTML = function()
362 for (var sNom
in this.smiles
)
364 XHTML
+= "<img class=\"" + sNom
+ "\" src=\"img/smileys/" + sNom
+ ".gif\" alt =\"" + sNom
+ "\" />"
370 * Formatage complet d'un texte.
372 * @pseudo facultatif, permet de contruire le label des images sous la forme : "<Pseudo> : <Message>"
374 Formateur
.prototype.traitementComplet = function(M
, pseudo
)
376 return this.traiterLiensConv(this.traiterSmiles(this.traiterURL(this.traiterWikiSyntaxe(this.remplacerBalisesHTML(M
)), pseudo
)))
380 * Transforme les liens en entités clickables.
381 * Un lien vers une conversation permet d'ouvrire celle ci, elle se marque comme ceci dans un message :
382 * "{5F}" ou 5F est la racine de la conversation.
383 * Ce lien sera transformer en <span class="lienConv">{5F}</span> pouvant être clické pour créer la conv 5F.
385 Formateur
.prototype.traiterLiensConv = function(M
)
391 return "<span class=\"lienConv\">" + lien
+ "</span>"
397 * FIXME : Cette méthode est attrocement lourde ! A optimiser.
398 * moyenne sur échantillon : 234ms
400 Formateur
.prototype.traiterSmiles = function(M
)
402 for (var sNom
in this.smiles
)
404 ss
= this.smiles
[sNom
]
405 for (var i
= 0; i
< ss
.length
; i
++)
406 M
= M
.replace(ss
[i
], "<img src=\"img/smileys/" + sNom
+ ".gif\" alt =\"" + sNom
+ "\" />")
411 Formateur
.prototype.remplacerBalisesHTML = function(M
)
413 return M
.replace(/</g
, "<").replace(/>/g
, ">").replace(/"/g, ""
;")
416 Formateur.prototype.traiterURL = function(M, pseudo)
420 var traitementUrl = function(url)
422 // si ya pas de protocole on rajoute "http://"
423 if (!thisFormateur
.regexTestProtocoleExiste
.test(url
))
424 url
= "http://" + url
425 var extension
= thisFormateur
.getShort(url
)
426 return "<a " + (extension
[1] ? "title=\"" + (pseudo
== undefined ? "" : thisFormateur
.traiterPourFenetreLightBox(pseudo
, url
) + ": ") + thisFormateur
.traiterPourFenetreLightBox(M
, url
) + "\"" + " rel=\"lightbox\"" : "") + " href=\"" + url
+ "\" >[" + extension
[0] + "]</a>"
428 return M
.replace(this.regexUrl
, traitementUrl
)
432 * Formatage en utilisant un sous-ensemble des règles de mediwiki.
433 * par exemple ''italic'' devient <i>italic</i>
435 Formateur
.prototype.traiterWikiSyntaxe = function(M
)
439 function(texte
, capture
)
441 return "<b>" + capture
+ "</b>"
445 function(texte
, capture
)
447 return "<i>" + capture
+ "</i>"
453 * Renvoie une version courte de l'url.
454 * par exemple : http://en.wikipedia.org/wiki/Yakov_Smirnoff devient wikipedia.org
456 Formateur
.prototype.getShort = function(url
)
458 var estUneImage
= false
459 var versionShort
= null
460 var rechercheImg
= this.regexImg
.exec(url
)
462 if (rechercheImg
!= null)
464 versionShort
= rechercheImg
[1].toLowerCase()
465 if (versionShort
== "jpeg") versionShort
= "jpg" // jpeg -> jpg
470 var rechercheDomaine
= this.regexDomaine
.exec(url
)
471 if (rechercheDomaine
!= null && rechercheDomaine
.length
>= 2)
472 versionShort
= rechercheDomaine
[1]
475 var nomProtocole
= this.regexNomProtocole
.exec(url
)
476 if (nomProtocole
!= null && nomProtocole
.length
>= 2)
477 versionShort
= nomProtocole
[1]
481 return [versionShort
== null ? "url" : versionShort
, estUneImage
]
485 * Traite les pseudo et messages à être affiché dans le titre d'une image visualisé avec lightbox.
487 Formateur
.prototype.traiterPourFenetreLightBox = function(M
, urlCourante
)
490 var traitementUrl = function(url
)
492 return "[" + thisFormateur
.getShort(url
)[0] + (urlCourante
== url
? "*" : "") + "]"
495 return this.remplacerBalisesHTML(M
).replace(this.regexUrl
, traitementUrl
)
499 ///////////////////////////////////////////////////////////////////////////////////////////////////
501 // les statuts possibes du client
503 // mode enregistré, peut poster des messages et modifier son profile
505 // mode identifié, peut poster des messages mais n'a pas accès au profile
506 auth_not_registered : 1,
507 // mode déconnecté, ne peut pas poster de message
511 function Client(util
)
516 this.regexCookie
= new RegExp("^cookie=([^;]*)")
518 // données personnels
519 this.resetDonneesPersonnelles()
521 this.setStatut(statutType
.deconnected
)
523 // si true alors chaque modification du client est mémorisé sur le serveur
524 this.autoflush
= $.browser
["opera"]
527 Client
.prototype.resetDonneesPersonnelles = function()
530 this.pseudo
= conf
.pseudoDefaut
534 this.css
= $("link#cssPrincipale").attr("href")
535 this.nickFormat
= "nick"
536 this.viewTimes
= true
537 this.viewTooltips
= true
538 this.cookie
= undefined
540 this.pagePrincipale
= 1
541 this.ekMaster
= false
543 // les conversations, une conversation est un objet possédant les attributs suivants :
546 this.conversations
= new Array()
549 Client
.prototype.setCss = function(css
)
551 if (this.css
== css
|| css
== "")
555 $("link#cssPrincipale").attr("href", this.css
)
558 if (this.autoflush
) this.flush(true)
561 Client
.prototype.pageSuivante = function(numConv
)
563 if (numConv
< 0 && this.pagePrincipale
> 1)
564 this.pagePrincipale
-= 1
565 else if (this.conversations
[numConv
].page
> 1)
566 this.conversations
[numConv
].page
-= 1
569 Client
.prototype.pagePrecedente = function(numConv
)
572 this.pagePrincipale
+= 1
574 this.conversations
[numConv
].page
+= 1
578 * Définit la première page pour la conversation donnée.
579 * @return true si la page a changé sinon false
581 Client
.prototype.goPremierePage = function(numConv
)
585 if (this.pagePrincipale
== 1)
587 this.pagePrincipale
= 1
591 if (this.conversations
[numConv
].page
== 1)
593 this.conversations
[numConv
].page
= 1
599 * Ajoute une conversation à la vue de l'utilisateur.
600 * Le profile de l'utilisateur est directement sauvegardé sur le serveur.
601 * @param racines la racine de la conversation (integer)
602 * @return true si la conversation a été créée sinon false (par exemple si la conv existe déjà)
604 Client
.prototype.ajouterConversation = function(racine
)
606 // vérification s'il elle n'existe pas déjà
607 for (var i
= 0; i
< this.conversations
.length
; i
++)
608 if (this.conversations
[i
].root
== racine
)
611 this.conversations
.push({root : racine
, page : 1})
613 if (this.autoflush
) this.flush(true)
618 Client
.prototype.supprimerConversation = function(num
)
620 if (num
< 0 || num
>= this.conversations
.length
) return
622 // décalage TODO : supprimer le dernier élément
623 for (var i
= num
; i
< this.conversations
.length
- 1; i
++)
624 this.conversations
[i
] = this.conversations
[i
+1]
625 this.conversations
.pop()
627 if (this.autoflush
) this.flush(true)
630 Client
.prototype.getJSONLogin = function(login
, password
)
633 "action" : "authentification",
635 "password" : password
639 Client
.prototype.getJSONLoginCookie = function()
642 "action" : "authentification",
643 "cookie" : this.cookie
648 * le couple (login, password) est facultatif. S'il n'est pas fournit alors il ne sera pas possible
649 * de s'autentifier avec (login, password).
651 Client
.prototype.getJSONEnregistrement = function(login
, password
)
653 var mess
= { "action" : "register" }
655 if (login
!= undefined && password
!= undefined)
657 mess
["login"] = login
658 mess
["password"] = password
664 Client
.prototype.getJSONConversations = function()
666 var conversations
= new Array()
667 for (var i
= 0; i
< this.conversations
.length
; i
++)
668 conversations
.push({ "root" : this.conversations
[i
].root
, "page" : this.conversations
[i
].page
})
672 Client
.prototype.getJSONProfile = function()
675 "action" : "set_profile",
676 "cookie" : this.cookie
,
677 "login" : this.login
,
678 "password" : this.password
,
679 "nick" : this.pseudo
,
680 "email" : this.email
,
682 "nick_format" : this.nickFormat
,
683 "view_times" : this.viewTimes
,
684 "view_tooltips" : this.viewTooltips
,
685 "main_page" : this.pagePrincipale
< 1 ? 1 : this.pagePrincipale
,
686 "conversations" : this.getJSONConversations()
691 * Renvoie null si pas définit.
693 Client
.prototype.getCookie = function()
695 var cookie
= this.regexCookie
.exec(document
.cookie
)
696 if (cookie
== null) this.cookie
= null
697 else this.cookie
= cookie
[1]
700 Client
.prototype.delCookie = function()
702 document
.cookie
= "cookie=; max-age=0"
705 Client
.prototype.setCookie = function(cookie
)
707 if (this.cookie
== null)
711 "cookie="+this.cookie
+
712 "; max-age=" + (60 * 60 * 24 * 365)
715 Client
.prototype.authentifie = function()
717 return this.statut
== statutType
.auth_registered
|| this.statut
== statutType
.auth_not_registered
720 Client
.prototype.setStatut = function(statut
)
722 // conversation en "enum" si en "string"
723 if (typeof(statut
) == "string")
726 statut
== "auth_registered" ?
727 statutType
.auth_registered :
728 (statut
== "auth_not_registered" ? statutType
.auth_not_registered : statutType
.deconnected
)
731 if (statut
== this.statut
) return
738 * Effectue la connexion vers le serveur.
739 * Cette fonction est bloquante tant que la connexion n'a pas été établie.
740 * S'il existe un cookie en local on s'authentifie directement avec lui.
741 * Si il n'est pas possible de s'authentifier alors on affiche un captcha anti-bot.
743 Client
.prototype.connexionCookie = function()
746 if (this.cookie
== null) return false;
747 return this.connexion(this.getJSONLoginCookie())
750 Client
.prototype.connexionLogin = function(login
, password
)
752 return this.connexion(this.getJSONLogin(login
, password
))
755 Client
.prototype.enregistrement = function(login
, password
)
757 if (this.authentifie())
760 this.password
= password
763 this.setStatut(statutType
.auth_registered
)
770 return this.connexion(this.getJSONEnregistrement(login
, password
))
774 Client
.prototype.connexion = function(messageJson
)
776 ;; dumpObj(messageJson
)
784 data: this.util
.jsonVersAction(messageJson
),
789 if (data
["reply"] == "error")
790 thisClient
.util
.messageDialogue(data
["error_message"])
792 thisClient
.chargerDonnees(data
)
796 return this.authentifie()
799 Client
.prototype.deconnexion = function()
803 this.resetDonneesPersonnelles()
804 this.setStatut(statutType
.deconnected
) // deconnexion
807 Client
.prototype.chargerDonnees = function(data
)
809 // la modification du statut qui suit met à jour le menu, le menu dépend (page admin)
810 // de l'état ekMaster
811 this.ekMaster
= data
["ek_master"] != undefined ? data
["ek_master"] : false
813 this.setStatut(data
["status"])
815 if (this.authentifie())
817 this.cookie
= data
["cookie"]
821 this.login
= data
["login"]
822 this.pseudo
= data
["nick"]
823 this.email
= data
["email"]
824 this.setCss(data
["css"])
825 this.nickFormat
= data
["nick_format"]
826 this.viewTimes
= data
["view_times"]
827 this.viewTooltips
= data
["view_tooltips"]
829 // la page de la conversation principale
830 this.pagePrincipale
= data
["main_page"] == undefined ? 1 : data
["main_page"]
833 this.conversations
= data
["conversations"]
840 * Met à jour les données personne sur serveur.
841 * @param async de manière asynchrone ? défaut = true
842 * @return false si le flush n'a pas pû se faire sinon true
844 Client
.prototype.flush = function(async
)
846 if (async
== undefined)
849 if (!this.authentifie())
852 var thisClient
= this
855 ;; dumpObj(this.getJSONProfile())
862 data: this.util
.jsonVersAction(this.getJSONProfile()),
867 if (data
["reply"] == "error")
869 thisClient
.util
.messageDialogue(data
["error_message"])
874 thisClient
.majBulle()
883 Client
.prototype.majMenu = function()
885 // TODO : à virer : ne plus changer de style de display ... spa beau .. ou trouver une autre méthode
886 // var displayType = this.css == "css/3/euphorik.css" ? "block" : "inline" //this.client
887 displayType
= "block"
889 $("#menu .admin").css("display", this.ekMaster
? displayType : "none")
891 // met à jour le menu
892 if (this.statut
== statutType
.auth_registered
)
894 $("#menu .profile").css("display", displayType
).text("profile")
895 $("#menu .logout").css("display", displayType
)
896 $("#menu .register").css("display", "none")
898 else if (this.statut
== statutType
.auth_not_registered
)
900 $("#menu .profile").css("display", "none")
901 $("#menu .logout").css("display", displayType
)
902 $("#menu .register").css("display", displayType
)
906 $("#menu .profile").css("display", displayType
).text("login")
907 $("#menu .logout").css("display", "none")
908 $("#menu .register").css("display", displayType
)
913 * Met à jour l'affichage des infos bulles en fonction du profile.
915 Client
.prototype.majBulle = function()
917 this.util
.bulleActive
= this.viewTooltips
920 Client
.prototype.slap = function(userId
, raison
)
922 var thisClient
= this
928 data: this.util
.jsonVersAction(
931 "cookie" : thisClient
.cookie
,
938 if (data
["reply"] == "error")
939 thisClient
.util
.messageDialogue(data
["error_message"])
944 Client
.prototype.ban = function(userId
, raison
, minutes
)
946 var thisClient
= this
948 // par défaut un ban correspond à 3 jours
949 if (typeof(minutes
) == "undefined")
950 minutes
= conf
.tempsBan
;
956 data: this.util
.jsonVersAction(
959 "cookie" : thisClient
.cookie
,
960 "duration" : minutes
,
967 if (data
["reply"] == "error")
968 thisClient
.util
.messageDialogue(data
["error_message"])
973 Client
.prototype.kick = function(userId
, raison
)
975 this.ban(userId
, raison
, conf
.tempsKick
)
978 ///////////////////////////////////////////////////////////////////////////////////////////////////
981 * classe permettant de gérer les événements (push serveur).
984 function PageEvent(page
, util
)
989 // l'objet JSONHttpRequest représentant la connexion d'attente
990 this.attenteCourante
= null
992 // le multhreading du pauvre, merci javascript de m'offrire autant de primitives pour la gestion de la concurrence...
997 * Arrête l'attente courante s'il y en a une.
999 PageEvent
.prototype.stopAttenteCourante = function()
1003 if (this.attenteCourante
!= null)
1005 this.attenteCourante
.abort()
1010 * Attend un événement lié à la page.
1011 * @funSend une fonction renvoyant les données json à envoyer
1012 * @funReceive une fonction qui accepte un paramètre correspondant au données reçues
1014 PageEvent
.prototype.waitEvent = function(funSend
, funReceive
)
1016 this.stopAttenteCourante()
1020 var thisPageEvent
= this
1022 // on doit conserver l'ordre des valeurs de l'objet JSON (le serveur les veut dans l'ordre définit dans le protocole)
1023 // TODO : ya pas mieux ?
1026 "action" : "wait_event",
1029 var poulpe
= funSend()
1031 dataToSend
[v
] = poulpe
[v
]
1033 ;; dumpObj(dataToSend
)
1035 this.attenteCourante
= jQuery
.ajax({
1039 data: this.util
.jsonVersAction(dataToSend
),
1047 // rappel de la fonction dans 100 ms
1048 setTimeout(function(){ thisPageEvent
.waitEvent2(funSend
, funReceive
) }, 100)
1051 function(XMLHttpRequest
, textStatus
, errorThrown
)
1053 setTimeout(function(){ thisPageEvent
.waitEvent2(funSend
, funReceive
) }, 1000)
1059 * Si un stopAttenteCourante survient un peu n'importe quand il faut imédiatement arreter de boucler.
1061 PageEvent
.prototype.waitEvent2 = function(funSend
, funReceive
)
1065 this.waitEvent(funSend
, funReceive
)
1068 ///////////////////////////////////////////////////////////////////////////////////////////////////
1070 function initialiserListeStyles(client
)
1072 $("#menuCss").change(
1075 client
.setCss("css/" + $("option:selected", this).attr("value") + "/euphorik.css")
1080 // charge dynamiquement le script de debug
1081 ;; jQuery
.ajax({async : false, url : "js/debug.js", dataType : "script"})
1087 var formateur
= new Formateur()
1088 var util
= new Util(formateur
)
1089 var client
= new Client(util
)
1090 var pages
= new Pages()
1092 // connexion vers le serveur (utilise un cookie qui traine)
1093 client
.connexionCookie()
1095 initialiserListeStyles(client
)
1097 // FIXME : ne fonctionne pas sous opera
1098 // voir : http://dev.jquery.com/ticket/2892#preview
1099 $(window
).unload(function(){client
.flush()})
1101 $("#menu .minichat").click(function(){ pages
.afficherPage("minichat") })
1102 $("#menu .admin").click(function(){ pages
.afficherPage("admin") })
1103 $("#menu .profile").click(function(){ pages
.afficherPage("profile") })
1104 $("#menu .logout").click(function(){
1105 util
.messageDialogue("Êtes-vous sur de vouloir vous délogger ?", messageType
.question
,
1108 client
.deconnexion();
1109 pages
.afficherPage("minichat", true)
1111 "Non" : function(){}
1115 $("#menu .register").click(function(){ pages
.afficherPage("register") })
1116 $("#menu .about").click(function(){ pages
.afficherPage("about") })
1118 pages
.ajouterPage(new PageMinichat(client
, formateur
, util
))
1119 pages
.ajouterPage(new PageAdmin(client
, formateur
, util
))
1120 pages
.ajouterPage(new PageProfile(client
, formateur
, util
))
1121 pages
.ajouterPage(new PageRegister(client
, formateur
, util
))
1122 pages
.ajouterPage(new PageAbout(client
, formateur
, util
))
1123 pages
.afficherPage("minichat")