lucaong / jQCloud

jQuery plugin for drawing neat word clouds that actually look like clouds
MIT License
646 stars 293 forks source link

nofollow link #14

Closed strobotta closed 12 years ago

strobotta commented 12 years ago

Hello,

in my tagcloud I want to have rel="nofollow" attributes in the anchor to prevent search engines follow the links (because this would create an endless loop as the links link to each other).

I added an option parameter for the call so that it may look like this:

$(document).ready(function() {
  $("#tagcloud").jQCloud(word_list, { randomClasses: 3, nofollow: true });
});

The patch to the jqcloud-0.2.4.js looks as follows:

--- jqcloud-0.2.4.js    2011-11-04 10:53:45.930038575 +0100
+++ /var/www/html/js/jqcloud.js 2011-11-04 10:52:15.322212800 +0100
@@ -25,7 +25,8 @@
         y: $this.height() / 2.0
       },
       delayedMode: word_array.length > 50,
-      randomClasses: 0
+      randomClasses: 0,
+      nofollow: false
     };

     // Maintain backward compatibility with old API (pre 0.2.0), where the second argument of jQCloud was a callback function
@@ -93,7 +94,7 @@
         // Linearly map the original weight to a discrete scale from 1 to 10
         var weight = Math.round((word.weight - word_array[word_array.length - 1].weight)/(word_array[0].weight - word_array[word_array.length - 1].weight) * 9.0) + 1;

-        var inner_html = word.url !== undefined ? "<a href='" + encodeURI(word.url).replace(/'/g, "%27") + "'>" + word.text + "</a>" : word.text;
+        var inner_html = word.url !== undefined ? "<a href='" + encodeURI(word.url).replace(/'/g, "%27") + "'" + ((options.nofollow) ? " rel='nofollow'" : "") + ">" + word.text + "</a>" : word.text;
         $this.append("<span id='" + word_id + "' class='w" + weight + random_class + "' title='" + (word.title || "") + "'>" + inner_html + "</span>");

         // Search for the word span only once, and within the context of the container, for better performance

Could this maybe considered in a future release? Thank you.

lucaong commented 12 years ago

This is cool! Thank you strobrotta, this will be part of the next release :)

lucaong commented 12 years ago

Do you want to send me a pull request? Otherwise I'll just add this mentioning your contribute.

strobotta commented 12 years ago

I have not checked out the project. Please just apply the patch on your version. Again thank you very much for the fast reply and for the great plugin.

lucaong commented 12 years ago

done. It's part of v0.2.6 together with some other improvements