Fixed #2027 - make sure that cloned elements (within appendTo, etc.) have their event...
[jquery.git] / build / js / Words.js
1 \r
2 var Words = Collection.extend({\r
3         constructor: function(script) {\r
4                 this.base();\r
5                 forEach (script.match(WORDS), this.add, this);\r
6                 this.encode();\r
7         },\r
8         \r
9         add: function(word) {\r
10                 if (!this.exists(word)) this.base(word);\r
11                 word = this.fetch(word);\r
12                 word.count++;\r
13                 return word;\r
14         },\r
15         \r
16         encode: function() {\r
17                 // sort by frequency\r
18                 this.sort(function(word1, word2) {\r
19                         return word2.count - word1.count;\r
20                 });\r
21                 \r
22                 eval("var a=62,e=" + Packer.ENCODE62);\r
23                 var encode = e;         \r
24                 var encoded = new Collection; // a dictionary of base62 -> base10\r
25                 var count = this.count();\r
26                 for (var i = 0; i < count; i++) {\r
27                         encoded.store(encode(i), i);\r
28                 }\r
29                 \r
30                 var empty = function() {return ""};\r
31                 var index = 0;\r
32                 forEach (this, function(word) {\r
33                         if (encoded.exists(word)) {\r
34                                 word.index = encoded.fetch(word);\r
35                                 word.toString = empty;\r
36                         } else {\r
37                                 while (this.exists(encode(index))) index++;\r
38                                 word.index = index++;\r
39                         }\r
40                         word.encoded = encode(word.index);\r
41                 }, this);\r
42                 \r
43                 // sort by encoding\r
44                 this.sort(function(word1, word2) {\r
45                         return word1.index - word2.index;\r
46                 });\r
47         },\r
48         \r
49         toString: function() {\r
50                 return this.values().join("|");\r
51         }\r
52 }, {\r
53         Item: {\r
54                 constructor: function(word) {\r
55                         this.toString = function() {return word};\r
56                 },\r
57                 \r
58                 count: 0,\r
59                 encoded: "",\r
60                 index: -1\r
61         }\r
62 });\r