Permalink
Browse files

gallery-2011.02.16-20-31 albertosantini gallery-tagcloud

  • Loading branch information...
1 parent d084eaf commit 25aea2cb4d556e06ec3b574b9d40a331bfa009c2 YUI Builder committed Feb 16, 2011
Showing with 23 additions and 9 deletions.
  1. +8 −6 src/gallery-tagcloud/js/tagCloud.js
  2. +15 −3 src/gallery-tagcloud/tests/tagCloud.html
@@ -1,4 +1,3 @@
-
function highlight(node, text) {
var skip = 0, pos, i, spannode, middlebit, endbit, middleclone;
@@ -41,15 +40,20 @@
Y.NodeList.importMethod(Y.Node.prototype, "removeHighlight");
function tagCloud(node, outId, options) {
- var out, cloud = {}, cl = [], max = 0, i, n, t,
- tags = Y.one(node).get("text").replace(/\W/g, ' ').split(' ');
+ var out, cloud = {}, cl = [], max = 0, i, n, t, tags;
outId = outId || "#dynacloud";
options = options || {};
options.max = options.max || 20;
options.scale = options.scale || 4;
options.sort = options.sort === undefined ? true : options.sort;
+ options.fieldDelimeter = options.fieldDelimeter || ' ';
+ options.fieldRegex = options.fieldRegex || new RegExp(/\W/g);
+
+ tags = Y.one(node).get("text")
+ .replace(options.fieldRegex, options.fieldDelimeter)
+ .split(options.fieldDelimeter);
n = tags.length;
for (i = 0; i < n; i += 1) {
@@ -85,8 +89,7 @@
Y.one("body").append('<p id="dynacloud"><\/p>');
out = Y.one(outId);
}
-
- out.get('children').remove(true);
+ out.empty(true);
n = Math.min(options.max, cl.length);
for (i = 0; i < n; i += 1) {
@@ -105,4 +108,3 @@
}
Y.Node.addMethod("tagCloud", tagCloud);
-
@@ -9,7 +9,7 @@
.highlight { background-color: yellow; }
</style>
-<script src="http://yui.yahooapis.com/3.2.0/build/yui/yui-min.js"></script>
+<script src="http://yui.yahooapis.com/3.3.0/build/yui/yui-min.js"></script>
<script src="../../../build/gallery-tagcloud/gallery-tagcloud.js"></script>
</head>
@@ -21,13 +21,19 @@
DynaCloud - a dynamic JavaScript tag/keyword cloud with jQuery</a>
<br /> <br />
- <div id="myTagCloud"></div>
<div id="text" class="dynacloud">
First Second SECOND Third THIRD THIRD Fourth FOURTH FOURTH FOURTH
Fifth FIFTH FIFTH FIFTH FIFTH Sixth SIXTH SIXTH SIXTH SIXTH SIXTH
</div>
+ <div id="text2" class="dynacloud">
+ First,Second,SECOND,Third,THIRD,THIRD,Fourth,FOURTH,FOURTH,FOURTH
+ Fifth,FIFTH,FIFTH,FIFTH,FIFTH,Sixth,SIXTH,SIXTH,SIXTH,SIXTH,SIXTH
+ </div>
+
+ <div id="myTagCloud"></div>
+ <div id="myTagCloud2"></div>
<script type="text/javascript">
/*global YUI */
@@ -36,7 +42,13 @@
YUI().use("gallery-tagcloud", function (Y) {
Y.on("domready", function () {
- Y.one("#text").tagCloud("#myTagCloud", { sort: false });
+ Y.one("#text").tagCloud("#myTagCloud", {
+ sort: false
+ });
+ Y.one("#text2").tagCloud("#myTagCloud2", {
+ sort: false,
+ fieldDelimeter: ','
+ });
Y.one("#text").tagCloud();
});
});

0 comments on commit 25aea2c

Please sign in to comment.