-
Notifications
You must be signed in to change notification settings - Fork 0
/
wrapm.js
93 lines (80 loc) · 3.14 KB
/
wrapm.js
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
$(document).ready(function() {
var textAreaHeight = $('#inp').height();
var textAreaWidth = $('#inp').width();
var fontSize = 200;
// Setup font.
$('#inp').css('font-family', "Tahoma, sans-serif");
$('#inp').css('font-size', fontSize + "px");
$('#hiddenSpan').css('font-family', "Tahoma, sans-serif");
$('#hiddenSpan').css('font-size', fontSize + "px");
// Global scope probably not required.
// var textHeight = 0;
var factor = 0.75;
$('#inp').keyup(resize);
function decreaseFontWidth(textHeight, factor, fontSize) {
// Special scaling for Courier font.
if ($('#inp').css('font-family') == "Courier") {
console.log("REFACTOR");
factor = factor*0.75;
}
// Console inspection.
console.log("Text area height:", textAreaHeight);
console.log("Font size:", fontSize);
if (textHeight > textAreaHeight) {
var newFontSize = fontSize*factor;
console.log("New font size:", newFontSize);
$('#inp').css("font-size", newFontSize+"px");
$('#hiddenSpan').css("font-size", newFontSize+"px");
textHeight = $('#hiddenSpan').height();
return decreaseFontWidth(textHeight, factor, newFontSize);
} else {
return factor;
}
}
function resize() {
$('#hiddenSpan').html($('#inp').val());
//var fontFamily = $('#inp').css('font-family');
var textHeight = $('#hiddenSpan').height();
decreaseFontWidth(textHeight, factor, fontSize);
if($('#inp').val()=="") {
$('#inp').css('font-family', 'Tahoma, sans-serif');
$('#inp').css('font-size', '200px');
$('#hiddenSpan').css('font-family', "Tahoma, sans-serif");
$('#hiddenSpan').css('font-size', "200px");
}
}
/* INCLUDE. ************************************************ */
$('#style_minimal').click(function() {
$('#inp').css('background-color', 'white');
$('#inp').css('border', '10px solid #aaaaaa');
$('#inp').css('color', 'black');
})
$('#style_matte').click(function() {
$('#inp').css('background-color', '#bbbaaa');
$('#inp').css('border', '10px solid #aaaaaa');
$('#inp').css('color', 'black');
})
$('#style_pop').click(function() {
$('#inp').css('background-color', 'white');
$('#inp').css('border', '10px solid magenta');
$('#inp').css('color', 'magenta');
})
$('#style_rich').click(function() {
$('#inp').css('background-color', '#2ecfff');
$('#inp').css('border', '10px solid #25a5cc');
$('#inp').css('color', 'white');
})
$('#font_tahoma').click(function() {
$('#inp').css('font-family', 'Tahoma, sans-serif');
})
$('#font_courier').click(function() {
$('#inp').css('font-family', 'Courier');
})
$('#font_times').click(function() {
$('#inp').css('font-family', 'Times');
})
$('#font_roboto').click(function() {
$('#inp').css('font-family', 'Roboto');
})
/* ********************************************************* */
});