Skip to content

Commit

Permalink
Night mode
Browse files Browse the repository at this point in the history
Rudimentary night mode
and little ordered JS functions
  • Loading branch information
andresSG committed Sep 19, 2018
1 parent d604c6f commit 3df54d9
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 1 deletion.
6 changes: 6 additions & 0 deletions admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
$conn = new connectionSQLite('.'); //conexion BD
session_start();

if (isset($_SESSION['nightMode'])) {
echo '<script> var night= "' . $_SESSION['nightMode'] . '"; </script>';
} else {
echo '<script> var night;</script>';
}

if ($_SESSION["logueado"] == TRUE) {
?>
<html lang="es">
Expand Down
11 changes: 11 additions & 0 deletions core/night.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
session_start();
if (isset($_POST['nightMode'])) {
//yes or no
$_SESSION['nightMode'] = $_POST['nightMode'];
echo "night mode: " . $_SESSION['nightMode'];
} else {
header("Location: ../index.php");
}

?>
6 changes: 6 additions & 0 deletions editText.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
require 'core/connectionSQLite.php';
$conn = new connectionSQLite('.');

if (isset($_SESSION['nightMode'])) {
echo '<script> var night= "' . $_SESSION['nightMode'] . '"; </script>';
} else {
echo '<script> var night;</script>';
}

if (isset($_SESSION["ident"]) && isset($_SESSION["clave"])) {
$clave = $_SESSION["clave"];
$identificador = $_SESSION["ident"];
Expand Down
6 changes: 6 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
<?php
session_start();

if (isset($_SESSION['nightMode'])) {
echo '<script> var night= "' . $_SESSION['nightMode'] . '"; </script>';
} else {
echo '<script> var night;</script>';
}

if (!empty($_SESSION["logueado"])) {
if ($_SESSION["logueado"] == TRUE) {
Header("Location: admin.php");
Expand Down
35 changes: 34 additions & 1 deletion js/funciones-basic.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,41 @@
$(document).ready(function(){
init(); //funciones cargas al inicio

checkNight();//funcion para comprobar el modo noche
});

function init(){
$("#tooglenight").change(function() {
const data = new FormData();//creamos datos para un form
if(this.checked) {
$("#bd").addClass("night");
$(".footer i").css("color", "white");
$(".by").css("color", "white");
data.append('nightMode', 'yes');//incluimos key y valor
}else{
data.append('nightMode', 'no');
$("#bd").removeClass("night");
$(".footer i").css("color", "#ff8d0c");
$(".by").css("color", "#ff8d0c");
}
//send data post con ajax JQuery
fetch('./core/night.php', {
method: 'POST',
body: data
})
.then(function(response) {
if(response.ok) {
return response.text();
} else {
throw "Error en la llamada Ajax";
}
})
.then(function(texto) {
console.log(texto);
})
.catch(function(err) {
console.log(err);
});
});

$(".btEditar").click(function(evt) {
Expand All @@ -29,4 +56,10 @@ $(document).ready(function(){
}
$('#'+evt.currentTarget.parentElement.parentElement.id+' .ocult').fadeIn(1000);
});
});
}

function checkNight(){
if(night === 'yes'){
$("#tooglenight").click();
}
}
6 changes: 6 additions & 0 deletions textos.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
$conn = new connectionSQLite('.');
$textos = $conn->getStrings();

if (isset($_SESSION['nightMode'])) {
echo '<script> var night= "' . $_SESSION['nightMode'] . '"; </script>';
} else {
echo '<script> var night;</script>';
}

if ($_SESSION["logueado"] == TRUE) {
?>
<html lang="es">
Expand Down
6 changes: 6 additions & 0 deletions usuarios.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@

$usuarios = $conn->getUsers();

if (isset($_SESSION['nightMode'])) {
echo '<script> var night= "' . $_SESSION['nightMode'] . '"; </script>';
} else {
echo '<script> var night;</script>';
}

if ($_SESSION["logueado"] == TRUE) {
?>
<html lang="es">
Expand Down

0 comments on commit 3df54d9

Please sign in to comment.