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
36 "smile" : [/:\)/g, /:-\)/g],
37 "bigsmile" : [/:D/g, /:-D/g],
38 "clin" : [/;\)/g, /;-\)/g],
39 "cool" : [/8\)/g, /8-\)/g],
40 "eheheh" : [/:P/g, /:-P/g],
41 "lol" : [/\[-lol\]/g],
42 "spliff" : [/\[-spliff\]/g],
43 "oh" : [/:o/g, /:O/g],
44 "heink" : [/\[-heink\]/g],
45 "hum" : [/\[-hum\]/g],
46 "boh" : [/\[-boh\]/g],
47 "sniff" : [/:\(/g, /:-\(/g],
48 "triste" : [/\[-triste\]/g],
49 "pascontent" : [/>\(/g, />\(/g],
50 "argn" : [/\[-argn\]/g],
51 "redface" : [/\[-redface\]/g],
52 "bunny" : [/\[-lapin\]/g],
53 "chat" : [/\[-chat\]/g],
54 "renne" : [/\[-renne\]/g],
55 "star" : [/\[-star\]/g],
56 "kirby" : [/\[-kirby\]/g],
57 "slurp" : [/\[-slurp\]/g],
58 "agreed" : [/\[-agreed\]/g],
59 "dodo" : [/\[-dodo\]/g],
64 ///////////////////////////////////////////////////////////////////////////////////////////////////
66 String
.prototype.trim = function()
68 return jQuery
.trim(this) // anciennement : this.replace(/^\s+|\s+$/g, "");
71 String
.prototype.ltrim = function()
73 return this.replace(/^\s+/, "");
76 String
.prototype.rtrim = function()
78 return this.replace(/\s+$/, "");
81 ///////////////////////////////////////////////////////////////////////////////////////////////////
84 * Cette classe regroupe des fonctions utilitaires (helpers).
85 * @formateur est permet de formater les messages affichés à l'aide de messageDialogue (facultatif)
87 function Util(formateur
)
89 $("#info .fermer").click(function(){
90 $("#info").slideUp(50)
93 this.formateur
= formateur
96 var messageType
= {informatif: 0, question: 1, erreur: 2}
99 * Affiche une boite de dialogue avec un message à l'intérieur.
100 * @param message le message (string)
101 * @param type voir 'messageType'. par défaut messageType.informatif
102 * @param les boutons sous la forme d'un objet ou les clefs sont les labels des boutons
103 * et les valeurs les fonctions executées lorsqu'un bouton est activé.
104 * @param formate faut-il formaté le message ? true par défaut
106 Util
.prototype.messageDialogue = function(message
, type
, boutons
, formate
)
110 if (type
== undefined)
111 type
= messageType
.informatif
113 if (formate
== undefined)
116 if (this.timeoutMessageDialogue
!= undefined)
117 clearTimeout(this.timeoutMessageDialogue
)
119 var fermer = function(){$("#info").slideUp(100)}
122 $("#info .message").html(thisUtil
.formateur
== undefined || !formate
? message : thisUtil
.formateur
.traitementComplet(message
))
125 case messageType
.informatif : $("#info #icone").attr("class", "information"); break
126 case messageType
.question : $("#info #icone").attr("class", "interrogation"); break
127 case messageType
.erreur : $("#info #icone").attr("class", "exclamation"); break
129 $("#info .boutons").html("")
130 for (var b
in boutons
)
131 $("#info .boutons").append("<div>" + b
+ "</div>").find("div:last").click(boutons
[b
]).click(fermer
)
133 $("#info").slideDown(200)
134 this.timeoutMessageDialogue
= setTimeout(fermer
, conf
.tempsAffichageMessageDialogue
)
138 * Utilisé pour l'envoie de donnée avec la méthode ajax de jQuery.
140 Util
.prototype.jsonVersAction = function(json
)
142 return {action : JSON
.stringify(json
) }
145 Util
.prototype.md5 = function(chaine
)
147 return hex_md5(chaine
)
150 // pompé de http://www.faqts.com/knowledge_base/view.phtml/aid/13562/fid/130
151 Util
.prototype.setSelectionRange = function(input
, selectionStart
, selectionEnd
)
153 if (input
.setSelectionRange
)
156 input
.setSelectionRange(selectionStart
, selectionEnd
)
158 else if (input
.createTextRange
)
160 var range
= input
.createTextRange()
162 range
.moveEnd('character', selectionEnd
)
163 range
.moveStart('character', selectionStart
)
168 Util
.prototype.setCaretToEnd = function(input
)
170 this.setSelectionRange(input
, input
.value
.length
, input
.value
.length
)
172 Util
.prototype.setCaretToBegin = function(input
)
174 this.setSelectionRange(input
, 0, 0)
176 Util
.prototype.setCaretToPos = function(input
, pos
)
178 this.setSelectionRange(input
, pos
, pos
)
180 Util
.prototype.selectString = function(input
, string
)
182 var match
= new RegExp(string
, "i").exec(input
.value
)
185 this.setSelectionRange (input
, match
.index
, match
.index
+ match
[0].length
)
188 Util
.prototype.replaceSelection = function(input
, replaceString
) {
189 if (input
.setSelectionRange
)
191 var selectionStart
= input
.selectionStart
192 var selectionEnd
= input
.selectionEnd
193 input
.value
= input
.value
.substring(0, selectionStart
) + replaceString
+ input
.value
.substring(selectionEnd
)
195 if (selectionStart
!= selectionEnd
) // has there been a selection
196 this.setSelectionRange(input
, selectionStart
, selectionStart
+ replaceString
.length
)
198 this.setCaretToPos(input
, selectionStart
+ replaceString
.length
)
200 else if (document
.selection
)
202 var range
= document
.selection
.createRange();
203 if (range
.parentElement() == input
)
205 var isCollapsed
= range
.text
== ''
206 range
.text
= replaceString
209 // there has been a selection
210 // it appears range.select() should select the newly
211 // inserted text but that fails with IE
212 range
.moveStart('character', -replaceString
.length
);
219 Util
.prototype.rot13 = function(chaine
)
221 var ACode
= 'A'.charCodeAt(0)
222 var aCode
= 'a'.charCodeAt(0)
223 var MCode
= 'M'.charCodeAt(0)
224 var mCode
= 'm'.charCodeAt(0)
225 var ZCode
= 'Z'.charCodeAt(0)
226 var zCode
= 'z'.charCodeAt(0)
228 var f = function(ch
, pos
) {
229 if (pos
== ch
.length
)
232 var c
= ch
.charCodeAt(pos
);
233 return String
.fromCharCode(
235 (c
>= ACode
&& c
<= MCode
|| c
>= aCode
&& c
<= mCode
? 13 :
236 (c
> MCode
&& c
<= ZCode
|| c
> mCode
&& c
<= zCode
? -13 : 0))
242 ///////////////////////////////////////////////////////////////////////////////////////////////////
246 this.pageCourante
= null
250 Pages
.prototype.ajouterPage = function(page
)
252 page
.pages
= this // la magie des langages dynamiques : le foutoire
253 this.pages
[page
.nom
] = page
256 Pages
.prototype.afficherPage = function(nomPage
, forcerChargement
)
258 if (forcerChargement
== undefined) forcerChargement
= false
260 var page
= this.pages
[nomPage
]
261 if (page
== undefined || (!forcerChargement
&& page
== this.pageCourante
)) return
263 if (this.pageCourante
!= null && this.pageCourante
.decharger
)
264 this.pageCourante
.decharger()
266 $("#menu li").removeClass("courante")
267 $("#menu li." + nomPage
).addClass("courante")
269 this.pageCourante
= page
270 $("#page").html(this.pageCourante
.contenu()).removeClass().addClass(this.pageCourante
.nom
)
272 if (this.pageCourante
.charger
)
273 this.pageCourante
.charger()
276 ///////////////////////////////////////////////////////////////////////////////////////////////////
279 * Classe permettant de formater du texte par exemple pour la substitution des liens dans les
280 * message par "[url]".
281 * TODO : améliorer l'efficacité des méthods notamment lié au smiles.
285 this.smiles
= conf
.smiles
286 this.protocoles
= "http|https|ed2k"
288 this.regexUrl
= new RegExp("(?:(?:" + this.protocoles
+ ")://|www\\.)[^ ]*", "gi")
289 this.regexImg
= new RegExp("^.*?\\.(gif|jpg|png|jpeg|bmp|tiff)$", "i")
290 this.regexDomaine
= new RegExp("^(?:(?:" + this.protocoles
+ ")://|www\\.).*?([^/.]+\\.[^/.]+)(?:$|/).*$", "i")
291 this.regexTestProtocoleExiste
= new RegExp("^(?:" + this.protocoles
+ ")://.*$", "i")
292 this.regexNomProtocole
= new RegExp("^(.*?)://")
296 * Formate un pseudo saise par l'utilisateur.
297 * @param pseudo le pseudo brut
298 * @return le pseudo filtré
300 Formateur
.prototype.filtrerInputPseudo = function(pseudo
)
302 return pseudo
.replace(/{|}/g, "").trim()
305 Formateur
.prototype.getSmilesHTML = function()
308 for (var sNom
in this.smiles
)
310 XHTML
+= "<img class=\"" + sNom
+ "\" src=\"img/smileys/" + sNom
+ ".gif\" alt =\"" + sNom
+ "\" />"
316 * Formatage complet d'un texte.
318 * @pseudo facultatif, permet de contruire le label des images sous la forme : "<Pseudo> : <Message>"
320 Formateur
.prototype.traitementComplet = function(M
, pseudo
)
322 return this.traiterLiensConv(this.traiterSmiles(this.traiterURL(this.traiterWikiSyntaxe(this.remplacerBalisesHTML(M
)), pseudo
)))
326 * Transforme les liens en entités clickables.
327 * Un lien vers une conversation permet d'ouvrire celle ci, elle se marque comme ceci dans un message :
328 * "{5F}" ou 5F est la racine de la conversation.
329 * Ce lien sera transformer en <span class="lienConv">{5F}</span> pouvant être clické pour créer la conv 5F.
331 Formateur
.prototype.traiterLiensConv = function(M
)
337 return "<span class=\"lienConv\">" + lien
+ "</span>"
343 * FIXME : Cette méthode est attrocement lourde ! A optimiser.
344 * moyenne sur échantillon : 234ms
346 Formateur
.prototype.traiterSmiles = function(M
)
348 for (var sNom
in this.smiles
)
350 ss
= this.smiles
[sNom
]
351 for (var i
= 0; i
< ss
.length
; i
++)
352 M
= M
.replace(ss
[i
], "<img src=\"img/smileys/" + sNom
+ ".gif\" alt =\"" + sNom
+ "\" />")
357 Formateur
.prototype.remplacerBalisesHTML = function(M
)
359 return M
.replace(/</g
, "<").replace(/>/g
, ">").replace(/"/g, ""
;")
362 Formateur.prototype.traiterURL = function(M, pseudo)
366 var traitementUrl = function(url)
368 // si ya pas de protocole on rajoute "http://"
369 if (!thisFormateur
.regexTestProtocoleExiste
.test(url
))
370 url
= "http://" + url
371 var extension
= thisFormateur
.getShort(url
)
372 return "<a " + (extension
[1] ? "title=\"" + (pseudo
== undefined ? "" : thisFormateur
.traiterPourFenetreLightBox(pseudo
, url
) + ": ") + thisFormateur
.traiterPourFenetreLightBox(M
, url
) + "\"" + " rel=\"lightbox\"" : "") + " href=\"" + url
+ "\" >[" + extension
[0] + "]</a>"
374 return M
.replace(this.regexUrl
, traitementUrl
)
378 * Formatage en utilisant un sous-ensemble des règles de mediwiki.
379 * par exemple ''italic'' devient <i>italic</i>
381 Formateur
.prototype.traiterWikiSyntaxe = function(M
)
385 function(texte
, capture
)
387 return "<b>" + capture
+ "</b>"
391 function(texte
, capture
)
393 return "<i>" + capture
+ "</i>"
399 * Renvoie une version courte de l'url.
400 * par exemple : http://en.wikipedia.org/wiki/Yakov_Smirnoff devient wikipedia.org
402 Formateur
.prototype.getShort = function(url
)
404 var estUneImage
= false
405 var versionShort
= null
406 var rechercheImg
= this.regexImg
.exec(url
)
408 if (rechercheImg
!= null)
410 versionShort
= rechercheImg
[1].toLowerCase()
411 if (versionShort
== "jpeg") versionShort
= "jpg" // jpeg -> jpg
416 var rechercheDomaine
= this.regexDomaine
.exec(url
)
417 if (rechercheDomaine
!= null && rechercheDomaine
.length
>= 2)
418 versionShort
= rechercheDomaine
[1]
421 var nomProtocole
= this.regexNomProtocole
.exec(url
)
422 if (nomProtocole
!= null && nomProtocole
.length
>= 2)
423 versionShort
= nomProtocole
[1]
427 return [versionShort
== null ? "url" : versionShort
, estUneImage
]
431 * Traite les pseudo et messages à être affiché dans le titre d'une image visualisé avec lightbox.
433 Formateur
.prototype.traiterPourFenetreLightBox = function(M
, urlCourante
)
436 var traitementUrl = function(url
)
438 return "[" + thisFormateur
.getShort(url
)[0] + (urlCourante
== url
? "*" : "") + "]"
441 return this.remplacerBalisesHTML(M
).replace(this.regexUrl
, traitementUrl
)
445 ///////////////////////////////////////////////////////////////////////////////////////////////////
447 // les statuts possibes du client
449 // mode enregistré, peut poster des messages et modifier son profile
451 // mode identifié, peut poster des messages mais n'a pas accès au profile
452 auth_not_registered : 1,
453 // mode déconnecté, ne peut pas poster de message
457 function Client(util
)
462 this.regexCookie
= new RegExp("^cookie=([^;]*)")
464 // données personnels
465 this.resetDonneesPersonnelles()
467 this.setStatut(statutType
.deconnected
)
470 Client
.prototype.resetDonneesPersonnelles = function()
473 this.pseudo
= conf
.pseudoDefaut
477 this.css
= $("link#cssPrincipale").attr("href")
478 this.nickFormat
= "nick"
479 this.cookie
= undefined
481 this.pagePrincipale
= 1
482 this.ekMaster
= false
484 // les conversations, une conversation est un objet possédant les attributs suivants :
487 this.conversations
= new Array()
490 Client
.prototype.setCss = function(css
)
492 if (this.css
== css
|| css
== "")
496 $("link#cssPrincipale").attr("href", this.css
)
500 Client
.prototype.pageSuivante = function(numConv
)
502 if (numConv
< 0 && this.pagePrincipale
> 1)
503 this.pagePrincipale
-= 1
504 else if (this.conversations
[numConv
].page
> 1)
505 this.conversations
[numConv
].page
-= 1
508 Client
.prototype.pagePrecedente = function(numConv
)
511 this.pagePrincipale
+= 1
513 this.conversations
[numConv
].page
+= 1
517 * Définit la première page pour la conversation donnée.
518 * @return true si la page a changé sinon false
520 Client
.prototype.goPremierePage = function(numConv
)
524 if (this.pagePrincipale
== 1)
526 this.pagePrincipale
= 1
530 if (this.conversations
[numConv
].page
== 1)
532 this.conversations
[numConv
].page
= 1
538 * Ajoute une conversation à la vue de l'utilisateur.
539 * Le profile de l'utilisateur est directement sauvegardé sur le serveur.
540 * @param racines la racine de la conversation (integer)
541 * @return true si la conversation a été créée sinon false (par exemple si la conv existe déjà)
543 Client
.prototype.ajouterConversation = function(racine
)
545 // vérification s'il elle n'existe pas déjà
546 for (var i
= 0; i
< this.conversations
.length
; i
++)
547 if (this.conversations
[i
].root
== racine
)
550 this.conversations
.push({root : racine
, page : 1})
554 Client
.prototype.supprimerConversation = function(num
)
556 if (num
< 0 || num
>= this.conversations
.length
) return
558 // décalage TODO : supprimer le dernier élément
559 for (var i
= num
; i
< this.conversations
.length
- 1; i
++)
560 this.conversations
[i
] = this.conversations
[i
+1]
561 this.conversations
.pop()
564 Client
.prototype.getJSONLogin = function(login
, password
)
567 "action" : "authentification",
569 "password" : password
573 Client
.prototype.getJSONLoginCookie = function()
576 "action" : "authentification",
577 "cookie" : this.cookie
582 * le couple (login, password) est facultatif. S'il n'est pas fournit alors il ne sera pas possible
583 * de s'autentifier avec (login, password).
585 Client
.prototype.getJSONEnregistrement = function(login
, password
)
587 var mess
= { "action" : "register" }
589 if (login
!= undefined && password
!= undefined)
591 mess
["login"] = login
592 mess
["password"] = password
598 Client
.prototype.getJSONConversations = function()
600 var conversations
= new Array()
601 for (var i
= 0; i
< this.conversations
.length
; i
++)
602 conversations
.push({ "root" : this.conversations
[i
].root
, "page" : this.conversations
[i
].page
})
606 Client
.prototype.getJSONProfile = function()
609 "action" : "set_profile",
610 "cookie" : this.cookie
,
611 "login" : this.login
,
612 "password" : this.password
,
613 "nick" : this.pseudo
,
614 "email" : this.email
,
616 "nick_format" : this.nickFormat
,
617 "main_page" : this.pagePrincipale
< 1 ? 1 : this.pagePrincipale
,
618 "conversations" : this.getJSONConversations()
623 * Renvoie null si pas définit.
625 Client
.prototype.getCookie = function()
627 var cookie
= this.regexCookie
.exec(document
.cookie
)
628 if (cookie
== null) this.cookie
= null
629 else this.cookie
= cookie
[1]
632 Client
.prototype.delCookie = function()
634 document
.cookie
= "cookie=; max-age=0"
637 Client
.prototype.setCookie = function(cookie
)
639 if (this.cookie
== null)
643 "cookie="+this.cookie
+
644 "; max-age=" + (60 * 60 * 24 * 365)
647 Client
.prototype.authentifie = function()
649 return this.statut
== statutType
.auth_registered
|| this.statut
== statutType
.auth_not_registered
652 Client
.prototype.setStatut = function(statut
)
654 // conversation en "enum" si en "string"
655 if (typeof(statut
) == "string")
658 statut
== "auth_registered" ?
659 statutType
.auth_registered :
660 (statut
== "auth_not_registered" ? statutType
.auth_not_registered : statutType
.deconnected
)
663 if (statut
== this.statut
) return
670 * Effectue la connexion vers le serveur.
671 * Cette fonction est bloquante tant que la connexion n'a pas été établie.
672 * S'il existe un cookie en local on s'authentifie directement avec lui.
673 * Si il n'est pas possible de s'authentifier alors on affiche un captcha anti-bot.
675 Client
.prototype.connexionCookie = function()
678 if (this.cookie
== null) return false;
679 return this.connexion(this.getJSONLoginCookie())
682 Client
.prototype.connexionLogin = function(login
, password
)
684 return this.connexion(this.getJSONLogin(login
, password
))
687 Client
.prototype.enregistrement = function(login
, password
)
689 if (this.authentifie())
692 this.password
= password
695 this.setStatut(statutType
.auth_registered
)
702 return this.connexion(this.getJSONEnregistrement(login
, password
))
706 Client
.prototype.connexion = function(messageJson
)
708 ;;; dumpObj(messageJson
)
716 data: this.util
.jsonVersAction(messageJson
),
721 if (data
["reply"] == "error")
722 thisClient
.util
.messageDialogue(data
["error_message"])
724 thisClient
.chargerDonnees(data
)
728 return this.authentifie()
731 Client
.prototype.deconnexion = function()
735 this.resetDonneesPersonnelles()
736 this.setStatut(statutType
.deconnected
) // deconnexion
739 Client
.prototype.chargerDonnees = function(data
)
741 // la modification du statut qui suit met à jour le menu, le menu dépend (page admin)
742 // de l'état ekMaster
743 this.ekMaster
= data
["ek_master"] != undefined ? data
["ek_master"] : false
745 this.setStatut(data
["status"])
747 if (this.authentifie())
749 this.cookie
= data
["cookie"]
753 this.login
= data
["login"]
754 this.pseudo
= data
["nick"]
755 this.email
= data
["email"]
756 this.setCss(data
["css"])
757 this.nickFormat
= data
["nick_format"]
759 // la page de la conversation principale
760 this.pagePrincipale
= data
["main_page"] == undefined ? 1 : data
["main_page"]
763 this.conversations
= data
["conversations"]
768 * Met à jour les données personne sur serveur.
769 * @param async de manière asynchrone ? défaut = true
770 * @return false si le flush n'a pas pû se faire sinon true
772 Client
.prototype.flush = function(async
)
774 if (async
== undefined)
777 if (!this.authentifie())
780 var thisClient
= this
783 ;;; dumpObj(this.getJSONProfile())
790 data: this.util
.jsonVersAction(this.getJSONProfile()),
795 if (data
["reply"] == "error")
797 thisClient
.util
.messageDialogue(data
["error_message"])
807 Client
.prototype.majMenu = function()
809 // TODO : à virer : ne plus changer de style de display ... spa beau .. ou trouver une autre méthode
810 // var displayType = this.css == "css/3/euphorik.css" ? "block" : "inline" //this.client
811 displayType
= "block"
813 $("#menu .admin").css("display", this.ekMaster
? displayType : "none")
815 // met à jour le menu
816 if (this.statut
== statutType
.auth_registered
)
818 $("#menu .profile").css("display", displayType
).text("profile")
819 $("#menu .logout").css("display", displayType
)
820 $("#menu .register").css("display", "none")
822 else if (this.statut
== statutType
.auth_not_registered
)
824 $("#menu .profile").css("display", "none")
825 $("#menu .logout").css("display", displayType
)
826 $("#menu .register").css("display", displayType
)
830 $("#menu .profile").css("display", displayType
).text("login")
831 $("#menu .logout").css("display", "none")
832 $("#menu .register").css("display", displayType
)
836 Client
.prototype.slap = function(userId
, raison
)
838 var thisClient
= this
844 data: this.util
.jsonVersAction(
847 "cookie" : thisClient
.cookie
,
854 if (data
["reply"] == "error")
855 thisClient
.util
.messageDialogue(data
["error_message"])
860 Client
.prototype.ban = function(userId
, raison
, minutes
)
862 var thisClient
= this
864 // par défaut un ban correspond à 3 jours
865 if (typeof(minutes
) == "undefined")
866 minutes
= 60 * 24 * 3
872 data: this.util
.jsonVersAction(
875 "cookie" : thisClient
.cookie
,
876 "duration" : minutes
,
883 if (data
["reply"] == "error")
884 thisClient
.util
.messageDialogue(data
["error_message"])
889 Client
.prototype.kick = function(userId
, raison
)
891 this.ban(userId
, raison
, 15)
894 ///////////////////////////////////////////////////////////////////////////////////////////////////
897 * classe permettant de gérer les événements (push serveur).
900 function PageEvent(page
, util
)
905 // l'objet JSONHttpRequest représentant la connexion d'attente
906 this.attenteCourante
= null
910 * Arrête l'attente courante s'il y en a une.
912 PageEvent
.prototype.stopAttenteCourante = function()
914 if (this.attenteCourante
!= null)
915 this.attenteCourante
.abort()
919 * Attend un événement lié à la page.
920 * @funSend une fonction renvoyant les données json à envoyer
921 * @funReceive une fonction qui accepte un paramètre correspondant au données reçues
923 PageEvent
.prototype.waitEvent = function(funSend
, funReceive
)
925 var thisPageEvent
= this
927 this.stopAttenteCourante()
929 // on doit conserver l'ordre des valeurs de l'objet JSON (le serveur les veux dans l'ordre définit dans le protocole)
930 // TODO : ya pas mieux ?
933 "action" : "wait_event",
936 var poulpe
= funSend()
938 dataToSend
[v
] = poulpe
[v
]
940 ;;; dumpObj(dataToSend
)
941 this.attenteCourante
= jQuery
.ajax({
945 data: this.util
.jsonVersAction(dataToSend
),
953 // rappel de la fonction dans 100 ms
954 setTimeout(function(){ thisPageEvent
.waitEvent(funSend
, funReceive
) }, 100);
957 function(XMLHttpRequest
, textStatus
, errorThrown
)
959 setTimeout(function(){ thisPageEvent
.waitEvent(funSend
, funReceive
) }, 1000);
965 ///////////////////////////////////////////////////////////////////////////////////////////////////
967 function initialiserListeStyles(client
)
969 $("#menuCss").change(
972 client
.setCss("css/" + $("option:selected", this).attr("value") + "/euphorik.css")
977 // charge dynamiquement le script de debug
978 ;;; jQuery
.ajax({async : false, url : "js/debug.js", dataType : "script"})
984 var formateur
= new Formateur()
985 var util
= new Util(formateur
)
986 var client
= new Client(util
)
987 var pages
= new Pages()
989 // connexion vers le serveur (utilise un cookie qui traine)
990 client
.connexionCookie()
992 initialiserListeStyles(client
)
994 // FIXME : ne fonctionne pas sous opera
995 // voir : http://dev.jquery.com/ticket/2892#preview
996 $(window
).unload(function(){client
.flush()})
998 $("#menu .minichat").click(function(){ pages
.afficherPage("minichat") })
999 $("#menu .admin").click(function(){ pages
.afficherPage("admin") })
1000 $("#menu .profile").click(function(){ pages
.afficherPage("profile") })
1001 $("#menu .logout").click(function(){
1002 util
.messageDialogue("Êtes-vous sur de vouloir vous délogger ?", messageType
.question
,
1005 client
.deconnexion();
1006 pages
.afficherPage("minichat", true)
1008 "Non" : function(){}
1012 $("#menu .register").click(function(){ pages
.afficherPage("register") })
1013 $("#menu .about").click(function(){ pages
.afficherPage("about") })
1015 pages
.ajouterPage(new PageMinichat(client
, formateur
, util
))
1016 pages
.ajouterPage(new PageAdmin(client
, formateur
, util
))
1017 pages
.ajouterPage(new PageProfile(client
, formateur
, util
))
1018 pages
.ajouterPage(new PageRegister(client
, formateur
, util
))
1019 pages
.ajouterPage(new PageAbout(client
, formateur
, util
))
1020 pages
.afficherPage("minichat")