From 5fd1cc0768a02607d750dd8d53149abfb94d483d Mon Sep 17 00:00:00 2001 From: Jakub Skoczen Date: Thu, 4 Mar 2010 13:10:01 +0100 Subject: [PATCH] Avoid string concats --- www/jsdemo/example_client.js | 66 +++++++++++++++++------------------------- 1 file changed, 27 insertions(+), 39 deletions(-) diff --git a/www/jsdemo/example_client.js b/www/jsdemo/example_client.js index e67f107..51c0e29 100644 --- a/www/jsdemo/example_client.js +++ b/www/jsdemo/example_client.js @@ -56,26 +56,26 @@ function my_onshow(data) { // navi var results = document.getElementById("results"); - var html = ''; + var html = []; for (var i = 0; i < data.hits.length; i++) { var hit = data.hits[i]; - html += '
' + html.push('
' +''+ (i + 1 + recPerPage * (curPage - 1)) +'. ' +'' - + hit["md-title"] +' '; - if (hit["md-title-remainder"] !== undefined) { - html += '' + hit["md-title-remainder"] + ' '; - } - if (hit["md-title-responsibility"] !== undefined) { - html += ''+ hit["md-title-responsibility"] +''; - } + + hit["md-title"] +' '); + if (hit["md-title-remainder"] !== undefined) { + html.push('' + hit["md-title-remainder"] + ' '); + } + if (hit["md-title-responsibility"] !== undefined) { + html.push(''+hit["md-title-responsibility"]+''); + } if (hit.recid == curDetRecId) { - html += renderDetails(curDetRecData); + html.push(renderDetails(curDetRecData)); } - html += '
'; + html.push('
'); } - replaceHtml(results, html); + replaceHtml(results, html.join('')); } function my_onstat(data) { @@ -91,42 +91,30 @@ function my_onstat(data) { } function my_onterm(data) { - var termlist = document.getElementById("termlist"); - termlist.innerHTML = "
TERMLISTS:
"; - - termlist.innerHTML += '
.::Sources
'; + var termlists = []; + termlists.push('
TERMLISTS:
.::Sources
'); for (var i = 0; i < data.xtargets.length && i < SourceMax; i++ ) { - termlist.innerHTML += '' - + data.xtargets[i].name - + ' (' - + data.xtargets[i].freq - + ')
'; + termlists.push('' + data.xtargets[i].name + + ' (' + data.xtargets[i].freq + ')
'); } - - termlist.innerHTML += "
"; - - termlist.innerHTML += '
.::Subjects
'; + + termlists.push('
.::Subjects
'); for (var i = 0; i < data.subject.length && i < SubjectMax; i++ ) { - termlist.innerHTML += '' - + data.subject[i].name - + ' (' - + data.subject[i].freq - + ')
'; + termlists.push('' + data.subject[i].name + ' (' + + data.subject[i].freq + ')
'); } - - termlist.innerHTML += "
"; - - termlist.innerHTML += '
.::Authors
'; + + termlists.push('
.::Authors
'); for (var i = 0; i < data.author.length && i < AuthorMax; i++ ) { - termlist.innerHTML += '' + termlists.push('' + data.author[i].name + ' (' + data.author[i].freq - + ')
'; + + ')
'); } - + var termlist = document.getElementById("termlist"); + replaceHtml(termlist, termlists.join('')); } function my_onrecord(data) { -- 1.7.10.4