www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 47068acebd21e15e001d4ea0c557a801b86f7448
parent 28b06e7dfc17beea30432ed5f5e2a2ca3f3b31f7
Author: Georges Dupéron <jahvascriptmaniac+github@free.fr>
Date:   Sun,  8 May 2011 20:54:22 +0200

Ne plus utiliser de basculement de feuille de style.

Diffstat:
Mcode/serveur/php/jeu.php | 15+++------------
Mcode/serveur/php/ressources/backend.inc | 3---
Dcode/serveur/php/ressources/black.css | 49-------------------------------------------------
Dcode/serveur/php/ressources/green.css | 45---------------------------------------------
Mcode/serveur/php/ressources/pticlic.js | 115+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------
Mcode/serveur/php/server.php | 14++++++++------
6 files changed, 118 insertions(+), 123 deletions(-)

diff --git a/code/serveur/php/jeu.php b/code/serveur/php/jeu.php @@ -1,26 +1,17 @@ <!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="<?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> <script src="ressources/jquery.JSON.js"></script> <script src="ressources/my-extensions.js"></script> <script src="ressources/pticlic.js"></script> + <script src="server.php?callback=prefs.loadPrefs&action=7"></script> </head> <body> <div id="nojs">Chargement…</div> @@ -107,8 +98,8 @@ if(isset($_SESSION['userId'])) <form id="prefs-form" action="#" method="GET"> <fieldset id="theme"> <legend>Thème</legend> - <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> + <input type="radio" id="theme-green" name="theme" value="green" /><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> </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/backend.inc b/code/serveur/php/ressources/backend.inc @@ -795,9 +795,6 @@ function userPrefs($user) { function setUserPref($user, $key, $value) { if (array_key_exists($key, userPrefsDefaults())) { setUserInfo($user, $key, $value); - echo 'true'; - } else { - echo 'false'; } } diff --git a/code/serveur/php/ressources/black.css b/code/serveur/php/ressources/black.css @@ -1,49 +0,0 @@ -/* Colors */ - -html, body { - background-color: black; - color: white; -} - -#nojs { - color: white; -} - -a, a:hover, a:visited, a:link, a:active { - color: #8888ff; -} - -.screen { - background-color: black; -} - -.frontpage-button:hover { - background-color: #222222; - outline: medium solid #cccccc; -} - -#splash.screen { - background-color: black; -} - -#mc-caption { - color: white; -} - -#mn-caption { - color: white; -} - -#mn-caption-block { - border-color: #aaaaaa; - background-color: #222222; -} - -#message, .relationBox { - border-color: #cccccc; - background-color: #222222; -} - -.relations .hot { - background-color: #cccccc; -} diff --git a/code/serveur/php/ressources/green.css b/code/serveur/php/ressources/green.css @@ -1,45 +0,0 @@ -/* Colors */ - -html, body { - background-color: black; - color: black; -} - -#nojs { - color: white; -} - -.screen { - background-color: #FFFFE0; -} - -.frontpage-button:hover { - background-color: #F0F8D0; - outline: medium solid #44AA44; -} - -#splash.screen { - background-color: black; -} - -#mc-caption { - color: #8b4; -} - -#mn-caption { - color: #4a4; -} - -#mn-caption-block { - border-color: #44AA44; - background-color: #F0F8D0; -} - -#message, .relationBox { - border-color: #44AA44; - background-color: #F0F8D0; -} - -.relations .hot { - background-color: yellow; -} diff --git a/code/serveur/php/ressources/pticlic.js b/code/serveur/php/ressources/pticlic.js @@ -108,9 +108,91 @@ function jss() { e.attr("src", "ressources/img/"+iconSize+"/"+e.data('image')+".png"); } catch(e) {alert("Error anonymous in jss");alert(e);} }); + + jssTheme(runstate.prefs.theme); } catch(e) {alert("Error jss");alert(e);} } +function jssTheme(theme) { + if (theme == "black") { + var bg1 = "black"; + var fg1 = "white"; + var bg2 = "#222222"; + var fg2 = "#cccccc"; + var fg3 = "white"; + var hot = "#aaaaaa"; + } else { + var bg1 = "#ffffe0"; + var fg1 = "black"; + var bg2 = "#f0f8d0"; + var fg2 = "#4a4"; + var fg3 = "#8b4"; + var hot = "yellow"; + } + var splashbg = "black"; + var splashfg = "white"; + var screenbg = bg1; + var screenfg = fg1; + var messagebg = bg2; + var messagefg = fg1; + var messagebd = fg2; + var centralfg = fg3; + var cloudbg = bg2; + var cloudfg = fg2; + var cloudbd = fg2; + var relationbg = bg2; + var relationbd = fg2; + var fphoverbg = bg2; + var fphoverbd = fg2; + var hotbg = hot; + + $('.screen').css({ + color: screenfg, + backgroundColor: screenbg + }); + + $('html, body, #splash.screen').css({ + backgroundColor: splashbg, + color: splashfg + }); + + $("#message").css({ + backgroundColor: messagebg, + color: messagefg, + borderColor: messagebd + }); + + $(".frontpage-button").hover(function() { + $(this).css({ + backgroundColor: fphoverbg, + outline: "medium solid "+fphoverbd + }); + }, function() { + $(this).css({ + outline: '', + backgroundColor: "transparent" + }); + }); + + $('#mc-caption').css({color: centralfg}); + + $('#mn-caption').css({color: cloudfg}); + + $('#mn-caption-block').css({ + borderColor: cloudbd, + backgroundColor: cloudbg + }); + + $('.relationBox').css({ + borderColor: relationbd, + backgroundColor: relationbg + }); + + $('.relations .hot').css({backgroundColor: hotbg}); + + $("a, a:visited").css({color: "#8888ff"}); +} + // ==== Interface Android function UI () { try { @@ -251,10 +333,10 @@ splash.jss = function(w,h,iconSize) { splash.enter = function() { try { // Si l'application est déjà chargée, on zappe directement jusqu'à la frontpage. - if (runstate.skipSplash) { + if (runstate.loaded) { splash.click.goFrontpage(); } else { - runstate.skipSplash = true; + runstate.loaded = true; jss(); $('#splash.screen').clickOnce(splash.click.goFrontpage); } @@ -718,13 +800,13 @@ connection.connect = function() { connection.connectFetched = function(data) { try { if (data && data.theme) { - UI().switchCSS(data.theme || "green"); + prefs.loadPrefs(); UIInfo("Connexion", "Vous êtes connecté !"); } else if (data && data.isError && data.error == 3) { - UI().switchCSS("green"); + prefs.loadPrefs(); UIInfo("Connexion", data.msg); } else { - UI().switchCSS("green"); + prefs.loadPrefs(); ajaj.smallError(data); } state.set('screen', 'frontpage').validate(); @@ -757,6 +839,9 @@ prefs.enter = function() { try { $("#prefs-form").unbind('submit', prefs.apply).submit(prefs.apply); $("#prefs-cancel").clickOnce(prefs.cancel); + $("#prefs-form input:radio[name=theme]").attr('checked', function(i,val) { + return $(this).val() == runstate.prefs.theme; + }); jss(); UI().dismiss(); } catch(e) {alert("Error prefs.enter");alert(e);} @@ -764,16 +849,16 @@ prefs.enter = function() { prefs.apply = function(){ try { - var newtheme = $("input:radio[name=theme]:checked").val(); + var newtheme = $("#prefs-form input:radio[name=theme]:checked").val(); ajaj.request("server.php?callback=?", { action: 8, key: 'theme', value: newtheme }, function(data) { try { - if (data) { + if (data.theme) { UIInfo("Préférences", "Les préférences ont été enregistrées."); - UI().switchCSS(newtheme); + prefs.loadPrefs(data); } else { UIInfo("Préférences", "Les préférences n'ont pas pu être enregistrées."); } @@ -789,3 +874,16 @@ prefs.cancel = function(){ state.set('screen', 'frontpage').validate(); } catch(e) {alert("Error anonymous in prefs.cancel");alert(e);} }; + +prefs.loadPrefs = function(data) { + try { + if (data && data.theme) { + runstate.prefs = data; + } else { + runstate.prefs = { + theme: "green" + }; + } + if (runstate.loaded) jss(); + } catch(e) {alert("Error anonymous in prefs.loadPrefs");alert(e);} +}; +\ No newline at end of file diff --git a/code/serveur/php/server.php b/code/serveur/php/server.php @@ -65,10 +65,6 @@ function main() return; } - // Sinon tout est bon on effectue l'opération correspondant à la commande passée. - // TODO : en production, utiliser : header("Content-Type: application/json; charset=utf-8"); - header("Content-Type: text/plain; charset=utf-8"); - if ($action == 2) { // "Create partie" // Requête POST : http://serveur/server.php?action=2&nb=2&mode=normal&user=foo&passwd=bar if (!isset($_GET['nb']) || !isset($_GET['mode'])) { @@ -110,14 +106,19 @@ function main() if (!isset($_GET['key']) || !isset($_GET['value'])) throw new Exception("La requête est incomplète", 2); setUserPref($user, $_GET['key'], $_GET['value']); + userPrefs($user); } else { throw new Exception("Commande inconnue", 2); } } function server() { - if(isset($_GET['callback'])) + if(isset($_GET['callback'])) { echo $_GET['callback'].'('; + header("Content-Type: application/javascript; charset=utf-8"); + } else { + header("Content-Type: application/json; charset=utf-8"); + } ob_start(); try { main(); @@ -140,4 +141,4 @@ function server() { server(); -?> +?> +\ No newline at end of file