diff options
Diffstat (limited to 'lib/scripts')
-rw-r--r-- | lib/scripts/ajax.js | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/lib/scripts/ajax.js b/lib/scripts/ajax.js index de009d448..d752edb38 100644 --- a/lib/scripts/ajax.js +++ b/lib/scripts/ajax.js @@ -31,6 +31,55 @@ addInitEvent(function () { outObj.innerHTML = data; outObj.style.display = 'block'; + outObj.style['white-space'] = 'nowrap'; + + // shorten namespaces if too long + var width = outObj.clientWidth; + var links = outObj.getElementsByTagName('a'); + for(var i=0; i<links.length; i++){ + // maximum allowed width: + var max = width - links[i].offsetLeft; + var isRTL = (document.documentElement.dir == 'rtl'); + + if(!isRTL && links[i].offsetWidth < max) continue; + if(isRTL && links[i].offsetLeft > 0) continue; + + var nsL = links[i].innerText.indexOf('('); + var nsR = links[i].innerText.indexOf(')'); + var eli = 0; + var runaway = 0; + + while( (nsR - nsL > 3) && + ( + (!isRTL && links[i].offsetWidth > max) || + (isRTL && links[i].offsetLeft < 0) + ) + ){ + if(runaway++ > 500) return; // just in case something went wrong + + if(eli){ + // elipsis already inserted + if( (eli - nsL) > (nsR - eli) ){ + // cut left + links[i].innerText = links[i].innerText.substring(0,eli-2)+ + links[i].innerText.substring(eli); + }else{ + // cut right + links[i].innerText = links[i].innerText.substring(0,eli+1)+ + links[i].innerText.substring(eli+2); + } + }else{ + // replace middle with ellipsis + var mid = Math.floor( nsL + ((nsR-nsL)/2) ); + links[i].innerText = links[i].innerText.substring(0,mid)+'…'+ + links[i].innerText.substring(mid+1); + } + eli = links[i].innerText.indexOf('…'); + nsL = links[i].innerText.indexOf('('); + nsR = links[i].innerText.indexOf(')'); + } + } + }; // attach eventhandler to search field |