From 301971b3769a2d1a440cf58fd84f2c100a1348e3 Mon Sep 17 00:00:00 2001
From: Andreas Gohr <andi@splitbrain.org>
Date: Fri, 14 Jan 2011 13:59:23 +0100
Subject: correctly(?) shorten namespaces for RTL langunages in quicksearch

---
 lib/scripts/ajax.js | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

(limited to 'lib/scripts')

diff --git a/lib/scripts/ajax.js b/lib/scripts/ajax.js
index 761329f0f..d752edb38 100644
--- a/lib/scripts/ajax.js
+++ b/lib/scripts/ajax.js
@@ -38,15 +38,23 @@ addInitEvent(function () {
         var links = outObj.getElementsByTagName('a');
         for(var i=0; i<links.length; i++){
             // maximum allowed width:
-            var max = width - links[i].offsetLeft; //FIXME use offsetRight for RTL!
-            if(links[i].offsetWidth < max) continue;
+            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) && links[i].offsetWidth > max ){
+            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){
-- 
cgit v1.2.3