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