Module: check_mk
Branch: master
Commit: 35f5090236d8f82555cde1d963b6ff56bcee86f9
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=35f5090236d8f8…
Author: Andreas Boesl <ab(a)mathias-kettner.de>
Date: Tue Feb 7 16:40:02 2017 +0100
replaced javascript replace_all(..) function, with a more performant implemenation
Change-Id: I181ca1ed3445b677ef06a6fbfd0b6d3641af4faa
---
web/htdocs/js/checkmk.js | 17 ++++++-----------
1 file changed, 6 insertions(+), 11 deletions(-)
diff --git a/web/htdocs/js/checkmk.js b/web/htdocs/js/checkmk.js
index 0d8e22b..1297202 100644
--- a/web/htdocs/js/checkmk.js
+++ b/web/htdocs/js/checkmk.js
@@ -45,15 +45,6 @@ function real_next_sibling(o) {
return n;
}
-// simple string replace that replaces all occurrances.
-// Unbelievable that JS does not have a builtin way to
-// to that.
-function replace_all(haystack, needle, r) {
- while (haystack.search(needle) != -1)
- haystack = haystack.replace(needle, r);
- return haystack;
-}
-
function has_class(o, cn) {
if (typeof(o.className) === 'undefined')
return false;
@@ -2017,9 +2008,13 @@ function valuespec_listof_add(varprefix, magic)
var oPrototype = document.getElementById(varprefix +
"_prototype").childNodes[0].childNodes[0]; // TR
var htmlcode = oPrototype.innerHTML;
// replace the magic
- htmlcode = replace_all(htmlcode, magic, strcount);
+ var re = new RegExp(magic, "g")
+ htmlcode = htmlcode.replace(re, strcount)
+
// in some cases the magic might be URL encoded. Also replace these occurences.
- htmlcode = replace_all(htmlcode, encodeURIComponent(magic).replace('!',
'%21'), strcount);
+ re = new RegExp(encodeURIComponent(magic).replace('!', '%21'),
"g")
+ htmlcode = htmlcode.replace(re, strcount)
+
var oTable = document.getElementById(varprefix + "_table");
var oTbody = oTable.childNodes[0];