+
diff --git a/assets/js/admin/fontSelect.js b/assets/js/admin/fontSelect.js
index 7117082c4..fa9b1f82b 100644
--- a/assets/js/admin/fontSelect.js
+++ b/assets/js/admin/fontSelect.js
@@ -1,5 +1,5 @@
// eslint-disable-next-line no-unused-vars
-function adminFontSelect(element, path) {
+function adminFontSelect(element, path, fontclass) {
const parent = element.closest('.adminFontSelection');
const origin = element.dataset.origin;
const src = element.src;
@@ -10,6 +10,7 @@ function adminFontSelect(element, path) {
previewElement.src = src;
textElement.textContent = origin;
inputElement.value = origin;
+ inputElement.setAttribute('data-fontclass', fontclass);
const event = new Event('change');
inputElement.dispatchEvent(event);
diff --git a/assets/js/admin/generator.js b/assets/js/admin/generator.js
index 699cdd014..ae2d78a92 100644
--- a/assets/js/admin/generator.js
+++ b/assets/js/admin/generator.js
@@ -103,9 +103,9 @@ function loadCurrentConfig() {
//text
$('input[name=\'text_enabled\'][data-trigger=\'general\']').prop('checked', text_enabled);
$('input[name=\'text_font_family\']').val(font_family);
- let fClass = $('input[name=\'text_font_family\']').data('fontclass');
+ $('input[name=\'text_font_family\']')[0].setAttribute('data-fontclass', 'font-selected');
$('#fontselectedStyle').html(
- `@font-face{font-family:"fontselected";src:url(${font_family}) format("truetype");} .${fClass}{font-family:"fontselected",Verdena,Tahoma;}`
+ `@font-face{font-family:"fontselected";src:url(${font_family}) format("truetype");} .font-selected{font-family:"fontselected",Verdena,Tahoma;}`
);
$('input[name=\'text_font_color\']').attr('value', font_color);
$('input[name=\'text_font_size\']').attr('value', font_size);
@@ -157,7 +157,7 @@ function changeGeneralSetting() {
const c_show_background = $('input[name=\'show-background\'][data-trigger=\'general\']').is(':checked');
const c_text_enabled = $('input[name=\'text_enabled\'][data-trigger=\'general\']').is(':checked');
- let c_text_font = $('input[name=\'text_font_family\']').data('fontclass');
+ let c_text_font = $('input[name=\'text_font_family\']')[0].getAttribute('data-fontclass');
let c_text_font_unique_id = $('input[name=\'text_font_family\']').data('unique-id');
let c_text_font_value = $('input[name=\'text_font_family\']').val();
const c_font_color = $('input[name=\'text_font_color\']').val();
@@ -217,7 +217,7 @@ function changeGeneralSetting() {
left: adjusted_tl + 'px'
});
if (c_text_font_value.startsWith('http')) {
- c_text_font = `customfont-${c_text_font_unique_id}`;
+ c_text_font = `font-${c_text_font_unique_id}`;
$('#fontselectedStyle').html(
`@font-face{font-family:"fontselected";src:url(${c_text_font_value}) format("truetype");} .${c_text_font}{font-family:"fontselected",Verdena,Tahoma;}`
);
@@ -225,7 +225,7 @@ function changeGeneralSetting() {
collageTextDOM.removeClass((index, classes) =>
classes
.split(' ')
- .filter((cName) => cName.startsWith('customfont'))
+ .filter((cName) => cName.startsWith('font-'))
.join(' ')
);
collageTextDOM.addClass(c_text_font);
diff --git a/src/Utility/AdminInput.php b/src/Utility/AdminInput.php
index 357007daf..1b0e8f77a 100644
--- a/src/Utility/AdminInput.php
+++ b/src/Utility/AdminInput.php
@@ -347,6 +347,13 @@ public static function renderFontSelect(array $setting, string $label): string
$languageService = LanguageService::getInstance();
$fonts = '';
+ $attributes = '';
+ if (isset($setting['attributes'])) {
+ foreach ($setting['attributes'] as $key => $prop) {
+ $attributes .= $key . '="' . $prop . '" ';
+ }
+ }
+
if (isset($setting['paths']) && is_array($setting['paths'])) {
$pathIndex = 0;
foreach ($setting['paths'] as $path) {
@@ -355,6 +362,7 @@ public static function renderFontSelect(array $setting, string $label): string
' . PathUtility::getPublicPath($path) . '
';
+ $fontClassName = 'font-' . $pathIndex;
try {
$files = FontUtility::getFontsFromPath($path, false);
$files = array_map(fn ($file): string => PathUtility::getPublicPath($file), $files);
@@ -365,14 +373,18 @@ public static function renderFontSelect(array $setting, string $label): string
';
}
- foreach ($files as $file) {
+ $fontIndex = 0;
+ foreach ($files as $name => $path) {
+ $fontClassName .= '-' . $fontIndex;
$imageAttributes = [
- 'onClick' => 'adminFontSelect(this, "' . $setting['name'] . '");',
- 'data-origin' => $file,
- 'title' => $file,
- 'class' => 'w-full h-full left-0 top-0 absolute object-contain cursor-pointer'
+ 'onClick' => 'adminFontSelect(this, "' . $setting['name'] . '", "' . $fontClassName . '");',
+ 'data-origin' => $path,
+ 'title' => $name,
+ 'class' => 'w-full h-full left-0 top-0 absolute object-contain cursor-pointer',
];
- $fonts .= '
' . FontUtility::getFontPreviewImage(fontPath: $file, attributes: $imageAttributes) . '
';
+ $fonts .= '';
+ $fonts .= '
' . FontUtility::getFontPreviewImage(fontPath: $path, attributes: $imageAttributes) . '
';
+ $fontIndex++;
}
} catch (\Exception $e) {
$fonts .= '
@@ -428,6 +440,7 @@ public static function renderFontSelect(array $setting, string $label): string
class="w-full h-10 border-2 border-solid border-gray-300 focus:border-brand-1 rounded-md px-3 mt-auto"
name="' . $setting['name'] . '"
value="' . $setting['value'] . '"
+ ' . $attributes . '
/>