Skip to content

Commit

Permalink
add 'noFollow' options
Browse files Browse the repository at this point in the history
  • Loading branch information
uudashr committed Jan 2, 2014
1 parent 95fad7b commit 9053e5a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
$("form input[type='submit']").click(function() {
str = this.form.content.value
$("#content").html(str);
$("#content").linkify(toHashtagUrl);
$("#content").linkify({hashtagUrlBuilder: toHashtagUrl, noFollow: false});
return false;
});
});
Expand Down
1 change: 0 additions & 1 deletion jquery-linkify.min.js

This file was deleted.

17 changes: 13 additions & 4 deletions jquery.linkify.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
function linkify(string, buildHashtagUrl, includeW3, target) {
function linkify(string, buildHashtagUrl, includeW3, target, noFollow) {
relNoFollow = "";
if (noFollow) {
relNoFollow = " rel=\"nofollow\"";
}

string = string.replace(/((http|https|ftp)\:\/\/|\bw{3}\.)[a-z0-9\-\.]+\.[a-z]{2,3}(:[a-z0-9]*)?\/?([a-z\u00C0-\u017F0-9\-\._\?\,\'\/\\\+&%\$#\=~])*/gi, function(captured) {
var uri;
if (captured.toLowerCase().indexOf("www.") == 0) {
Expand All @@ -9,11 +14,11 @@ function linkify(string, buildHashtagUrl, includeW3, target) {
} else {
uri = captured;
}
return "<a href=\"" + uri+ "\" target=\"" + target + "\" rel=\"nofollow\">" + captured + "</a>";;
return "<a href=\"" + uri+ "\" target=\"" + target + "\"" + relNoFollow + ">" + captured + "</a>";
});

if (buildHashtagUrl) {
string = string.replace(/\B#(\w+)/g, "<a href=" + buildHashtagUrl("$1") +" target=\"" + target + "\" rel=\"nofollow\">#$1</a>");
string = string.replace(/\B#(\w+)/g, "<a href=" + buildHashtagUrl("$1") +" target=\"" + target + "\"" + relNoFollow + ">#$1</a>");
}
return string;
}
Expand All @@ -25,6 +30,7 @@ function linkify(string, buildHashtagUrl, includeW3, target) {
var buildHashtagUrl;
var includeW3 = true;
var target = '_self';
var noFollow = true;
if (opts) {
if (typeof opts == "function") {
buildHashtagUrl = opts;
Expand All @@ -38,14 +44,17 @@ function linkify(string, buildHashtagUrl, includeW3, target) {
if (typeof opts.target == "string") {
target = opts.target;
}
if (typeof opts.noFollow == "boolean") {
noFollow = opts.noFollow;
}
}
}
$this.html(
$.map(
$this.contents(),
function(n, i) {
if (n.nodeType == 3) {
return linkify(n.data, buildHashtagUrl, includeW3, target);
return linkify(n.data, buildHashtagUrl, includeW3, target, noFollow);
} else {
return n.outerHTML;
}
Expand Down
4 changes: 4 additions & 0 deletions 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 9053e5a

Please sign in to comment.