commit ac8ef724edf1cca08d6f0a9d727ddea8e8e3f5f7
parent 52a08215869588e01c73bc03f7f01408df943e9f
Author: Georges Dupéron <jahvascriptmaniac+github@free.fr>
Date: Thu, 28 Apr 2011 17:34:17 +0200
Ignorer le hashchange lorsqu'il est volontaire. Cela permet d'éviter de lancer deux fois le jss, donc plus rapide.
Diffstat:
3 files changed, 18 insertions(+), 9 deletions(-)
diff --git a/code/serveur/php/jeu.html b/code/serveur/php/jeu.html
@@ -52,6 +52,8 @@ body {
<script src="ressources/pticlic.js"></script>
</head>
<body>
+ <div class="screen" id="logo">
+ </div>
<div class="screen" id="game">
<div id="mc-caption-block"></div>
<div id="mn-caption-block"></div>
diff --git a/code/serveur/php/ressources/my-extensions.js b/code/serveur/php/ressources/my-extensions.js
@@ -4,7 +4,7 @@ Number.prototype.clip = function(min, max, floor) {
} catch(e) {alert("Error Number.prototype.clip");alert(e);}
};
-function dichotomy(start, isBigger) {
+function dichotomy(start, isBigger, foo) {
try {
var i = 0, min = 0, max, half;
@@ -13,7 +13,8 @@ function dichotomy(start, isBigger) {
if (!isBigger(half)) min = half;
else max = half;
}
- while (half > 1 && isBigger(half)) { --half; }
+ while (half > 1 && isBigger(half)) { --half; ++i; }
+ console.log(i,foo);
return half;
} catch(e) {alert("Error dichotomy");alert(e);}
}
@@ -57,7 +58,7 @@ $.fn.fitFont = function(w, h, minFont, maxFont) {
fubar = wrappers;
return (wrappers.maxHeight() > h || wrappers.maxWidth() > w);
} catch(e) {alert("Error anonymous in $.fn.fitFont");alert(e);}
- }).clip(minFont || 0, maxFont || Infinity));
+ },this).clip(minFont || 0, maxFont || Infinity));
// Restore stuff
this.css("position", oldpos);
diff --git a/code/serveur/php/ressources/pticlic.js b/code/serveur/php/ressources/pticlic.js
@@ -5,10 +5,12 @@ function State(init) {
if (!this.screen) this.screen = 'frontpage';
} catch(e) {alert("Error State");alert(e);}
};
+var futureHashChange = null;
State.prototype.commit = function() {
try {
- location.hash="#"+encodeURI($.JSON.encode(this));
- return this;
+ futureHashChange = "#"+encodeURI($.JSON.encode(this));
+ location.hash = futureHashChange;
+ return this;
} catch(e) {alert("Error State.prototype.commit");alert(e);}
};
State.prototype.get = function(key) {
@@ -41,8 +43,12 @@ var oldScreen = '';
var ui = {};
function hashchange() {
try {
- var stateJSON = decodeURI(location.hash.substring(location.hash.indexOf("#") + 1));
- state = new State($.parseJSON(stateJSON)).validate();
+ if (futureHashChange === location.hash) {
+ futureHashChange = null;
+ } else {
+ var stateJSON = decodeURI(location.hash.substring(location.hash.indexOf("#") + 1));
+ state = new State($.parseJSON(stateJSON)).validate();
+ }
} catch(e) {alert("Error hashchange");alert(e);}
}
@@ -73,6 +79,7 @@ function jss() {
if (window[state.screen] && window[state.screen].jss) window[state.screen].jss(w, h, iconSize);
} catch(e) {alert("Error jss");alert(e);}
+ window.console && console.log("ok");
}
// ==== Interface Android
function UI () {
@@ -87,7 +94,7 @@ function UI () {
show: function(title, text) {},
dismiss: function() {},
exit: function() {},
- log: function() {},
+ log: function(msg) { window.console && console.log(msg); },
setScreen: function() {}
};
}
@@ -266,7 +273,6 @@ game.enter = function () {
} else {
game.buildUi();
}
- jss();
} catch(e) {alert("Error game.enter");alert(e);}
};