1var SITE = SITE || {}; 2 3SITE.alwaysFirstGeoGuessItem = 'Hozzám legközelebbi'; 4SITE.alwaysSecondFullBalatonItem = 'Teljes Balaton'; 5 6SITE.LocationSearchIndex = (function() { 7 'use strict'; 8 9 var _ = window.lodash || window._; 10 11 function LocationSearchIndex(o) { 12 o = o || {}; 13 this.queryNormalizer = o.queryNormalizer; 14 this.reset(); 15 } 16 17 _.mixin(LocationSearchIndex.prototype, { 18 bootstrap: function bootstrap(o) { 19 this.dataElems = o.datums; 20 }, 21 22 add: function(data) { 23 data = _.isArray(data) ? data : [data]; 24 _.each(data, jQuery.proxy(function(dataElem) { this.dataElems[dataElem.value] = dataElem; }, this)); 25 }, 26 27 get: function get(ids) { 28 return _.map(ids, jQuery.proxy(function(id) { return this.dataElems[id]; }, this)); 29 }, 30 31 search: function search(query) { 32 var normalizedQuery = this.queryNormalizer(query); 33 var queryMatcher = _.partial(fuzzysearch, normalizedQuery); 34 35 var matches = []; 36 for (var dataElemKey in this.dataElems) { 37 var dataElem = this.dataElems[dataElemKey]; 38 39 if(isGeoLocationDisabled() && dataElem.displayValue === SITE.alwaysFirstGeoGuessItem){ 40 continue; 41 } 42 43 if (isPermanentItem(dataElem)) { 44 dataElem.htmlDisplayValue = '<strong class="fixElement">' + dataElem.displayValue + '</strong>'; 45 matches.push(dataElem); 46 continue; 47 } 48 49 if (normalizedQuery === '') { 50 continue; 51 } 52 53 var matchIndexes = queryMatcher(dataElemKey); 54 if (matchIndexes) { 55 dataElem.htmlDisplayValue = highlight(dataElem.displayValue, matchIndexes); 56 matches.push(dataElem); 57 } 58 } 59 return matches; 60 }, 61 62 all: function all() { 63 var values = []; 64 for (var key in this.dataElems) { 65 values.push(this.dataElems[key]); 66 } 67 return values; 68 }, 69 70 reset: function reset() { 71 this.dataElems = {}; 72 }, 73 74 serialize: function serialize() { 75 return { dataElems: this.dataElems }; 76 } 77 }); 78 79 function highlight (string, indexes) { 80 var returnString = ''; 81 for (var i = 0; i < string.length; i++) { 82 if (indexes.indexOf(i) !== -1) { 83 returnString += '<strong>' + string[i] + '</strong>'; 84 } else { 85 returnString += string[i]; 86 } 87 } 88 return returnString; 89 } 90 91 function isGeoLocationDisabled() { 92 93 try{ 94 return localStorage.getItem('geoLocationDisabled') === 'true'; 95 }catch (error){ 96 return false; 97 } 98 } 99 100 function isPermanentItem(item) { 101 if (isGeoLocationDisabled() && item.displayValue === SITE.alwaysFirstGeoGuessItem) { 102 return false; 103 } 104 105 return (item.displayValue === SITE.alwaysFirstGeoGuessItem 106 || item.displayValue === SITE.alwaysSecondFullBalatonItem); 107 } 108 109 function fuzzysearch (needle, haystack) { 110 needle = needle.trim(); 111 var index = haystack.search(needle); 112 113 if (index < 0) { 114 return false; 115 } 116 117 return _.range(index, index + needle.length); 118 } 119 120 return LocationSearchIndex; 121 122})();
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.