[Rt-devel] Small patch to /Elements/MakeClicky

Tim Cutts tjrc at sanger.ac.uk
Thu Mar 5 13:43:24 EST 2009


Some users of mine didn't like the fact that we're using a space every  
30 characters instead of using <wbr>, because it means copying and  
pasting the URL as displayed (rather than clicking on it) doesn't work  
correctly.

Now, I realise that <wbr> is a bit broken on some browsers, but Google  
found what appears to be a useful workaround for those broken  
browsers, which is to use a bit of CSS.  I could put that into each  
theme, but because this is a theme-independent thing, I've done it as  
inline CSS - I hope that isn't too abhorrent.  I've also modified the  
regex to put the <wbr> at each / in the URL, or every 30 non-/  
characters, which most of the time makes it put the line breaks in a  
more meaningful location.

The patch is as follows:

--- share/html/Elements/MakeClicky	2009-02-03 11:53:02.000000000 +0000
+++ local/html/Elements/MakeClicky	2009-03-05 17:52:30.000000000 +0000
@@ -60,9 +60,11 @@
      },
      url_overwrite => sub {
          my %args = @_;
-        my $result = qq{<a target="new" href="$args{'value'}">};
-        #XXX: use spaces here. &shy; <wbr> are not well supported :(
-        $args{'value'} =~ s/(\S{30})/$1 /g;
+	# Inline CSS is a fix for wbr in Opera/Safari, from
+	# http://gojomo.blogspot.com/2005/03/cross-browser-invisible-word-break-in.html
+	# and comments thereon
+        my $result = qq{<a style="wbr { display: inline-block; }"  
target="new" href="$args{'value'}">};
+        $args{'value'} =~ s:(/|[^/]{30}):$1<wbr>:g;
          $result .= qq{$args{'value'}</a>};
          return qq{<span class="clickylink">$result</span>};
      },

So far I have tested this on Safari 4.0, Firefox 3.0.7 and IE 7, and  
it seems to be OK...

Have I missed something?

Tim



-- 
 The Wellcome Trust Sanger Institute is operated by Genome Research 
 Limited, a charity registered in England with number 1021457 and a 
 company registered in England with number 2742969, whose registered 
 office is 215 Euston Road, London, NW1 2BE. 


More information about the Rt-devel mailing list