From dbe91cac884dea4dfc901c53093cb032065252c9 Mon Sep 17 00:00:00 2001 From: rxu Date: Mon, 19 May 2025 17:37:52 +0700 Subject: [PATCH] [ticket/16413] Add icon color picker PHPBB3-16413 --- phpBB/adm/style/acp_profile.html | 7 +++- phpBB/adm/style/admin.css | 26 ++++++++++++ phpBB/adm/style/ajax.js | 41 ++++++++++++++++++- .../prosilver/template/viewtopic_body.html | 4 +- 4 files changed, 72 insertions(+), 6 deletions(-) diff --git a/phpBB/adm/style/acp_profile.html b/phpBB/adm/style/acp_profile.html index 982bd5c4f5..40e5b28bca 100644 --- a/phpBB/adm/style/acp_profile.html +++ b/phpBB/adm/style/acp_profile.html @@ -92,8 +92,11 @@

{{ lang('FIELD_ICON_EXPLAIN') }}
-
{{ Icon('font', FIELD_ICON, '', true, '', {'style': 'font-size: 16px; margin:0 6px; vertical-align: middle;' ~ (FIELD_ICON_COLOR ? (' color: #' ~ FIELD_ICON_COLOR ~ ';') : '')}) }}
-
+
{{ Icon('font', FIELD_ICON, '', true, 'acp-icon', {'style': 'margin:0 6px;' ~ (FIELD_ICON_COLOR ? (' color: #' ~ FIELD_ICON_COLOR ~ ';') : '')}) }}
+
+ + +
{% EVENT acp_profile_contact_after %} diff --git a/phpBB/adm/style/admin.css b/phpBB/adm/style/admin.css index 290eaffcf8..78e380da9f 100644 --- a/phpBB/adm/style/admin.css +++ b/phpBB/adm/style/admin.css @@ -3152,3 +3152,29 @@ span + .o-icon { .acp-icon-disabled { color: #d0d0d0; } + + +input[type="color"] { + background-color: transparent; + border: solid 1px #d3d3d3; + border-radius: 50%; + width: 24px; + height: 24px; + padding: 2px; + cursor: pointer; + -webkit-appearance: none; +} + +input[type="color"]::-webkit-color-swatch-wrapper { + padding: 0; +} + +input[type="color"]::-webkit-color-swatch { + border: 0; + border-radius: 50%; +} + +input[type="color"]::-moz-color-swatch { + border: 0; + border-radius: 50%; +} diff --git a/phpBB/adm/style/ajax.js b/phpBB/adm/style/ajax.js index a68301ea68..18ed04d9ef 100644 --- a/phpBB/adm/style/ajax.js +++ b/phpBB/adm/style/ajax.js @@ -429,12 +429,49 @@ $(function() { $field_icon.after(''); } - $('#field_icon').on('keyup blur', function() { + $field_icon.on('keyup blur', function() { var input = $(this).val(); var $icon = $(this).next('i'); - $icon.attr('class', 'o-icon o-icon-font fa-fw fa-' + input + ' fas'); + $icon.attr('class', 'o-icon o-icon-font fa-fw fa-' + input + ' fas acp-icon'); }); + const DEFAULT_COLOR = '#000000'; + const HEX_REGEX = /^#[A-Fa-f0-9]{6}$/; + const colorPicker = document.getElementById('field_icon_color_picker'); + + if (!colorPicker) { + return; + } + + const colorText = colorPicker.previousElementSibling; + + if (!colorText || colorText.type !== 'text') { + return; + } + + const syncColors = (source, target) => { + const value = '#' + source.value.trim(); + target.value = HEX_REGEX.test(value) ? value : DEFAULT_COLOR; + }; + + const handleInput = ({ target }) => { + if (target === colorPicker) { + colorText.value = target.value.substring(1); + } else { + syncColors(colorText, colorPicker); + } + var icon = $field_icon.next('i'); + icon.css('color', colorPicker.value); + }; + + colorPicker.addEventListener("input", handleInput); + colorText.addEventListener("input", handleInput); + colorText.addEventListener('blur', () => { + if (!colorText.value.trim()) { + colorPicker.value = DEFAULT_COLOR; + } + }); + syncColors(colorText, colorPicker); }); })(jQuery); // Avoid conflicts with other libraries diff --git a/phpBB/styles/prosilver/template/viewtopic_body.html b/phpBB/styles/prosilver/template/viewtopic_body.html index 778830429a..97ada402f7 100644 --- a/phpBB/styles/prosilver/template/viewtopic_body.html +++ b/phpBB/styles/prosilver/template/viewtopic_body.html @@ -194,8 +194,8 @@ class="last-cell"> {% EVENT viewtopic_body_contact_icon_prepend %} {% if postrow.contact.ICON %} - {% set color = postrow.contact.ICON_COLOR ? ('color: #' ~ contact.ICON_COLOR) : '' %} - {{ Icon('font', contact.ICON, '', true, '', '', {'style': color}) }} + {% set color = postrow.contact.ICON_COLOR ? ({style: 'color: #' ~ contact.ICON_COLOR}) : [] %} + {{ Icon('font', contact.ICON, '', true, '', color) }} {% elseif postrow.contact.ID == 'pm' %} {{ Icon('font', 'message', '', true, 'far contact-icon') }} {% elseif postrow.contact.ID == 'email' %}