Files
notifications-admin/app/assets/javascripts
Tom Byers 476ed1593c Make updateContent handle all AJAX the same
The current updateContent JS replaces the in-page
HTML with the HTML from the server the first time
an AJAX request is fired, even if the HTML from
the server has no changes. This is because the
code that compares the two operates on two
different things:

The HTML in the page is the component HTML, with
all the data attributes and the partial HTML
(marked with the 'ajax-block-container' class) as
its first child:

```
<div data-module="update-content" data-url="...">
  <div class="ajax-block-container">
    ...
  </div>
</div>
```

The HTML from the server only contains the
partial:

```
<div class="ajax-block-container">
  ...
</div>
```

The diffing code just sees them as different at
the top level so replaces the page HTML with the
partial from the server. This means all subsequent
diffs are between partial HTML and partial HTML so
only update on actual changes.

These replace the component with the partial, as
part of the component initialising. This means all
code that runs on an AJAX response will only
compare like-for-like so will result in actual
changes (or none at all), not just swapping one
element out for another.

Note: this commit also removes the
aria-live="polite" from the ajax_block component.
It has always been overwritten by the first
response so never announces anything to assistive
technologies. Removing it makes this more clear.
2022-02-09 12:25:15 +00:00
..