1Handlebars.registerHelper("ifeq", function (v1, v2, options) { 2 if (v1 == v2) { 3 return options.fn(this) 4 } 5 return options.inverse(this) 6}) 7Handlebars.registerHelper("ifselected", function (v1, hash, options) { 8 for (const set of hash) { 9 if (set.value === v1) { 10 return options.fn(this) 11 } 12 } 13 return options.inverse(this) 14}) 15Handlebars.registerHelper("getLabel", function (options, fields, fieldName, _options) { 16 return fields[fieldName + "_text"] 17 // if(options && fields && fieldName && typeof fields[fieldName] !== "undefined"){ 18 // let value = fields[fieldName]; 19 // let object = options.get(value); 20 // if(typeof object !== "undefined"){ 21 // return object.label; 22 // } else { 23 // return "" 24 // } 25 // }else{ 26 // return ''; 27 // } 28}) 29Handlebars.registerHelper("getPostTitle", function (fields, fieldName, _options) { 30 return typeof fields[fieldName] === "object" && fields[fieldName] && fields[fieldName].post_title 31 ? fields[fieldName].post_title 32 : "" 33 // if(options && fields && fieldName && typeof fields[fieldName] !== "undefined"){ 34 // let value = fields[fieldName]; 35 // let object = options.get(value); 36 // if(typeof object !== "undefined"){ 37 // return object.label; 38 // } else { 39 // return "" 40 // } 41 // }else{ 42 // return ''; 43 // } 44}) 45Handlebars.registerHelper("getStatusText", function (options, region, status, _options) { 46 return typeof options !== "undefined" && 47 typeof region[status] !== "undefined" && 48 typeof options.findById(region[status]) !== "undefined" 49 ? options.findById(region[status]).label 50 : "..." 51}) 52Handlebars.registerHelper("round", function (x, options) { 53 return Math.round(x) 54}) 55Handlebars.registerHelper("ifinr", function (v1, v2, options) { 56 for (const i in v2) { 57 if (v2[i].id == v1) return options.fn(this) 58 } 59 return options.inverse(this) 60}) 61Handlebars.registerHelper("ifselected", function (v1, v2, options) { 62 for (const i in v2) { 63 if (v2[i].value == v1) return options.fn(this) 64 } 65 return options.inverse(this) 66}) 67Handlebars.registerHelper("ifin", function (v1, v2, options) { 68 if (v2.indexOf(v1) != -1) { 69 return options.fn(this) 70 } 71 return options.inverse(this) 72}) 73Handlebars.registerHelper("ifnoteq", function (v1, v2, options) { 74 if (v1 != v2) { 75 return options.fn(this) 76 } 77 return options.inverse(this) 78}) 79Handlebars.registerHelper("ifjson", function (v1, v2, options) { 80 if (typeof v1[v2] == "object") { 81 return options.fn(this) 82 } 83 return options.inverse(this) 84}) 85Handlebars.registerHelper("ifnotjson", function (v1, v2, options) { 86 if (typeof v1[v2] != "object") { 87 return options.fn(this) 88 } 89 return options.inverse(this) 90}) 91Handlebars.registerHelper("getRegions", function (v1, v2, options) { 92 const regions = v1[v2] 93 let str = "" 94 if (regions && regions.length) { 95 // regions.forEach(function(region){ 96 str += 97 '<label class="badge bg-secondary">' + 98 (regions[0].title ? regions[0].title : regions[0].id) + 99 "</label> " 100 // }); 101 if (regions.length > 1) 102 str += '<span class="mapsvg-data-image-counter">+' + (regions.length - 1) + "</span>" 103 104 return new Handlebars.SafeString(str) 105 } 106}) 107Handlebars.registerHelper("getSelectedOptions", function (v1, v2, options) { 108 const regions = v1[v2] 109 let str = "" 110 if (regions && regions.length) { 111 const label = regions[0].label === undefined ? regions[0].value : regions[0].label 112 str += '<label class="badge bg-secondary">' + label + "</label> " 113 if (regions.length > 1) 114 str += '<span class="mapsvg-data-image-counter">+' + (regions.length - 1) + "</span>" 115 116 return new Handlebars.SafeString(str) 117 } 118}) 119Handlebars.registerHelper("getRegionIDs", function (v1, v2, options) { 120 const regions = v1[v2] 121 let str = "" 122 if (regions && regions.length) { 123 regions.forEach(function (region) { 124 str += 125 '<label class="badge bg-secondary">' + 126 (region.title ? region.title : region.id) + 127 "</label> " 128 }) 129 if (regions.length > 1) 130 str += '<span class="mapsvg-data-image-counter">+' + (regions.length - 1) + "</span>" 131 132 return new Handlebars.SafeString(str) 133 } 134}) 135 136Handlebars.registerHelper("getThumbs", function (v1, v2, options) { 137 const images = v1[v2] 138 let str = "" 139 if (images && images.length) {
140 // images.forEach(function(img){ 141 // str += '<img src="'+img.thumbnail+'" class="mapsvg-data-thumbnail"/>'; 142 // }); 143 str += '<img src="' + images[0].thumbnail + '" class="mapsvg-data-thumbnail"/>' 144 if (images.length > 1) 145 str += '<span class="mapsvg-data-image-counter">+' + (images.length - 1) + "</span>" 146 return new Handlebars.SafeString(str) 147 } 148}) 149Handlebars.registerHelper("getMarkerImage", function (v1, v2, options) { 150 const location = v1[v2] 151 152 if (!location || !location.markerImagePath) { 153 return "" 154 } 155 return new Handlebars.SafeString( 156 '<img src="' + 157 location.markerImagePath + 158 '" class="mapsvg-marker-image"/> ' + 159 (location.address && location.address.formatted ? location.address.formatted : ""), 160 ) 161}) 162Handlebars.registerHelper("not", function (v1, v2, options) { 163 if (v1 != v2) { 164 return options.fn(this) 165 } 166 return options.inverse(this) 167}) 168Handlebars.registerHelper("if_starts", function (v1, v2, options) { 169 if (v1 && v1.indexOf(v2) == 0) { 170 return options.fn(this) 171 } 172 return options.inverse(this) 173}) 174Handlebars.registerHelper("if_function", function (v1, options) { 175 return typeof v1 == "function" ? options.fn(this) : options.inverse(this) 176}) 177Handlebars.registerHelper("if_number", function (v1, options) { 178 return jQuery.isNumeric(v1) ? options.fn(this) : options.inverse(this) 179}) 180Handlebars.registerHelper("if_string", function (v1, options) { 181 return typeof v1 == "string" && !jQuery.isNumeric(v1) ? options.fn(this) : options.inverse(this) 182}) 183Handlebars.registerHelper("toString", function (object) { 184 return object != undefined ? MapSVG.convertToText(object) : "" 185}) 186Handlebars.registerHelper("jsonToString", function (object) { 187 return object != undefined ? JSON.stringify(object) : "" 188}) 189Handlebars.registerHelper("log", function (object) { 190 console.log(object) 191}) 192 193function getDistanceFromLatLonInKm(lat1, lon1, lat2, lon2) { 194 const R = 6371 // Radius of the earth in km 195 const dLat = deg2rad(lat2 - lat1) // deg2rad below 196 const dLon = deg2rad(lon2 - lon1) 197 const a = 198 Math.sin(dLat / 2) * Math.sin(dLat / 2) + 199 Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) * Math.sin(dLon / 2) * Math.sin(dLon / 2) 200 const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)) 201 const d = R * c // Distance in km 202 return d 203} 204function deg2rad(deg) { 205 return deg * (Math.PI / 180) 206} 207 208Handlebars.registerHelper("distanceFrom", function (location) { 209 if (window.mapsvg.distanceSearch) { 210 let distance = getDistanceFromLatLonInKm( 211 location.geoPoint.lat, 212 location.geoPoint.lng, 213 window.mapsvg.distanceSearch.geoPoint.lat, 214 window.mapsvg.distanceSearch.geoPoint.lng, 215 ) 216 if (window.mapsvg.distanceSearch.units === "mi") { 217 distance = distance * 0.62137 218 } 219 return distance.toFixed(2) + " " + window.mapsvg.distanceSearch.units 220 } else { 221 return "" 222 } 223}) 224Handlebars.registerHelper("distanceTo", function (location) { 225 if (window.mapsvg.distanceSearch) { 226 let distance = getDistanceFromLatLonInKm( 227 location.geoPoint.lat, 228 location.geoPoint.lng, 229 window.mapsvg.distanceSearch.geoPoint.lat, 230 window.mapsvg.distanceSearch.geoPoint.lng, 231 ) 232 if (window.mapsvg.distanceSearch.units === "mi") { 233 distance = distance * 0.62137 234 } 235 return distance.toFixed(2) + " " + window.mapsvg.distanceSearch.units 236 } else { 237 return "" 238 } 239}) 240Handlebars.registerHelper("stripUnderscores", function (object) { 241 return object != undefined ? object.replace(/_/g, " ") : "" 242}) 243Handlebars.registerHelper("spacesToUnderscores", function (object) { 244 return object != undefined ? object.replace(/ /g, "_") : "" 245}) 246Handlebars.registerHelper("switch", function (value, options) { 247 this._switch_value_ = value 248 this._switch_break_ = false 249 const html = options.fn(this) 250 delete this._switch_break_ 251 delete this._switch_value_ 252 return html 253}) 254 255Handlebars.registerHelper("case", function () { 256 const args = Array.from(arguments) 257 const options = args.pop() 258 const caseValues = args 259 260 if ( 261 this._switch_break_ || 262 (!this._open_break_ && caseValues.indexOf(this._switch_value_) === -1) 263 ) { 264 return "" 265 } else { 266 if (options.hash.break === "true" || options.hash.break === true) { 267 this._switch_break_ = true 268 } else { 269 this._open_break_ = true 270 } 271 return options.fn(this) 272 } 273}) 274 275Handlebars.registerHelper("default", function (options) { 276 if (!this._switch_break_) { 277 return options.fn(this) 278 } 279}) 280 281Handlebars.registerHelper("numberFormat", function (value, options) { 282 // Helper parameters 283 const dl = options.hash["decimalLength"] || 2 284 const ts = options.hash["thousandsSep"] || " " 285 const ds = options.hash["decimalSep"] || "." 286 287 // Parse to float 288 const valueFormatted = parseFloat(value) 289 290 // The regex 291 const re = "\\d(?=(\\d{3})+" + (dl > 0 ? "\\D" : "$") + ")" 292 293 // Formats the number with the decimals 294 const num = valueFormatted.toFixed(Math.max(0, ~~dl)) 295 296 // Returns the formatted number 297 return (ds ? num.replace(".", ds) : num).replace(new RegExp(re, "g"), "$&" + ts) 298}) 299 300Handlebars.registerHelper("shortcode", function (...args) { 301 const options = args.pop() 302 const shortcodeTemplate = args[0] 303 const values = args.slice(1) 304 305 let shortcode = shortcodeTemplate 306 307 const getNestedValue = (obj, path) => { 308 return path.split(".").reduce((current, key) => {
309 return current && current[key] !== undefined ? current[key] : undefined 310 }, obj) 311 } 312 313 const matches = shortcode.match(/{{([^}]+)}}/g) || [] 314 315 if (values.length > 0) { 316 // Replace placeholders in order using values[] 317 matches.forEach((match, i) => { 318 const placeholder = match 319 const value = values[i] !== undefined ? values[i] : "" 320 shortcode = shortcode.replace(new RegExp(placeholder, "g"), value) 321 }) 322 } else { 323 // Fallback to context-based path resolution 324 matches.forEach((match) => { 325 const path = match.slice(2, -2) 326 const value = getNestedValue(this, path) 327 if (value !== undefined) { 328 shortcode = shortcode.replace(new RegExp(match, "g"), value) 329 } 330 }) 331 } 332 333 const url = mapsvg.routes.home + "/_mapsvg/shortcode/" + encodeURI(shortcode) 334 335 return new Handlebars.SafeString( 336 '<iframe width="100%" class="mapsvg-iframe-shortcode" src="' + url + '"></iframe>', 337 ) 338}) 339 340Handlebars.registerHelper("shortcode_inline", function (...args) { 341 const options = args.pop() 342 const shortcodeTemplate = args[0] 343 const values = args.slice(1) 344 345 let shortcode = shortcodeTemplate 346 347 const getNestedValue = (obj, path) => { 348 return path.split(".").reduce((current, key) => { 349 return current && current[key] !== undefined ? current[key] : undefined 350 }, obj) 351 } 352 353 const matches = shortcode.match(/{{([^}]+)}}/g) || [] 354 355 if (values.length > 0) { 356 // Replace placeholders in order using values[] 357 matches.forEach((match, i) => { 358 const placeholder = match 359 const value = values[i] !== undefined ? values[i] : "" 360 shortcode = shortcode.replace(new RegExp(placeholder, "g"), value) 361 }) 362 } else { 363 // Fallback to context-based path resolution 364 matches.forEach((match) => { 365 const path = match.slice(2, -2) 366 const value = getNestedValue(this, path) 367 if (value !== undefined) { 368 shortcode = shortcode.replace(new RegExp(match, "g"), value) 369 } 370 }) 371 } 372 373 if (typeof mapsvg.meta.shortcodeCounter === "undefined") { 374 mapsvg.meta.shortcodeCounter = 0 375 } 376 377 const id = "mapsvg-inline-shortcode-" + ++mapsvg.meta.shortcodeCounter 378 const shortcodeBlock = '<span class="mapsvg-inline-shortcode" id="' + id + '"></span>' 379 const url = mapsvg.routes.home + "/mapsvg_sc" 380 jQuery 381 .get(mapsvg.routes.api + "shortcodes/" + shortcode, function (data) { 382 jQuery("#" + id).replaceWith(data) 383 }) 384 .done(() => {}) 385 .fail(() => { 386 console.log(`Shortcode ${shortcode} return error`) 387 }) 388 .always(() => {}) 389 390 return new Handlebars.SafeString(shortcodeBlock) 391}) 392 393Handlebars.registerHelper("post", function (value) { 394 if (this.post) { 395 return new Handlebars.SafeString( 396 '<iframe width="100%" class="mapsvg-iframe-post" src="/_mapsvg/post/' + 397 encodeURI(this.post.id) + 398 '"></iframe>', 399 ) 400 } else { 401 return "" 402 } 403}) 404 405Handlebars.registerHelper("premiumFeatureAlert", function (text, object) { 406 let additionalText 407 // Check if the first argument is the options object 408 if (text && typeof text === "object" && text.name === "premiumFeatureAlert") { 409 // If so, no arguments were passed 410 additionalText = undefined 411 } else { 412 additionalText = text 413 } 414 415 var additionalTextDom = additionalText 416 ? `: <span class="mapsvg-premium-feature-text">${additionalText}</span>` 417 : "" 418 419 return new Handlebars.SafeString( 420 `<div class="alert alert-info mapsvg-premium-feature"> 421 <i class="bi bi-star-fill"></i> Premium feature${additionalTextDom} 422 <a class="btn btn-xs mx-1 btn-outline-primary" target="_blank" href="https://mapsvg.com/pricing??utm_source=mapsvg-lite&utm_medium=lite-upgrade&utm_content=mapsvg&utm_campaign=mapsvg-lite">Upgrade</a> 423 </div>`, 424 ) 425}) 426 427Handlebars.registerHelper("math", function (lvalue, operator, rvalue) { 428 lvalue = parseFloat(lvalue) 429 rvalue = parseFloat(rvalue) 430 return { 431 "+": lvalue + rvalue, 432 "-": lvalue - rvalue, 433 "*": lvalue * rvalue, 434 "/": lvalue / rvalue, 435 "%": lvalue % rvalue, 436 }[operator] 437}) 438 439Handlebars.registerHelper("for", function (from, to, incr, block) { 440 let accum = "" 441 for (let i = from; i < to; i += incr) accum += block.fn(i) 442 return accum 443}) 444 445// Define the helper function 446function toSnakeCase(str) { 447 return typeof str === "string" ? str.replace(/\s+/g, "_") : str 448} 449 450// Register the helper with Handlebars 451Handlebars.registerHelper("toSnakeCase", function (str) { 452 return toSnakeCase(str) 453})
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.