Added javascript truncation to long env keys

This commit is contained in:
rxi 2014-04-12 19:54:50 +01:00
parent c47412b846
commit 24328d5adb

View File

@ -158,13 +158,9 @@ end
<script> <script>
document.getElementById("inputbox").focus(); document.getElementById("inputbox").focus();
var updateDivContent = function(id, content) { var truncate = function(str, len) {
var div = document.getElementById(id); if (str.length <= len) return str;
if (div.innerHTML != content) { return str.substring(0, len - 3) + "...";
div.innerHTML = content;
return true;
}
return false;
} }
var geturl = function(url, onComplete, onFail) { var geturl = function(url, onComplete, onFail) {
@ -182,6 +178,15 @@ end
req.send(); req.send();
} }
var updateDivContent = function(id, content) {
var div = document.getElementById(id);
if (div.innerHTML != content) {
div.innerHTML = content;
return true;
}
return false;
}
var onInputSubmit = function() { var onInputSubmit = function() {
var b = document.getElementById("inputbox"); var b = document.getElementById("inputbox");
var req = new XMLHttpRequest(); var req = new XMLHttpRequest();
@ -219,7 +224,7 @@ end
for (var i = 0; i < p.length; i++) { for (var i = 0; i < p.length; i++) {
acc += "." + p[i]; acc += "." + p[i];
html += " <a href='#' onclick=\"setEnvPath('" + acc + "')\">" + html += " <a href='#' onclick=\"setEnvPath('" + acc + "')\">" +
p[i] + "</a>"; truncate(p[i], 10) + "</a>";
} }
updateDivContent("envheader", html); updateDivContent("envheader", html);
@ -234,7 +239,7 @@ end
for (var i = 0; json.vars[i]; i++) { for (var i = 0; json.vars[i]; i++) {
var x = json.vars[i]; var x = json.vars[i];
var fullpath = (json.path + "." + x.key).replace(/^\./, ""); var fullpath = (json.path + "." + x.key).replace(/^\./, "");
var k = x.key; var k = truncate(x.key, 15);
if (x.type == "table") { if (x.type == "table") {
k = "<a href='#' onclick=\"setEnvPath('" + fullpath + "')\">" + k = "<a href='#' onclick=\"setEnvPath('" + fullpath + "')\">" +
k + "</a>"; k + "</a>";
@ -377,7 +382,7 @@ end
function lovebird.truncate(str, len) function lovebird.truncate(str, len)
if #str < len then if #str <= len then
return str return str
end end
return str:sub(1, len - 3) .. "..." return str:sub(1, len - 3) .. "..."