@@ -39,6 +39,22 @@ const debounce = (func, wait) => {
3939 return debounced ;
4040} ;
4141
42+
43+ /**
44+ * Wrapper around underscorejs's template function.
45+ *
46+ * This is to make it work with new and old versions.
47+ */
48+ const render_template = ( template , data ) => {
49+ // pre-1.7 syntax from underscorejs.
50+ let result = $u . template ( template , data ) ;
51+ if ( typeof result === 'function' ) {
52+ // New syntax.
53+ result = $u . template ( template ) ( data ) ;
54+ }
55+ return result ;
56+ } ;
57+
4258/**
4359 * Take an object as parameter and convert it to
4460 * url params string.
@@ -219,7 +235,7 @@ const get_section_html = (sectionData, page_link, id) => {
219235
220236 let section_id = "hit__" + id ;
221237
222- let section_html = $u . template ( section_template , {
238+ let section_html = render_template ( section_template , {
223239 section_link : section_link ,
224240 section_id : section_id ,
225241 section_subheading : section_subheading ,
@@ -269,7 +285,7 @@ const get_domain_html = (domainData, page_link, id) => {
269285 let domain_id = "hit__" + id ;
270286 domain_role_name = "[" + domain_role_name + "]" ;
271287
272- let domain_html = $u . template ( domain_template , {
288+ let domain_html = render_template ( domain_template , {
273289 domain_link : domain_link ,
274290 domain_id : domain_id ,
275291 domain_content : domain_content ,
@@ -311,7 +327,7 @@ const generateSingleResult = (resultData, projectName, id) => {
311327 if ( projectName !== resultData . project ) {
312328 page_title +=
313329 " " +
314- $u . template (
330+ render_template (
315331 '<small class="rtd_ui_search_subtitle"> \
316332 (from project <%= project %>) \
317333 </small>' ,
@@ -323,7 +339,7 @@ const generateSingleResult = (resultData, projectName, id) => {
323339
324340 page_title += "<br>" ;
325341
326- content . innerHTML += $u . template ( page_link_template , {
342+ content . innerHTML += render_template ( page_link_template , {
327343 page_link : page_link ,
328344 page_title : page_title
329345 } ) ;
0 commit comments