PageSourceSearch

https://www.pathsolutions.com/hubfs/hub_generated/module_assets/1/…_Search_-_Path_Solutions_October2018.min.js

js pathsolutions.com collected 2026-10-02 05:04:20 UTC 5,643 bytes, 181 lines download raw bytes

1  var module_4269736 = (function() {
2    var __hs_messages = {};
3    i18n_getmessage = function() {
4      return hs_i18n_getMessage(__hs_messages, hsVars['language'], arguments); 
5    };
6    i18n_getlanguage = function() {
7      return hsVars['language']; 
8    };
9var hsSearch = function(_instance) {
10  var TYPEAHEAD_LIMIT			= 3;
11  var searchTerm      		= "",
12      searchForm 					=	_instance,
13      searchField 				= _instance.querySelector('.hs-search-field__input'),
14      searchResults 			= _instance.querySelector('.hs-search-field__suggestions'),
15     	searchOptions				= function() {
16        var formParams = [];
17        var form = _instance.querySelector('form');
18        for ( var i = 0; i < form.querySelectorAll('input[type=hidden]').length; i++ ) {
19           var e = form.querySelectorAll('input[type=hidden]')[i];
20          	if (e.name !== 'limit') {
21            	formParams.push(encodeURIComponent(e.name) + "=" + encodeURIComponent(e.value));
22            }
23        }
24        var queryString = formParams.join("&");
25				return queryString;
26      };
27  
28  var debounce = function(func, wait, immediate) {
29    var timeout;
30    return function() {
31      var context = this,
32          args = arguments;
33      var later = function() { 
34        timeout = null;
35        if ( !immediate ) {
36          func.apply(context, args);
37        }
38      };
39      var callNow = immediate && !timeout;
40      clearTimeout(timeout);
41      timeout = setTimeout(later, wait || 200);
42      if ( callNow ) { 
43        func.apply(context, args); 
44      }
45    };
46  },
47  emptySearchResults = function(){
48    searchResults.innerHTML = '';
49    searchField.focus();
50    searchForm.classList.remove('hs-search-field--open');
51  },
52  fillSearchResults = function(response){
53    var items = [];
54		items.push( "<li id='results-for'>Results for \"" + response.searchTerm + "\"</li>" );
55    response.results.forEach(function(val, index) {
56      items.push( "<li id='result" + index + "'><a href='" + val.url + "'>" + val.title + "</a></li>" );
57    });
58
59    emptySearchResults();
60    searchResults.innerHTML = items.join("");
61    searchForm.classList.add('hs-search-field--open');
62  },
63  getSearchResults = function() {
64			var request = new XMLHttpRequest();
65   		var requestUrl = "/_hcms/search?&term="+encodeURIComponent(searchTerm)+"&limit="+encodeURIComponent(TYPEAHEAD_LIMIT)+"&autocomplete=true&analytics=true&" + searchOptions();
66
67      request.open('GET', requestUrl, true);
68      request.onload = function() {
69        if (request.status >= 200 && request.status < 400) {
70          var data = JSON.parse(request.responseText);
71          if (data.total > 0) {
72            fillSearchResults(data);
73            trapFocus();      
74          }
75          else {
76            emptySearchResults();
77          }
78        } else {
79          console.error('Server reached, error retrieving results.');
80        }
81      };
82      request.onerror = function() {
83        console.error('Could not reach the server.');
84      };
85      request.send();
86    },
87  trapFocus = function(){
88    var tabbable = [];
89    tabbable.push(searchField);
90    var tabbables = searchResults.getElementsByTagName('A');
91    for (var i = 0; i < tabbables.length; i++) {
92      tabbable.push(tabbables[i]);
93    }
94    var firstTabbable = tabbable[0],
95        lastTabbable  = tabbable[tabbable.length-1];
96    var tabResult = function(e){
97      if (e.target == lastTabbable && !e.shiftKey) {
98        e.preventDefault();
99        firstTabbable.focus();   		
100      }
101      else if (e.target == firstTabbable && e.shiftKey) {
102        e.preventDefault();
103        lastTabbable.focus();
104      } 
105    },
106    nextResult = function(e) {
107      e.preventDefault();
108      if (e.target == lastTabbable) {
109        firstTabbable.focus();
110      }
111      else {
112        tabbable.forEach(function(el){
113          if (el == e.target) {
114            tabbable[tabbable.indexOf(el) + 1].focus();
115          }
116        });
117      }
118    },
119    lastResult = function(e) {
120      e.preventDefault();
121      if (e.target == firstTabbable) {
122        lastTabbable.focus();
123      }
124      else {
125        tabbable.forEach(function(el){
126          if (el == e.target) {
127            tabbable[tabbable.indexOf(el) - 1].focus();
128          }
129        });
130      }
131    };
132    searchForm.addEventListener('keydown', function(e){
133      switch (e.which) {
134        case 9:
135          tabResult(e);
136          break;
137        case 27:
138          emptySearchResults();
139          break;
140        case 38:
141          lastResult(e);
142          break;
143        case 40:
144          nextResult(e);
145          break;
146      }
147    });      
148  },
149  isSearchTermPresent = debounce(function() {
150    searchTerm = searchField.value;
151    if(searchTerm.length > 2) {
152      getSearchResults();
153    }    
154    else if (searchTerm.length == 0)  {
155      emptySearchResults(); 
156    }
157  }, 250),
158  init = (function(){
159    searchField.addEventListener('input', function(e) {
160      if ((e.which != 9) && (e.which != 40) && (e.which != 38) && (e.which != 27) && (searchTerm != searchField.value)) {
161        isSearchTermPresent();
162      }
163    });
164  })();
165}
166
167if (document.attachEvent ? document.readyState === "complete" : document.readyState !== "loading"){
168  var searchResults = document.querySelectorAll('.hs-search-field');
169  Array.prototype.forEach.call(searchResults, function(el){
170    var hsSearchModule = hsSearch(el);
171  });
172} else {
173  document.addEventListener('DOMContentLoaded', function() {
174    var searchResults = document.querySelectorAll('.hs-search-field');
175    Array.prototype.forEach.call(searchResults, function(el){
176      var hsSearchModule = hsSearch(el);
177    });
178  });
179}
180
181  })();

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.