diff --git a/app/assets/javascripts/collapsibleCheckboxes.js b/app/assets/javascripts/collapsibleCheckboxes.js index 7139e9a1b..cde89d278 100644 --- a/app/assets/javascripts/collapsibleCheckboxes.js +++ b/app/assets/javascripts/collapsibleCheckboxes.js @@ -5,7 +5,7 @@ function Summary (module) { this.module = module; - this.$el = module.$formGroup.find('.selection-summary').first(); + this.el = module.formGroup.querySelector('.selection-summary'); this.fieldLabel = module.fieldLabel; this.total = module.total; this.addContent(); @@ -20,14 +20,15 @@ }[field] || `No ${field}s`) }; Summary.prototype.addContent = function() { - const $hint = this.module.$formGroup.find('.usa-hint'); - this.$text = $(`
`); + const hint = this.module.formGroup.querySelector('.usa-hint'); + this.text = document.createElement('p'); + this.text.className = 'selection-summary__text'; - if (this.fieldLabel === 'folder') { this.$text.addClass('selection-summary__text--folders'); } + if (this.fieldLabel === 'folder') { this.text.classList.add('selection-summary__text--folders'); } - this.$el.attr('id', $hint.attr('id')); - this.$el.append(this.$text); - $hint.remove(); + this.el.setAttribute('id', hint.getAttribute('id')); + this.el.appendChild(this.text); + hint.remove(); }; Summary.prototype.update = function(selection) { let template; @@ -40,19 +41,19 @@ template = 'none'; } - this.$text.html(this.templates[template](selection, this.total, this.fieldLabel)); + this.text.innerHTML = this.templates[template](selection, this.total, this.fieldLabel); }; Summary.prototype.bindEvents = function () { // take summary out of tab order when focus moves - this.$el.on('blur', (e) => $(this).attr('tabindex', '-1')); + this.el.addEventListener('blur', (e) => e.target.setAttribute('tabindex', '-1')); }; function Footer (module) { this.module = module; this.fieldLabel = module.fieldLabel; - this.fieldsetId = module.$fieldset.attr('id'); - this.$el = this.getEl(this.module.expanded); - this.module.$formGroup.append(this.$el); + this.fieldsetId = module.fieldset.getAttribute('id'); + this.el = this.getEl(this.module.expanded); + this.module.formGroup.appendChild(this.el); } Footer.prototype.buttonContent = { change: (fieldLabel) => `Choose ${fieldLabel}s`, @@ -63,37 +64,37 @@ const buttonContent = this.buttonContent[buttonState](this.fieldLabel); const stickyClass = expanded ? ' js-stick-at-bottom-when-scrolling' : ''; - return $(``); + `; + return div; }; Footer.prototype.update = function (expanded) { - this.$el.remove(); - this.$el = this.getEl(expanded); + this.el.remove(); + this.el = this.getEl(expanded); - this.module.$formGroup.append(this.$el); + this.module.formGroup.appendChild(this.el); }; function CollapsibleCheckboxes () {} - CollapsibleCheckboxes.prototype._focusTextElement = ($el) => { - $el - .attr('tabindex', '-1') - .focus(); + CollapsibleCheckboxes.prototype._focusTextElement = (el) => { + el.setAttribute('tabindex', '-1'); + el.focus(); }; CollapsibleCheckboxes.prototype.start = function(component) { - this.$component = $(component); - this.$formGroup = this.$component.find('.usa-form-group').first(); - this.$fieldset = this.$formGroup.find('fieldset').first(); - this.$checkboxes = this.$fieldset.find('input[type=checkbox]'); - this.fieldLabel = this.$component.data('fieldLabel'); - this.total = this.$checkboxes.length; - this.legendText = this.$fieldset.find('legend').first().text().trim(); + this.component = component; + this.formGroup = component.querySelector('.usa-form-group'); + this.fieldset = this.formGroup.querySelector('fieldset'); + this.checkboxes = this.fieldset.querySelectorAll('input[type=checkbox]'); + this.fieldLabel = component.dataset.fieldLabel; + this.total = this.checkboxes.length; + this.legendText = this.fieldset.querySelector('legend').textContent.trim(); this.expanded = false; this.checkUncheckButtonsAdded = false; @@ -103,71 +104,78 @@ this.footer = new Footer(this); this.summary = new Summary(this); - this.$fieldset.before(this.summary.$el); + this.fieldset.insertAdjacentElement('beforebegin', this.summary.el); // add custom classes - this.$formGroup.addClass('selection-wrapper'); - this.$fieldset.addClass('selection-content'); + this.formGroup.classList.add('selection-wrapper'); + this.fieldset.classList.add('selection-content'); // hide checkboxes - this.$fieldset.hide(); + this.fieldset.style.display = 'none'; this.bindEvents(); }; - CollapsibleCheckboxes.prototype.getSelection = function() { return this.$checkboxes.filter(':checked').length; }; + CollapsibleCheckboxes.prototype.getSelection = function() { + return Array.from(this.checkboxes).filter(cb => cb.checked).length; + }; CollapsibleCheckboxes.prototype.addHeadingHideLegend = function() { - const headingLevel = this.$component.data('heading-level') || '2'; + const headingLevel = this.component.dataset.headingLevel || '2'; - this.$heading = $(`