X-Git-Url: http://git.euphorik.ch/?a=blobdiff_plain;ds=sidebyside;f=js%2Feuphorik.js;h=893a32afcefad024173839cbbcdfea61d333dfe6;hb=808fb60f6c10dfcaccee94c6a49f768de84dc2ef;hp=28cba42f848e6c73878136ecf6803c7894c8c2a8;hpb=deff7a2f11dca2b300b258d1e93d71e3b2e34c84;p=euphorik.git
diff --git a/js/euphorik.js b/js/euphorik.js
index 28cba42..893a32a 100755
--- a/js/euphorik.js
+++ b/js/euphorik.js
@@ -16,129 +16,61 @@
// You should have received a copy of the GNU General Public License
// along with Euphorik. If not, see .
-/**
- * Contient la base javascript pour le site euphorik.ch.
- * Chaque page possède son propre fichier js nommé "page.js".
- * Auteur : GBurri
- * Date : 6.11.2007
- */
-
-// tout euphorik est contenu dans cet objet
-var euphorik = {}
-// ;; euphorik.include =
-// ;; euphorik.include = function(f) { var s = document.createElement('script'); s.type = 'text/javascript'; s.src = "js/" + f + ".js"; document.getElementsByTagName('head')[0].appendChild(s); }
-
-
-// version jQuery : function(f) { jQuery.ajax({async : false, url : "js/" + f + ".js", dataType : "script"}) }
-// mais comme il n'est pas encore chargé...
-;; euphorik.include = function(f) {
-;; var req, url = 'js/' + f + '.js'
-;; if (window.XMLHttpRequest) {
-;; req = new XMLHttpRequest(); req.open("GET", url, false /* async */); req.send(null);
-;; } else if (window.ActiveXObject) {
-;; req = new ActiveXObject((navigator.userAgent.toLowerCase().indexOf('msie 5') != -1) ? "Microsoft.XMLHTTP" : "Msxml2.XMLHTTP");
-;; if (req) { req.open("GET", url, false); req.send(); }
-;; }
-;; if (req!==false) { if (req.status==200) { window.eval(req.responseText); } else if (req.status==404) { alert("erreur de chargement (404) de : " + url) } }
-;; }
-
-;; euphorik.include("jquery")
-;; euphorik.include("jquery.lightbox")
-;; euphorik.include("md5")
-;; euphorik.include("json2")
-
-;; euphorik.include("conf")
-;; euphorik.include("util")
-;; euphorik.include("formateur")
-;; euphorik.include("pages")
-
-;; euphorik.include("pageMinichat")
-;; euphorik.include("pageAdmin")
-;; euphorik.include("pageProfile")
-;; euphorik.include("pageRegister")
-;; euphorik.include("pageAbout")
-
-
-// tout un tas d'améliorations de JavaScript ;)
-/**
- * Pour chaque propriété de l'objet execute f(p, v) ou p est le nom de la propriété et v sa valeur.
- * Ne parcours pas les propriétés des prototypes.
- */
-Object.prototype.each = function(f) {
- for (var k in this) {
- if (this.hasOwnProperty(k)) {
- f(k, this[k])
- }
- }
-}
-
-Array.prototype.each = function(f) {
- for (var i = 0; i < this.length; i++) {
- f(i, this[i])
- }
-}
-
-String.prototype.trim = function() {
- return jQuery.trim(this) // anciennement : this.replace(/^\s+|\s+$/g, "");
-}
-
-String.prototype.ltrim = function() {
- return this.replace(/^\s+/, "");
-}
-
-String.prototype.rtrim = function() {
- return this.replace(/\s+$/, "");
-}
-
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
+/*jslint laxbreak:true */
+// all euphorik is contained in this object
+var euphorik = {};
// le main
$(document).ready(
- function()
- {
- var formateur = new euphorik.Formateur()
- var util = new euphorik.Util(formateur)
- var client = new Client(util)
- var pages = new euphorik.Pages()
-
- // connexion vers le serveur (utilise un cookie qui traine)
- client.connexionCookie()
-
- $("#menuCss").change(function(){ client.setCss("styles/" + $("option:selected", this).attr("value") + "/euphorik.css")})
-
- // FIXME : ne fonctionne pas sous opera
- // voir : http://dev.jquery.com/ticket/2892#preview
- $(window).unload(function(){client.flush()})
-
- $("#menu .minichat").click(function(){ pages.afficherPage("minichat") })
- $("#menu .admin").click(function(){ pages.afficherPage("admin") })
- $("#menu .profile").click(function(){ pages.afficherPage("profile") })
- $("#menu .logout").click(function(){
- util.messageDialogue("Ãtes-vous sur de vouloir vous délogger ?", euphorik.Util.messageType.question,
- {"Oui" : function()
- {
- client.deconnexion();
- pages.afficherPage("minichat", true)
+ function() {
+ var fragment = new Fragment();
+ var formatter = new euphorik.Formatter();
+ var util = new euphorik.Util(formatter);
+ var communication = new euphorik.Communication(
+ function(data) { util.messageDialog(data.error_message); },
+ function() { util.showWaitBar(); },
+ function() { util.hideWaitBar(); }
+ );
+ var client = new euphorik.Client(util, communication);
+ var pages = new euphorik.Pages(fragment, communication);
+
+ // Client authentification with the cookie information (if it exists).
+ client.connectionCookie();
+
+ $("#menuCss").change(function() { client.setCss("styles/" + $("option:selected", this).attr("value") + "/euphorik.css"); });
+
+ $(window).unload(function() { client.flush(); });
+
+ $("#menu .minichat").click(function() { pages.displayPage("minichat"); });
+ $("#menu .admin").click(function() { pages.displayPage("admin"); });
+ $("#menu .profile").click(function() { pages.displayPage("profile"); });
+ $("#menu .logout").click(function() {
+ util.messageDialog("Are you sure you want to log out?", euphorik.Util.messageType.question,
+ {
+ "Yes" : function() {
+ client.disconnect();
+ pages.displayPage("minichat", true);
},
- "Non" : function(){}
+ "No" : function() {}
}
- )
- })
- $("#menu .register").click(function(){ pages.afficherPage("register") })
- $("#menu .about").click(function(){ pages.afficherPage("about") })
-
- // TODO : simplifier et pouvoir créer des liens par exemple : Conditions d'utilisation
- $("#footer .conditions").click(function(){ pages.afficherPage("conditions_utilisation") })
-
- pages.ajouterPage(new PageMinichat(client, formateur, util))
- pages.ajouterPage(new PageAdmin(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.ajouterPage("conditions_utilisation")
-
- pages.afficherPage("minichat")
+ );
+ });
+ $("#menu .register").click(function(){ pages.displayPage("register"); });
+ $("#menu .about").click(function(){ pages.displayPage("about"); });
+
+ // TODO : simplification : such link[1] should be created and automatically open the right page without
+ // explicitly add a page.
+ // [1] : Terms of use
+ $("#footer .termsOfUse").click(function(){ pages.displayPage("terms_of_use"); });
+
+ pages.addPage(new euphorik.PageMinichat(client, formatter, util, communication), true);
+ pages.addPage(new euphorik.PageAdmin(client, formatter, util, communication));
+ pages.addPage(new euphorik.PageProfile(client, formatter, util));
+ pages.addPage(new euphorik.PageRegister(client, formatter, util));
+ pages.addPage(new euphorik.PageAbout(client, formatter, util, communication));
+ pages.addPage("terms_of_use");
+
+ pages.displayPage(); // display the default page
}
-)
+);