-// coding: utf-8\r
-\r
-/**\r
- * Contient la base javascript pour le site euphorik.ch.\r
- * Chaque page possède son propre fichier js nommé "page<nom de la page>.js".
- * Auteur : GBurri
- * Date : 6.11.2007
- */
-
-/**
- * La configuration.\r
- * Normalement 'const' à la place de 'var' mais non supporté par IE7.
- */\r
-var conf = {\r
- nbMessageAffiche : 10, // (par page)
- pseudoDefaut : "<nick>",\r
- tempsAffichageMessageDialogue : 4000, // en ms\r
- smiles : { \r
- "smile" : [/:\)/g, /:-\)/g], \r
- "bigsmile" : [/:D/g, /:-D/g],\r
- "clin" : [/;\)/g, /;-\)/g],\r
- "cool" : [/8\)/g, /8-\)/g],\r
- "eheheh" : [/:P/g, /:-P/g],\r
- "oh" : [/:o/g, /:O/g],\r
- "pascontent" : [/>\(/g, />\(/g],\r
- "sniff" : [/:\(/g, /:-\(/g],\r
- "argn" : [/\[:argn\]/g],\r
- "bunny" : [/\[:lapin\]/g],\r
- "chat" : [/\[:chat\]/g],\r
- "renne" : [/\[:renne\]/g],\r
- "lol" : [/\[:lol\]/g],\r
- "spliff" : [/\[:spliff\]/g],\r
- "star" : [/\[:star\]/g],\r
- "triste" : [/\[:triste\]/g],\r
- "kirby" : [/\[:kirby\]/g]\r
- }\r
-}\r
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-\r
-String.prototype.trim = function()\r
-{\r
- return this.replace(/^\s+|\s+$/g, "");\r
-}\r
-\r
-String.prototype.ltrim = function()\r
-{\r
- return this.replace(/^\s+/, "");\r
-}\r
-\r
-String.prototype.rtrim = function()\r
-{\r
- return this.replace(/\s+$/, "");\r
-}\r
-\r
-String.prototype.dump = function(titre)\r
-{
- titre = titre == undefined ? "" : titre\r
- if (typeof dump != "undefined")\r
- {\r
- dump("\n--- EUPHORIK.CH : " + titre + " ---\n")\r
- dump(this)\r
- dump("\n------\n")\r
- }\r
-}\r
-\r
-///////////////////////////////////////////////////////////////////////////////////////////////////\r
-\r
-/**\r
- * Cette classe regroupe des fonctions utilitaires (helpers).\r
- */
-function Util()
-{\r
- if(typeof XMLSerializer != "undefined")
- this.serializer = new XMLSerializer()
-
- jQuery("#info .fermer").click(function(){
- jQuery("#info").slideUp(50)
- })
-}
-
-/**
- * Affiche une boite de dialogue avec un message à l'intérieur.
- * @param message le message (string)\r
- * @param type voir 'messageType'. par défaut messageType.informatif\r
- * @param les boutons sous la forme d'un objet ou les clefs sont les labels des boutons\r
- * et les valeurs les fonctions executées lorsqu'un bouton est activé.
- */
-Util.prototype.messageDialogue = function(message, type, boutons)
-{
- if (type == undefined)
- type = messageType.informatif
-
- if (this.timeoutMessageDialogue != undefined)
- clearTimeout(this.timeoutMessageDialogue)
-
- var fermer = function(){jQuery("#info").slideUp(100)}
- fermer()
-
- jQuery("#info .message").html(message)
- switch(type)
- {
- case messageType.informatif : jQuery("#info #icone").attr("class", "information"); break
- case messageType.question : jQuery("#info #icone").attr("class", "interrogation"); break
- case messageType.erreur : jQuery("#info #icone").attr("class", "exclamation"); break
- }
- jQuery("#info .boutons").html("")
- for (var b in boutons)
- jQuery("#info .boutons").append("<div>" + b + "</div>").find("div:last").click(boutons[b]).click(fermer)
-
- jQuery("#info").slideDown(200)
- this.timeoutMessageDialogue = setTimeout(fermer, conf.tempsAffichageMessageDialogue)
-}
-var messageType = {informatif: 0, question: 1, erreur: 2}
-\r
-/**\r
- * Transforme un document XML en string.\r
- */\r
-Util.prototype.serializeXML = function(documentXML)\r
-{\r
- if (this.serializer)\r
- return this.serializer.serializeToString(documentXML)\r
- else\r
- return documentXML.xml\r
-}\r
-
-var documentXMLBase = undefined // singleton
-Util.prototype.creerDocumentXMLAction = function()
-{
- // FIXME : essayer de garder le doc de base en cache (singleton) et d'en retourner une copie
- if (true)//documentXMLBase == undefined)
- {\r
- if (document.implementation && document.implementation.createDocument)\r
- {\r
- // var doc = document.implementation.createDocument("", "action", null)
- var parser = new DOMParser();
- documentXMLBase = parser.parseFromString("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n<action/>", "text/xml")
- //alert(this.serializeXML(doc))\r
- }\r
- else if (window.ActiveXObject)\r
- {\r
- documentXMLBase = new ActiveXObject("MSXML2.DOMDocument") //("Microsoft.XMLDOM")\r
- documentXMLBase.appendChild(doc.createElement("action"));\r
- //doc.loadXML("<action></action>")\r
- //alert(doc.documentElement)\r
- //doc.createElement("action")\r
- }
- }
- return documentXMLBase
-}
-
-Util.prototype.xmlVersAction = function(xml)
-{
- //return {action: this.to_utf8(this.serializeXML(xml /*, "UTF-8"*/))}
- return {action: this.serializeXML(xml)}
-}
-\r
-Util.prototype.md5 = function(chaine)\r
-{\r
- return hex_md5(chaine)\r
-}
-\r
-// pompé de http://www.faqts.com/knowledge_base/view.phtml/aid/13562/fid/130\r
-Util.prototype.setSelectionRange = function(input, selectionStart, selectionEnd)
-{\r
- if (input.setSelectionRange)
- {\r
- input.focus()\r
- input.setSelectionRange(selectionStart, selectionEnd)\r
- }\r
- else if (input.createTextRange)
- {\r
- var range = input.createTextRange()\r
- range.collapse(true)\r
- range.moveEnd('character', selectionEnd)\r
- range.moveStart('character', selectionStart)\r
- range.select()\r
- }\r
-}
-\r
-Util.prototype.setCaretToEnd = function(input)
-{\r
- this.setSelectionRange(input, input.value.length, input.value.length)\r
-}\r
-Util.prototype.setCaretToBegin = function(input)
-{\r
- this.setSelectionRange(input, 0, 0)\r
-}\r
-Util.prototype.setCaretToPos = function(input, pos)
-{\r
- this.setSelectionRange(input, pos, pos)\r
-}\r
-Util.prototype.selectString = function(input, string)
-{\r
- var match = new RegExp(string, "i").exec(input.value)\r
- if (match)
- {\r
- this.setSelectionRange (input, match.index, match.index + match[0].length)\r
- }\r
-}\r
-Util.prototype.replaceSelection = function(input, replaceString) {\r
- if (input.setSelectionRange)
- {\r
- var selectionStart = input.selectionStart\r
- var selectionEnd = input.selectionEnd\r
- input.value = input.value.substring(0, selectionStart) + replaceString + input.value.substring(selectionEnd)
- \r
- if (selectionStart != selectionEnd) // has there been a selection\r
- this.setSelectionRange(input, selectionStart, selectionStart + replaceString.length)\r
- else // set caret\r
- this.setCaretToPos(input, selectionStart + replaceString.length)\r
- }\r
- else if (document.selection)
- {\r
- var range = document.selection.createRange();\r
- if (range.parentElement() == input)
- {\r
- var isCollapsed = range.text == ''\r
- range.text = replaceString\r
- if (!isCollapsed)
- {
- // there has been a selection\r
- // it appears range.select() should select the newly \r
- // inserted text but that fails with IE\r
- range.moveStart('character', -replaceString.length);\r
- range.select();\r
- }\r
- }\r
- }\r
-}
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-function Pages()
-{
- this.pageCourante = null
- this.pages = {}
-}
-
-Pages.prototype.ajouterPage = function(page)
-{
- page.pages = this // la magie des langages dynamiques : le foutoire
- this.pages[page.nom] = page
-}
-
-Pages.prototype.afficherPage = function(nomPage, forcerChargement)
-{\r
- if (forcerChargement == undefined) forcerChargement = false\r
-
- var page = this.pages[nomPage]
- if (page == undefined || (!forcerChargement && page == this.pageCourante)) return
-
- if (this.pageCourante != null && this.pageCourante.decharger)
- this.pageCourante.decharger()
-
- jQuery("#menu div").removeClass("courante")
- jQuery("#menu div." + nomPage).addClass("courante")
-
- this.pageCourante = page
- jQuery("#page").html(this.pageCourante.contenu()).removeClass().addClass(this.pageCourante.nom)
-
- if (this.pageCourante.charger)
- this.pageCourante.charger()
-}
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-function Formateur()
-{
- this.smiles = conf.smiles\r
- this.protocoles = "http|https|ed2k"\r
- \r
- this.regexUrl = new RegExp("(?:(?:" + this.protocoles + ")://|www\\.)[^ ]*", "gi")\r
- this.regexImg = new RegExp("^.*?\\.(gif|jpg|png|jpeg|bmp|tiff)$", "i")\r
- this.regexDomaine = new RegExp("^(?:(?:" + this.protocoles + ")://|www\\.).*?([^/.]+\\.[^/.]+)(?:$|/).*$", "i")\r
- this.regexTestProtocoleExiste = new RegExp("^(?:" + this.protocoles + ")://.*$", "i")\r
- this.regexNomProtocole = new RegExp("^(.*?)://")
-}
-
-/**
- * Formate un pseudo saise par l'utilisateur.
- * @param pseudo le pseudo brut
- * @return le pseudo filtré
- */
-Formateur.prototype.filtrerInputPseudo = function(pseudo)
-{
- return pseudo.replace(/{|}/g, "").trim()
-}
-\r
-Formateur.prototype.getSmilesHTML = function()\r
-{\r
- var XHTML = ""\r
- for (var sNom in this.smiles)\r
- {\r
- XHTML += "<img class=\"" + sNom + "\" src=\"img/smileys/" + sNom + ".gif\" />"\r
- }\r
- return XHTML\r
-}\r
-
-Formateur.prototype.traitementComplet = function(M, pseudo)
-{
- return this.traiterSmiles(this.traiterURL(this.remplacerBalisesHTML(M), pseudo))
-}
-\r
-/**\r
- * FIXME : Cette méthode est attrocement lourde ! A optimiser.\r
- */
-Formateur.prototype.traiterSmiles = function(M)
-{
- for (var sNom in this.smiles)
- {
- ss = this.smiles[sNom]
- for (var i = 0; i < ss.length; i++)
- M = M.replace(ss[i], "<img src=\"img/smileys/" + sNom + ".gif\" />")
- }
- return M
-}
-
-Formateur.prototype.remplacerBalisesHTML = function(M)
-{
- return M.replace(/</g, "<").replace(/>/g, ">")
-}
-
-Formateur.prototype.traiterURL = function(M, pseudo)
-{
- thisFormateur = this
-
- if (pseudo == undefined)
- pseudo = ""
-
- var traitementUrl = function(url)
- { \r
- // si ya pas de protocole on rajoute "http://"\r
- if (!thisFormateur.regexTestProtocoleExiste.test(url))\r
- url = "http://" + url
- var extension = thisFormateur.getShort(url)
- return "<a " + (extension[1] ? "title=\"" + thisFormateur.traiterPourFenetreLightBox(pseudo, url) + ": " + thisFormateur.traiterPourFenetreLightBox(M, url) + "\"" + " rel=\"lightbox[groupe]\"" : "") + " href=\"" + url + "\" >[" + extension[0] + "]</a>"
- }
- return M.replace(this.regexUrl, traitementUrl)
-}
-\r
-/**\r
- * Renvoie une version courte de l'url.\r
- * par exemple : http://en.wikipedia.org/wiki/Yakov_Smirnoff devient wikipedia.org\r
- */
-Formateur.prototype.getShort = function(url)
-{\r
- var estUneImage = false
- var versionShort = null
- var rechercheImg = this.regexImg.exec(url)\r
- //alert(url)
- if (rechercheImg != null)\r
- {
- versionShort = rechercheImg[1].toLowerCase()\r
- if (versionShort == "jpeg") versionShort = "jpg" // jpeg -> jpg\r
- estUneImage = true\r
- }\r
- else\r
- {\r
- var rechercheDomaine = this.regexDomaine.exec(url)\r
- if (rechercheDomaine != null && rechercheDomaine.length >= 2)\r
- versionShort = rechercheDomaine[1]\r
- else\r
- {\r
- var nomProtocole = this.regexNomProtocole.exec(url)\r
- if (nomProtocole != null && nomProtocole.length >= 2)\r
- versionShort = nomProtocole[1]\r
- }\r
- }\r
-
- return [versionShort == null ? "url" : versionShort, estUneImage]
- }
-
-/**
- * Traite les pseudo et messages à être affiché dans le titre d'une image visualisé avec lightbox.
- */
-Formateur.prototype.traiterPourFenetreLightBox = function(M, urlCourante)
-{
- thisFormateur = this
- var traitementUrl = function(url)
- {
- return "[" + thisFormateur.getShort(url)[0] + (urlCourante == url ? ": image courante" : "") + "]"
- }
- \r
- return this.remplacerBalisesHTML(M).replace(this.regexUrl, traitementUrl)
-}
-
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-var statutType = {enregistre: 0, identifie: 1, non_identifie: 2}
-\r
-function Client(util)\r
-{
- this.util = util
- \r
- this.cookie = null
- this.regexCookie = new RegExp("^cookie=([^;]*)")
-
- // données personnels\r
- this.resetDonneesPersonnelles()
-
- this.setStatut(statutType.non_identifie)
-
- // le dernier message d'erreur recut du serveur (par exemple une connexion foireuse : "login impossible")
- this.dernierMessageErreur = ""\r
-}
-\r
-Client.prototype.resetDonneesPersonnelles = function()\r
-{\r
- this.pseudo = conf.pseudoDefaut\r
- this.login = ""\r
- this.password = ""\r
- this.email = ""\r
- this.css = jQuery("link#cssPrincipale").attr("href")
-
- this.pagePrincipale = 1
-
- // les conversations, une conversation est un objet possédant les attributs suivants :
- // - racine (entier)
- // - page (entier)
- this.conversations = new Array()\r
-}
-
-Client.prototype.setCss = function(css)
-{
- if (this.css == css)
- return
-
- this.css = css
- jQuery("link#cssPrincipale").attr("href", this.css)
- this.majMenu()