Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drupal
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
drupal
Merge requests
!5098
allow 3-character hexadecimal color inputs
Code
Review changes
Check out branch
Open in Workspace
Download
Patches
Plain diff
Expand sidebar
Open
allow 3-character hexadecimal color inputs
issue/drupal-3396018:3396018-allow-three-character
into
11.x
Overview
4
Commits
6
Pipelines
7
Changes
3
1 open thread
Hide all comments
Open
allow 3-character hexadecimal color inputs
Andy Blum
requested to merge
issue/drupal-3396018:3396018-allow-three-character
into
11.x
Oct 23, 2023
Overview
4
Commits
6
Pipelines
7
Changes
3
1 open thread
Hide all comments
Closes
#3396018
0
0
Merge request reports
Compare
11.x
version 6
04955956
Oct 24, 2023
version 5
ff55bda0
Oct 24, 2023
version 4
d76323ac
Oct 23, 2023
version 3
27f862bf
Oct 23, 2023
version 2
97649638
Oct 23, 2023
version 1
8cb75a38
Oct 23, 2023
11.x (base)
and
latest version
latest version
fb71a829
6 commits,
Oct 25, 2023
version 6
04955956
5 commits,
Oct 24, 2023
version 5
ff55bda0
5 commits,
Oct 24, 2023
version 4
d76323ac
4 commits,
Oct 23, 2023
version 3
27f862bf
3 commits,
Oct 23, 2023
version 2
97649638
2 commits,
Oct 23, 2023
version 1
8cb75a38
1 commit,
Oct 23, 2023
3 files
+
54
−
10
Side-by-side
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
3
core/themes/olivero/js/color-picker.js
+
35
−
4
View file @ fb71a829
Edit in single-file editor
Open in Web IDE
Show full file
@@ -27,6 +27,31 @@
@@ -27,6 +27,31 @@
Drupal
.
announce
(
announcement
);
Drupal
.
announce
(
announcement
);
}
}
/**
* Formats hexcode to full 6-character string for HTMLColorInput.
*
* @param {string} hex The hex code input.
* @returns {string} The same hex code, formatted.
*/
function
formatHex
(
hex
)
{
// Temporarily remove hash
if
(
hex
.
startsWith
(
'
#
'
))
{
hex
=
hex
.
substring
(
1
);
}
// Convert three-value to six-value syntax.
if
(
hex
.
length
===
3
)
{
hex
=
hex
.
split
(
''
)
.
flatMap
((
character
)
=>
[
character
,
character
])
.
join
(
''
);
}
hex
=
`#
${
hex
}
`
;
return
hex
;
}
/**
/**
* `input` event callback to keep text & color inputs in sync.
* `input` event callback to keep text & color inputs in sync.
*
*
@@ -34,10 +59,16 @@
@@ -34,10 +59,16 @@
* @param {HTMLElement} inputToSync input element to synchronize
* @param {HTMLElement} inputToSync input element to synchronize
*/
*/
function
synchronizeInputs
(
changedInput
,
inputToSync
)
{
function
synchronizeInputs
(
changedInput
,
inputToSync
)
{
inputToSync
.
value
=
changedInput
.
value
;
inputToSync
.
value
=
formatHex
(
changedInput
.
value
)
;
changedInput
.
setAttribute
(
'
data-olivero-custom-color
'
,
changedInput
.
value
);
changedInput
.
setAttribute
(
inputToSync
.
setAttribute
(
'
data-olivero-custom-color
'
,
changedInput
.
value
);
'
data-olivero-custom-color
'
,
formatHex
(
changedInput
.
value
),
);
inputToSync
.
setAttribute
(
'
data-olivero-custom-color
'
,
formatHex
(
changedInput
.
value
),
);
const
colorSchemeSelect
=
document
.
querySelector
(
const
colorSchemeSelect
=
document
.
querySelector
(
'
[data-drupal-selector="edit-color-scheme"]
'
,
'
[data-drupal-selector="edit-color-scheme"]
'
,
@@ -130,7 +161,7 @@
@@ -130,7 +161,7 @@
'
form-element--type-color
'
,
'
form-element--type-color
'
,
'
form-element--api-color
'
,
'
form-element--api-color
'
,
);
);
colorInput
.
value
=
textInput
.
value
;
colorInput
.
value
=
formatHex
(
textInput
.
value
)
;
colorInput
.
setAttribute
(
'
name
'
,
`
${
textInput
.
name
}
_visual`
);
colorInput
.
setAttribute
(
'
name
'
,
`
${
textInput
.
name
}
_visual`
);
colorInput
.
setAttribute
(
colorInput
.
setAttribute
(
'
data-olivero-custom-color
'
,
'
data-olivero-custom-color
'
,
Loading