Move the color picker to its own initializer file (#11693)

* refactor: move the color picker to its own initializer file

* fix:wrap in the initializecolorpicker function with use strict
This commit is contained in:
Ridhwana 2020-12-01 15:34:44 +02:00 committed by GitHub
parent 3785274199
commit 57b13ffa72
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 21 deletions

View file

@ -12,7 +12,7 @@
initializeHeroBannerClose, initializeOnboardingTaskCard, initScrolling,
nextPage:writable, fetching:writable, done:writable, adClicked:writable,
initializePaymentPointers, initializeSpecialNavigationFunctionality, initializeBroadcast,
initializeDateHelpers
initializeDateHelpers, initializeColorPicker
*/
function callInitializers() {
@ -65,6 +65,7 @@ function callInitializers() {
initializeHeroBannerClose();
initializeOnboardingTaskCard();
initializeDateHelpers();
initializeColorPicker();
function freezeScrolling(event) {
event.preventDefault();

View file

@ -0,0 +1,21 @@
'use strict';
function initializeColorPicker() {
var pickers = Array.from(document.getElementsByClassName('js-color-field'));
function colorValueChange(e) {
var field = e.target;
var sibling = '';
if (field.nextElementSibling) {
sibling = field.nextElementSibling;
} else {
sibling = field.previousElementSibling;
}
sibling.value = field.value;
}
pickers.forEach(function (picker) {
picker.addEventListener('change', colorValueChange);
});
}

View file

@ -81,23 +81,3 @@
<button type="submit" class="crayons-btn">Save Profile Information</button>
</div>
<% end %>
<script>
var pickers = Array.from(document.getElementsByClassName('js-color-field'));
function colorValueChange(e) {
var field = e.target;
var sibling = '';
if (field.nextElementSibling) {
sibling = field.nextElementSibling;
} else {
sibling = field.previousElementSibling;
}
sibling.value = field.value;
}
pickers.forEach(function(picker) {
picker.addEventListener('change', colorValueChange);
});
</script>