Debut de l'utilisation d'urls persistantes

This commit is contained in:
Bertrand BRUN 2011-04-27 10:36:18 +02:00
parent 0b1ebc6747
commit ca58c5eee5
4 changed files with 35 additions and 12 deletions

View File

@ -46,6 +46,7 @@ body {
</style>
<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/my-extensions.js"></script>
<script src="ressources/pticlic.js"></script>
</head>

View File

@ -0,0 +1,9 @@
/*
* jQuery hashchange event - v1.3 - 7/21/2010
* http://benalman.com/projects/jquery-hashchange-plugin/
*
* Copyright (c) 2010 "Cowboy" Ben Alman
* Dual licensed under the MIT and GPL licenses.
* http://benalman.com/about/license/
*/
(function($,e,b){var c="hashchange",h=document,f,g=$.event.special,i=h.documentMode,d="on"+c in e&&(i===b||i>7);function a(j){j=j||location.href;return"#"+j.replace(/^[^#]*#?(.*)$/,"$1")}$.fn[c]=function(j){return j?this.bind(c,j):this.trigger(c)};$.fn[c].delay=50;g[c]=$.extend(g[c],{setup:function(){if(d){return false}$(f.start)},teardown:function(){if(d){return false}$(f.stop)}});f=(function(){var j={},p,m=a(),k=function(q){return q},l=k,o=k;j.start=function(){p||n()};j.stop=function(){p&&clearTimeout(p);p=b};function n(){var r=a(),q=o(m);if(r!==m){l(m=r,q);$(e).trigger(c)}else{if(q!==m){location.href=location.href.replace(/#.*/,"")+q}}p=setTimeout(n,$.fn[c].delay)}$.browser.msie&&!d&&(function(){var q,r;j.start=function(){if(!q){r=$.fn[c].src;r=r&&r+a();q=$('<iframe tabindex="-1" title="empty"/>').hide().one("load",function(){r||l(a());n()}).attr("src",r||"javascript:0").insertAfter("body")[0].contentWindow;h.onpropertychange=function(){try{if(event.propertyName==="title"){q.document.title=h.title}}catch(s){}}}};j.stop=k;o=function(){return a(q.location.href)};l=function(v,s){var u=q.document,t=$.fn[c].domain;if(v!==s){u.title=h.title;u.open();t&&u.write('<script>document.domain="'+t+'"<\/script>');u.close();q.location.hash=v}}})();return j})()})(jQuery,this);

View File

@ -0,0 +1 @@
http://benalman.com/projects/jquery-hashchange-plugin/

View File

@ -44,9 +44,9 @@ jss.frontpage = function(w, h, iconSize) {
$fp(".frontpage-button.about")
.northWest({left:w*0.55,top:h*0.3});
$fp(".frontpage-button.connection")
.southEast({left:w*0.45,top:h*0.9});
.southEast({left:w*0.45,top:h*0.8});
$fp(".frontpage-button.prefs")
.southWest({left:w*0.55,top:h*0.9});
.southWest({left:w*0.55,top:h*0.8});
};
// ==== JavaScript Style pour le jeu
@ -98,6 +98,12 @@ jss.game = function(w, h, iconSize) {
jss.score = function(w, h, iconSize) {
};
// ==== URL persistante
function hashchange() {
var info = location.hash.substring(location.hash.indexOf("#") + 1).split("/");;
screen[info[0]]();
};
// ==== Interface Android
var UI = {
setPreference: function() {},
@ -114,7 +120,9 @@ if (typeof(PtiClicAndroid) != "undefined") {
// ==== Code métier général
$(function() {
$(window).resize(jss);
frontpage();
$(window).hashchange(hashchange);
location.hash="#frontpage";
hashchange();
});
function ajaxError(x) {
@ -123,27 +131,30 @@ function ajaxError(x) {
}
// ==== Code métier pour la frontpage
function frontpage() {
screen = {};
ui = {};
screen.frontpage = function () {
state="frontpage";
$("#frontpage .frontpage-button.game").click(function(){
getGame();
location.hash = "#game";
});
jss();
UI.dismiss();
}
// ==== Code métier pour le jeu
function getGame() {
screen.game = function () {
state="game";
UI.show("PtiClic", "Récupération de la partie");
$.getJSON("getGame.php?callback=?", {
user:"foo",
passwd:"bar",
}, uiGame).error(ajaxError);
nonce:Math.random()
}, ui.game).error(ajaxError);
jss();
}
function uiGame(game) {
ui.game = function (game) {
var currentWordNb = 0;
game.answers = [];
@ -160,7 +171,7 @@ function uiGame(game) {
} else {
$("#game .relations").empty();
$('#game #mn-caption').stop().clearQueue();
getScore(game);
ui.score(game);
}
}
@ -211,7 +222,7 @@ function uiGame(game) {
}
// ==== Code métier pour les scores
function getScore(game) {
screen.score = function (game) {
state="score";
UI.show("PtiClic", "Calcul de votre score");
$.getJSON("server.php?callback=?", {
@ -220,7 +231,8 @@ function getScore(game) {
action: 1,
pgid: game.pgid,
gid: game.gid,
answers: game.answers
answers: game.answers,
nonce: Math.random()
}, function(data) {
for (var i = 0; i < data.scores.length; i++) {
game.cloud[i].score = data.scores[i];
@ -231,7 +243,7 @@ function getScore(game) {
jss();
}
function uiScore(game) {
ui.score = function (game) {
$.each(game.cloud, function(i,e) {
var percentScore = (e.score - game.minScore) / (game.maxScore - game.minScore);
u = $("#templates .scoreLine");