-
Notifications
You must be signed in to change notification settings - Fork 148
Expand file tree
/
Copy pathshared_iconFormField.tpl
More file actions
58 lines (48 loc) · 2.18 KB
/
shared_iconFormField.tpl
File metadata and controls
58 lines (48 loc) · 2.18 KB
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
<span id="{$field->getPrefixedId()}_icon">
{if $field->getIcon()}
{unsafe:$field->getIcon()->toHtml(64)}
{/if}
</span>
{if !$field->isImmutable()}
<button type="button" class="button small" id="{$field->getPrefixedId()}_openIconDialog">{lang}wcf.global.button.edit{/lang}</button>
<button type="button" class="button small" id="{$field->getPrefixedId()}_removeIcon"{if !$field->getIcon()} hidden{/if}>{lang}wcf.global.button.delete{/lang}</button>
{/if}
<input type="hidden" id="{$field->getPrefixedId()}" name="{$field->getPrefixedId()}" value="{$field->getValue()}">
{if !$field->isImmutable()}
{if $__iconFormFieldIncludeJavaScript}
{include file='shared_fontAwesomeJavaScript'}
{/if}
<script data-relocate="true">
require(['WoltLabSuite/Core/Ui/Style/FontAwesome'], (UiStyleFontAwesome) => {
const iconContainer = document.getElementById('{unsafe:$field->getPrefixedId()|encodeJS}_icon');
const input = document.getElementById('{unsafe:$field->getPrefixedId()|encodeJS}');
const buttonRemoveIcon = document.getElementById('{unsafe:$field->getPrefixedId()|encodeJS}_removeIcon');
const renderNativePreview = (iconName, forceSolid) => {
let icon = iconContainer.querySelector("fa-icon");
if (!icon || icon.parentElement !== iconContainer || iconContainer.childElementCount !== 1) {
iconContainer.replaceChildren();
icon = document.createElement("fa-icon");
icon.size = 64;
iconContainer.append(icon);
}
icon.setIcon(iconName, forceSolid);
};
const callback = (iconName, forceSolid, value, previewHtml) => {
input.value = typeof value === 'string' ? value : `${ iconName };${ forceSolid }`;
if (typeof previewHtml === 'string') {
iconContainer.innerHTML = previewHtml;
} else {
renderNativePreview(iconName, forceSolid);
}
buttonRemoveIcon.hidden = false;
};
const button = document.getElementById('{unsafe:$field->getPrefixedId()|encodeJS}_openIconDialog');
button.addEventListener('click', () => UiStyleFontAwesome.open(callback));
buttonRemoveIcon.addEventListener("click", () => {
input.value = "";
iconContainer.replaceChildren();
buttonRemoveIcon.hidden = true;
});
});
</script>
{/if}