default_font_size function obj ratio var minFontSize Infinity obj each

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
default_font_size = function ($obj, ratio) {
var minFontSize = Infinity;
$obj.each(function (index, elem) {
$(elem).css({
fontSize: body_height * ratio
});
var wd = $(elem).width();
var fs = parseInt($($(elem).children("div")[0]).css('font-size'));
var tl = $($(elem).children("div")[0]).text().trim().length;
if ((wd - fs) < tl * fs) {
if (tl != 0 && fs != 0) {
minFontSize = Math.min(minFontSize, fs * ((wd - fs) / (fs * tl)));
}
}
});
if (minFontSize != Infinity) {
$obj.css({
'font-size': minFontSize + "px"
});
}
$obj.each(function (index, elem) {
if(!$(elem).hasClass("costs") && !$(elem).hasClass("bank") && !$(elem).hasClass("question")){
$($(elem).children("div")[0]).css({
position: 'relative',
width: '100%',
left: 0,
top: ($(elem).height() - $($(elem).children("div")[0]).height()) / 2
});
} else {
if ($(elem).hasClass("big")) {
$($(elem).children("div")[0]).css({
position: 'relative',
width: '100%',
left: 0,
top: (($(elem).height() - $($(elem).children("div")[0]).height()) / 2) * 0.025,
'font-size': body_height * 0.08
});
}
if ($(elem).hasClass("little")) {
$($(elem).children("div")[0]).css({
position: 'relative',
width: '100%',
left: 0,
top: (($(elem).height() - $($(elem).children("div")[0]).height()) / 2) * 0.025,
'font-size': body_height * 0.05
});
}
if ($(elem).hasClass("bank")) {
$($(elem).children("div")[0]).css({
position: 'relative',
width: '100%',
left: 0,
top: 16,
'font-size': body_height * 0.08
});
}
if ($(elem).hasClass("question")) {
$($(elem).children("div")[0]).css({
position: 'relative',
width: '100%',
left: 0,
'font-size': body_height * 0.05
});
}
}
});
};