refactor around the card resize code so it's only in one place
This commit is contained in:
parent
f4ef1b3521
commit
89da813b28
|
@ -445,31 +445,24 @@ cah.Game.prototype.windowResize_ = function() {
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
cah.Game.prototype.resizeHandCards_ = function() {
|
cah.Game.prototype.resizeHandCards_ = function() {
|
||||||
var elems = $(".game_hand_cards .card_holder", this.element_);
|
var data = {
|
||||||
var ct = elems.length;
|
class : ".game_hand_cards",
|
||||||
this.handCardSmallSize_ = ($(".game_hand_cards", this.element_).width() - 20) / (ct + 1);
|
cardSmallSize : this.handCardSmallSize_,
|
||||||
if (this.handCardSmallSize_ > 150) {
|
cardLargeSize : this.handCardLargeSize_,
|
||||||
this.handCardSmallSize_ = 150;
|
cardSmallScale : this.handCardSmallScale_,
|
||||||
}
|
cardLargeScale : this.handCardLargeScale_,
|
||||||
if (this.handCardSmallSize_ < 66) {
|
maxSmallSize : 150,
|
||||||
this.handCardSmallSize_ = 66;
|
minSmallSize : 66,
|
||||||
}
|
smallSize : function() {
|
||||||
var maxScale = 236 / this.handCardSmallSize_;
|
return ($(".game_hand_cards", this.element_).width() - 20)
|
||||||
var scale = maxScale < 1.8 ? maxScale : 1.8;
|
/ ($(".game_hand_cards .card_holder", this.element_).length + 1);
|
||||||
this.handCardLargeSize_ = this.handCardSmallSize_ * scale;
|
},
|
||||||
if (this.handCardLargeSize_ > 236) {
|
};
|
||||||
this.handCardLargeSize_ = 236;
|
this.resizeCardHelper_(data);
|
||||||
}
|
this.handCardSmallSize_ = data.cardSmallSize;
|
||||||
this.handCardSmallScale_ = this.handCardSmallSize_ / 236;
|
this.handCardLargeSize_ = data.cardLargeSize;
|
||||||
this.handCardLargeScale_ = this.handCardSmallScale_ * scale;
|
this.handCardSmallScale_ = data.cardSmallScale;
|
||||||
if (this.handCardLargeScale_ > maxScale) {
|
this.handCardLargeScale_ = data.cardLargeScale;
|
||||||
this.handCardLargeScale_ = maxScale;
|
|
||||||
}
|
|
||||||
elems.width(this.handCardSmallSize_).height(this.handCardSmallSize_).animate({
|
|
||||||
scale : this.handCardSmallScale_,
|
|
||||||
}, {
|
|
||||||
duration : 0,
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -481,33 +474,58 @@ cah.Game.prototype.resizeHandCards_ = function() {
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
cah.Game.prototype.resizeRoundCards_ = function() {
|
cah.Game.prototype.resizeRoundCards_ = function() {
|
||||||
var elems = $(".game_white_cards .card_holder", this.element_);
|
|
||||||
var ct = elems.length;
|
|
||||||
// 30 by experiment in chrome.
|
|
||||||
$(".game_right_side", this.element_).width(
|
$(".game_right_side", this.element_).width(
|
||||||
$(window).width() - $(".game_left_side", this.element_).width() - 30);
|
$(window).width() - $(".game_left_side", this.element_).width() - 30);
|
||||||
this.roundCardSmallSize_ = ($(".game_white_cards", this.element_).width() - 20 - $(
|
var data = {
|
||||||
".game_left_side", this.element_).width())
|
class : ".game_white_cards",
|
||||||
/ ct;
|
cardSmallSize : this.roundCardSmallSize_,
|
||||||
if (this.roundCardSmallSize_ > 236) {
|
cardLargeSize : this.roundCardLargeSize_,
|
||||||
this.roundCardSmallSize_ = 236;
|
cardSmallScale : this.roundCardSmallScale_,
|
||||||
|
cardLargeScale : this.roundCardLargeScale_,
|
||||||
|
maxSmallSize : 236,
|
||||||
|
minSmallSize : 118,
|
||||||
|
smallSize : function() {
|
||||||
|
return ($(window).width() - $(".game_left_side", this.element_).width() - 60)
|
||||||
|
/ $(".game_white_cards .card_holder", this.element_).length;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
this.resizeCardHelper_(data);
|
||||||
|
this.roundCardSmallSize_ = data.cardSmallSize;
|
||||||
|
this.roundCardLargeSize_ = data.cardLargeSize;
|
||||||
|
this.roundCardSmallScale_ = data.cardSmallScale;
|
||||||
|
this.roundCardLargeScale_ = data.cardLargeScale;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper for resizing cards, so the logic only needs to be in one place.
|
||||||
|
*
|
||||||
|
* @param {Object}
|
||||||
|
* data In/out. Scale, size, and callback helper.
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
cah.Game.prototype.resizeCardHelper_ = function(data) {
|
||||||
|
var elems = $(data.class + " .card_holder", this.element_);
|
||||||
|
|
||||||
|
data.cardSmallSize = data.smallSize();
|
||||||
|
if (data.cardSmallSize > data.maxSmallSize) {
|
||||||
|
data.cardSmallSize = data.maxSmallSize;
|
||||||
}
|
}
|
||||||
if (this.roundCardSmallSize_ < 118) {
|
if (data.cardSmallSize < data.minSmallSize) {
|
||||||
this.roundCardSmallSize_ = 118;
|
data.cardSmallSize = data.minSmallSize;
|
||||||
}
|
}
|
||||||
var maxScale = 236 / this.roundCardSmallSize_;
|
var maxScale = 236 / data.cardSmallSize;
|
||||||
var scale = maxScale < 1.8 ? maxScale : 1.8;
|
var scale = maxScale < 1.8 ? maxScale : 1.8;
|
||||||
this.roundCardLargeSize_ = this.roundCardSmallSize_ * scale;
|
data.cardLargeSize = data.cardSmallSize * scale;
|
||||||
if (this.roundCardLargeSize_ > 236) {
|
if (data.cardLargeSize > 236) {
|
||||||
this.roundCardLargeSize_ = 236;
|
data.cardLargeSize = 236;
|
||||||
}
|
}
|
||||||
this.roundCardSmallScale_ = this.roundCardSmallSize_ / 236;
|
data.cardSmallScale = data.cardSmallSize / 236;
|
||||||
this.roundCardLargeScale_ = this.roundCardSmallScale_ * scale;
|
data.cardLargeScale = data.cardSmallScale * scale;
|
||||||
if (this.roundCardLargeScale_ > maxScale) {
|
if (data.cardLargeScale > maxScale) {
|
||||||
this.roundCardLargeScale_ = maxScale;
|
data.cardLargeScale = maxScale;
|
||||||
}
|
}
|
||||||
elems.width(this.roundCardSmallSize_).height(this.roundCardSmallSize_).animate({
|
elems.width(data.cardSmallSize).height(data.cardSmallSize).animate({
|
||||||
scale : this.roundCardSmallScale_,
|
scale : data.cardSmallScale,
|
||||||
}, {
|
}, {
|
||||||
duration : 0,
|
duration : 0,
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue