From c976db3bdaf7896fe8e4908fd0fbe446afb29849 Mon Sep 17 00:00:00 2001 From: Arcovion Date: Tue, 7 May 2013 02:52:18 +0200 Subject: [PATCH 1/7] Changed rel attr to data-weight Reserving rel for "tag" http://microformats.org/wiki/rel-tag --- jquery.tagcloud.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jquery.tagcloud.js b/jquery.tagcloud.js index 4e5d5a3..47b7e9f 100644 --- a/jquery.tagcloud.js +++ b/jquery.tagcloud.js @@ -58,7 +58,7 @@ var opts = $.extend({}, $.fn.tagcloud.defaults, options); var tagWeights = this.map(function(){ - return $(this).attr("rel"); + return $(this).attr("data-weight"); }); tagWeights = jQuery.makeArray(tagWeights).sort(compareWeights); var lowest = tagWeights[0]; @@ -75,7 +75,7 @@ colorIncr = colorIncrement (opts.color, range); } return this.each(function() { - var weighting = $(this).attr("rel") - lowest; + var weighting = $(this).attr("data-weight") - lowest; if (opts.size) { $(this).css({"font-size": opts.size.start + (weighting * fontIncr) + opts.size.unit}); } From 67d9228497a340b41c7c924c4bf6b4af81bb55ff Mon Sep 17 00:00:00 2001 From: Eliott Appleford Date: Tue, 21 May 2013 20:34:22 +0100 Subject: [PATCH 2/7] add support for zepto & update readme --- README.md | 10 ++++++---- jquery.tagcloud.js | 16 ++++++++-------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 0ee468b..4270b04 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,15 @@ jquery.tagcloud.js ================== +A simple tag cloud plugin for jQuery & Zepto. + Usage ----- and then: diff --git a/jquery.tagcloud.js b/jquery.tagcloud.js index 47b7e9f..be16b08 100644 --- a/jquery.tagcloud.js +++ b/jquery.tagcloud.js @@ -1,13 +1,13 @@ /*! - * jquery.tagcloud.js - * A Simple Tag Cloud Plugin for JQuery + * jQuery.tagcloud.js + * A Simple Tag Cloud Plugin for jQuery & Zepto * * https://github.com/addywaddy/jquery.tagcloud.js * created by Adam Groves */ (function($) { - /*global jQuery*/ + /*global Zepto*/ "use strict"; var compareWeights = function(a, b) @@ -26,7 +26,7 @@ // Converts an RGB array to hex var toHex = function(ary) { - return "#" + jQuery.map(ary, function(i) { + return "#" + Zepto.map(ary, function(i) { var hex = i.toString(16); hex = (hex.length === 1) ? "0" + hex : hex; return hex; @@ -34,13 +34,13 @@ }; var colorIncrement = function(color, range) { - return jQuery.map(toRGB(color.end), function(n, i) { + return Zepto.map(toRGB(color.end), function(n, i) { return (n - toRGB(color.start)[i])/range; }); }; var tagColor = function(color, increment, weighting) { - var rgb = jQuery.map(toRGB(color.start), function(n, i) { + var rgb = Zepto.map(toRGB(color.start), function(n, i) { var ref = Math.round(n + (increment[i] * weighting)); if (ref > 255) { ref = 255; @@ -60,7 +60,7 @@ var tagWeights = this.map(function(){ return $(this).attr("data-weight"); }); - tagWeights = jQuery.makeArray(tagWeights).sort(compareWeights); + tagWeights = Array.prototype.slice.call(tagWeights, 0).sort(compareWeights); var lowest = tagWeights[0]; var highest = tagWeights.pop(); var range = highest - lowest; @@ -89,4 +89,4 @@ size: {start: 14, end: 18, unit: "pt"} }; -})(jQuery); +})(jQuery || Zepto); From 548e9e198aed384cb76ddde9ce51466003635232 Mon Sep 17 00:00:00 2001 From: Arcovion Date: Tue, 21 May 2013 21:40:19 +0200 Subject: [PATCH 3/7] Update README.md --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 4270b04..01289a2 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,6 @@ jquery.tagcloud.js ================== -A simple tag cloud plugin for jQuery & Zepto. - Usage -----
From 8691a8b51fda71bdace94706b77a25e2a4ab334f Mon Sep 17 00:00:00 2001 From: Arcovion Date: Tue, 21 May 2013 21:50:45 +0200 Subject: [PATCH 4/7] Update jquery.tagcloud.js --- jquery.tagcloud.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jquery.tagcloud.js b/jquery.tagcloud.js index be16b08..c3cada2 100644 --- a/jquery.tagcloud.js +++ b/jquery.tagcloud.js @@ -89,4 +89,4 @@ size: {start: 14, end: 18, unit: "pt"} }; -})(jQuery || Zepto); +})(window.jQuery || window.Zepto); From d823945314431466e53a9c367044ed97bc0e7a56 Mon Sep 17 00:00:00 2001 From: Arcovion Date: Tue, 21 May 2013 22:15:45 +0200 Subject: [PATCH 5/7] Update and rename jquery.tagcloud.js to zepto.tagcloud.js --- jquery.tagcloud.js => zepto.tagcloud.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename jquery.tagcloud.js => zepto.tagcloud.js (98%) diff --git a/jquery.tagcloud.js b/zepto.tagcloud.js similarity index 98% rename from jquery.tagcloud.js rename to zepto.tagcloud.js index c3cada2..026c785 100644 --- a/jquery.tagcloud.js +++ b/zepto.tagcloud.js @@ -89,4 +89,4 @@ size: {start: 14, end: 18, unit: "pt"} }; -})(window.jQuery || window.Zepto); +})(Zepto); From fd0ff6a6dbab2d503b1ae65092e744e87ed8d65d Mon Sep 17 00:00:00 2001 From: Arcovion Date: Tue, 21 May 2013 22:22:59 +0200 Subject: [PATCH 6/7] Create jquery.tagcloud.js --- jquery.tagcloud.js | 92 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 jquery.tagcloud.js diff --git a/jquery.tagcloud.js b/jquery.tagcloud.js new file mode 100644 index 0000000..47b7e9f --- /dev/null +++ b/jquery.tagcloud.js @@ -0,0 +1,92 @@ +/*! + * jquery.tagcloud.js + * A Simple Tag Cloud Plugin for JQuery + * + * https://github.com/addywaddy/jquery.tagcloud.js + * created by Adam Groves + */ +(function($) { + + /*global jQuery*/ + "use strict"; + + var compareWeights = function(a, b) + { + return a - b; + }; + + // Converts hex to an RGB array + var toRGB = function(code) { + if (code.length === 4) { + code = code.replace(/(\w)(\w)(\w)/gi, "\$1\$1\$2\$2\$3\$3"); + } + var hex = /(\w{2})(\w{2})(\w{2})/.exec(code); + return [parseInt(hex[1], 16), parseInt(hex[2], 16), parseInt(hex[3], 16)]; + }; + + // Converts an RGB array to hex + var toHex = function(ary) { + return "#" + jQuery.map(ary, function(i) { + var hex = i.toString(16); + hex = (hex.length === 1) ? "0" + hex : hex; + return hex; + }).join(""); + }; + + var colorIncrement = function(color, range) { + return jQuery.map(toRGB(color.end), function(n, i) { + return (n - toRGB(color.start)[i])/range; + }); + }; + + var tagColor = function(color, increment, weighting) { + var rgb = jQuery.map(toRGB(color.start), function(n, i) { + var ref = Math.round(n + (increment[i] * weighting)); + if (ref > 255) { + ref = 255; + } else { + if (ref < 0) { + ref = 0; + } + } + return ref; + }); + return toHex(rgb); + }; + + $.fn.tagcloud = function(options) { + + var opts = $.extend({}, $.fn.tagcloud.defaults, options); + var tagWeights = this.map(function(){ + return $(this).attr("data-weight"); + }); + tagWeights = jQuery.makeArray(tagWeights).sort(compareWeights); + var lowest = tagWeights[0]; + var highest = tagWeights.pop(); + var range = highest - lowest; + if(range === 0) {range = 1;} + // Sizes + var fontIncr, colorIncr; + if (opts.size) { + fontIncr = (opts.size.end - opts.size.start)/range; + } + // Colors + if (opts.color) { + colorIncr = colorIncrement (opts.color, range); + } + return this.each(function() { + var weighting = $(this).attr("data-weight") - lowest; + if (opts.size) { + $(this).css({"font-size": opts.size.start + (weighting * fontIncr) + opts.size.unit}); + } + if (opts.color) { + $(this).css({"color": tagColor(opts.color, colorIncr, weighting)}); + } + }); + }; + + $.fn.tagcloud.defaults = { + size: {start: 14, end: 18, unit: "pt"} + }; + +})(jQuery); From 8fcc334f89e8a06258e4317c313b2f73c86d8033 Mon Sep 17 00:00:00 2001 From: Arcovion Date: Tue, 21 May 2013 22:29:01 +0200 Subject: [PATCH 7/7] Update README.md --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 01289a2..f5b5d2e 100644 --- a/README.md +++ b/README.md @@ -4,10 +4,10 @@ jquery.tagcloud.js Usage ----- and then: