1/** 2 * @file 3 * Helper js for all Find a Doctor forms. 4 */ 5 6(function ($, window, Drupal) { 7 Drupal.behaviors.tsLvhnFAD = { 8 attach: function (context, settings) { 9 // Open/close location list 10 $('.view-locations.dropdown', context).click(function(e) { 11 e.preventDefault(); 12 $(this).toggleClass('collapse'); 13 if($(this).hasClass('collapse')) { 14 $(this).attr('aria-label', Drupal.t('Collapse doctor\'s locations')); 15 } else { 16 $(this).attr('aria-label', Drupal.t('View doctor\'s locations')); 17 } 18 }); 19 20 // Set select2 facet placeholder text. 21 once('clinician-name-filter', '#block-ts-lvhn-doctornameanddegree', context).forEach(function (element) { 22 setTimeout(function() { 23 const $placeholder = $(element).find('.select2-selection__placeholder'); 24 if ($placeholder.length) { 25 $placeholder.text(Drupal.t('Filter by name')); 26 } 27 }, 100); 28 }); 29 30 // Put a class on the autocomplete div on pages that use FAD 31 if ($('.block-fad-initial-simple,.block-fad-refine-results-top', context).length) { 32 $('ul.ui-autocomplete.ui-widget.ui-widget-content', context).addClass('fax-autosuggest'); 33 } 34 35 function waitForFacetFilter($facetBlock, selector, callback) { 36 const interval = setInterval(function() { 37 const $el = $facetBlock.find(selector).next('a'); 38 if ($el.length && $el.attr('data-facet-filter')) { 39 clearInterval(interval); 40 callback($el.attr('data-facet-filter')); 41 } 42 }, 100); 43 } 44 45 // Show the type of care block after certain keyword searches. 46 // Run the code when the Type of Care facet context is loaded. 47 if ($(context).closest('.block-facets').hasClass('block-facet-blocktype-of-care')) { 48 const $block = $('.type-of-care-block'); 49 const $facetBlock = $('.block-facet-blocktype-of-care'); 50 const params = new URLSearchParams(location.search); 51 const keys = params.get('keys'); 52 const showBlock = params.get('typeofcare'); 53 let buttonLabelSpecialist, buttonLabelPrimary, hrefLabelSpecialist, hrefLabelPrimary; 54 let specialistReady = false, primaryReady = false; 55 56 if ($(context).closest('.block-facets').hasClass('block-facet-blocktype-of-care')) { 57 if ($facetBlock.length && $facetBlock.find('li.facet-item').length > 1) { 58 buttonLabelSpecialist = $facetBlock.find("[for='type-of-care-specialist']").text(); 59 buttonLabelPrimary = $facetBlock.find("[for='type-of-care-primary']").text(); 60 61 waitForFacetFilter($facetBlock, "[for='type-of-care-specialist']", function(value) { 62 hrefLabelSpecialist = value; 63 specialistReady = true; 64 maybeShowBlock(); 65 }); 66 waitForFacetFilter($facetBlock, "[for='type-of-care-primary']", function(value) { 67 hrefLabelPrimary = value; 68 primaryReady = true; 69 maybeShowBlock(); 70 }); 71 } 72 } 73 74 function maybeShowBlock() { 75 if (specialistReady && primaryReady) { 76 77 if ((!showBlock || showBlock !== 'no') && keys && !['primary care', 'internal medicine', 'family medicine'].includes(decodeURIComponent(keys).toLowerCase())) { 78 if (buttonLabelSpecialist && buttonLabelPrimary) { 79 $block.find('.specialist').text(buttonLabelSpecialist); 80 $block.find('.primary-care').text(buttonLabelPrimary); 81 $block.find('.specialist').attr('href', hrefLabelSpecialist + '&typeofcare=no'); 82 $block.find('.primary-care').attr('href', hrefLabelPrimary + '&typeofcare=no'); 83 84 // Conditional css. Everything is complicated by the facet summary 85 // block showing up even when it is empty. 86 if ($('.facets-summary-block__wrapper').length) { 87 $block.css("margin-top", "0"); 88 } 89 $block.removeClass('hidden'); 90 } 91 } 92 } 93 } 94 } 95 96 // Show the First Available Appt block when a specialty is selected. 97 if (context === document || $(context).hasClass('view-find-a-doctor')) { 98 let params = new URLSearchParams(location.search); 99 let showFirstAvailableAppt = false;
100 for (const value of params.values()) { 101 let valParts = value.split(":"); 102 if (valParts[0] !== undefined && valParts[0] === 'specialty') { 103 // Check if selected specialty qualifies for first available appt. 104 if (valParts[1] !== undefined && drupalSettings.firstApptSpecialties.includes(valParts[1])) { 105 showFirstAvailableAppt = true; 106 } 107 } else if (valParts[0] !== undefined && valParts[0] === 'conditions') { 108 // Check if selected condition qualifies for first available appt. 109 if (valParts[1] !== undefined && drupalSettings.firstApptConditions.includes(valParts[1])) { 110 showFirstAvailableAppt = true; 111 } 112 // @todo - Uncomment if filtering by services becomes an option. 113 // } else if (valParts[0] !== undefined && valParts[0] === 'services') { 114 // // Check if selected location qualifies for first available appt. 115 // if (valParts[1] !== undefined && drupalSettings.firstApptServices.includes(valParts[1])) { 116 // showFirstAvailableAppt = true; 117 // } 118 // } 119 } 120 } 121 // Show or hide the block. 122 if (showFirstAvailableAppt) { 123 $('.first-available-appt-block', context).removeClass('hidden') 124 .find('a').attr('href', 'https://my.lvhn.org/mychart/openscheduling?linksource=lvhn-org|first-available'); 125 } else { 126 $('.first-available-appt-block', context).addClass('hidden'); 127 } 128 } 129 130 // On a doctor subpage, hide the filters if there is no pager. 131 var $subpageView = $('.page-node-type-subpage,.subpage.doctors', context).find('.view-find-a-doctor'); 132 if ($subpageView.length && !$('nav.pager', $subpageView).length ) { 133 $('.view-filters', $subpageView).hide(); 134 $('button.filter-icon', $subpageView).hide(); 135 } 136 } 137 } 138})(jQuery, window, Drupal );
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.