Commit 56c75c13f3ccc24d3a153e85447c33a1c66af9e8

Authored by Geoffrey PREUD'HOMME
1 parent fab2252b

[Navigation] Ouvre la page dernièrement ouverte en cas de refresh

Marre de faire F5 puis de cliquer sur Organisation à chaque fois
pour voir mes changements.
Showing 3 changed files with 32 additions and 22 deletions   Show diff stats
index.php
... ... @@ -14,10 +14,10 @@ require_once("creds.php");
14 14 <link rel="stylesheet" href="css/bootstrap.min.css">
15 15 <link rel="stylesheet" href="css/crep.css">
16 16 <link rel="shortcut icon" href="favicon.ico"/>
17   - <script type="text/javascript" src="js/crep.js"></script>
18 17 <script type="text/javascript" src="js/jquery.js"></script>
19 18 <script type="text/javascript" src="js/bootstrap.min.js"></script>
20 19 <script type="text/javascript" src="js/whirlpool.min.js"></script>
  20 + <script type="text/javascript" src="js/crep.js"></script>
21 21 </head>
22 22 <body>
23 23 <?php require_once("topnavbar.php");?>
... ...
js/crep.js
1   -function file(fichier)
2   -{
3   - if(window.XMLHttpRequest)
4   - xhr_object = new XMLHttpRequest();
5   - else if(window.ActiveXObject)
6   - xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
7   - else
8   - return(false);
9   - xhr_object.open("GET", fichier, false);
10   - xhr_object.send(null);
11   - if(xhr_object.readyState == 4)
12   - return(xhr_object.responseText);
  1 +function file(fichier) {
  2 + if (window.XMLHttpRequest)
  3 + xhr_object = new XMLHttpRequest();
  4 + else if (window.ActiveXObject)
  5 + xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
13 6 else
14   - return(false);
  7 + return (false);
  8 + xhr_object.open("GET", fichier, false);
  9 + xhr_object.send(null);
  10 + if (xhr_object.readyState == 4)
  11 + return (xhr_object.responseText);
  12 + else
  13 + return (false);
15 14 }
16 15  
17   -function loadNewDoc(doc)
18   -{
19   - $("#mainContainer").html(file(doc));
  16 +function loadNewDoc(doc) {
  17 + $("#mainContainer").html(file(doc));
  18 + return false
20 19 }
  20 +
  21 +$().ready(function() {
  22 + // Navigue vers la page indiquée dans l'URL en cas de refresh
  23 + if (window.location.hash) {
  24 + $('ul.nav a').each(function() {
  25 + if ($(this).attr('href') == window.location.hash) {
  26 + loadNewDoc($(this).attr('onclick').replace(/loadNewDoc\(\'(.+)\'\);?/, '$1'))
  27 + }
  28 + })
  29 + }
  30 +})
... ...
menu.php
1 1 <div class="well well-sm" role="complementary">
2 2 <ul class="nav">
3 3 <li>
4   - <a href="#" onClick="loadNewDoc('news.php');">News</a>
  4 + <a href="#news" onClick="loadNewDoc('news.php');">News</a>
5 5 </li>
6 6 <li>
7   - <a href="#" onClick="loadNewDoc('agenda.php');">Agenda</a>
  7 + <a href="#agenda" onClick="loadNewDoc('agenda.php');">Agenda</a>
8 8 </li>
9 9 <li>
10   - <a href="#" onClick="loadNewDoc('orga.php');">Organisation</a>
  10 + <a href="#orga" onClick="loadNewDoc('orga.php');">Organisation</a>
11 11 </li>
12 12 <?php
13 13 if (!(isset($_SESSION["connected"]) && $_SESSION["connected"]))
14 14 {
15 15 ?>
16 16 <li>
17   - <a href="#" onClick="loadNewDoc('connect.php');">Connexion</a>
  17 + <a href="#connect" onClick="loadNewDoc('connect.php');">Connexion</a>
18 18 </li>
19 19 <?php
20 20 }
... ... @@ -22,7 +22,7 @@
22 22 {
23 23 ?>
24 24 <li>
25   - <a href="#" onClick="loadNewDoc('???????.php;)">Profil</a>
  25 + <a href="#profil" onClick="loadNewDoc('???????.php);">Profil</a>
26 26 </li>
27 27 <?php
28 28 }
... ...