X-Git-Url: http://git.euphorik.ch/?a=blobdiff_plain;f=js%2Feuphorik.js;h=8892035084063f08d89910e0964dbee0d1e1f216;hb=f55ef9d6bc7352e2dffe18ded028a5a2e0cc3936;hp=88ef6e73266c9e0ce30a6c1cc716bd8aaed09338;hpb=35838780dce22af9f2dc80af9149a30a0433de0a;p=euphorik.git diff --git a/js/euphorik.js b/js/euphorik.js index 88ef6e7..8892035 100755 --- a/js/euphorik.js +++ b/js/euphorik.js @@ -21,19 +21,27 @@ var conf = { "bigsmile" : [/:D/g, /:-D/g], "clin" : [/;\)/g, /;-\)/g], "cool" : [/8\)/g, /8-\)/g], - "eheheh" : [/:P/g, /:-P/g], - "oh" : [/:o/g, /:O/g], + "eheheh" : [/:P/g, /:-P/g], + "lol" : [/\[-lol\]/g], + "spliff" : [/\[-spliff\]/g], + "oh" : [/:o/g, /:O/g], + "heink" : [/\[-heink\]/g], + "hum" : [/\[-hum\]/g], + "boh" : [/\[-boh\]/g], + "sniff" : [/:\(/g, /:-\(/g], + "triste" : [/\[-triste\]/g], "pascontent" : [/>\(/g, />\(/g], - "sniff" : [/:\(/g, /:-\(/g], - "argn" : [/\[:argn\]/g], - "bunny" : [/\[:lapin\]/g], - "chat" : [/\[:chat\]/g], - "renne" : [/\[:renne\]/g], - "lol" : [/\[:lol\]/g], - "spliff" : [/\[:spliff\]/g], - "star" : [/\[:star\]/g], - "triste" : [/\[:triste\]/g], - "kirby" : [/\[:kirby\]/g] + "argn" : [/\[-argn\]/g], + "redface" : [/\[-redface\]/g], + "bunny" : [/\[-lapin\]/g], + "chat" : [/\[-chat\]/g], + "renne" : [/\[-renne\]/g], + "star" : [/\[-star\]/g], + "kirby" : [/\[-kirby\]/g], + "slurp" : [/\[-slurp\]/g], + "agreed" : [/\[-agreed\]/g], + "dodo" : [/\[-dodo\]/g], + "bn" : [/\[-bn\]/g] } } @@ -106,8 +114,7 @@ var messageType = {informatif: 0, question: 1, erreur: 2} */ Util.prototype.jsonVersAction = function(json) { - // FIXME : ne plus encapsuler json dans de l'xml (problème avec yaws) - return {action: "" + JSON.stringify(json) + "" } + return {action : JSON.stringify(json) } } Util.prototype.md5 = function(chaine) @@ -184,6 +191,29 @@ Util.prototype.replaceSelection = function(input, replaceString) { } } +Util.prototype.rot13 = function(chaine) +{ + var ACode = 'A'.charCodeAt(0) + var aCode = 'a'.charCodeAt(0) + var MCode = 'M'.charCodeAt(0) + var mCode = 'm'.charCodeAt(0) + var ZCode = 'Z'.charCodeAt(0) + var zCode = 'z'.charCodeAt(0) + + var f = function(ch, pos) { + if (pos == ch.length) + return "" + + var c = ch.charCodeAt(pos); + return String.fromCharCode( + c + + (c >= ACode && c <= MCode || c >= aCode && c <= mCode ? 13 : + (c > MCode && c <= ZCode || c > mCode && c <= zCode ? -13 : 0)) + ) + f(ch, pos + 1) + } + return f(chaine, 0) +} + /////////////////////////////////////////////////////////////////////////////////////////////////// function Pages() @@ -275,7 +305,8 @@ Formateur.prototype.traiterLiensConv = function(M) } /** - * FIXME : Cette méthode est attrocement lourde ! A optimiser. + * FIXME : Cette méthode est attrocement lourde ! A optimiser. + * moyenne su échantillon : 234ms */ Formateur.prototype.traiterSmiles = function(M) { @@ -306,7 +337,7 @@ Formateur.prototype.traiterURL = function(M, pseudo) if (!thisFormateur.regexTestProtocoleExiste.test(url)) url = "http://" + url var extension = thisFormateur.getShort(url) - return "[" + extension[0] + "]" + return "[" + extension[0] + "]" } return M.replace(this.regexUrl, traitementUrl) } @@ -393,8 +424,10 @@ Client.prototype.resetDonneesPersonnelles = function() this.password = "" this.email = "" this.css = jQuery("link#cssPrincipale").attr("href") + this.nickFormat = "nick" this.pagePrincipale = 1 + this.ekMaster = false // les conversations, une conversation est un objet possédant les attributs suivants : // - racine (entier) @@ -459,10 +492,10 @@ Client.prototype.ajouterConversation = function(racine) { // vérification s'il elle n'existe pas déjà for (var i = 0; i < this.conversations.length; i++) - if (this.conversations[i].racine == racine) + if (this.conversations[i].root == racine) return false - this.conversations.push({racine : racine, page : 1}) + this.conversations.push({root : racine, page : 1}) return true } @@ -514,7 +547,7 @@ Client.prototype.getJSONConversations = function() { var conversations = new Array() for (var i = 0; i < this.conversations.length; i++) - conversations.push({ "racine" : this.conversations[i].racine, "page" : this.conversations[i].page}) + conversations.push({ "root" : this.conversations[i].root, "page" : this.conversations[i].page}) return conversations } @@ -525,8 +558,10 @@ Client.prototype.getJSONProfile = function() "cookie" : this.cookie, "login" : this.login, "password" : this.password, + "nick" : this.pseudo, "email" : this.email, "css" : this.css, + "nick_format" : this.nickFormat, "main_page" : this.pagePrincipale < 1 ? 1 : this.pagePrincipale, "conversations" : this.getJSONConversations() } @@ -564,11 +599,12 @@ Client.prototype.authentifie = function() Client.prototype.setStatut = function(statut) { + //alert(statut) // conversation en "enum" si en "string" if (typeof(statut) == "string") { statut = - statut == "registered" ? + statut == "auth_registered" ? statutType.auth_registered : (statut == "auth_not_registered" ? statutType.auth_not_registered : statutType.deconnected) } @@ -636,10 +672,11 @@ Client.prototype.connexion = function(messageJson) } Client.prototype.deconnexion = function() -{ +{ + this.flush() + this.delCookie() this.setStatut(statutType.deconnected) // deconnexion this.resetDonneesPersonnelles() - this.delCookie () } Client.prototype.chargerDonnees = function(data) @@ -657,6 +694,7 @@ Client.prototype.chargerDonnees = function(data) this.pseudo = data["nick"] this.email = data["email"] this.css = data["css"] + this.nickFormat = data["nick_format"] // la page de la conversation principale this.pagePrincipale = data["main_page"] == undefined ? 1 : data["main_page"] @@ -670,6 +708,7 @@ Client.prototype.chargerDonnees = function(data) // les conversations thisClient.conversations = data["conversations"] + thisClient.ekMaster = data["ek_master"] } this.dernierMessageErreur = data["error_message"] } @@ -688,7 +727,7 @@ Client.prototype.flush = function(async) return false thisClient = this - //this.util.jsonVersAction(this.getJSONProfile()).action.dump("Flush client") + ;;; dumpObj(this.getJSONProfile()) jQuery.ajax( { async: async, @@ -732,9 +771,50 @@ Client.prototype.majMenu = function() } } +Client.prototype.ban = function(userId, minutes) +{ + var thisClient = this + + // par défaut un ban correspond à 3 jours + if (typeof(minutes) == "undefined") + minutes = 60 * 24 * 3 + + jQuery.ajax({ + type: "POST", + url: "request", + dataType: "json", + data: this.util.jsonVersAction( + { + "action" : "ban", + "cookie" : thisClient.cookie, + "duration" : minutes, + "user_id" : userId + }), + success: + function(data) + { + if (data["reply"] == "error") + thisClient.util.messageDialogue(data["error_message"]) + } + }) +} + +Client.prototype.kick = function(userId) +{ + this.ban(userId, 15) +} + /////////////////////////////////////////////////////////////////////////////////////////////////// -jQuery.noConflict() +function initialiserListeStyles(client) +{ + jQuery("#menuCss").change( + function() + { + client.setCss("css/" + jQuery("option:selected", this).attr("value") + "/euphorik.css") + } + ) +} // charge dynamiquement le script de debug ;;; jQuery.ajax({async : false, url : "js/debug.js", dataType : "script"}) @@ -743,12 +823,6 @@ jQuery.noConflict() jQuery(document).ready( function() { - /* FIXME : ce code pose problème sur konqueror, voir : http://www.kde-forum.org/thread.php?threadid=17993 - var p = new DOMParser(); - var doc = p.parseFromString("\n", "text/xml") - var s = new XMLSerializer() - alert(s.serializeToString(doc)) */ - var util = new Util() var client = new Client(util) var pages = new Pages() @@ -757,21 +831,10 @@ jQuery(document).ready( // connexion vers le serveur (utilise un cookie qui traine) client.connexionCookie() - // les styles css - for (var i = 1; i <= 3; i++) - { - jQuery("#css"+i).click(function(){ - client.setCss("css/" + jQuery(this).attr("id").charAt(3) + "/euphorik.css") - }) - } + initialiserListeStyles(client) - jQuery(document).unload( - function() - { - alert("ok") - client.flush() - } - ) + // TODO : pourquoi jQuery(document).unload ne fonctionne pas ? + jQuery(window).unload(function(){client.flush(false)}) jQuery("#menu .minichat").click(function(){ pages.afficherPage("minichat") }) jQuery("#menu .profile").click(function(){ pages.afficherPage("profile") }) @@ -787,10 +850,12 @@ jQuery(document).ready( ) }) jQuery("#menu .register").click(function(){ pages.afficherPage("register") }) + jQuery("#menu .about").click(function(){ pages.afficherPage("about") }) pages.ajouterPage(new PageMinichat(client, formateur, util)) pages.ajouterPage(new PageProfile(client, formateur, util)) pages.ajouterPage(new PageRegister(client, formateur, util)) + pages.ajouterPage(new PageAbout(client, formateur, util)) pages.afficherPage("minichat") } ) \ No newline at end of file