Permalink
Browse files

Merge branch 'change_url_class' into add_tag_on_symbol

Conflicts:
	twitter-text.js
  • Loading branch information...
2 parents fb2221a + 9c14e95 commit 52217f27c28c718d6d66f9dbe4847df415e98b16 @keitaf keitaf committed Jun 5, 2012
Showing with 17 additions and 13 deletions.
  1. +5 −0 test/tests.js
  2. +12 −13 twitter-text.js
View
@@ -120,6 +120,11 @@ test("twttr.txt.autolink", function() {
ok(twttr.txt.autoLink("#hi", { textWithSymbolTag: "b" }).match(/<a[^>]+>#<b>hi<\/b><\/a>/), "Apply textWithSymbolTag to hash");
ok(twttr.txt.autoLink("#hi", { symbolTag: "s", textWithSymbolTag: "b" }).match(/<a[^>]+><s>#<\/s><b>hi<\/b><\/a>/), "Apply symbolTag and textWithSymbolTag to hash");
+ // test urlClass
+ same(twttr.txt.autoLink("http://twitter.com"), "<a href=\"http://twitter.com\" rel=\"nofollow\">http://twitter.com</a>", "AutoLink without urlClass");
+ same(twttr.txt.autoLink("http://twitter.com", {urlClass: "testClass"}), "<a href=\"http://twitter.com\" rel=\"nofollow\" class=\"testClass\">http://twitter.com</a>", "autoLink with urlClass");
+ ok(!twttr.txt.autoLink("#hash @tw", {urlClass: "testClass"}).match(/class=\"testClass\"/), "urlClass won't be used for hashtag and @mention auto-links")
+
// url entities
var autoLinkResult = twttr.txt.autoLink("http://t.co/0JG5Mcq", {
invisibleTagAttrs: "style='font-size:0'",
View
@@ -368,16 +368,14 @@ if (typeof twttr === "undefined" || twttr === null) {
, "i");
- // Default CSS class for auto-linked URLs
- var DEFAULT_URL_CLASS = "tweet-url";
// Default CSS class for auto-linked lists (along with the url class)
- var DEFAULT_LIST_CLASS = "list-slug";
+ var DEFAULT_LIST_CLASS = "tweet-url list-slug";
// Default CSS class for auto-linked usernames (along with the url class)
- var DEFAULT_USERNAME_CLASS = "username";
+ var DEFAULT_USERNAME_CLASS = "tweet-url username";
// Default CSS class for auto-linked hashtags (along with the url class)
- var DEFAULT_HASHTAG_CLASS = "hashtag";
+ var DEFAULT_HASHTAG_CLASS = "tweet-url hashtag";
// Default CSS class for auto-linked cashtags (along with the url class)
- var DEFAULT_CASHTAG_CLASS = "cashtag";
+ var DEFAULT_CASHTAG_CLASS = "tweet-url cashtag";
// HTML attribute for robot nofollow behavior (default)
var HTML_ATTR_NO_FOLLOW = " rel=\"nofollow\"";
// Options which should not be passed as HTML attributes
@@ -424,7 +422,7 @@ if (typeof twttr === "undefined" || twttr === null) {
var attrs = {
href: options.hashtagUrlBase + hashtag,
title: "#" + hashtag,
- class: options.urlClass + " " + options.hashtagClass
+ class: options.hashtagClass
};
return twttr.txt.linkToTextWithSymbol(hash, hashtag, attrs, options);
@@ -435,7 +433,7 @@ if (typeof twttr === "undefined" || twttr === null) {
var attrs = {
href: options.cashtagUrlBase + cashtag,
title: "$" + cashtag,
- class: options.urlClass + " " + options.cashtagClass
+ class: options.cashtagClass
};
return twttr.txt.linkToTextWithSymbol("$", cashtag, attrs, options);
@@ -447,7 +445,7 @@ if (typeof twttr === "undefined" || twttr === null) {
var slashListname = twttr.txt.htmlEscape(entity.listSlug);
var isList = entity.listSlug && !options.suppressLists;
var attrs = {
- class: options.urlClass + " " + (isList ? options.listClass : options.usernameClass),
+ class: (isList ? options.listClass : options.usernameClass),
href: isList ? options.listUrlBase + user + slashListname : options.usernameUrlBase + user
};
if (!isList && !options.suppressDataScreenName) {
@@ -470,6 +468,11 @@ if (typeof twttr === "undefined" || twttr === null) {
linkText = twttr.txt.linkTextWithEntity(urlEntity, options);
}
+ // set class only if urlClass is specified.
+ if (options.urlClass) {
+ options.htmlAttrs = (options.htmlAttrs || "") + " class=\"" + options.urlClass + "\"";
+ }
+
var d = {
htmlAttrs: options.htmlAttrs + (!options.title && urlEntity.display_url ? " title=\"" + urlEntity.expanded_url + "\"" : ""),
url: twttr.txt.htmlEscape(url),
@@ -554,10 +557,6 @@ if (typeof twttr === "undefined" || twttr === null) {
if (!options.suppressNoFollow) {
options.rel = "nofollow";
}
- if (options.urlClass) {
- options["class"] = options.urlClass;
- }
- options.urlClass = options.urlClass || DEFAULT_URL_CLASS;
options.hashtagClass = options.hashtagClass || DEFAULT_HASHTAG_CLASS;
options.hashtagUrlBase = options.hashtagUrlBase || "https://twitter.com/#!/search?q=%23";
options.cashtagClass = options.cashtagClass || DEFAULT_CASHTAG_CLASS;

0 comments on commit 52217f2

Please sign in to comment.