From 5ba8d196ffe346ef6fbd8e6ffc11f0c849537ed3 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Fri, 14 Jan 2011 12:20:19 +0100 Subject: shorten quicksearch namespaces in JavaScript This patch moves the shortening of namespaces in the quicksearch results to JavaScript. This makes it independend from used template and will always try to fill the width of the result pane correctly. Things missing: * Make it work with RTL-languages * Check Browser compatibility (only tested in Chrome so far) --- lib/scripts/ajax.js | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'lib/scripts') diff --git a/lib/scripts/ajax.js b/lib/scripts/ajax.js index de009d448..761329f0f 100644 --- a/lib/scripts/ajax.js +++ b/lib/scripts/ajax.js @@ -31,6 +31,47 @@ 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 3) && links[i].offsetWidth > max ){ + 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 -- cgit v1.2.3