blob: 0e2e71145c1741e00f5e94084807b20cb9cdb43e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
|
jQuery(function ($) {
let inputSel = 'form.gradebook-lecturer-weights input[type="number"]'
const inputs = document.querySelectorAll.bind(document, inputSel)
const adder = inputEls => [...inputEls].reduce((a, b) => a + parseInt(b.value, 10), 0)
const percenter = (sum, item) => sum ? (parseInt(item.value, 10) / sum * 100).toFixed(1) : 0
$(document).on('change blur', inputSel, function (event) {
const sum = adder(inputs())
inputs().forEach(input => {
input.parentElement.querySelector("output").value = percenter(sum, input)
})
})
});
|