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:
parent
3785274199
commit
57b13ffa72
3 changed files with 23 additions and 21 deletions
|
|
@ -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();
|
||||
|
|
|
|||
21
app/assets/javascripts/initializers/initializeColorPicker.js
Normal file
21
app/assets/javascripts/initializers/initializeColorPicker.js
Normal 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);
|
||||
});
|
||||
}
|
||||
|
|
@ -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>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue