Files
notifications-admin/app/assets/javascripts/updateStatus.js
Tom Byers 2b91d1d524 Fix mis-spelling of aria-describedby
This is currently spelt incorrectly though it
seemed to work nonetheless. Can only assume this
is a common error, for this attribute or all
attribute names, so browsers work it out.

This makes the spelling match the spec:

https://www.w3.org/TR/wai-aria/#aria-describedby
2021-10-19 11:09:37 +01:00

83 lines
1.6 KiB
JavaScript

(function(window) {
"use strict";
window.GOVUK.Modules.UpdateStatus = function() {
const getRenderer = $component => response => $component.html(
response.html
);
const throttle = (func, limit) => {
let throttleOn = false;
let callsHaveBeenThrottled = false;
let timeout;
return function() {
const args = arguments;
const context = this;
if (throttleOn) {
callsHaveBeenThrottled = true;
} else {
func.apply(context, args);
throttleOn = true;
}
clearTimeout(timeout);
timeout = setTimeout(() => {
throttleOn = false;
if (callsHaveBeenThrottled) func.apply(context, args);
callsHaveBeenThrottled = false;
}, limit);
};
};
this.start = component => {
let id = 'update-status';
this.$component = $(component);
this.$textbox = $('#' + this.$component.data('target'));
this.$component
.attr('id', id);
this.$textbox
.attr(
'aria-describedby',
(
this.$textbox.attr('aria-describedby') || ''
) + (
this.$textbox.attr('aria-describedby') ? ' ' : ''
) + id
)
.on('input', throttle(this.update, 150))
.trigger('input');
};
this.update = () => {
$.ajax(
this.$component.data('updates-url'),
{
'method': 'post',
'data': this.$textbox.parents('form').serialize()
}
).done(
getRenderer(this.$component)
).fail(
() => {}
);
};
};
})(window);