commit ba7d27a4e3b6aaa1c1a8cbd041e73948307ddc8e
parent ca4980bc6e9462462b010b799d0aa3f47e4e4a2a
Author: Georges Dupéron <jahvascriptmaniac+github@free.fr>
Date: Sun, 8 May 2011 18:02:21 +0200
Chargement automatique du thème de l'utilisateur, au démarrage et lorsqu'il se connecte + ne plus utiliser la fonction UI().info() qui semble faire buguer android.
Diffstat:
3 files changed, 56 insertions(+), 38 deletions(-)
diff --git a/code/serveur/php/jeu.php b/code/serveur/php/jeu.php
@@ -1,12 +1,20 @@
<!DOCTYPE html>
+<?php
+require_once("ressources/backend.inc");
+session_start();
+
+$theme = "green";
+if(isset($_SESSION['userId']))
+ $theme = getUserInfo($_SESSION['userId'], "theme");
+?>
<html>
<head>
<title>PtiClic pre-alpha 0.2</title>
<meta charset="utf-8" />
<meta name="viewport" content="target-densitydpi=device-dpi" />
<style>.screen { display: none; }</style>
- <link rel="stylesheet" href="ressources/green.css" title="green" />
- <link rel="alternate stylesheet" href="ressources/black.css" title="black" />
+ <link rel="<?php if ($theme != "green") echo "alternate "; ?>stylesheet" href="ressources/green.css" title="green" />
+ <link rel="<?php if ($theme != "black") echo "alternate "; ?>stylesheet" href="ressources/black.css" title="black" />
<script src="ressources/jquery-1.5.1.min.js"></script>
<script src="ressources/jquery-ui-1.8.11.custom.min.js"></script>
<script src="ressources/jquery.ba-hashchange.min.js"></script>
@@ -99,8 +107,8 @@
<form id="prefs-form" action="#" method="GET">
<fieldset id="theme">
<legend>Thème</legend>
- <input type="radio" id="theme-green" name="theme" value="green" checked="checked" /><label for="theme-green">Colline verdoyante</label><br/>
- <input type="radio" id="theme-black" name="theme" value="black" /><label for="theme-black">Bas-fond de cachot</label>
+ <input type="radio" id="theme-green" name="theme" value="green" <?php if ($theme == "green") echo 'checked="checked" '; ?>/><label for="theme-green">Colline verdoyante</label><br/>
+ <input type="radio" id="theme-black" name="theme" value="black" <?php if ($theme == "black") echo 'checked="checked" '; ?>/><label for="theme-black">Bas-fond de cachot</label>
</fieldset>
<input type="submit" name="prefs-apply" id="prefs-apply" value="Appliquer" />
<input type="reset" name="prefs-cancel" id="prefs-cancel" value="Annuler" />
diff --git a/code/serveur/php/ressources/black.css b/code/serveur/php/ressources/black.css
@@ -9,6 +9,10 @@ html, body {
color: white;
}
+a, a:hover, a:visited, a:link, a:active {
+ color: #8888ff;
+}
+
.screen {
background-color: black;
}
diff --git a/code/serveur/php/ressources/pticlic.js b/code/serveur/php/ressources/pticlic.js
@@ -128,34 +128,35 @@ function UI () {
window.console && console.log(msg);
} catch(e) {alert("Error UI().log");alert(e);}
},
- info: function(title, msg) {
- try {
- $('#message')
- .qCss('opacity',0)
- .qShow()
- .queue(function(next){
- $('#message')
- .text(msg);
- jss();
- next();
- })
- .animate({opacity:0.9}, 700)
- .delay(5000)
- .animate({opacity:0}, 700);
- } catch(e) {alert("Error UI().info");alert(e);}
- },
setScreen: function() {}
};
}
} catch(e) {alert("Error UI");alert(e);}
}
+function UIInfo(title, msg) {
+ try {
+ $('#message')
+ .qCss('opacity',0)
+ .qShow()
+ .queue(function(next){
+ $('#message')
+ .text(msg);
+ jss();
+ next();
+ })
+ .animate({opacity:0.9}, 700)
+ .delay(5000)
+ .animate({opacity:0}, 700);
+ } catch(e) {alert("Error UI().info");alert(e);}
+}
+
// ==== Code métier général
$(function() {
try {
- $(window).resize(jss);
- $(window).hashchange(hashchange);
- hashchange();
+ $(window).resize(jss);
+ $(window).hashchange(hashchange);
+ hashchange();
} catch(e) {alert("Error main function");alert(e);}
});
@@ -180,10 +181,11 @@ ajaj.request = function(url, data, okFunction, smallErrorFunction, bigErrorFunct
}).error(bigErrorFunction);
} catch(e) {alert("Error ajaj.request");alert(e);}
}
-ajaj.smallError = function(x) {
+ajaj.smallError = function(x, ignoreConnect) {
try {
if (x.error == 10) {
- state.set('screen', 'connection').commit().validate();
+ if (!ignoreConnect)
+ state.set('screen', 'connection').commit().validate();
} else {
ajaj.error(
"Erreur fatale. Merci de nous envoyer ce message : \n"
@@ -208,7 +210,7 @@ ajaj.bigError = function(x) {
ajaj.error = function(msg) {
try {
UI().dismiss();
- UI().info("Erreur !", msg);
+ UIInfo("Erreur !", msg);
UI().exit();
} catch(e) {alert("Error ajaj.error");alert(e);}
}
@@ -685,7 +687,7 @@ connection.connect = function() {
UI().setPreference("user", $("#user").val());
UI().setPreference("passwd", $("#passwd").val());
ajaj.request("server.php?callback=?", {
- action: 3,
+ action: 7,
user: $("#user").val(),
passwd: $("#passwd").val(),
}, connection.connectFetched, connection.connectFetched);
@@ -695,11 +697,14 @@ connection.connect = function() {
connection.connectFetched = function(data) {
try {
- if (data && data.loginOk) {
- UI().info("Connexion", "Vous êtes connecté !");
+ if (data && data.theme) {
+ switchCSS(data.theme || "green");
+ UIInfo("Connexion", "Vous êtes connecté !");
} else if (data && data.isError && data.error == 3) {
- UI().info("Connexion", data.msg);
+ switchCSS("green");
+ UIInfo("Connexion", data.msg);
} else {
+ switchCSS("green");
ajaj.smallError(data);
}
state.set('screen', 'frontpage').validate();
@@ -746,21 +751,22 @@ prefs.apply = function(){
value: newtheme
}, function(data) {
if (data)
- UI().info("Préférences", "Les préférences ont été enregistrées.");
+ UIInfo("Préférences", "Les préférences ont été enregistrées.");
else
- UI().info("Préférences", "Les préférences n'ont pas pu être enregistrées.");
- });
- $("link[@rel*=stylesheet][title]").each(function(i,e){
- // Il semblerait que pour qu'un "aleternate stylesheet" puisse être activé, il faut d'abord qu'il ait été désactivé…
- e.disabled = true;
- e.disabled = (e.getAttribute('title') != newtheme);
+ UIInfo("Préférences", "Les préférences n'ont pas pu être enregistrées.");
});
+ switchCSS(newtheme);
state.set('screen', 'frontpage').validate();
return false;
} catch(e) {alert("Error anonymous in prefs.apply");alert(e);}
};
-function switchStylestyle(styleName) {
+function switchCSS(newtheme) {
+ $("link[@rel*=stylesheet][title]").each(function(i,e){
+ // Il semblerait que pour qu'un "aleternate stylesheet" puisse être activé, il faut d'abord qu'il ait été désactivé…
+ e.disabled = true;
+ e.disabled = (e.getAttribute('title') != newtheme);
+ });
}
prefs.cancel = function(){