MOD begining of #100 (code broken)
[euphorik.git] / js / euphorik.js
1 // coding: utf-8
2 // Copyright 2008 Grégory Burri
3 //
4 // This file is part of Euphorik.
5 //
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.
10 //
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.
15 //
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/>.
18
19 /*jslint laxbreak:true */
20
21 // all euphorik is contained in this object
22 var euphorik = {};
23
24 // le main
25 $(document).ready(
26 function() {
27 var fragment = new Fragment();
28 var formater = new euphorik.Formater();
29 var util = new euphorik.Util(formater);
30 var communication = new euphorik.Communication(
31 function(data) { util.messageDialog(data.error_message); },
32 function() { util.showWaitBar(); },
33 function() { util.hideWaitBar(); }
34 );
35 var client = new euphorik.Client(util, communication);
36 var pages = new euphorik.Pages(fragment, communication);
37
38 // Client authentification with the cookie information (if it exists).
39 client.connectionCookie();
40
41 $("#menuCss").change(function() { client.setCss("styles/" + $("option:selected", this).attr("value") + "/euphorik.css"); });
42
43 // FIXME : doesn't work under Opera
44 // see : http://dev.jquery.com/ticket/2892#preview
45 $(window).unload(function() { client.flush(); });
46
47 $("#menu .minichat").click(function() { pages.displayPage("minichat"); });
48 $("#menu .admin").click(function() { pages.displayPage("admin"); });
49 $("#menu .profile").click(function() { pages.displayPage("profile"); });
50 $("#menu .logout").click(function() {
51 util.messageDialog("Are you sure you want to log out?", euphorik.Util.messageType.question,
52 {
53 "Yes" : function() {
54 client.disconnect();
55 pages.displayPage("minichat", true);
56 },
57 "No" : function() {}
58 }
59 );
60 });
61 $("#menu .register").click(function(){ pages.displayPage("register"); });
62 $("#menu .about").click(function(){ pages.displayPage("about"); });
63
64 // TODO : simplification : such link[1] should be created and automatically open the right page without
65 // explicitly add a page.
66 // [1] : <a class="pageLink" href="termes_of_use">Terms of use</a>
67 $("#footer .termsOfUse").click(function(){ pages.displayPage("terms_of_use"); });
68
69 pages.addPage(new euphorik.PageMinichat(client, formater, util, communication), true);
70 pages.addPage(new euphorik.PageAdmin(client, formater, util, communication));
71 pages.addPage(new euphorik.PageProfile(client, formater, util));
72 pages.addPage(new euphorik.PageRegister(client, formater, util));
73 pages.addPage(new euphorik.PageAbout(client, formater, util, communication));
74 pages.addPage("terms_of_use");
75
76 pages.displayPage(); // display the default page
77 }
78 );