ea13deffa622f3bb3577ec2b8188b8f6558efb98
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 * Add a new page, must be done one time per page after the website is loaded.
35 * Accept a string or a Page object.
36 * If a string is given then a static object page is automatically created.
37 * A string is the name of the page without the 'html' extension, for example
38 * "page" -> "page.html"
39 * @defaultPage If true then the page will be flaged as 'default'. It must be only one default page.
41 euphorik
.Pages
.prototype.addPage = function(page
, defaultPage
) {
42 if (typeof page
=== "string") {
43 page
= new euphorik
.PageStatique(page
, this.communication
);
46 page
.pages
= this; // la magie des langages dynamiques : le foutoire
47 page
.fragment
= this.fragment
;
49 this.pages
[page
.nom
] = page
;
52 this.pageDefaut
= page
;
57 * Display a given page.
58 * If no page name given the the default page will be loaded.
59 * @pageName [optional] The page name to load.
60 * @forceToLoad [optional] If true then the page will be reloaded even it already displayed.
62 euphorik
.Pages
.prototype.displayPage = function(pageName
, forceToLoad
) {
63 forceToLoad
= forceToLoad
|| false;
65 // si le nom de la page n'est pas donné on le prend du fragment
67 pageName
= this.fragment
.getVal("page");
70 var page
= this.pages
[pageName
];
72 page
= this.pageDefaut
;
75 if (!page
|| (!forceToLoad
&& page
=== this.pageCourante
)) {
79 if (this.pageCourante
&& this.pageCourante
.decharger
) {
80 this.pageCourante
.decharger();
83 $("#menu li").removeClass("courante");
84 $("#menu li." + page
.nom
).addClass("courante");
86 this.pageCourante
= page
;
87 var contenu
= this.pageCourante
.contenu();
89 $("#page").html(contenu
).removeClass().addClass(
90 this.pageCourante
.nom
+
91 // A page can bring some additionnals CSS classes
92 (this.pageCourante
.classes
? " " + this.pageCourante
.classes() : "")
95 if (this.pageCourante
.charger
) {
96 this.pageCourante
.charger();
99 this.fragment
.setVal("page", this.pageCourante
.nom
);
100 this.fragment
.write();