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".
26 // tout euphorik est contenu dans cet objet
28 // ;; euphorik.include =
29 //;; euphorik.include = function(f) { var s = document.createElement('script'); s.type = 'text/javascript'; s.src = "js/" + f + ".js"; document.getElementsByTagName('head')[0].appendChild(s); }
32 // version jQuery : function(f) { jQuery.ajax({async : false, url : "js/" + f + ".js", dataType : "script"}) }
33 // mais comme il n'est pas encore chargé...
34 ;; euphorik
.include = function(f
) {
35 ;; var req
, url
= 'js/' + f
+ '.js'
36 ;; if (window
.XMLHttpRequest
) {
37 ;; req
= new XMLHttpRequest(); req
.open("GET", url
, false); req
.send(null);
38 ;; } else if (window
.ActiveXObject
) {
39 ;; req
= new ActiveXObject((navigator
.userAgent
.toLowerCase().indexOf('msie 5') != -1) ? "Microsoft.XMLHTTP" : "Msxml2.XMLHTTP");
40 ;; if (req
) { req
.open("GET", url
, false); req
.send(); }
42 ;; if (req
!==false) { if (req
.status
==200) { window
.eval(req
.responseText
); } else if (req
.status
==404) { alert("erreur de chargement (404) de : " + url
) } }
45 ;; euphorik
.include("jquery");
46 ;; euphorik
.include("jquery.lightbox");
47 ;; euphorik
.include("md5");
48 ;; euphorik
.include("json2");
50 ;; euphorik
.include("conf");
51 ;; euphorik
.include("util");
52 ;; euphorik
.include("formateur");
53 ;; euphorik
.include("pages");
54 ;; euphorik
.include("client");
55 ;; euphorik
.include("pageEvent");
57 ;; euphorik
.include("pageMinichat");
58 ;; euphorik
.include("pageAdmin");
59 ;; euphorik
.include("pageProfile");
60 ;; euphorik
.include("pageRegister");
61 ;; euphorik
.include("pageAbout");
63 // tout un tas d'améliorations de JavaScript ;)
65 * Pour chaque propriété de l'objet execute f(p, v) ou p est le nom de la propriété et v sa valeur.
66 * Ne parcours pas les propriétés des prototypes.
67 * FIXME : Normalement : Object.prototype.each = function(f) mais non supporté par jquery
69 //Object.prototype.each = function(f) {
70 var objectEach = function(o
, f
) {
72 if (o
.hasOwnProperty(k
)) {
78 Array
.prototype.each = function(f
) {
79 for (var i
= 0; i
< this.length
; i
++) {
84 Array
.prototype.map = function(f
) {
85 for (var i
= 0; i
< this.length
; i
++) {
90 String
.prototype.trim = function() {
91 return jQuery
.trim(this) // anciennement : this.replace(/^\s+|\s+$/g, "");
94 String
.prototype.ltrim = function() {
95 return this.replace(/^\s+/, "");
98 String
.prototype.rtrim = function() {
99 return this.replace(/\s+$/, "");
104 * Voir : http://www.coolpage.com/developer/javascript/Correct%20OOP%20for%20Javascript.html
108 * function Mammal(name) {
112 * Cat.Inherits(Mammal);
113 * function Cat(name) {
114 * this.Super(Mammal, name);
117 /*Object.prototype.Super = function(parent) {
118 if(arguments.length > 1) {
119 parent.apply( this, Array.prototype.slice.call( arguments, 1 ) );
124 Function.prototype.Inherits = function(parent) {
125 this.prototype = new parent();
126 this.prototype.constructor = this;
131 ///////////////////////////////////////////////////////////////////////////////////////////////////
138 var formateur
= new euphorik
.Formateur()
139 var util
= new euphorik
.Util(formateur
)
140 var client
= new euphorik
.Client(util
)
141 var pages
= new euphorik
.Pages()
144 // connexion vers le serveur (utilise un cookie qui traine)
145 client
.connexionCookie()
147 $("#menuCss").change(function(){ client
.setCss("styles/" + $("option:selected", this).attr("value") + "/euphorik.css")})
149 // FIXME : ne fonctionne pas sous opera
150 // voir : http://dev.jquery.com/ticket/2892#preview
151 $(window
).unload(function(){client
.flush()})
153 $("#menu .minichat").click(function(){ pages
.afficherPage("minichat") })
154 $("#menu .admin").click(function(){ pages
.afficherPage("admin") })
155 $("#menu .profile").click(function(){ pages
.afficherPage("profile") })
156 $("#menu .logout").click(function(){
157 util
.messageDialogue("Êtes-vous sur de vouloir vous délogger ?", euphorik
.Util
.messageType
.question
,
160 client
.deconnexion();
161 pages
.afficherPage("minichat", true)
167 $("#menu .register").click(function(){ pages
.afficherPage("register") })
168 $("#menu .about").click(function(){ pages
.afficherPage("about") })
170 // TODO : simplifier et pouvoir créer des liens par exemple : <span class="lien" href="conditions">Conditions d'utilisation</span>
171 $("#footer .conditions").click(function(){ pages
.afficherPage("conditions_utilisation") })
173 pages
.ajouterPage(new PageMinichat(client
, formateur
, util
))
174 pages
.ajouterPage(new euphorik
.PageAdmin(client
, formateur
, util
))
175 pages
.ajouterPage(new euphorik
.PageProfile(client
, formateur
, util
))
176 pages
.ajouterPage(new euphorik
.PageRegister(client
, formateur
, util
))
177 pages
.ajouterPage(new euphorik
.PageAbout(client
, formateur
, util
))
178 pages
.ajouterPage("conditions_utilisation")
180 pages
.afficherPage("minichat")