Skip to content

Commit 9053e5a

Browse files
committed
add 'noFollow' options
1 parent 95fad7b commit 9053e5a

4 files changed

+18
-6
lines changed

demo.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
$("form input[type='submit']").click(function() {
1919
str = this.form.content.value
2020
$("#content").html(str);
21-
$("#content").linkify(toHashtagUrl);
21+
$("#content").linkify({hashtagUrlBuilder: toHashtagUrl, noFollow: false});
2222
return false;
2323
});
2424
});

jquery-linkify.min.js

-1
This file was deleted.

jquery.linkify.js

+13-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
function linkify(string, buildHashtagUrl, includeW3, target) {
1+
function linkify(string, buildHashtagUrl, includeW3, target, noFollow) {
2+
relNoFollow = "";
3+
if (noFollow) {
4+
relNoFollow = " rel=\"nofollow\"";
5+
}
6+
27
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) {
38
var uri;
49
if (captured.toLowerCase().indexOf("www.") == 0) {
@@ -9,11 +14,11 @@ function linkify(string, buildHashtagUrl, includeW3, target) {
914
} else {
1015
uri = captured;
1116
}
12-
return "<a href=\"" + uri+ "\" target=\"" + target + "\" rel=\"nofollow\">" + captured + "</a>";;
17+
return "<a href=\"" + uri+ "\" target=\"" + target + "\"" + relNoFollow + ">" + captured + "</a>";
1318
});
1419

1520
if (buildHashtagUrl) {
16-
string = string.replace(/\B#(\w+)/g, "<a href=" + buildHashtagUrl("$1") +" target=\"" + target + "\" rel=\"nofollow\">#$1</a>");
21+
string = string.replace(/\B#(\w+)/g, "<a href=" + buildHashtagUrl("$1") +" target=\"" + target + "\"" + relNoFollow + ">#$1</a>");
1722
}
1823
return string;
1924
}
@@ -25,6 +30,7 @@ function linkify(string, buildHashtagUrl, includeW3, target) {
2530
var buildHashtagUrl;
2631
var includeW3 = true;
2732
var target = '_self';
33+
var noFollow = true;
2834
if (opts) {
2935
if (typeof opts == "function") {
3036
buildHashtagUrl = opts;
@@ -38,14 +44,17 @@ function linkify(string, buildHashtagUrl, includeW3, target) {
3844
if (typeof opts.target == "string") {
3945
target = opts.target;
4046
}
47+
if (typeof opts.noFollow == "boolean") {
48+
noFollow = opts.noFollow;
49+
}
4150
}
4251
}
4352
$this.html(
4453
$.map(
4554
$this.contents(),
4655
function(n, i) {
4756
if (n.nodeType == 3) {
48-
return linkify(n.data, buildHashtagUrl, includeW3, target);
57+
return linkify(n.data, buildHashtagUrl, includeW3, target, noFollow);
4958
} else {
5059
return n.outerHTML;
5160
}

jquery.linkify.min.js

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)