1(function($, Drupal, drupalSettings, once){ 2 "use strict"; 3 4 Drupal.behaviors.HologicViews = { 5 attach: function (context, settings){ 6 function triggerSubmit(element, forceReload){ 7 if($(element).attr("data-reload-on-change") === 'true' || forceReload === true){ 8 var submitButton = $($(element).data('submit-button-id')); 9 //Auto submit the form if it's not a text field, if it is submit only if enter is pressed or on blur 10 if ($(element).attr('type') !== 'text' && !$(element).hasClass('form-text')) { 11 submitButton.trigger('click'); 12 } 13 else if ((event.keyCode && event.keyCode === 13) || event.type === 'blur') { 14 submitButton.trigger('click'); 15 } 16 } 17 } 18 19 // Initially try and unbind everything (Drupal AJAX causes multiple calls of the attach() function). 20 $(once('hologic-views', '*[data-hologic-bind]', context)).each(function() { 21 let $element = $(this); 22 $element.on('click', function(event) { 23 // List style element. 24 if ($(this).is('a')) { 25 event.preventDefault(); 26 27 // Is a multiselect. 28 if ($(this).attr('data-multiple') === 'true') { 29 30 $(this).parent().toggleClass('active'); 31 32 // Get all values from matching <a> 33 var vals = $('li.active a[data-key="'+$(this).attr('data-key')+'"]').map(function(i, v) { 34 return $(this).attr('data-value'); 35 }).toArray(); 36 37 $($(this).attr('data-hologic-bind')).val(vals); // Apply the multi-select values. 38 } 39 // Not a multiselect. 40 else { 41 42 if ($(this).attr('data-hologic-bind') !== 'sort') { 43 $($(this).attr('data-hologic-bind')).val($(this).attr('data-value')); 44 } 45 else { 46 $($(this).attr('data-form-bind') + ' [name="sort_by"]').val($(this).attr('data-key')); 47 $($(this).attr('data-form-bind') + ' [name="sort_order"]').val($(this).attr('data-value')); 48 } 49 } 50 51 triggerSubmit(this, true); 52 } 53 54 55 }).on('change', function(event) { 56 let $view = $($(this).data('view-bind')); 57 if($(this).is('input') || $(this).is('select')){ 58 if ($(this).attr('data-hologic-bind') !== 'sort') { 59 if ($(this).data('multiple') === true) { 60 // If checkbox 61 if ($(this).is(':checkbox')) { 62 if ($(this).data('target-type') === 'select') { 63 let vals = $('input[data-key="' + $(this).attr('data-key') + '"]:checked', $view).map(function (i, v) { 64 return $(this).attr('data-value'); 65 }).toArray(); 66 $($(this).attr('data-hologic-bind')).val(vals); // Apply the multi-select values. 67 } 68 else { 69 $('input[data-drupal-selector="' + $(this).attr('data-drupal-selector') + '"]', $view).prop('checked', $(this).is(':checked')); 70 } 71 } 72 else { 73 $($(this).attr('data-hologic-bind')).val($(this).val()); 74 } 75 } 76 else { 77 // Checkbox 78 if ($(this).is(':checkbox')) { 79 $('input[data-drupal-selector="' + $(this).attr('data-drupal-selector') + '"]', $view).prop('checked', $(this).is(':checked')); 80 } 81 else { 82 $($(this).attr('data-hologic-bind')).val($(this).val()); 83 } 84 } 85 } 86 else { 87 $($(this).attr('data-form-bind') + ' [name="sort_by"]').val($(this).attr('name')); 88 $($(this).attr('data-form-bind') + ' [name="sort_order"]').val($(this).val()); 89 } 90 } 91 92 triggerSubmit(this); 93 }).on('keyup', function(event) { 94 triggerSubmit(this); 95 }); 96 }); 97 98 $(once('hologic-views', '.hologic-apply-filters')).each(function() { 99 $(this).on('click', function(event) { 100 event.preventDefault(); 101
102 let $view = $($(this).data('view-bind')); 103 104 $.each($("*[data-reload-on-change='false']", $view), function() { 105 if ($(this).attr('data-bind') !== 'sort') { 106 $($(this).attr('data-bind')).val($(this).val()); 107 } 108 else { 109 $($(this).attr('data-form-bind') + ' [name="sort_by"]').val($(this).attr('name')); 110 $($(this).attr('data-form-bind') + ' [name="sort_order"]').val($(this).val()); 111 } 112 }); 113 114 $($(this).data('submit-button-id')).trigger('click'); 115 }); 116 }); 117 118 $('.hologic-reset-filters').on('click', function(event) { 119 event.preventDefault(); 120 $($(this).data('reset-button-id')).trigger('click'); 121 }); 122 } 123 }; 124 125 Drupal.behaviors.HologicSearchForm = { 126 attach: function (context, settings) { 127 // Process filter button only for Newsroom view. 128 const $newsroom = $(once('newsroom', '.view-id-newsroom', context)); 129 $newsroom.each(function() { 130 let isActive = false; 131 132 $(document).on('ajaxComplete', function() { 133 if (isActive == true) { 134 $('.close-filters').removeClass('hidden-sm hidden-xs'); 135 } 136 else { 137 $('.close-filters').addClass('hidden-sm hidden-xs'); 138 } 139 $(once('filter', '.view-id-newsroom .filter-form-button')).on('click', function() { 140 isActive = !isActive; 141 $('.close-filters').toggleClass('hidden-sm hidden-xs'); 142 }); 143 }); 144 145 $(once('filter', '.view-id-newsroom .filter-form-button')).on('click', function() { 146 $(this).closest('.view-filters').find('.close-filters').toggleClass('hidden-sm hidden-xs'); 147 }); 148 }); 149 150 // Process filter button for other views. 151 const $filterFormButton = $(once('filter-form-button', '.filter-form-button', context)); 152 if (!$filterFormButton.closest('.view-id-newsroom').length) { 153 $filterFormButton.click(function () { 154 $(this).closest('.view-filters').find('.close-filters').toggleClass('hidden-sm hidden-xs'); 155 }); 156 } 157 158 $(once('hologic-search', '.icon-inside', context)).each(function() { 159 let wrapper = $(this); 160 $('.icon-cross', this).on('click', function() { 161 // Redirect When the clear button is clicked. 162 const urlObj = new URL(window.location.href); 163 urlObj.searchParams.delete('search_api_fulltext'); 164 location.href = urlObj.toString(); 165 166 $('input[type="text"]', wrapper).val(''); 167 }); 168 }); 169 } 170 }; 171 172 Drupal.behaviors.HologicCleanFilterUrl = { 173 attach: function (context, settings) { 174 if (context !== document) { 175 return; 176 } 177 178 const originalPushState = history.pushState; 179 const originalReplaceState = history.replaceState; 180 const cleanUrl = function (url) { 181 if (!url) { 182 return url; 183 } 184 const parsedUrl = new URL(url, window.location.origin); 185 // Remove query parameters before the URL reaches the browser. 186 parsedUrl.search = ''; 187 return parsedUrl.pathname + parsedUrl.hash; 188 }; 189 190 history.pushState = function (state, title, url) { 191 return originalPushState.call( 192 history, 193 state, 194 title, 195 cleanUrl(url) 196 ); 197 }; 198 199 history.replaceState = function (state, title, url) { 200 return originalReplaceState.call( 201 history, 202 state, 203 title, 204 cleanUrl(url) 205 ); 206 }; 207 } 208 }; 209 210 Drupal.behaviors.HologicViewsBootstrap = { 211 attach: function (context, settings) { 212 213 // Fix Bootstrap 3.4.3 collapse plugin 214 $(document) 215 .off('click.bs.collapse.data-api') 216 .on('click.bs.collapse.data-api', '[data-toggle="collapse"]', function (e) { 217 var $this = $(this); 218 var target = $this.attr('data-target'); 219 var href; 220 221 if (!target) { 222 e.preventDefault(); 223 href = $this.attr('href'); 224 target = href && href.replace(/.*(?=#[^\s]+$)/, ''); 225 } 226 227 var $target = $(target); 228 if (!$target.length) { 229 return; 230 } 231 232 var parent = $this.attr('data-parent'); 233 if (parent && !$target.data('bs.collapse')) { 234 // Initialize with the parent option so Bootstrap treats this 235 // as part of an accordion group (closes sibling panels). 236 $target.collapse({ parent: parent, toggle: false }); 237 } 238 239 $target.collapse('toggle'); 240 }); 241 // Manual tab switching. 242 $(document) 243 .off('click.hologicTabs') 244 .on('click.hologicTabs', '.tabs-left .nav-tabs a', function (e) { 245 e.preventDefault(); 246 247 const $link = $(this); 248 const target = $link.attr('href'); 249 const $tabs = $link.closest('.tabs-left'); 250 251 // Activate tab. 252 $tabs.find('.nav-tabs li').removeClass('active'); 253 $tabs.find('.nav-tabs a').removeClass('active'); 254 255 $link.parent().addClass('active'); 256 $link.addClass('active'); 257 258 // Activate pane. 259 $tabs.find('.tab-pane').removeClass('active in show'); 260 $tabs.find(target).addClass('active'); 261 262 // Remove hash from URL. 263 if (window.location.hash) { 264 history.replaceState( 265 null, 266 '', 267 window.location.pathname + window.location.search 268 ); 269 } 270 }); 271
272 // Support opening a tab from URL hash. 273 $(once('view-content', '.view-support-3', context)).each(function () { 274 275 const hash = window.location.hash; 276 277 if (hash) { 278 279 const supportDesktopView = $( 280 `.tabs-left .nav-tabs a[href="${hash}"]`, 281 context 282 ); 283 284 if (supportDesktopView.length) { 285 supportDesktopView.trigger('click'); 286 } 287 288 // Mobile accordion support. 289 const mobileHash = hash.replace('tab-views-bootstrap-tab-', ''); 290 291 const supportMobileView = $( 292 `#view-support-3-support-mobile ${mobileHash.replace('desktop', 'mobile-collapse')}`, 293 context 294 ); 295 296 if (supportMobileView.length && $.fn.collapse) { 297 supportMobileView.collapse('show'); 298 } 299 } 300 }); 301 } 302 }; 303 304})(jQuery, Drupal, drupalSettings, once);
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.