diff --git a/js/office_hours.js b/js/office_hours.js index 8816efb..87fd1f3 100644 --- a/js/office_hours.js +++ b/js/office_hours.js @@ -92,6 +92,7 @@ // Show the next slot item, slowly. const nextSlot = $(this).closest('tr').next(); + nextSlot.removeClass('js-office-hours-hide'); nextSlot.fadeIn('slow'); fixStriping($(this).parents('.field--type-office-hours')); @@ -126,6 +127,13 @@ // Clear the comment. slot.find('.form-text').each(clearValue); + slot.addClass('js-office-hours-hide'); + slot.fadeOut('slow'); + + const previousSelector = $(this).closest('tr').prev(); + previousSelector.find('[data-drupal-selector$=add]') + .show(); + // @todo Hide subsequent slot that is cleared. } @@ -204,7 +212,7 @@ Drupal.behaviors.office_hours = { attach: function doUpdateElement(context) { - $(document).ready(function prepareElements() { + $(once('office-hours', '.field--type-office-hours', context)).each(function prepareElements() { // Attach a function to each JS link and initialize if needed. // N.B.: using * wildcard, since initially, no suffix is added, // but after 'Add exception'button, a suffix is added to the ID.