+ };
+
+ // Find all <th> with class select-all, and insert the check all checkbox.
+ $table
+ .find('th.select-all')
+ .prepend(
+ $('<input type="checkbox" class="form-checkbox" />').attr(
+ 'title',
+ strings.selectAll,
+ ),
+ )
+ .on('click', event => {
+ if ($(event.target).is('input[type="checkbox"]')) {
+ // Loop through all checkboxes and set their state to the select all
+ // checkbox' state.
+ checkboxes.each(function() {
+ const $checkbox = $(this);
+ const stateChanged =
+ $checkbox.prop('checked') !== event.target.checked;
+
+ /**
+ * @checkbox {HTMLElement}
+ */
+ if (stateChanged) {
+ $checkbox.prop('checked', event.target.checked).trigger('change');
+ }
+ // Either add or remove the selected class based on the state of the
+ // check all checkbox.
+
+ /**
+ * @checkbox {HTMLElement}
+ */
+ $checkbox.closest('tr').toggleClass('selected', this.checked);
+ });
+ // Update the title and the state of the check all box.
+ updateSelectAll(event.target.checked);
+ }
+ });