Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix text-hiding technique to be compatible with IE7, and make invisib…

…le_tag_attrs configurable.
  • Loading branch information...
commit 6ca14a72c76adc9cdb209551eb39f81be3e13960 1 parent 55364e2
@keitaf keitaf authored
View
8 src/com/twitter/Autolink.java
@@ -24,6 +24,8 @@
public static final String DEFAULT_HASHTAG_URL_BASE = "https://twitter.com/#!/search?q=%23";
/** HTML attribute to add when noFollow is true (default) */
public static final String NO_FOLLOW_HTML_ATTRIBUTE = " rel=\"nofollow\"";
+ /** Default attribute for invisible span tag */
+ public static final String DEFAULT_INVISIBLE_TAG_ATTRS = "style='position:absolute;left:-999px;'";
protected String urlClass;
protected String listClass;
@@ -32,6 +34,7 @@
protected String usernameUrlBase;
protected String listUrlBase;
protected String hashtagUrlBase;
+ protected String invisibleTagAttrs;
protected boolean noFollow = true;
protected boolean usernameIncludeSymbol = false;
@@ -60,6 +63,7 @@ public Autolink() {
usernameUrlBase = DEFAULT_USERNAME_URL_BASE;
listUrlBase = DEFAULT_LIST_URL_BASE;
hashtagUrlBase = DEFAULT_HASHTAG_URL_BASE;
+ invisibleTagAttrs = DEFAULT_INVISIBLE_TAG_ATTRS;
extractor.setExtractURLWithoutProtocol(false);
}
@@ -175,7 +179,7 @@ public void linkToURL(Entity entity, String text, StringBuilder builder) {
String afterDisplayURL = entity.expandedURL.substring(diplayURLIndexInExpandedURL + displayURLSansEllipses.length());
String precedingEllipsis = entity.displayURL.startsWith("") ? "" : "";
String followingEllipsis = entity.displayURL.endsWith("") ? "" : "";
- String invisibleSpan = "<span style='font-size:0; line-height:0'>";
+ String invisibleSpan = "<span " + invisibleTagAttrs + ">";
StringBuilder sb = new StringBuilder("<span class='tco-ellipsis'>");
sb.append(precedingEllipsis);
@@ -186,6 +190,8 @@ public void linkToURL(Entity entity, String text, StringBuilder builder) {
sb.append("<span class='tco-ellipsis'>").append(invisibleSpan).append("&nbsp;</span>").append(followingEllipsis).append("</span>");
linkText = sb;
+ } else {
+ linkText = entity.displayURL;
}
}
View
2  tests/com/twitter/AutolinkTest.java
@@ -58,7 +58,7 @@ public void testURLEntities() {
List<Entity> entities = new ArrayList<Entity>();
entities.add(entity);
String tweet = "http://t.co/0JG5Mcq";
- String expected = "<a href=\"http://t.co/0JG5Mcq\" rel=\"nofollow\"><span class='tco-ellipsis'><span style='font-size:0; line-height:0'>&nbsp;</span></span><span style='font-size:0; line-height:0'>http://</span><span class='js-display-url'>blog.twitter.com/2011/05/twitte</span><span style='font-size:0; line-height:0'>r-for-mac-update.html</span><span class='tco-ellipsis'><span style='font-size:0; line-height:0'>&nbsp;</span>…</span></a>";
+ String expected = "<a href=\"http://t.co/0JG5Mcq\" rel=\"nofollow\"><span class='tco-ellipsis'><span style='position:absolute;left:-999px;'>&nbsp;</span></span><span style='position:absolute;left:-999px;'>http://</span><span class='js-display-url'>blog.twitter.com/2011/05/twitte</span><span style='position:absolute;left:-999px;'>r-for-mac-update.html</span><span class='tco-ellipsis'><span style='position:absolute;left:-999px;'>&nbsp;</span>…</span></a>";
assertAutolink(expected, linker.autoLinkEntities(tweet, entities));
}
Please sign in to comment.
Something went wrong with that request. Please try again.