add util function to escape strings for manual building of HTML, and use this for the portal title

fix #319
This commit is contained in:
Jon Atkins 2013-05-27 00:35:56 +01:00
parent e609c64775
commit bfd9f39067
2 changed files with 9 additions and 1 deletions

View File

@ -54,7 +54,7 @@ window.renderPortalDetails = function(guid) {
$('#portaldetails')
.attr('class', TEAM_TO_CSS[getTeam(d)])
.html(''
+ '<h3 class="title">'+d.portalV2.descriptiveText.TITLE+'</h3>'
+ '<h3 class="title">'+escapeHtmlSpecialChars(d.portalV2.descriptiveText.TITLE)+'</h3>'
+ '<span class="close" onclick="unselectOldPortal();" title="Close">X</span>'
// help cursor via ".imgpreview img"
+ '<div class="imgpreview" '+imgTitle+' style="background-image: url('+img+')">'

View File

@ -365,6 +365,14 @@ window.escapeJavascriptString = function(str) {
return (str+'').replace(/[\\"']/g,'\\$&');
}
//escape special characters, such as tags
window.escapeHtmlSpecialChars = function(str) {
var div = document.createElement(div);
var text = document.createTextNode(str);
div.appendChild(text);
return div.innerHTML;
}
window.prettyEnergy = function(nrg) {
return nrg> 1000 ? Math.round(nrg/1000) + ' k': nrg;
}