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