jspaint/src/$FontBox.js

94 lines
2.6 KiB
JavaScript
Raw Normal View History

2014-08-16 01:57:01 +00:00
function $FontBox() {
const $fb = $(E("div")).addClass("font-box");
const $family = $(E("select")).addClass("inset-deep").attr({
"aria-label": "Font Family",
"aria-description": localize("Selects the font used by the text."),
});
2021-12-08 10:09:59 +00:00
const $size = $(E("input")).addClass("inset-deep").attr({
type: "number",
min: 8,
max: 72,
value: text_tool_font.size,
"aria-label": "Font Size",
"aria-description": localize("Selects the point size of the text."),
2020-12-11 03:00:00 +00:00
}).css({
maxWidth: 50,
});
const $button_group = $(E("span")).addClass("text-toolbar-button-group");
// @TODO: localized labels
const $bold = $Toggle(0, "bold", "Bold", localize("Sets or clears the text bold attribute."));
const $italic = $Toggle(1, "italic", "Italic", localize("Sets or clears the text italic attribute."));
const $underline = $Toggle(2, "underline", "Underline", localize("Sets or clears the text underline attribute."));
const $vertical = $Toggle(3, "vertical", "Vertical Writing Mode", localize("Only a Far East font can be used for vertical editing."));
$vertical.attr("disabled", true);
2014-08-16 01:57:01 +00:00
$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();
2014-08-16 01:57:01 +00:00
$G.trigger("option-changed");
};
FontDetective.each(font => {
const $option = $(E("option"));
$option.val(font).text(font.name);
2014-08-18 17:20:22 +00:00
$family.append($option);
if (!text_tool_font.family) {
update_font();
}
2014-08-18 17:20:22 +00:00
});
if (text_tool_font.family) {
$family.val(text_tool_font.family);
}
$family.on("change", update_font);
$size.on("change", update_font);
2020-03-24 14:20:05 +00:00
const $w = $ToolWindow();
2020-12-05 22:33:21 +00:00
$w.title(localize("Fonts"));
2014-08-16 01:57:01 +00:00
$w.$content.append($fb);
$w.center();
return $w;
function $Toggle(xi, thing, label, description) {
const $button = $(E("button")).addClass("toggle").attr({
"aria-pressed": false,
"aria-label": label,
"aria-description": description,
});
const $icon = $(E("span")).addClass("icon").appendTo($button);
$button.css({
width: 23,
2020-12-11 03:00:00 +00:00
height: 22,
padding: 0,
display: "inline-flex",
alignContent: "center",
alignItems: "center",
justifyContent: "center",
});
$icon.css({
flex: "0 0 auto",
display: "block",
width: 16,
height: 16,
"--icon-index": xi,
});
$button.on("click", () => {
$button.toggleClass("selected");
text_tool_font[thing] = $button.hasClass("selected");
$button.attr("aria-pressed", $button.hasClass("selected"));
update_font();
});
if (text_tool_font[thing]) {
$button.addClass("selected").attr("aria-pressed", true);
}
return $button;
}
2014-08-16 01:57:01 +00:00
}