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
)
469 // si true alors chaque modification du client est mémorisé sur le serveur
470 this.autoflush
= $.browser
["opera"]
473 Client
.prototype.resetDonneesPersonnelles = function()
476 this.pseudo
= conf
.pseudoDefaut
480 this.css
= $("link#cssPrincipale").attr("href")
481 this.nickFormat
= "nick"
482 this.cookie
= undefined
484 this.pagePrincipale
= 1
485 this.ekMaster
= false
487 // les conversations, une conversation est un objet possédant les attributs suivants :
490 this.conversations
= new Array()
493 Client
.prototype.setCss = function(css
)
495 if (this.css
== css
|| css
== "")
499 $("link#cssPrincipale").attr("href", this.css
)
502 if (this.autoflush
) this.flush(true)
505 Client
.prototype.pageSuivante = function(numConv
)
507 if (numConv
< 0 && this.pagePrincipale
> 1)
508 this.pagePrincipale
-= 1
509 else if (this.conversations
[numConv
].page
> 1)
510 this.conversations
[numConv
].page
-= 1
513 Client
.prototype.pagePrecedente = function(numConv
)
516 this.pagePrincipale
+= 1
518 this.conversations
[numConv
].page
+= 1
522 * Définit la première page pour la conversation donnée.
523 * @return true si la page a changé sinon false
525 Client
.prototype.goPremierePage = function(numConv
)
529 if (this.pagePrincipale
== 1)
531 this.pagePrincipale
= 1
535 if (this.conversations
[numConv
].page
== 1)
537 this.conversations
[numConv
].page
= 1
543 * Ajoute une conversation à la vue de l'utilisateur.
544 * Le profile de l'utilisateur est directement sauvegardé sur le serveur.
545 * @param racines la racine de la conversation (integer)
546 * @return true si la conversation a été créée sinon false (par exemple si la conv existe déjà)
548 Client
.prototype.ajouterConversation = function(racine
)
550 // vérification s'il elle n'existe pas déjà
551 for (var i
= 0; i
< this.conversations
.length
; i
++)
552 if (this.conversations
[i
].root
== racine
)
555 this.conversations
.push({root : racine
, page : 1})
557 if (this.autoflush
) this.flush(true)
562 Client
.prototype.supprimerConversation = function(num
)
564 if (num
< 0 || num
>= this.conversations
.length
) return
566 // décalage TODO : supprimer le dernier élément
567 for (var i
= num
; i
< this.conversations
.length
- 1; i
++)
568 this.conversations
[i
] = this.conversations
[i
+1]
569 this.conversations
.pop()
571 if (this.autoflush
) this.flush(true)
574 Client
.prototype.getJSONLogin = function(login
, password
)
577 "action" : "authentification",
579 "password" : password
583 Client
.prototype.getJSONLoginCookie = function()
586 "action" : "authentification",
587 "cookie" : this.cookie
592 * le couple (login, password) est facultatif. S'il n'est pas fournit alors il ne sera pas possible
593 * de s'autentifier avec (login, password).
595 Client
.prototype.getJSONEnregistrement = function(login
, password
)
597 var mess
= { "action" : "register" }
599 if (login
!= undefined && password
!= undefined)
601 mess
["login"] = login
602 mess
["password"] = password
608 Client
.prototype.getJSONConversations = function()
610 var conversations
= new Array()
611 for (var i
= 0; i
< this.conversations
.length
; i
++)
612 conversations
.push({ "root" : this.conversations
[i
].root
, "page" : this.conversations
[i
].page
})
616 Client
.prototype.getJSONProfile = function()
619 "action" : "set_profile",
620 "cookie" : this.cookie
,
621 "login" : this.login
,
622 "password" : this.password
,
623 "nick" : this.pseudo
,
624 "email" : this.email
,
626 "nick_format" : this.nickFormat
,
627 "main_page" : this.pagePrincipale
< 1 ? 1 : this.pagePrincipale
,
628 "conversations" : this.getJSONConversations()
633 * Renvoie null si pas définit.
635 Client
.prototype.getCookie = function()
637 var cookie
= this.regexCookie
.exec(document
.cookie
)
638 if (cookie
== null) this.cookie
= null
639 else this.cookie
= cookie
[1]
642 Client
.prototype.delCookie = function()
644 document
.cookie
= "cookie=; max-age=0"
647 Client
.prototype.setCookie = function(cookie
)
649 if (this.cookie
== null)
653 "cookie="+this.cookie
+
654 "; max-age=" + (60 * 60 * 24 * 365)
657 Client
.prototype.authentifie = function()
659 return this.statut
== statutType
.auth_registered
|| this.statut
== statutType
.auth_not_registered
662 Client
.prototype.setStatut = function(statut
)
664 // conversation en "enum" si en "string"
665 if (typeof(statut
) == "string")
668 statut
== "auth_registered" ?
669 statutType
.auth_registered :
670 (statut
== "auth_not_registered" ? statutType
.auth_not_registered : statutType
.deconnected
)
673 if (statut
== this.statut
) return
680 * Effectue la connexion vers le serveur.
681 * Cette fonction est bloquante tant que la connexion n'a pas été établie.
682 * S'il existe un cookie en local on s'authentifie directement avec lui.
683 * Si il n'est pas possible de s'authentifier alors on affiche un captcha anti-bot.
685 Client
.prototype.connexionCookie = function()
688 if (this.cookie
== null) return false;
689 return this.connexion(this.getJSONLoginCookie())
692 Client
.prototype.connexionLogin = function(login
, password
)
694 return this.connexion(this.getJSONLogin(login
, password
))
697 Client
.prototype.enregistrement = function(login
, password
)
699 if (this.authentifie())
702 this.password
= password
705 this.setStatut(statutType
.auth_registered
)
712 return this.connexion(this.getJSONEnregistrement(login
, password
))
716 Client
.prototype.connexion = function(messageJson
)
718 ;;; dumpObj(messageJson
)
726 data: this.util
.jsonVersAction(messageJson
),
731 if (data
["reply"] == "error")
732 thisClient
.util
.messageDialogue(data
["error_message"])
734 thisClient
.chargerDonnees(data
)
738 return this.authentifie()
741 Client
.prototype.deconnexion = function()
745 this.resetDonneesPersonnelles()
746 this.setStatut(statutType
.deconnected
) // deconnexion
749 Client
.prototype.chargerDonnees = function(data
)
751 // la modification du statut qui suit met à jour le menu, le menu dépend (page admin)
752 // de l'état ekMaster
753 this.ekMaster
= data
["ek_master"] != undefined ? data
["ek_master"] : false
755 this.setStatut(data
["status"])
757 if (this.authentifie())
759 this.cookie
= data
["cookie"]
763 this.login
= data
["login"]
764 this.pseudo
= data
["nick"]
765 this.email
= data
["email"]
766 this.setCss(data
["css"])
767 this.nickFormat
= data
["nick_format"]
769 // la page de la conversation principale
770 this.pagePrincipale
= data
["main_page"] == undefined ? 1 : data
["main_page"]
773 this.conversations
= data
["conversations"]
778 * Met à jour les données personne sur serveur.
779 * @param async de manière asynchrone ? défaut = true
780 * @return false si le flush n'a pas pû se faire sinon true
782 Client
.prototype.flush = function(async
)
784 if (async
== undefined)
787 if (!this.authentifie())
790 var thisClient
= this
793 ;;; dumpObj(this.getJSONProfile())
800 data: this.util
.jsonVersAction(this.getJSONProfile()),
805 if (data
["reply"] == "error")
807 thisClient
.util
.messageDialogue(data
["error_message"])
817 Client
.prototype.majMenu = function()
819 // TODO : à virer : ne plus changer de style de display ... spa beau .. ou trouver une autre méthode
820 // var displayType = this.css == "css/3/euphorik.css" ? "block" : "inline" //this.client
821 displayType
= "block"
823 $("#menu .admin").css("display", this.ekMaster
? displayType : "none")
825 // met à jour le menu
826 if (this.statut
== statutType
.auth_registered
)
828 $("#menu .profile").css("display", displayType
).text("profile")
829 $("#menu .logout").css("display", displayType
)
830 $("#menu .register").css("display", "none")
832 else if (this.statut
== statutType
.auth_not_registered
)
834 $("#menu .profile").css("display", "none")
835 $("#menu .logout").css("display", displayType
)
836 $("#menu .register").css("display", displayType
)
840 $("#menu .profile").css("display", displayType
).text("login")
841 $("#menu .logout").css("display", "none")
842 $("#menu .register").css("display", displayType
)
846 Client
.prototype.slap = function(userId
, raison
)
848 var thisClient
= this
854 data: this.util
.jsonVersAction(
857 "cookie" : thisClient
.cookie
,
864 if (data
["reply"] == "error")
865 thisClient
.util
.messageDialogue(data
["error_message"])
870 Client
.prototype.ban = function(userId
, raison
, minutes
)
872 var thisClient
= this
874 // par défaut un ban correspond à 3 jours
875 if (typeof(minutes
) == "undefined")
876 minutes
= 60 * 24 * 3
882 data: this.util
.jsonVersAction(
885 "cookie" : thisClient
.cookie
,
886 "duration" : minutes
,
893 if (data
["reply"] == "error")
894 thisClient
.util
.messageDialogue(data
["error_message"])
899 Client
.prototype.kick = function(userId
, raison
)
901 this.ban(userId
, raison
, 15)
904 ///////////////////////////////////////////////////////////////////////////////////////////////////
907 * classe permettant de gérer les événements (push serveur).
910 function PageEvent(page
, util
)
915 // l'objet JSONHttpRequest représentant la connexion d'attente
916 this.attenteCourante
= null
918 // le multhreading du pauvre, merci javascript de m'offrire autant de primitives pour la gestion de la concurrence...
923 * Arrête l'attente courante s'il y en a une.
925 PageEvent
.prototype.stopAttenteCourante = function()
929 if (this.attenteCourante
!= null)
931 this.attenteCourante
.abort()
936 * Attend un événement lié à la page.
937 * @funSend une fonction renvoyant les données json à envoyer
938 * @funReceive une fonction qui accepte un paramètre correspondant au données reçues
940 PageEvent
.prototype.waitEvent = function(funSend
, funReceive
)
942 this.stopAttenteCourante()
946 var thisPageEvent
= this
948 // on doit conserver l'ordre des valeurs de l'objet JSON (le serveur les veut dans l'ordre définit dans le protocole)
949 // TODO : ya pas mieux ?
952 "action" : "wait_event",
955 var poulpe
= funSend()
957 dataToSend
[v
] = poulpe
[v
]
959 ;;; dumpObj(dataToSend
)
961 this.attenteCourante
= jQuery
.ajax({
965 data: this.util
.jsonVersAction(dataToSend
),
973 // rappel de la fonction dans 100 ms
974 setTimeout(function(){ thisPageEvent
.waitEvent2(funSend
, funReceive
) }, 100)
977 function(XMLHttpRequest
, textStatus
, errorThrown
)
979 setTimeout(function(){ thisPageEvent
.waitEvent2(funSend
, funReceive
) }, 1000)
985 * Si un stopAttenteCourante survient un peu n'importe quand il faut imédiatement arreter de boucler.
987 PageEvent
.prototype.waitEvent2 = function(funSend
, funReceive
)
991 this.waitEvent(funSend
, funReceive
)
994 ///////////////////////////////////////////////////////////////////////////////////////////////////
996 function initialiserListeStyles(client
)
998 $("#menuCss").change(
1001 client
.setCss("css/" + $("option:selected", this).attr("value") + "/euphorik.css")
1006 // charge dynamiquement le script de debug
1007 ;;; jQuery
.ajax({async : false, url : "js/debug.js", dataType : "script"})
1013 var formateur
= new Formateur()
1014 var util
= new Util(formateur
)
1015 var client
= new Client(util
)
1016 var pages
= new Pages()
1018 // connexion vers le serveur (utilise un cookie qui traine)
1019 client
.connexionCookie()
1021 initialiserListeStyles(client
)
1023 // FIXME : ne fonctionne pas sous opera
1024 // voir : http://dev.jquery.com/ticket/2892#preview
1025 $(window
).unload(function(){client
.flush()})
1027 $("#menu .minichat").click(function(){ pages
.afficherPage("minichat") })
1028 $("#menu .admin").click(function(){ pages
.afficherPage("admin") })
1029 $("#menu .profile").click(function(){ pages
.afficherPage("profile") })
1030 $("#menu .logout").click(function(){
1031 util
.messageDialogue("Êtes-vous sur de vouloir vous délogger ?", messageType
.question
,
1034 client
.deconnexion();
1035 pages
.afficherPage("minichat", true)
1037 "Non" : function(){}
1041 $("#menu .register").click(function(){ pages
.afficherPage("register") })
1042 $("#menu .about").click(function(){ pages
.afficherPage("about") })
1044 pages
.ajouterPage(new PageMinichat(client
, formateur
, util
))
1045 pages
.ajouterPage(new PageAdmin(client
, formateur
, util
))
1046 pages
.ajouterPage(new PageProfile(client
, formateur
, util
))
1047 pages
.ajouterPage(new PageRegister(client
, formateur
, util
))
1048 pages
.ajouterPage(new PageAbout(client
, formateur
, util
))
1049 pages
.afficherPage("minichat")