DEL lightbox
[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 * moyenne su échantillon : 234ms
310 */
311 Formateur.prototype.traiterSmiles = function(M)
312 {
313 for (var sNom in this.smiles)
314 {
315 ss = this.smiles[sNom]
316 for (var i = 0; i < ss.length; i++)
317 M = M.replace(ss[i], "<img src=\"img/smileys/" + sNom + ".gif\" />")
318 }
319 return M
320 }
321
322 Formateur.prototype.remplacerBalisesHTML = function(M)
323 {
324 return M.replace(/</g, "&lt;").replace(/>/g, "&gt;")
325 }
326
327 Formateur.prototype.traiterURL = function(M, pseudo)
328 {
329 thisFormateur = this
330
331 if (pseudo == undefined)
332 pseudo = ""
333
334 var traitementUrl = function(url)
335 {
336 // si ya pas de protocole on rajoute "http://"
337 if (!thisFormateur.regexTestProtocoleExiste.test(url))
338 url = "http://" + url
339 var extension = thisFormateur.getShort(url)
340 return "<a " + (extension[1] ? "title=\"" + thisFormateur.traiterPourFenetreLightBox(pseudo, url) + ": " + thisFormateur.traiterPourFenetreLightBox(M, url) + "\"" + " rel=\"lightbox[groupe]\"" : "") + " href=\"" + url + "\" >[" + extension[0] + "]</a>"
341 }
342 return M.replace(this.regexUrl, traitementUrl)
343 }
344
345 /**
346 * Renvoie une version courte de l'url.
347 * par exemple : http://en.wikipedia.org/wiki/Yakov_Smirnoff devient wikipedia.org
348 */
349 Formateur.prototype.getShort = function(url)
350 {
351 var estUneImage = false
352 var versionShort = null
353 var rechercheImg = this.regexImg.exec(url)
354 //alert(url)
355 if (rechercheImg != null)
356 {
357 versionShort = rechercheImg[1].toLowerCase()
358 if (versionShort == "jpeg") versionShort = "jpg" // jpeg -> jpg
359 estUneImage = true
360 }
361 else
362 {
363 var rechercheDomaine = this.regexDomaine.exec(url)
364 if (rechercheDomaine != null && rechercheDomaine.length >= 2)
365 versionShort = rechercheDomaine[1]
366 else
367 {
368 var nomProtocole = this.regexNomProtocole.exec(url)
369 if (nomProtocole != null && nomProtocole.length >= 2)
370 versionShort = nomProtocole[1]
371 }
372 }
373
374 return [versionShort == null ? "url" : versionShort, estUneImage]
375 }
376
377 /**
378 * Traite les pseudo et messages à être affiché dans le titre d'une image visualisé avec lightbox.
379 */
380 Formateur.prototype.traiterPourFenetreLightBox = function(M, urlCourante)
381 {
382 thisFormateur = this
383 var traitementUrl = function(url)
384 {
385 return "[" + thisFormateur.getShort(url)[0] + (urlCourante == url ? ": image courante" : "") + "]"
386 }
387
388 return this.remplacerBalisesHTML(M).replace(this.regexUrl, traitementUrl)
389 }
390
391
392 ///////////////////////////////////////////////////////////////////////////////////////////////////
393
394 // les statuts possibes du client
395 var statutType = {
396 // mode enregistré, peut poster des messages et modifier son profile
397 auth_registered : 0,
398 // mode identifié, peut poster des messages mais n'a pas accès au profile
399 auth_not_registered : 1,
400 // mode déconnecté, ne peut pas poster de message
401 deconnected : 2
402 }
403
404 function Client(util)
405 {
406 this.util = util
407
408 this.cookie = null
409 this.regexCookie = new RegExp("^cookie=([^;]*)")
410
411 // données personnels
412 this.resetDonneesPersonnelles()
413
414 this.setStatut(statutType.deconnected)
415
416 // le dernier message d'erreur recut du serveur (par exemple une connexion foireuse : "login impossible")
417 this.dernierMessageErreur = ""
418 }
419
420 Client.prototype.resetDonneesPersonnelles = function()
421 {
422 this.pseudo = conf.pseudoDefaut
423 this.login = ""
424 this.password = ""
425 this.email = ""
426 this.css = jQuery("link#cssPrincipale").attr("href")
427 this.nickFormat = "nick"
428
429 this.pagePrincipale = 1
430 this.ekMaster = false
431
432 // les conversations, une conversation est un objet possédant les attributs suivants :
433 // - racine (entier)
434 // - page (entier)
435 this.conversations = new Array()
436 }
437
438 Client.prototype.setCss = function(css)
439 {
440 if (this.css == css)
441 return
442
443 this.css = css
444 jQuery("link#cssPrincipale").attr("href", this.css)
445 this.majMenu()
446 }
447
448 Client.prototype.pageSuivante = function(numConv)
449 {
450 if (numConv < 0 && this.pagePrincipale > 1)
451 this.pagePrincipale -= 1
452 else if (this.conversations[numConv].page > 1)
453 this.conversations[numConv].page -= 1
454 }
455
456 Client.prototype.pagePrecedente = function(numConv)
457 {
458 if (numConv < 0)
459 this.pagePrincipale += 1
460 else
461 this.conversations[numConv].page += 1
462 }
463
464 /**
465 * Définit la première page pour la conversation donnée.
466 * @return true si la page a changé sinon false
467 */
468 Client.prototype.goPremierePage = function(numConv)
469 {
470 if (numConv < 0)
471 {
472 if (this.pagePrincipale == 1)
473 return false
474 this.pagePrincipale = 1
475 }
476 else
477 {
478 if (this.conversations[numConv].page == 1)
479 return false
480 this.conversations[numConv].page = 1
481 }
482 return true
483 }
484
485 /**
486 * Ajoute une conversation à la vue de l'utilisateur.
487 * Le profile de l'utilisateur est directement sauvegardé sur le serveur.
488 * @param racines la racine de la conversation (integer)
489 * @return true si la conversation a été créée sinon false (par exemple si la conv existe déjà)
490 */
491 Client.prototype.ajouterConversation = function(racine)
492 {
493 // vérification s'il elle n'existe pas déjà
494 for (var i = 0; i < this.conversations.length; i++)
495 if (this.conversations[i].root == racine)
496 return false
497
498 this.conversations.push({root : racine, page : 1})
499 return true
500 }
501
502 Client.prototype.supprimerConversation = function(num)
503 {
504 if (num < 0 || num >= this.conversations.length) return
505
506 // décalage TODO : supprimer le dernier élément
507 for (var i = num; i < this.conversations.length - 1; i++)
508 this.conversations[i] = this.conversations[i+1]
509 this.conversations.pop()
510 }
511
512 Client.prototype.getJSONLogin = function(login, password)
513 {
514 return {
515 "action" : "authentification",
516 "login" : login,
517 "password" : password
518 }
519 }
520
521 Client.prototype.getJSONLoginCookie = function()
522 {
523 return {
524 "action" : "authentification",
525 "cookie" : this.cookie
526 }
527 }
528
529 /**
530 * le couple (login, password) est facultatif. S'il n'est pas fournit alors il ne sera pas possible
531 * de s'autentifier avec (login, password).
532 */
533 Client.prototype.getJSONEnregistrement = function(login, password)
534 {
535 var mess = { "action" : "register" }
536
537 if (login != undefined && password != undefined)
538 {
539 mess["login"] = login
540 mess["password"] = password
541 }
542
543 return mess;
544 }
545
546 Client.prototype.getJSONConversations = function()
547 {
548 var conversations = new Array()
549 for (var i = 0; i < this.conversations.length; i++)
550 conversations.push({ "root" : this.conversations[i].root, "page" : this.conversations[i].page})
551 return conversations
552 }
553
554 Client.prototype.getJSONProfile = function()
555 {
556 return {
557 "action" : "set_profile",
558 "cookie" : this.cookie,
559 "login" : this.login,
560 "password" : this.password,
561 "nick" : this.pseudo,
562 "email" : this.email,
563 "css" : this.css,
564 "nick_format" : this.nickFormat,
565 "main_page" : this.pagePrincipale < 1 ? 1 : this.pagePrincipale,
566 "conversations" : this.getJSONConversations()
567 }
568 }
569
570 /**
571 * Renvoie null si pas définit.
572 */
573 Client.prototype.getCookie = function()
574 {
575 var cookie = this.regexCookie.exec(document.cookie)
576 if (cookie == null) this.cookie = null
577 else this.cookie = cookie[1]
578 }
579
580 Client.prototype.delCookie = function()
581 {
582 document.cookie = "cookie=; max-age=0"
583 }
584
585 Client.prototype.setCookie = function(cookie)
586 {
587 if (this.cookie == null)
588 return
589
590 document.cookie =
591 "cookie="+this.cookie+
592 "; max-age=" + (60 * 60 * 24 * 365)
593 }
594
595 Client.prototype.authentifie = function()
596 {
597 return this.statut == statutType.auth_registered || this.statut == statutType.auth_not_registered
598 }
599
600 Client.prototype.setStatut = function(statut)
601 {
602 //alert(statut)
603 // conversation en "enum" si en "string"
604 if (typeof(statut) == "string")
605 {
606 statut =
607 statut == "auth_registered" ?
608 statutType.auth_registered :
609 (statut == "auth_not_registered" ? statutType.auth_not_registered : statutType.deconnected)
610 }
611
612 if (statut == this.statut) return
613
614 this.statut = statut
615 this.majMenu()
616 }
617
618 /**
619 * Effectue la connexion vers le serveur.
620 * Cette fonction est bloquante tant que la connexion n'a pas été établie.
621 * S'il existe un cookie en local on s'authentifie directement avec lui.
622 * Si il n'est pas possible de s'authentifier alors on affiche un captcha anti-bot.
623 */
624 Client.prototype.connexionCookie = function()
625 {
626 this.getCookie()
627 if (this.cookie == null) return false;
628 return this.connexion(this.getJSONLoginCookie())
629 }
630
631 Client.prototype.connexionLogin = function(login, password)
632 {
633 return this.connexion(this.getJSONLogin(login, password))
634 }
635
636 Client.prototype.enregistrement = function(login, password)
637 {
638 if (this.authentifie())
639 {
640 this.login = login
641 this.password = password
642 if(this.flush())
643 this.setStatut(statutType.auth_registered)
644 return true
645 }
646 else
647 {
648 return this.connexion(this.getJSONEnregistrement(login, password))
649 }
650 }
651
652 Client.prototype.connexion = function(messageJson)
653 {
654 ;;; dumpObj(messageJson)
655 thisClient = this
656 jQuery.ajax(
657 {
658 async: false,
659 type: "POST",
660 url: "request",
661 dataType: "json",
662 data: this.util.jsonVersAction(messageJson),
663 success:
664 function(data)
665 {
666 ;;; dumpObj(data)
667 thisClient.chargerDonnees(data)
668 }
669 }
670 )
671 return this.authentifie()
672 }
673
674 Client.prototype.deconnexion = function()
675 {
676 this.flush()
677 this.delCookie()
678 this.setStatut(statutType.deconnected) // deconnexion
679 this.resetDonneesPersonnelles()
680 }
681
682 Client.prototype.chargerDonnees = function(data)
683 {
684 var thisClient = this
685
686 this.setStatut(data["status"])
687
688 if (this.authentifie())
689 {
690 this.cookie = data["cookie"]
691 this.setCookie()
692
693 this.login = data["login"]
694 this.pseudo = data["nick"]
695 this.email = data["email"]
696 this.css = data["css"]
697 this.nickFormat = data["nick_format"]
698
699 // la page de la conversation principale
700 this.pagePrincipale = data["main_page"] == undefined ? 1 : data["main_page"]
701
702 // met à jour la css
703 if (this.css != "")
704 {
705 jQuery("link#cssPrincipale").attr("href", this.css)
706 this.majMenu()
707 }
708 // les conversations
709 thisClient.conversations = data["conversations"]
710
711 thisClient.ekMaster = data["ek_master"]
712 }
713 this.dernierMessageErreur = data["error_message"]
714 }
715
716 /**
717 * Met à jour les données personne sur serveur.
718 * @param async de manière asynchrone ? défaut = true
719 * @return false si le flush n'a pas pû se faire sinon true
720 */
721 Client.prototype.flush = function(async)
722 {
723 if (async == undefined)
724 async = true
725
726 if (!this.authentifie())
727 return false
728
729 thisClient = this
730 ;;; dumpObj(this.getJSONProfile())
731 jQuery.ajax(
732 {
733 async: async,
734 type: "POST",
735 url: "request",
736 dataType: "json",
737 data: this.util.jsonVersAction(this.getJSONProfile()),
738 success:
739 function(data)
740 {
741 //thisClient.util.log(thisClient.util.serializer.serializeToString(data))
742 }
743 }
744 )
745 // TODO : retourner false si un problème est survenu lors de l'update du profile
746 return true
747 }
748
749 Client.prototype.majMenu = function()
750 {
751 var displayType = this.css == "css/3/euphorik.css" ? "block" : "inline" //this.client
752
753 // met à jour le menu
754 if (this.statut == statutType.auth_registered)
755 {
756 jQuery("#menu .profile").css("display", displayType).text("profile")
757 jQuery("#menu .logout").css("display", displayType)
758 jQuery("#menu .register").css("display", "none")
759 }
760 else if (this.statut == statutType.auth_not_registered)
761 {
762 jQuery("#menu .profile").css("display", "none")
763 jQuery("#menu .logout").css("display", displayType)
764 jQuery("#menu .register").css("display", displayType)
765 }
766 else
767 {
768 jQuery("#menu .profile").css("display", displayType).text("login")
769 jQuery("#menu .logout").css("display", "none")
770 jQuery("#menu .register").css("display", displayType)
771 }
772 }
773
774 Client.prototype.ban = function(userId, minutes)
775 {
776 var thisClient = this
777
778 // par défaut un ban correspond à 3 jours
779 if (typeof(minutes) == "undefined")
780 minutes = 60 * 24 * 3
781
782 jQuery.ajax({
783 type: "POST",
784 url: "request",
785 dataType: "json",
786 data: this.util.jsonVersAction(
787 {
788 "action" : "ban",
789 "cookie" : thisClient.cookie,
790 "duration" : minutes,
791 "user_id" : userId
792 }),
793 success:
794 function(data)
795 {
796 if (data["reply"] == "error")
797 thisClient.util.messageDialogue(data["error_message"])
798 }
799 })
800 }
801
802 Client.prototype.kick = function(userId)
803 {
804 this.ban(userId, 15)
805 }
806
807 ///////////////////////////////////////////////////////////////////////////////////////////////////
808
809 function initialiserListeStyles(client)
810 {
811 jQuery("#menuCss").change(
812 function()
813 {
814 client.setCss("css/" + jQuery("option:selected", this).attr("value") + "/euphorik.css")
815 }
816 )
817 }
818
819 // charge dynamiquement le script de debug
820 ;;; jQuery.ajax({async : false, url : "js/debug.js", dataType : "script"})
821
822 // le main
823 jQuery(document).ready(
824 function()
825 {
826 var util = new Util()
827 var client = new Client(util)
828 var pages = new Pages()
829 var formateur = new Formateur()
830
831 // connexion vers le serveur (utilise un cookie qui traine)
832 client.connexionCookie()
833
834 initialiserListeStyles(client)
835
836 // TODO : pourquoi jQuery(document).unload ne fonctionne pas ?
837 jQuery(window).unload(function(){client.flush(false)})
838
839 jQuery("#menu .minichat").click(function(){ pages.afficherPage("minichat") })
840 jQuery("#menu .profile").click(function(){ pages.afficherPage("profile") })
841 jQuery("#menu .logout").click(function(){
842 util.messageDialogue("Êtes-vous sur de vouloir vous délogger ?", messageType.question,
843 {"Oui" : function()
844 {
845 client.deconnexion();
846 pages.afficherPage("minichat", true)
847 },
848 "Non" : function(){}
849 }
850 )
851 })
852 jQuery("#menu .register").click(function(){ pages.afficherPage("register") })
853 jQuery("#menu .about").click(function(){ pages.afficherPage("about") })
854
855 pages.ajouterPage(new PageMinichat(client, formateur, util))
856 pages.ajouterPage(new PageProfile(client, formateur, util))
857 pages.ajouterPage(new PageRegister(client, formateur, util))
858 pages.ajouterPage(new PageAbout(client, formateur, util))
859 pages.afficherPage("minichat")
860 }
861 )