PageSourceSearch

https://www.steinel.de/modules/laudert/laudert_factfinder/Applicat…/js/swFFSuggestRenderer.js?ts=1790241160

js steinel.de collected 2026-09-24 09:35:38 UTC 4,849 bytes, 122 lines download raw bytes

1/**
2 * swFFSuggestRenderer
3 *
4 * initializes helpers of Handlebars and returns function to render suggestions
5 *
6 * @param string swFFSuggestTplID id of the dom-element which contains the handlebar tpl to be used to render the suggestions
7 * @param object swFFSuggestTranslations object containing mapping of translations for suggestions {"ID" : "TRANSLATION"}
8 * @returns Function function callable with suggestions object to return rendered html
9 */
10function swFFSuggestRenderer(swFFSuggestTplID, swFFSuggestTranslations) {
11    if(Handlebars === undefined) {
12        console.log("ERROR: swFFSuggestRenderer needs Handlebars Javascript");
13        return;
14    }
15    var handlebarsTpl;
16    //precompiled templates
17    if(Handlebars.templates != null) {
18        if(Handlebars.templates.blockSuggest != null) {
19            handlebarsTpl = Handlebars.templates.blockSuggest;
20        } else if (Handlebars.templates.listSuggest != null) {
21            handlebarsTpl = Handlebars.templates.listSuggest;
22        }
23    }
24    //no precompiled template found
25    if(handlebarsTpl == null) {
26        // compile template
27        var tpl = $('#' + swFFSuggestTplID);
28        var handlebarsTpl = Handlebars.compile(tpl.html());
29    }
30
31    // return function which gets called with the suggest data as parameter and returns the fully rendered html for suggestions
32    var render = function(oSuggestJson) {
33        return handlebarsTpl(oSuggestJson);
34    }
35
36    //return translation for an ID if it exists else return ID
37    //usage: {{swFFTranslate TRANSLATIONID}}
38    Handlebars.registerHelper('swFFTranslate', function(translationID) {
39        var translation;
40        if(swFFSuggestTranslations[translationID] !== undefined) {
41            translation = swFFSuggestTranslations[translationID];
42        }
43        else {
44            translation = translationID;
45        }
46        return new Handlebars.SafeString(translation);
47    });
48
49    //return translation for hitCount
50    //usage: {{swFFTranslateHitCount TRANSLATIONID}}
51    Handlebars.registerHelper('swFFTranslateHitCount', function(count) {
52        var translation;
53        if(count === 0) {
54            translation = new Handlebars.SafeString(' ');
55        }
56        else if (count === 1) {
57            translation = Handlebars.helpers.swFFTranslate('hitCount.one');
58        }
59        else {
60            translation = Handlebars.helpers.swFFTranslate('hitCount.multiple');
61            translation = translation.string.replace(/\{0\}/, count);
62            translation = new Handlebars.SafeString(translation);
63        }
64        return translation;
65    });
66
67    //return translation for block headline
68    //usage: {{swFFTranslateTypeHeadline TYPE}}
69    Handlebars.registerHelper('swFFTranslateTypeHeadline', function(type) {
70        var headlineId = type + '.headline';
71        var translation = Handlebars.helpers.swFFTranslate(headlineId);
72        //if string could not be translated return original id instead of "ID.headline"
73        if(translation.string === headlineId) {
74            return new Handlebars.SafeString(type);
75        } else {
76            return translation;
77        }
78    });
79
80    //return parameter string with parameter query inside wrapped with span with class from parameter hightlightClass
81    //essentially used to highlight user query inside result names
82    //usage: {{swFFTranslateTypeHeadline STRING QUERY HIGHTLIGHTCLASS}}
83    Handlebars.registerHelper('swFFWrapSuggestQuery', function(string, query, highlightClass) {
84        if(query === undefined)
85            return string;
86        query = htmlEncode(query);
87        // if the query contains regular expression metacharacters then escape them.
88        query = query.replace(/[^a-zA-Z0-9]/g, "\\$&");
89        //escape html special characters in name because we return Handlebars.SafeString which does not get escaped
90        string = htmlEncode(string);
91        string = string.replace(new RegExp("(" + query + ")", "ig"), '<span class="' + highlightClass + '">$1</span>');
92        return new Handlebars.SafeString(string);
93    });
94
95    Handlebars.registerHelper('formatPrice', function(value, locale, currency){
96        if(Intl.NumberFormat){
97            return new Intl.NumberFormat(locale, { style: 'currency', currency: currency }).format(value);
98        }
99    });
100
101    Handlebars.registerHelper('formatCategories', function(categories){
102        return categories.replace(/\>/g,'/');
103    });
104
105    Handlebars.registerHelper('columnCount', function(suggestions){
106        var columns = 0;
107        for (var key in suggestions){
108            for(var column in suggestions[key]){
109                columns++;
110            }
111        }
112        return columns;
113    });
114
115    Handlebars.registerHelper('swFF')
116
117    var htmlEncode = function(string) {
118        return $('<div/>').text(string).html();
119    }
120
121    return render;
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.