Skip to content

Commit

Permalink
Take string out of function. clean up code a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
laszlof committed Feb 29, 2016
1 parent 08cbcc6 commit 9819f71
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
19 changes: 6 additions & 13 deletions jquery.linkify.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,14 @@ function linkify(string, buildHashtagUrl, includeW3, target, noFollow) {
relNoFollow = " rel=\"nofollow\"";
}

string = function() {
var uri;
if (string.toLowerCase().indexOf("www.") === 0) {
if (!includeW3) {
return string;
}
uri = "http://" + string;
} else {
uri = string;
}
return "<a href=\"" + uri+ "\" target=\"" + target + "\"" + relNoFollow + ">" + string + "</a>";
}();
if (string.toLowerCase().indexOf("www.") === 0 && includeW3) {
string = '<a href="http://' + string + '" target="' + target + '"' + relNoFollow + '>' + string + '</a>';
} else {
string = '<a href="' + string + '" target="' + target + '"' + relNoFollow + '>' + string + '</a>';
}

if (buildHashtagUrl) {
string = string.replace(/\B#(\w+)/g, "<a href=" + buildHashtagUrl("$1") +" target=\"" + target + "\"" + relNoFollow + ">#$1</a>");
string = string.replace(/\B#(\w+)/g, '<a href=' + buildHashtagUrl("$1") + ' target="' + target + '"' + relNoFollow + '>#$1</a>');
}
return string;
}
Expand Down
2 changes: 1 addition & 1 deletion jquery.linkify.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9819f71

Please sign in to comment.