PageSourceSearch

https://spotlight-timisoara.eu/wp-content/plugins/mapsvg_wp/js/ven…/handlebars/handlebars-helpers.js?ver=7.3.0

js spotlight-timisoara.eu collected 2026-09-24 10:17:09 UTC 11,204 bytes, 361 lines download raw bytes

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("getLabel", function (options, fields, fieldName, _options) {
8  return fields[fieldName + "_text"]
9  // if(options && fields && fieldName && typeof fields[fieldName] !== "undefined"){
10  //     let value = fields[fieldName];
11  //     let object = options.get(value);
12  //     if(typeof object !== "undefined"){
13  //         return object.label;
14  //     } else {
15  //         return ""
16  //     }
17  // }else{
18  //     return '';
19  // }
20})
21Handlebars.registerHelper("getPostTitle", function (fields, fieldName, _options) {
22  return typeof fields[fieldName] === "object" && fields[fieldName] && fields[fieldName].post_title
23    ? fields[fieldName].post_title
24    : ""
25  // if(options && fields && fieldName && typeof fields[fieldName] !== "undefined"){
26  //     let value = fields[fieldName];
27  //     let object = options.get(value);
28  //     if(typeof object !== "undefined"){
29  //         return object.label;
30  //     } else {
31  //         return ""
32  //     }
33  // }else{
34  //     return '';
35  // }
36})
37Handlebars.registerHelper("getStatusText", function (options, region, status, _options) {
38  return typeof options !== "undefined" &&
39    typeof region[status] !== "undefined" &&
40    typeof options.findById(region[status]) !== "undefined"
41    ? options.findById(region[status]).label
42    : "..."
43})
44Handlebars.registerHelper("round", function (x, options) {
45  return Math.round(x)
46})
47Handlebars.registerHelper("ifinr", function (v1, v2, options) {
48  for (const i in v2) {
49    if (v2[i].id == v1) return options.fn(this)
50  }
51  return options.inverse(this)
52})
53Handlebars.registerHelper("ifselected", function (v1, v2, options) {
54  for (const i in v2) {
55    if (v2[i].value == v1) return options.fn(this)
56  }
57  return options.inverse(this)
58})
59Handlebars.registerHelper("ifin", function (v1, v2, options) {
60  if (v2.indexOf(v1) != -1) {
61    return options.fn(this)
62  }
63  return options.inverse(this)
64})
65Handlebars.registerHelper("ifnoteq", function (v1, v2, options) {
66  if (v1 != v2) {
67    return options.fn(this)
68  }
69  return options.inverse(this)
70})
71Handlebars.registerHelper("ifjson", function (v1, v2, options) {
72  if (typeof v1[v2] == "object") {
73    return options.fn(this)
74  }
75  return options.inverse(this)
76})
77Handlebars.registerHelper("ifnotjson", function (v1, v2, options) {
78  if (typeof v1[v2] != "object") {
79    return options.fn(this)
80  }
81  return options.inverse(this)
82})
83Handlebars.registerHelper("getRegions", function (v1, v2, options) {
84  const regions = v1[v2]
85  let str = ""
86  if (regions && regions.length) {
87    // regions.forEach(function(region){
88    str +=
89      '<label class="badge bg-secondary">' +
90      (regions[0].title ? regions[0].title : regions[0].id) +
91      "</label> "
92    // });
93    if (regions.length > 1)
94      str += '<span class="mapsvg-data-image-counter">+' + (regions.length - 1) + "</span>"
95
96    return new Handlebars.SafeString(str)
97  }
98})
99Handlebars.registerHelper("getSelectedOptions", function (v1, v2, options) {
100  const regions = v1[v2]
101  let str = ""
102  if (regions && regions.length) {
103    const label = regions[0].label === undefined ? regions[0].value : regions[0].label
104    str += '<label class="badge bg-secondary">' + label + "</label> "
105    if (regions.length > 1)
106      str += '<span class="mapsvg-data-image-counter">+' + (regions.length - 1) + "</span>"
107
108    return new Handlebars.SafeString(str)
109  }
110})
111Handlebars.registerHelper("getRegionIDs", function (v1, v2, options) {
112  const regions = v1[v2]
113  let str = ""
114  if (regions && regions.length) {
115    regions.forEach(function (region) {
116      str +=
117        '<label class="badge bg-secondary">' +
118        (region.title ? region.title : region.id) +
119        "</label> "
120    })
121    if (regions.length > 1)
122      str += '<span class="mapsvg-data-image-counter">+' + (regions.length - 1) + "</span>"
123
124    return new Handlebars.SafeString(str)
125  }
126})
127
128Handlebars.registerHelper("getThumbs", function (v1, v2, options) {
129  const images = v1[v2]
130  let str = ""
131  if (images && images.length) {
132    // images.forEach(function(img){
133    //     str += '<img src="'+img.thumbnail+'" class="mapsvg-data-thumbnail"/>';
134    // });
135    str += '<img src="' + images[0].thumbnail + '" class="mapsvg-data-thumbnail"/>'
136    if (images.length > 1)
137      str += '<span class="mapsvg-data-image-counter">+' + (images.length - 1) + "</span>"
138    return new Handlebars.SafeString(str)
139  }
140})
141Handlebars.registerHelper("getMarkerImage", function (v1, v2, options) {
142  const location = v1[v2]
143
144  if (!location || !location.markerImagePath) {
145    return ""
146  }
147  return new Handlebars.SafeString(
148    '<img src="' +
149      location.markerImagePath +
150      '" class="mapsvg-marker-image"/> ' +
151      (location.address && location.address.formatted ? location.address.formatted : ""),
152  )
153})
154Handlebars.registerHelper("not", function (v1, v2, options) {
155  if (v1 != v2) {
156    return options.fn(this)
157  }
158  return options.inverse(this)
159})
160Handlebars.registerHelper("if_starts", function (v1, v2, options) {
161  if (v1 && v1.indexOf(v2) == 0) {
162    return options.fn(this)
163  }
164  return options.inverse(this)
165})
166Handlebars.registerHelper("if_function", function (v1, options) {
167  return typeof v1 == "function" ? options.fn(this) : options.inverse(this)
168})
169Handlebars.registerHelper("if_number", function (v1, options) {
170  return jQuery.isNumeric(v1) ? options.fn(this) : options.inverse(this)
171})
172Handlebars.registerHelper("if_string", function (v1, options) {
173  return typeof v1 == "string" && !jQuery.isNumeric(v1) ? options.fn(this) : options.inverse(this)
174})
175Handlebars.registerHelper("toString", function (object) {
176  return object != undefined ? MapSVG.convertToText(object) : ""
177})
178Handlebars.registerHelper("jsonToString", function (object) {
179  return object != undefined ? JSON.stringify(object) : ""
180})
181Handlebars.registerHelper("log", function (object) {
182  console.log(object)
183})
184
185function getDistanceFromLatLonInKm(lat1, lon1, lat2, lon2) {
186  const R = 6371 // Radius of the earth in km
187  const dLat = deg2rad(lat2 - lat1) // deg2rad below
188  const dLon = deg2rad(lon2 - lon1)
189  const a =
190    Math.sin(dLat / 2) * Math.sin(dLat / 2) +
191    Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) * Math.sin(dLon / 2) * Math.sin(dLon / 2)
192  const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a))
193  const d = R * c // Distance in km
194  return d
195}
196function deg2rad(deg) {
197  return deg * (Math.PI / 180)
198}
199
200Handlebars.registerHelper("distanceFrom", function (location) {
201  if (MapSVG.distanceSearch) {
202    let distance = getDistanceFromLatLonInKm(
203      location.geoPoint.lat,
204      location.geoPoint.lng,
205      MapSVG.distanceSearch.geoPoint.lat,
206      MapSVG.distanceSearch.geoPoint.lng,
207    )
208    if (MapSVG.distanceSearch.units === "mi") {
209      distance = distance * 0.62137
210    }
211    return distance.toFixed(2) + " " + MapSVG.distanceSearch.units
212  } else {
213    return ""
214  }
215})
216Handlebars.registerHelper("distanceTo", function (location) {
217  if (MapSVG.distanceSearch) {
218    let distance = getDistanceFromLatLonInKm(
219      location.geoPoint.lat,
220      location.geoPoint.lng,
221      MapSVG.distanceSearch.geoPoint.lat,
222      MapSVG.distanceSearch.geoPoint.lng,
223    )
224    if (MapSVG.distanceSearch.units === "mi") {
225      distance = distance * 0.62137
226    }
227    return distance.toFixed(2) + " " + MapSVG.distanceSearch.units
228  } else {
229    return ""
230  }
231})
232Handlebars.registerHelper("stripUnderscores", function (object) {
233  return object != undefined ? object.replace(/_/g, " ") : ""
234})
235Handlebars.registerHelper("spacesToUnderscores", function (object) {
236  return object != undefined ? object.replace(/ /g, "_") : ""
237})
238Handlebars.registerHelper("switch", function (value, options) {
239  this._switch_value_ = value
240  this._switch_break_ = false
241  const html = options.fn(this)
242  delete this._switch_break_
243  delete this._switch_value_
244  return html
245})
246
247Handlebars.registerHelper("case", function () {
248  const args = Array.from(arguments)
249  const options = args.pop()
250  const caseValues = args
251
252  if (
253    this._switch_break_ ||
254    (!this._open_break_ && caseValues.indexOf(this._switch_value_) === -1)
255  ) {
256    return ""
257  } else {
258    if (options.hash.break === "true" || options.hash.break === true) {
259      this._switch_break_ = true
260    } else {
261      this._open_break_ = true
262    }
263    return options.fn(this)
264  }
265})
266
267Handlebars.registerHelper("default", function (options) {
268  if (!this._switch_break_) {
269    return options.fn(this)
270  }
271})
272
273Handlebars.registerHelper("numberFormat", function (value, options) {
274  // Helper parameters
275  const dl = options.hash["decimalLength"] || 2
276  const ts = options.hash["thousandsSep"] || " "
277  const ds = options.hash["decimalSep"] || "."
278
279  // Parse to float
280  const valueFormatted = parseFloat(value)
281
282  // The regex
283  const re = "\\d(?=(\\d{3})+" + (dl > 0 ? "\\D" : "$") + ")"
284
285  // Formats the number with the decimals
286  const num = valueFormatted.toFixed(Math.max(0, ~~dl))
287
288  // Returns the formatted number
289  return (ds ? num.replace(".", ds) : num).replace(new RegExp(re, "g"), "$&" + ts)
290})
291
292Handlebars.registerHelper("shortcode", function (shortcode) {
293  for (const item in this) {
294    shortcode = shortcode.replace(new RegExp("{{" + item + "}}", "g"), this[item])
295  }
296
297  const url = MapSVG.urls.home + "/mapsvg_sc?mapsvg_shortcode=" + encodeURI(shortcode)
298
299  return new Handlebars.SafeString(
300    '<iframe width="100%" class="mapsvg-iframe-shortcode"  src="' + url + '"></iframe>',
301  )
302})
303
304Handlebars.registerHelper("shortcode_inline", function (shortcode) {
305  for (const item in this) {
306    shortcode = shortcode.replace(new RegExp("{{" + item + "}}", "g"), this[item])
307  }
308
309  if (typeof MapSVG.meta.shortcodeCounter === "undefined") {
310    MapSVG.meta.shortcodeCounter = 0
311  }
312
313  const id = "mapsvg-inline-shortcode-" + ++MapSVG.meta.shortcodeCounter
314  const shortcodeBlock = '<span class="mapsvg-inline-shortcode" id="' + id + '"></span>'
315  const url = MapSVG.urls.home + "/mapsvg_sc"
316  jQuery
317    .get(MapSVG.urls.api + "shortcodes/" + shortcode, function (data) {
318      jQuery("#" + id).replaceWith(data)
319    })
320    .done(() => {
321      console.log("done")
322    })
323    .fail(() => {
324      console.log("fail")
325    })
326    .always(() => {
327      console.log("always")
328    })
329
330  return new Handlebars.SafeString(shortcodeBlock)
331})
332
333Handlebars.registerHelper("post", function (value) {
334  if (this.post) {
335    return new Handlebars.SafeString(
336      '<iframe width="100%" class="mapsvg-iframe-post"  src="/mapsvg_sc?mapsvg_embed_post=' +
337        encodeURI(this.post.id) +
338        '"></iframe>',
339    )
340  } else {
341    return ""
342  }
343})
344
345Handlebars.registerHelper("math", function (lvalue, operator, rvalue) {
346  lvalue = parseFloat(lvalue)
347  rvalue = parseFloat(rvalue)
348  return {
349    "+": lvalue + rvalue,
350    "-": lvalue - rvalue,
351    "*": lvalue * rvalue,
352    "/": lvalue / rvalue,
353    "%": lvalue % rvalue,
354  }[operator]
355})
356
357Handlebars.registerHelper("for", function (from, to, incr, block) {
358  let accum = ""
359  for (let i = from; i < to; i += incr) accum += block.fn(i)
360  return accum
361})

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.