FIX gros bug moisi (ajout de l'information du dernier message au niveau des conversat...
[euphorik.git] / js / euphorik.js
1 // coding: utf-8
2
3 /**
4 * Contient la base javascript pour le site euphorik.ch.
5 * Chaque page possède son propre fichier js nommé "page<nom de la page>.js".
6 * Auteur : GBurri
7 * Date : 6.11.2007
8 */
9
10
11 /**
12 * La configuration.
13 * Normalement 'const' à la place de 'var' mais non supporté par IE7.
14 */
15 var conf = {
16 nbMessageAffiche : 10, // (par page)
17 pseudoDefaut : "<nick>",
18 tempsAffichageMessageDialogue : 4000, // en ms
19 smiles : {
20 "smile" : [/:\)/g, /:-\)/g],
21 "bigsmile" : [/:D/g, /:-D/g],
22 "clin" : [/;\)/g, /;-\)/g],
23 "cool" : [/8\)/g, /8-\)/g],
24 "eheheh" : [/:P/g, /:-P/g],
25 "oh" : [/:o/g, /:O/g],
26 "pascontent" : [/>\(/g, /&gt;\(/g],
27 "sniff" : [/:\(/g, /:-\(/g],
28 "argn" : [/\[:argn\]/g],
29 "bunny" : [/\[:lapin\]/g],
30 "chat" : [/\[:chat\]/g],
31 "renne" : [/\[:renne\]/g],
32 "lol" : [/\[:lol\]/g],
33 "spliff" : [/\[:spliff\]/g],
34 "star" : [/\[:star\]/g],
35 "triste" : [/\[:triste\]/g],
36 "kirby" : [/\[:kirby\]/g]
37 }
38 }
39
40 ///////////////////////////////////////////////////////////////////////////////////////////////////
41
42 String.prototype.trim = function()
43 {
44 return jQuery.trim(this) // anciennement : this.replace(/^\s+|\s+$/g, "");
45 }
46
47 String.prototype.ltrim = function()
48 {
49 return this.replace(/^\s+/, "");
50 }
51
52 String.prototype.rtrim = function()
53 {
54 return this.replace(/\s+$/, "");
55 }
56
57 ///////////////////////////////////////////////////////////////////////////////////////////////////
58
59 /**
60 * Cette classe regroupe des fonctions utilitaires (helpers).
61 */
62 function Util()
63 {
64 jQuery("#info .fermer").click(function(){
65 jQuery("#info").slideUp(50)
66 })
67 }
68
69 /**
70 * Affiche une boite de dialogue avec un message à l'intérieur.
71 * @param message le message (string)
72 * @param type voir 'messageType'. par défaut messageType.informatif
73 * @param les boutons sous la forme d'un objet ou les clefs sont les labels des boutons
74 * et les valeurs les fonctions executées lorsqu'un bouton est activé.
75 */
76 Util.prototype.messageDialogue = function(message, type, boutons)
77 {
78 if (type == undefined)
79 type = messageType.informatif
80
81 if (this.timeoutMessageDialogue != undefined)
82 clearTimeout(this.timeoutMessageDialogue)
83
84 var fermer = function(){jQuery("#info").slideUp(100)}
85 fermer()
86
87 jQuery("#info .message").html(message)
88 switch(type)
89 {
90 case messageType.informatif : jQuery("#info #icone").attr("class", "information"); break
91 case messageType.question : jQuery("#info #icone").attr("class", "interrogation"); break
92 case messageType.erreur : jQuery("#info #icone").attr("class", "exclamation"); break
93 }
94 jQuery("#info .boutons").html("")
95 for (var b in boutons)
96 jQuery("#info .boutons").append("<div>" + b + "</div>").find("div:last").click(boutons[b]).click(fermer)
97
98 jQuery("#info").slideDown(200)
99 this.timeoutMessageDialogue = setTimeout(fermer, conf.tempsAffichageMessageDialogue)
100 }
101
102 var messageType = {informatif: 0, question: 1, erreur: 2}
103
104 /**
105 * Utilisé pour l'envoie de donnée avec la méthode ajax de jQuery.
106 */
107 Util.prototype.jsonVersAction = function(json)
108 {
109 return {action : JSON.stringify(json) }
110 }
111
112 Util.prototype.md5 = function(chaine)
113 {
114 return hex_md5(chaine)
115 }
116
117 // pompé de http://www.faqts.com/knowledge_base/view.phtml/aid/13562/fid/130
118 Util.prototype.setSelectionRange = function(input, selectionStart, selectionEnd)
119 {
120 if (input.setSelectionRange)
121 {
122 input.focus()
123 input.setSelectionRange(selectionStart, selectionEnd)
124 }
125 else if (input.createTextRange)
126 {
127 var range = input.createTextRange()
128 range.collapse(true)
129 range.moveEnd('character', selectionEnd)
130 range.moveStart('character', selectionStart)
131 range.select()
132 }
133 }
134
135 Util.prototype.setCaretToEnd = function(input)
136 {
137 this.setSelectionRange(input, input.value.length, input.value.length)
138 }
139 Util.prototype.setCaretToBegin = function(input)
140 {
141 this.setSelectionRange(input, 0, 0)
142 }
143 Util.prototype.setCaretToPos = function(input, pos)
144 {
145 this.setSelectionRange(input, pos, pos)
146 }
147 Util.prototype.selectString = function(input, string)
148 {
149 var match = new RegExp(string, "i").exec(input.value)
150 if (match)
151 {
152 this.setSelectionRange (input, match.index, match.index + match[0].length)
153 }
154 }
155 Util.prototype.replaceSelection = function(input, replaceString) {
156 if (input.setSelectionRange)
157 {
158 var selectionStart = input.selectionStart
159 var selectionEnd = input.selectionEnd
160 input.value = input.value.substring(0, selectionStart) + replaceString + input.value.substring(selectionEnd)
161
162 if (selectionStart != selectionEnd) // has there been a selection
163 this.setSelectionRange(input, selectionStart, selectionStart + replaceString.length)
164 else // set caret
165 this.setCaretToPos(input, selectionStart + replaceString.length)
166 }
167 else if (document.selection)
168 {
169 var range = document.selection.createRange();
170 if (range.parentElement() == input)
171 {
172 var isCollapsed = range.text == ''
173 range.text = replaceString
174 if (!isCollapsed)
175 {
176 // there has been a selection
177 // it appears range.select() should select the newly
178 // inserted text but that fails with IE
179 range.moveStart('character', -replaceString.length);
180 range.select();
181 }
182 }
183 }
184 }
185
186 Util.prototype.rot13 = function(chaine)
187 {
188 var ACode = 'A'.charCodeAt(0)
189 var aCode = 'a'.charCodeAt(0)
190 var MCode = 'M'.charCodeAt(0)
191 var mCode = 'm'.charCodeAt(0)
192 var ZCode = 'Z'.charCodeAt(0)
193 var zCode = 'z'.charCodeAt(0)
194
195 var f = function(ch, pos) {
196 if (pos == ch.length)
197 return ""
198
199 var c = ch.charCodeAt(pos);
200 return String.fromCharCode(
201 c +
202 (c >= ACode && c <= MCode || c >= aCode && c <= mCode ? 13 :
203 (c > MCode && c <= ZCode || c > mCode && c <= zCode ? -13 : 0))
204 ) + f(ch, pos + 1)
205 }
206 return f(chaine, 0)
207 }
208
209 ///////////////////////////////////////////////////////////////////////////////////////////////////
210
211 function Pages()
212 {
213 this.pageCourante = null
214 this.pages = {}
215 }
216
217 Pages.prototype.ajouterPage = function(page)
218 {
219 page.pages = this // la magie des langages dynamiques : le foutoire
220 this.pages[page.nom] = page
221 }
222
223 Pages.prototype.afficherPage = function(nomPage, forcerChargement)
224 {
225 if (forcerChargement == undefined) forcerChargement = false
226
227 var page = this.pages[nomPage]
228 if (page == undefined || (!forcerChargement && page == this.pageCourante)) return
229
230 if (this.pageCourante != null && this.pageCourante.decharger)
231 this.pageCourante.decharger()
232
233 jQuery("#menu div").removeClass("courante")
234 jQuery("#menu div." + nomPage).addClass("courante")
235
236 this.pageCourante = page
237 jQuery("#page").html(this.pageCourante.contenu()).removeClass().addClass(this.pageCourante.nom)
238
239 if (this.pageCourante.charger)
240 this.pageCourante.charger()
241 }
242
243 ///////////////////////////////////////////////////////////////////////////////////////////////////
244
245 function Formateur()
246 {
247 this.smiles = conf.smiles
248 this.protocoles = "http|https|ed2k"
249
250 this.regexUrl = new RegExp("(?:(?:" + this.protocoles + ")://|www\\.)[^ ]*", "gi")
251 this.regexImg = new RegExp("^.*?\\.(gif|jpg|png|jpeg|bmp|tiff)$", "i")
252 this.regexDomaine = new RegExp("^(?:(?:" + this.protocoles + ")://|www\\.).*?([^/.]+\\.[^/.]+)(?:$|/).*$", "i")
253 this.regexTestProtocoleExiste = new RegExp("^(?:" + this.protocoles + ")://.*$", "i")
254 this.regexNomProtocole = new RegExp("^(.*?)://")
255 }
256
257 /**
258 * Formate un pseudo saise par l'utilisateur.
259 * @param pseudo le pseudo brut
260 * @return le pseudo filtré
261 */
262 Formateur.prototype.filtrerInputPseudo = function(pseudo)
263 {
264 return pseudo.replace(/{|}/g, "").trim()
265 }
266
267 Formateur.prototype.getSmilesHTML = function()
268 {
269 var XHTML = ""
270 for (var sNom in this.smiles)
271 {
272 XHTML += "<img class=\"" + sNom + "\" src=\"img/smileys/" + sNom + ".gif\" />"
273 }
274 return XHTML
275 }
276
277 Formateur.prototype.traitementComplet = function(M, pseudo)
278 {
279 return this.traiterLiensConv(this.traiterSmiles(this.traiterURL(this.remplacerBalisesHTML(M), pseudo)))
280 }
281
282 /**
283 * Transforme les liens en entités clickables.
284 * Un lien vers une conversation permet d'ouvrire celle ci, elle se marque comme ceci dans un message :
285 * "{5F}" ou 5F est la racine de la conversation.
286 * Ce lien sera transformer en <span class="lienConv">{5F}</span> pouvant être clické pour créer la conv 5F.
287 */
288 Formateur.prototype.traiterLiensConv = function(M)
289 {
290 return M.replace(
291 /\{\w+\}/g,
292 function(lien)
293 {
294 return "<span class=\"lienConv\">" + lien + "</span>"
295 }
296 )
297 }
298
299 /**
300 * FIXME : Cette méthode est attrocement lourde ! A optimiser.
301 */
302 Formateur.prototype.traiterSmiles = function(M)
303 {
304 for (var sNom in this.smiles)
305 {
306 ss = this.smiles[sNom]
307 for (var i = 0; i < ss.length; i++)
308 M = M.replace(ss[i], "<img src=\"img/smileys/" + sNom + ".gif\" />")
309 }
310 return M
311 }
312
313 Formateur.prototype.remplacerBalisesHTML = function(M)
314 {
315 return M.replace(/</g, "&lt;").replace(/>/g, "&gt;")
316 }
317
318 Formateur.prototype.traiterURL = function(M, pseudo)
319 {
320 thisFormateur = this
321
322 if (pseudo == undefined)
323 pseudo = ""
324
325 var traitementUrl = function(url)
326 {
327 // si ya pas de protocole on rajoute "http://"
328 if (!thisFormateur.regexTestProtocoleExiste.test(url))
329 url = "http://" + url
330 var extension = thisFormateur.getShort(url)
331 return "<a " + (extension[1] ? "title=\"" + thisFormateur.traiterPourFenetreLightBox(pseudo, url) + ": " + thisFormateur.traiterPourFenetreLightBox(M, url) + "\"" + " rel=\"lightbox[groupe]\"" : "") + " href=\"" + url + "\" >[" + extension[0] + "]</a>"
332 }
333 return M.replace(this.regexUrl, traitementUrl)
334 }
335
336 /**
337 * Renvoie une version courte de l'url.
338 * par exemple : http://en.wikipedia.org/wiki/Yakov_Smirnoff devient wikipedia.org
339 */
340 Formateur.prototype.getShort = function(url)
341 {
342 var estUneImage = false
343 var versionShort = null
344 var rechercheImg = this.regexImg.exec(url)
345 //alert(url)
346 if (rechercheImg != null)
347 {
348 versionShort = rechercheImg[1].toLowerCase()
349 if (versionShort == "jpeg") versionShort = "jpg" // jpeg -> jpg
350 estUneImage = true
351 }
352 else
353 {
354 var rechercheDomaine = this.regexDomaine.exec(url)
355 if (rechercheDomaine != null && rechercheDomaine.length >= 2)
356 versionShort = rechercheDomaine[1]
357 else
358 {
359 var nomProtocole = this.regexNomProtocole.exec(url)
360 if (nomProtocole != null && nomProtocole.length >= 2)
361 versionShort = nomProtocole[1]
362 }
363 }
364
365 return [versionShort == null ? "url" : versionShort, estUneImage]
366 }
367
368 /**
369 * Traite les pseudo et messages à être affiché dans le titre d'une image visualisé avec lightbox.
370 */
371 Formateur.prototype.traiterPourFenetreLightBox = function(M, urlCourante)
372 {
373 thisFormateur = this
374 var traitementUrl = function(url)
375 {
376 return "[" + thisFormateur.getShort(url)[0] + (urlCourante == url ? ": image courante" : "") + "]"
377 }
378
379 return this.remplacerBalisesHTML(M).replace(this.regexUrl, traitementUrl)
380 }
381
382
383 ///////////////////////////////////////////////////////////////////////////////////////////////////
384
385 // les statuts possibes du client
386 var statutType = {
387 // mode enregistré, peut poster des messages et modifier son profile
388 auth_registered : 0,
389 // mode identifié, peut poster des messages mais n'a pas accès au profile
390 auth_not_registered : 1,
391 // mode déconnecté, ne peut pas poster de message
392 deconnected : 2
393 }
394
395 function Client(util)
396 {
397 this.util = util
398
399 this.cookie = null
400 this.regexCookie = new RegExp("^cookie=([^;]*)")
401
402 // données personnels
403 this.resetDonneesPersonnelles()
404
405 this.setStatut(statutType.deconnected)
406
407 // le dernier message d'erreur recut du serveur (par exemple une connexion foireuse : "login impossible")
408 this.dernierMessageErreur = ""
409 }
410
411 Client.prototype.resetDonneesPersonnelles = function()
412 {
413 this.pseudo = conf.pseudoDefaut
414 this.login = ""
415 this.password = ""
416 this.email = ""
417 this.css = jQuery("link#cssPrincipale").attr("href")
418 this.nickFormat = "nick"
419
420 this.pagePrincipale = 1
421
422 // les conversations, une conversation est un objet possédant les attributs suivants :
423 // - racine (entier)
424 // - page (entier)
425 this.conversations = new Array()
426 }
427
428 Client.prototype.setCss = function(css)
429 {
430 if (this.css == css)
431 return
432
433 this.css = css
434 jQuery("link#cssPrincipale").attr("href", this.css)
435 this.majMenu()
436 }
437
438 Client.prototype.pageSuivante = function(numConv)
439 {
440 if (numConv < 0 && this.pagePrincipale > 1)
441 this.pagePrincipale -= 1
442 else if (this.conversations[numConv].page > 1)
443 this.conversations[numConv].page -= 1
444 }
445
446 Client.prototype.pagePrecedente = function(numConv)
447 {
448 if (numConv < 0)
449 this.pagePrincipale += 1
450 else
451 this.conversations[numConv].page += 1
452 }
453
454 /**
455 * Définit la première page pour la conversation donnée.
456 * @return true si la page a changé sinon false
457 */
458 Client.prototype.goPremierePage = function(numConv)
459 {
460 if (numConv < 0)
461 {
462 if (this.pagePrincipale == 1)
463 return false
464 this.pagePrincipale = 1
465 }
466 else
467 {
468 if (this.conversations[numConv].page == 1)
469 return false
470 this.conversations[numConv].page = 1
471 }
472 return true
473 }
474
475 /**
476 * Ajoute une conversation à la vue de l'utilisateur.
477 * Le profile de l'utilisateur est directement sauvegardé sur le serveur.
478 * @param racines la racine de la conversation (integer)
479 * @return true si la conversation a été créée sinon false (par exemple si la conv existe déjà)
480 */
481 Client.prototype.ajouterConversation = function(racine)
482 {
483 // vérification s'il elle n'existe pas déjà
484 for (var i = 0; i < this.conversations.length; i++)
485 if (this.conversations[i].root == racine)
486 return false
487
488 this.conversations.push({root : racine, page : 1})
489 return true
490 }
491
492 Client.prototype.supprimerConversation = function(num)
493 {
494 if (num < 0 || num >= this.conversations.length) return
495
496 // décalage TODO : supprimer le dernier élément
497 for (var i = num; i < this.conversations.length - 1; i++)
498 this.conversations[i] = this.conversations[i+1]
499 this.conversations.pop()
500 }
501
502 Client.prototype.getJSONLogin = function(login, password)
503 {
504 return {
505 "action" : "authentification",
506 "login" : login,
507 "password" : password
508 }
509 }
510
511 Client.prototype.getJSONLoginCookie = function()
512 {
513 return {
514 "action" : "authentification",
515 "cookie" : this.cookie
516 }
517 }
518
519 /**
520 * le couple (login, password) est facultatif. S'il n'est pas fournit alors il ne sera pas possible
521 * de s'autentifier avec (login, password).
522 */
523 Client.prototype.getJSONEnregistrement = function(login, password)
524 {
525 var mess = { "action" : "register" }
526
527 if (login != undefined && password != undefined)
528 {
529 mess["login"] = login
530 mess["password"] = password
531 }
532
533 return mess;
534 }
535
536 Client.prototype.getJSONConversations = function()
537 {
538 var conversations = new Array()
539 for (var i = 0; i < this.conversations.length; i++)
540 conversations.push({ "root" : this.conversations[i].root, "page" : this.conversations[i].page})
541 return conversations
542 }
543
544 Client.prototype.getJSONProfile = function()
545 {
546 return {
547 "action" : "set_profile",
548 "cookie" : this.cookie,
549 "login" : this.login,
550 "password" : this.password,
551 "nick" : this.pseudo,
552 "email" : this.email,
553 "css" : this.css,
554 "nick_format" : this.nickFormat,
555 "main_page" : this.pagePrincipale < 1 ? 1 : this.pagePrincipale,
556 "conversations" : this.getJSONConversations()
557 }
558 }
559
560 /**
561 * Renvoie null si pas définit.
562 */
563 Client.prototype.getCookie = function()
564 {
565 var cookie = this.regexCookie.exec(document.cookie)
566 if (cookie == null) this.cookie = null
567 else this.cookie = cookie[1]
568 }
569
570 Client.prototype.delCookie = function()
571 {
572 document.cookie = "cookie=; max-age=0"
573 }
574
575 Client.prototype.setCookie = function(cookie)
576 {
577 if (this.cookie == null)
578 return
579
580 document.cookie =
581 "cookie="+this.cookie+
582 "; max-age=" + (60 * 60 * 24 * 365)
583 }
584
585 Client.prototype.authentifie = function()
586 {
587 return this.statut == statutType.auth_registered || this.statut == statutType.auth_not_registered
588 }
589
590 Client.prototype.setStatut = function(statut)
591 {
592 //alert(statut)
593 // conversation en "enum" si en "string"
594 if (typeof(statut) == "string")
595 {
596 statut =
597 statut == "auth_registered" ?
598 statutType.auth_registered :
599 (statut == "auth_not_registered" ? statutType.auth_not_registered : statutType.deconnected)
600 }
601
602 if (statut == this.statut) return
603
604 this.statut = statut
605 this.majMenu()
606 }
607
608 /**
609 * Effectue la connexion vers le serveur.
610 * Cette fonction est bloquante tant que la connexion n'a pas été établie.
611 * S'il existe un cookie en local on s'authentifie directement avec lui.
612 * Si il n'est pas possible de s'authentifier alors on affiche un captcha anti-bot.
613 */
614 Client.prototype.connexionCookie = function()
615 {
616 this.getCookie()
617 if (this.cookie == null) return false;
618 return this.connexion(this.getJSONLoginCookie())
619 }
620
621 Client.prototype.connexionLogin = function(login, password)
622 {
623 return this.connexion(this.getJSONLogin(login, password))
624 }
625
626 Client.prototype.enregistrement = function(login, password)
627 {
628 if (this.authentifie())
629 {
630 this.login = login
631 this.password = password
632 if(this.flush())
633 this.setStatut(statutType.auth_registered)
634 return true
635 }
636 else
637 {
638 return this.connexion(this.getJSONEnregistrement(login, password))
639 }
640 }
641
642 Client.prototype.connexion = function(messageJson)
643 {
644 ;;; dumpObj(messageJson)
645 thisClient = this
646 jQuery.ajax(
647 {
648 async: false,
649 type: "POST",
650 url: "request",
651 dataType: "json",
652 data: this.util.jsonVersAction(messageJson),
653 success:
654 function(data)
655 {
656 ;;; dumpObj(data)
657 thisClient.chargerDonnees(data)
658 }
659 }
660 )
661 return this.authentifie()
662 }
663
664 Client.prototype.deconnexion = function()
665 {
666 this.flush()
667 this.setStatut(statutType.deconnected) // deconnexion
668 this.resetDonneesPersonnelles()
669 this.delCookie ()
670 }
671
672 Client.prototype.chargerDonnees = function(data)
673 {
674 var thisClient = this
675
676 this.setStatut(data["status"])
677
678 if (this.authentifie())
679 {
680 this.cookie = data["cookie"]
681 this.setCookie()
682
683 this.login = data["login"]
684 this.pseudo = data["nick"]
685 this.email = data["email"]
686 this.css = data["css"]
687 this.nickFormat = data["nick_format"]
688
689 // la page de la conversation principale
690 this.pagePrincipale = data["main_page"] == undefined ? 1 : data["main_page"]
691
692 // met à jour la css
693 if (this.css != "")
694 {
695 jQuery("link#cssPrincipale").attr("href", this.css)
696 this.majMenu()
697 }
698 // les conversations
699 thisClient.conversations = data["conversations"]
700
701 }
702 this.dernierMessageErreur = data["error_message"]
703 }
704
705 /**
706 * Met à jour les données personne sur serveur.
707 * @param async de manière asynchrone ? défaut = true
708 * @return false si le flush n'a pas pû se faire sinon true
709 */
710 Client.prototype.flush = function(async)
711 {
712 if (async == undefined)
713 async = true
714
715 if (!this.authentifie())
716 return false
717
718 thisClient = this
719 ;;; dumpObj(this.getJSONProfile())
720 jQuery.ajax(
721 {
722 async: async,
723 type: "POST",
724 url: "request",
725 dataType: "json",
726 data: this.util.jsonVersAction(this.getJSONProfile()),
727 success:
728 function(data)
729 {
730 //thisClient.util.log(thisClient.util.serializer.serializeToString(data))
731 }
732 }
733 )
734 // TODO : retourner false si un problème est survenu lors de l'update du profile
735 return true
736 }
737
738 Client.prototype.majMenu = function()
739 {
740 var displayType = this.css == "css/3/euphorik.css" ? "block" : "inline" //this.client
741
742 // met à jour le menu
743 if (this.statut == statutType.auth_registered)
744 {
745 jQuery("#menu .profile").css("display", displayType).text("profile")
746 jQuery("#menu .logout").css("display", displayType)
747 jQuery("#menu .register").css("display", "none")
748 }
749 else if (this.statut == statutType.auth_not_registered)
750 {
751 jQuery("#menu .profile").css("display", "none")
752 jQuery("#menu .logout").css("display", displayType)
753 jQuery("#menu .register").css("display", displayType)
754 }
755 else
756 {
757 jQuery("#menu .profile").css("display", displayType).text("login")
758 jQuery("#menu .logout").css("display", "none")
759 jQuery("#menu .register").css("display", displayType)
760 }
761 }
762
763 ///////////////////////////////////////////////////////////////////////////////////////////////////
764
765 function initialiserListeStyles(client)
766 {
767 jQuery("#menuCss").change(
768 function()
769 {
770 client.setCss("css/" + jQuery("option:selected", this).attr("value") + "/euphorik.css")
771 }
772 )
773 }
774
775 jQuery.noConflict()
776
777 // charge dynamiquement le script de debug
778 ;;; jQuery.ajax({async : false, url : "js/debug.js", dataType : "script"})
779
780 // le main
781 jQuery(document).ready(
782 function()
783 {
784 var util = new Util()
785 var client = new Client(util)
786 var pages = new Pages()
787 var formateur = new Formateur()
788
789 // connexion vers le serveur (utilise un cookie qui traine)
790 client.connexionCookie()
791
792 initialiserListeStyles(client)
793
794 // TODO : pourquoi jQuery(document).unload ne fonctionne pas ?
795 jQuery(window).unload(
796 function()
797 {
798 client.flush(false)
799 }
800 )
801
802 jQuery("#menu .minichat").click(function(){ pages.afficherPage("minichat") })
803 jQuery("#menu .profile").click(function(){ pages.afficherPage("profile") })
804 jQuery("#menu .logout").click(function(){
805 util.messageDialogue("Êtes-vous sur de vouloir vous délogger ?", messageType.question,
806 {"Oui" : function()
807 {
808 client.deconnexion();
809 pages.afficherPage("minichat", true)
810 },
811 "Non" : function(){}
812 }
813 )
814 })
815 jQuery("#menu .register").click(function(){ pages.afficherPage("register") })
816 jQuery("#menu .about").click(function(){ pages.afficherPage("about") })
817
818 pages.ajouterPage(new PageMinichat(client, formateur, util))
819 pages.ajouterPage(new PageProfile(client, formateur, util))
820 pages.ajouterPage(new PageRegister(client, formateur, util))
821 pages.ajouterPage(new PageAbout(client, formateur, util))
822 pages.afficherPage("minichat")
823 }
824 )