-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move inline JavaScript to Webpack entry points
Issue #111
- Loading branch information
1 parent
21d5550
commit 60ef5a6
Showing
11 changed files
with
170 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// Enforce leading zeros in typed values ("87.6" -> "87.60"). | ||
// Do not use "input" event. It looks better but makes manual typing hard. | ||
// Works only in Webkit/Blink. "input.valueAsNumber" condition needed for MSEdge. | ||
// See: https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/6367416/ | ||
function setupDecimalFields() | ||
{ | ||
let inputs = document.querySelectorAll('input.decimal'); | ||
|
||
inputs.forEach(input => { | ||
let decimals = (input.step.match(/\..*/) || [''])[0].length - 1; | ||
|
||
if (decimals && input.valueAsNumber != undefined) { | ||
let updateFixed = () => { | ||
input.value = input.valueAsNumber.toFixed(decimals); | ||
}; | ||
|
||
input.addEventListener('change', updateFixed); | ||
updateFixed(); | ||
} | ||
}); | ||
} | ||
|
||
// Keep original "0.01" step for values smaller than 74, otherwise use "0.05". | ||
// This way entering usual frequencies is simpler while OIRT frequencies are | ||
// available too. See https://github.com/TomaszGasior/RadioLista-v3/issues/35 | ||
function setupFrequencyField() | ||
{ | ||
let frequencyInput = document.querySelector('.frequency-input'); | ||
|
||
const REPLACED_STEP = '0.05'; | ||
const ORIGINAL_STEP = frequencyInput.step; | ||
|
||
let updateStep = () => { | ||
if (frequencyInput.value >= 74) { | ||
if (frequencyInput.step != REPLACED_STEP) { | ||
frequencyInput.step = REPLACED_STEP; | ||
frequencyInput.min = REPLACED_STEP; | ||
} | ||
} | ||
else if (frequencyInput.step != ORIGINAL_STEP) { | ||
frequencyInput.step = ORIGINAL_STEP; | ||
frequencyInput.min = ORIGINAL_STEP; | ||
} | ||
}; | ||
|
||
updateStep(); | ||
frequencyInput.addEventListener('input', updateStep); | ||
frequencyInput.addEventListener('blur', updateStep); | ||
} | ||
|
||
function setupLocalityField() | ||
{ | ||
let localityTypeInput = document.querySelector('.locality-type-input'); | ||
let localityCityWrapper = document.querySelector('.locality-city-wrapper'); | ||
|
||
const LOCALITY_COUNTRY = localityTypeInput.dataset.localityCountryValue; | ||
|
||
let updateFieldVisibility = () => { | ||
localityCityWrapper.hidden = (localityTypeInput.value == LOCALITY_COUNTRY); | ||
}; | ||
|
||
updateFieldVisibility(); | ||
localityTypeInput.addEventListener('change', updateFieldVisibility); | ||
localityTypeInput.addEventListener('blur', updateFieldVisibility); | ||
} | ||
|
||
document.addEventListener('DOMContentLoaded', function(){ | ||
setupDecimalFields(); | ||
setupFrequencyField(); | ||
setupLocalityField(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
function setupRemoveConfirmDialog() | ||
{ | ||
let input = document.querySelector('.radio-table-remove-confirm'); | ||
|
||
let confirmDialog = () => { | ||
if (input.checked && false === window.confirm(input.dataset.confirmMessage)) { | ||
input.checked = false; | ||
input.blur(); | ||
} | ||
|
||
input.removeEventListener('change', confirmDialog); | ||
}; | ||
|
||
input.addEventListener('change', confirmDialog); | ||
} | ||
|
||
document.addEventListener('DOMContentLoaded', function(){ | ||
setupRemoveConfirmDialog(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,44 @@ | ||
import { RadioTableColumnsUI } from './src/RadioTableColumnsUI.js'; | ||
|
||
function setupCustomThemeField() | ||
{ | ||
let themeSelectorField = document.querySelector('.radio-table-theme'); | ||
let customThemeFieldsWrapper = document.querySelector('.radio-table-custom-theme-wrapper'); | ||
|
||
const CUSTOM_THEME_NAME = themeSelectorField.dataset.customThemeName; | ||
|
||
let updateFieldVisibility = () => { | ||
customThemeFieldsWrapper.hidden = (themeSelectorField.value != CUSTOM_THEME_NAME); | ||
}; | ||
|
||
updateFieldVisibility(); | ||
themeSelectorField.addEventListener('change', updateFieldVisibility); | ||
themeSelectorField.addEventListener('blur', updateFieldVisibility); | ||
} | ||
|
||
function setupCustomWidthField() | ||
{ | ||
let widthTypeInput = document.querySelector('.radio-table-width-type'); | ||
let customWidthFieldWrapper = document.querySelector('.radio-table-custom-width-wrapper'); | ||
|
||
const WIDTH_CUSTOM = widthTypeInput.dataset.customWidthValue; | ||
|
||
let updateFieldVisibility = () => { | ||
customWidthFieldWrapper.hidden = (widthTypeInput.value != WIDTH_CUSTOM); | ||
}; | ||
|
||
updateFieldVisibility(); | ||
widthTypeInput.addEventListener('change', updateFieldVisibility); | ||
widthTypeInput.addEventListener('blur', updateFieldVisibility); | ||
} | ||
|
||
document.addEventListener('DOMContentLoaded', function(){ | ||
let container = document.querySelector('.radio-table-columns'); | ||
let radioTableColumnsContainer = document.querySelector('.radio-table-columns'); | ||
|
||
if (container) { | ||
new RadioTableColumnsUI(container); | ||
if (radioTableColumnsContainer) { | ||
new RadioTableColumnsUI(radioTableColumnsContainer); | ||
} | ||
|
||
setupCustomThemeField(); | ||
setupCustomWidthField(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters