forked from 1j01/jspaint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path$FontBox.js
78 lines (68 loc) · 1.84 KB
/
$FontBox.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
function $FontBox(){
const $fb = $(E("div")).addClass("font-box");
const $family = $(E("select"));
const $size = $(E("input")).attr({
type: "number",
min: 8,
max: 72,
value: text_tool_font.size,
});
const $button_group = $(E("span")).addClass("text-toolbar-button-group");
const $bold = $Toggle(0, "bold");
const $italic = $Toggle(1, "italic");
const $underline = $Toggle(2, "underline");
const $vertical = $Toggle(3, "vertical");
$vertical.attr("disabled", true);
$vertical.find("span").css({
filter: "grayscale(1) contrast(0.3) brightness(1.3) drop-shadow(1px 1px 0px white)" // approximate
});
$button_group.append($bold, $italic, $underline, $vertical);
$fb.append($family, $size, $button_group);
const update_font = () => {
text_tool_font.size = Number($size.val());
text_tool_font.family = $family.val();
$G.trigger("option-changed");
};
FontDetective.each(font => {
const $option = $(E("option"));
$option.val(font).text(font.name);
$family.append($option);
if (!text_tool_font.family) {
update_font();
}
});
if (text_tool_font.family) {
$family.val(text_tool_font.family);
}
$family.on("change", update_font);
$size.on("change", update_font);
const $w = $ToolWindow();
$w.title("Fonts");
$w.$content.append($fb);
$w.center();
return $w;
function $Toggle(xi, thing){
const $button = $(E("button"));
const $image = $(E("span")).appendTo($button);
$button.css({
width: 23,
height: 22
});
$image.css({
display: "block",
width: 16,
height: 16,
backgroundImage: "url(images/text-tools.png)",
backgroundPosition: `${xi*-16}px 0px`
});
$button.on("click", () => {
$button.toggleClass("selected");
text_tool_font[thing] = $button.hasClass("selected");
update_font();
});
if(text_tool_font[thing]){
$button.addClass("selected");
}
return $button;
}
}