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/>.
19 /*jslint laxbreak:true */
25 euphorik
.Pages = function(fragment
, communication
) {
26 this.fragment
= fragment
;
27 this.communication
= communication
;
28 this.pageCourante
= undefined;
29 this.pageDefaut
= undefined;
34 * Accepte soit un objet soit un string.
35 * un string correspond au nom de la page, par exemple : "page" -> "page.html"
36 * @defaut si vrai alors la page est la page par défaut
38 euphorik
.Pages
.prototype.ajouterPage = function(page
, defaut
) {
39 if (typeof page
=== "string") {
40 page
= new euphorik
.PageStatique(page
, this.communication
);
43 page
.pages
= this; // la magie des langages dynamiques : le foutoire
44 page
.fragment
= this.fragment
;
46 this.pages
[page
.nom
] = page
;
49 this.pageDefaut
= page
;
53 euphorik
.Pages
.prototype.afficherPage = function(nomPage
, forcerChargement
) {
54 forcerChargement
= forcerChargement
|| false;
56 // si le nom de la page n'est pas donné on le prend du fragment
58 nomPage
= this.fragment
.getVal("page");
61 var page
= this.pages
[nomPage
];
63 page
= this.pageDefaut
;
66 if (!page
|| (!forcerChargement
&& page
=== this.pageCourante
)) {
70 if (this.pageCourante
&& this.pageCourante
.decharger
) {
71 this.pageCourante
.decharger();
74 $("#menu li").removeClass("courante");
75 $("#menu li." + page
.nom
).addClass("courante");
77 this.pageCourante
= page
;
78 var contenu
= this.pageCourante
.contenu();
80 $("#page").html(contenu
).removeClass().addClass(
81 this.pageCourante
.nom
+
82 (this.pageCourante
.classes
? " " + this.pageCourante
.classes() : "") // l'objet peut fournire des classes css supplémentaires sous la forme d'un string
85 if (this.pageCourante
.charger
) {
86 this.pageCourante
.charger();
89 this.fragment
.setVal("page", this.pageCourante
.nom
);
90 this.fragment
.write();