commit 436c3f1886b859f333454e23211d99b409b77bd5
parent 4bc59ed81c5b949d1594455444ad76e7eb1bc2af
Author: Georges Dupéron <jahvascriptmaniac+github@free.fr>
Date: Thu, 7 Apr 2011 10:20:13 +0200
Refactorisation, encore et toujours.
Diffstat:
2 files changed, 26 insertions(+), 24 deletions(-)
diff --git a/code/html5/my-extensions.js b/code/html5/my-extensions.js
@@ -1,9 +1,10 @@
$.fn.fitFont = function(w, h, minFont, maxFont) {
minFont = minFont || 0;
maxFont = maxFont || Infinity;
- e = $(this)
+ e = $(this);
var oldpos = e.css("position");
e.css("position", "absolute");
+ // TODO : reset temporairement le max-width.
var size = parseInt(e.css("font-size"), 10);
var i = 0;
@@ -34,6 +35,21 @@ $.fn.fitFont = function(w, h, minFont, maxFont) {
return e;
}
+$.fn.fitIn = function(e, t, r, b, l) {
+ e = $(e);
+ if (isNaN(+t)) t = 0;
+ if (isNaN(+r)) r = t;
+ if (isNaN(+b)) b = t;
+ if (isNaN(+l)) l = r;
+ var w = e.width();
+ var h = e.height();
+ t *= h;
+ r *= w;
+ b *= h;
+ l *= w;
+ $(this).fitFont(w - r - l, h - t - b, 20).center(e.center());
+}
+
function queueize(method) {
return function() {
var that = $(this);
@@ -54,8 +70,8 @@ $.fn.wh = function(w, h) {
$.fn.relativePos = function(xAnchor, yAnchor, to) {
var that = $(this);
- var deltaX = that.width() * xAnchor;
- var deltaY = that.height() * yAnchor;
+ var deltaX = that.outerWidth() * xAnchor;
+ var deltaY = that.outerHeight() * yAnchor;
if (to) {
that.css("position", "absolute");
diff --git a/code/html5/pticlic.js b/code/html5/pticlic.js
@@ -2,7 +2,7 @@ function jss() {
var w=480, h=800;
var mch = h/8, mnh = h*0.075;
- $("body")
+ $("body, html")
.css({
padding: 0,
margin: 0,
@@ -18,30 +18,16 @@ function jss() {
.north($("#screen").north());
$("#mc-caption")
- .css({
- maxWidth: w*0.9,
- textAlign: "center"
- })
- .fitFont(w*0.9, mch*0.9, 20)
- .center($("#mc-caption-block").center());
+ .fitIn("#mc-caption-block", 0.1);
$("#mn-caption-block")
- .css({
- borderWidth: h/100,
- position: "absolute"
- })
+ .css({borderWidth: h/100})
.wh(w, mnh)
.north($("#mc-caption-block").south());
$("#mn-caption")
- .css({
- maxWidth: w*0.9,
- textAlign: "center",
- position: "absolute",
- zIndex: 10
- })
- .fitFont(w*0.9, mnh*0.9, 20)
- .center($("#mn-caption-block").center());
+ .css({zIndex: 10})
+ .fitIn("#mn-caption-block");
$(".relations > div")
.css({
@@ -71,8 +57,8 @@ function jss() {
function animateNext(e, button) {
console.log(e, e.clientX, e.clientY);
- $(button).qAddClass("hot").delay(100).qRemoveClass("hot");
- $("#mn-caption").animate({left:e.clientX, top:e.clientY},1500);
+ $(button).clearQueue().qAddClass("hot").delay(100).qRemoveClass("hot");
+ $("#mn-caption").clearQueue().animate({left:e.clientX, top:e.clientY},1500);
}