X-Git-Url: http://git.euphorik.ch/?p=euphorik.git;a=blobdiff_plain;f=js%2Fpages.js;fp=js%2Fpages.js;h=fe288604035848fb14a28a22c0f8bb82da6842f2;hp=0000000000000000000000000000000000000000;hb=7fb422d6d4a7a59c8f74d938371a4a10474e8ea4;hpb=1ab57f78d9f702dc09b1af80f36546c79edfccca diff --git a/js/pages.js b/js/pages.js new file mode 100644 index 0000000..fe28860 --- /dev/null +++ b/js/pages.js @@ -0,0 +1,74 @@ +// coding: utf-8 +// Copyright 2008 Grégory Burri +// +// This file is part of Euphorik. +// +// Euphorik is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Euphorik is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Euphorik. If not, see . + +/*jslint laxbreak:true */ + + +/** + * Gestion des pages. + */ +euphorik.Pages = function() { + this.pageCourante = undefined; + this.pages = {}; +}; + +/** + * Accepte soit un objet soit un string. + * un string correspond au nom de la page, par exemple : "page" -> "page.html" + */ +euphorik.Pages.prototype.ajouterPage = function(page) { + if (typeof page == "string") { + this.pages[page] = page; + } else { + page.pages = this; // la magie des langages dynamiques : le foutoire + this.pages[page.nom] = page; + } +}; + +euphorik.Pages.prototype.afficherPage = function(nomPage, forcerChargement) { + forcerChargement = forcerChargement || false; + + var page = this.pages[nomPage]; + if (!page || (!forcerChargement && page == this.pageCourante)) { + return; + } + + if (this.pageCourante && this.pageCourante.decharger) { + this.pageCourante.decharger(); + } + + $("#menu li").removeClass("courante"); + $("#menu li." + nomPage).addClass("courante"); + + this.pageCourante = page; + var contenu = ""; + if (typeof page == "string") { + $.ajax({async: false, url: "pages/" + page + ".html", success : function(page) { contenu += page; }}); + } else { + contenu += this.pageCourante.contenu(); + } + + $("#page").html(contenu).removeClass().addClass( + this.pageCourante.nom + + (this.pageCourante.classes ? " " + this.pageCourante.classes() : "") // l'objet peut fournire des classes css supplémentaires sous la forme d'un string + ); + + if (this.pageCourante.charger) { + this.pageCourante.charger(); + } +};