use localstorage instead of cookies

master
Aurelien Labate 3 years ago
parent a0a258dbc4
commit b640a41bfe
  1. 7
      assets/css/stylesheet.css
  2. 4
      assets/js/compil1.js
  3. 15
      assets/js/exemples.js
  4. 9
      assets/js/functions.js
  5. 17
      assets/js/interface.js
  6. 6
      exemples.php
  7. 13
      includes/footer.php
  8. 9
      includes/header.php
  9. 11
      index.php

@ -200,9 +200,14 @@ article
/**************
* example page specific layout
***************/
.example form {
.example .try_it {
text-align: right;
}
.example .try_it button {
border: 0;
background: none;
cursor: pointer;
}
/**************
* programm page specific layout

@ -317,8 +317,8 @@ function compilation(langage_source) {
var i, mot = "", dernier_mot = 0, espace_position , mot_en_cours;
var ligne = 1, type;
var calcul_memoire = "undefined", ligne_memoire, chaine = 0;
createCookie("last_algo", encodeURIComponent(texte), 30);
createCookie("last_language", langage_source, 30);
localStorage.setItem('saved_code', texte);
localStorage.setItem('saved_language', langage_source);
debug_efface();
// remise à 0 des variables

@ -0,0 +1,15 @@
$(document).ready(function() {
$(".example .try_it button").click(function() {
let textarea = $(this).parent().children('textarea').first();
if (!textarea) {
console.error('Textarea associated to this button not found.')
}
// Save example to local storage
localStorage.setItem('saved_code', textarea.val());
localStorage.setItem('saved_language', 1);
// Redirect to home page
document.location.href=".";
});
});

@ -1,9 +0,0 @@
function createCookie(name,value,days) {
expires = "";
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
document.cookie = name+"="+value + expires;
}

@ -467,6 +467,22 @@ $(document).ready(function() {
return false;
});
}
/**
* Try to restore a code saved to localstorage
*/
function default_code()
{
if ($("#saisie").length > 0 && localStorage.getItem('saved_code') && localStorage.getItem('saved_language') !== null) {
langage = parseInt(localStorage.getItem('saved_language'));
let code = localStorage.getItem('saved_code');
document.getElementById("saisie").value = code;
$("#saisie").cleditor()[0].updateFrame().focus();
affiche_conversion();
affiche_langage();
}
}
$("#saisie").cleditor().focus(); // transforme le textarea en éditeur html
@ -481,6 +497,7 @@ $(document).ready(function() {
boutons();
signes();
menus_deroulants_show();
default_code();
alert_mobile();
});

@ -143,10 +143,10 @@ La suite de Fibonacci sert à déterminer une approximation du nombre d\'Or en d
<h3>Description :</h3>
<?php echo $dnn['description']; ?>
<form method="POST" action="<?= $base_url ?>">
<div class="try_it">
<button><img src="assets/img/examples/tester.png" /></button>
<textarea style="display:none;" name="programme"><?= $dnn['programme'] ?></textarea>
<input type="image" src="assets/img/examples/tester.png" alt="Submit" />
</form>
</div>
</article>
<?php
}

@ -18,6 +18,19 @@
<p class="copyright">Festiv'Algo <!--&copy; créé par <strong>Nitrosax</strong> -->- 2013 - 2019</p>
<p class="credits_images">Crédits images : <a class="lien" href="http://www.siteduzero.com" target=_blank>Site du Zéro</a></p>
</footer>
<?php
if(!empty($footer_js_script)) {
echo '<script>' . $footer_js_script . '</script>';
}
?>
<script type="text/javascript" src="assets/js/jquery/jquery.js"></script>
<script type="text/javascript" src="assets/js/jquery/jquery.cleditor.js"></script>
<script type="text/javascript" src="assets/js/exemples.js"></script>
<script type="text/javascript" src="assets/js/interface.js"></script>
<script type="text/javascript" src="assets/js/compil1.js"></script>
<script type="text/javascript" src="assets/js/compil2.js"></script>
<script type="text/javascript" src="assets/js/traduction.js"></script>
<script type="text/javascript" src="assets/js/execution.js"></script>
<script>
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-40310477-1']);

@ -9,15 +9,6 @@
<link rel="stylesheet" type="text/css" href="assets/css/stylesheet.css" />
<link rel="stylesheet" type="text/css" href="assets/css/jquery/jquery.cleditor.css" />
<script type="text/javascript" src="assets/js/jquery/jquery.js"></script>
<script type="text/javascript" src="assets/js/jquery/jquery.cleditor.js"></script>
<script type="text/javascript" src="assets/js/functions.js"></script>
<script type="text/javascript" src="assets/js/interface.js"></script>
<script type="text/javascript" src="assets/js/compil1.js"></script>
<script type="text/javascript" src="assets/js/compil2.js"></script>
<script type="text/javascript" src="assets/js/traduction.js"></script>
<script type="text/javascript" src="assets/js/execution.js"></script>
<title>Festiv'Algo - <?= $page_title ?></title>
<meta name="keywords" content="festivalgo, Festiv'Algo, algobox, site, application gratuite, nitrosax, algorithme, algorithmique, programmation, Casio, TI, HP, apprendre, bac, mathématiques, ROC, nouveaux programmes, réformes" />

@ -57,16 +57,7 @@
</div>
<form name="code" class="code">
<div id="disable"></div>
<textarea cols="41" rows="22" name="Saisie" id="saisie" spellcheck="false" method="post" action="<?= $base_url ?>">
<?php
if (!empty($_POST["programme"])) {
echo $_POST["programme"];
}
elseif (!empty($_COOKIE['last_algo']) && urldecode($_COOKIE['last_algo'])) {
echo urldecode($_COOKIE['last_algo']);
}
?>
</textarea></form>
<textarea cols="41" rows="22" name="Saisie" id="saisie" spellcheck="false" method="post" action="<?= $base_url ?>"></textarea></form>
</div>
<section id="debug">

Loading…
Cancel
Save