jquery-plugins-rails 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/.rvmrc CHANGED
@@ -1 +1 @@
1
- rvm --create ruby-1.9.3-p0@jquery-plugins-rails
1
+ rvm --create ruby-1.9.3-p125@jquery-plugins-rails
@@ -1,5 +1,5 @@
1
1
  module JqueryPlugins
2
2
  module Rails
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
@@ -170,7 +170,7 @@ drag = $special.drag = {
170
170
  switch ( event.type ){
171
171
  // mousemove, check distance, start dragging
172
172
  case !dd.dragging && 'mousemove':
173
- // drag tolerance, x + y = distance
173
+ // drag tolerance, x² + y² = distance²
174
174
  if ( Math.pow( event.pageX-dd.pageX, 2 ) + Math.pow( event.pageY-dd.pageY, 2 ) < Math.pow( dd.distance, 2 ) )
175
175
  break; // distance tolerance not reached
176
176
  event.target = dd.target; // force target from "mousedown" event (fix distance issue)
@@ -0,0 +1,198 @@
1
+ /**
2
+ * jQuery.fuzzyMatch.js, version 0.3 (2011-06-22)
3
+ *
4
+ * https://github.com/rapportive-oss/jquery-fuzzymatch
5
+ *
6
+ * A fuzzy string-matching plugin for autocompleting in jQuery,
7
+ * based on LiquidMetal http://github.com/rmm5t/liquidmetal/blob/master/liquidmetal.js
8
+ * quicksilver.js http://code.google.com/p/rails-oceania/source/browse/lachiecox/qs_score/trunk/qs_score.js
9
+ * QuickSilver http://code.google.com/p/blacktree-alchemy/source/browse/trunk/Crucible/Code/NSString_BLTRExtensions.m#61
10
+ * FuzzyString https://github.com/dcparker/jquery_plugins/blob/master/fuzzy-string/fuzzy-string.js
11
+ *
12
+ * Copyright (c) 2011, Conrad Irwin (conrad@rapportive.com)
13
+ * Licensed under the MIT: http://www.opensource.org/licenses/mit-license.php
14
+ *
15
+ * TODO: Tweak heuristics, typo correction support?
16
+ **/
17
+ (function ($) {
18
+
19
+ // The scores are arranged so that a continuous match of characters will
20
+ // result in a total score of 1.
21
+ //
22
+ // The best case, this character is a match, and either this is the start
23
+ // of the string, or the previous character was also a match.
24
+ var SCORE_CONTINUE_MATCH = 1,
25
+
26
+ // A new match at the start of a word scores better than a new match
27
+ // elsewhere as it's more likely that the user will type the starts
28
+ // of fragments.
29
+ // (Our notion of word includes CamelCase and hypen-separated, etc.)
30
+ SCORE_START_WORD = 0.9,
31
+
32
+ // Any other match isn't ideal, but it's probably ok.
33
+ SCORE_OK = 0.8,
34
+
35
+ // The goodness of a match should decay slightly with each missing
36
+ // character.
37
+ //
38
+ // i.e. "bad" is more likely than "bard" when "bd" is typed.
39
+ //
40
+ // This will not change the order of suggestions based on SCORE_* until
41
+ // 100 characters are inserted between matches.
42
+ PENALTY_SKIPPED = 0.999,
43
+
44
+ // The goodness of an exact-case match should be higher than a
45
+ // case-insensitive match by a small amount.
46
+ //
47
+ // i.e. "HTML" is more likely than "haml" when "HM" is typed.
48
+ //
49
+ // This will not change the order of suggestions based on SCORE_* until
50
+ // 1000 characters are inserted between matches.
51
+ PENALTY_CASE_MISMATCH = 0.9999,
52
+
53
+ // If the word has more characters than the user typed, it should
54
+ // be penalised slightly.
55
+ //
56
+ // i.e. "html" is more likely than "html5" if I type "html".
57
+ //
58
+ // However, it may well be the case that there's a sensible secondary
59
+ // ordering (like alphabetical) that it makes sense to rely on when
60
+ // there are many prefix matches, so we don't make the penalty increase
61
+ // with the number of tokens.
62
+ PENALTY_NOT_COMPLETE = 0.99;
63
+
64
+ /**
65
+ * Generates all possible split objects by splitting a string around a
66
+ * character in as many ways as possible.
67
+ *
68
+ * @param string The string to split
69
+ * @param char A character on which to split it.
70
+ *
71
+ * @return [{
72
+ * before: The fragment of the string before this occurance of the
73
+ * character.
74
+ *
75
+ * char: The original coy of this character (which may differ in case
76
+ * from the "char" parameter).
77
+ *
78
+ * after: The fragment of the string after the occurance of the character.
79
+ * }]
80
+ **/
81
+ function allCaseInsensitiveSplits(string, chr) {
82
+ var lower = string.toLowerCase(),
83
+ lchr = chr.toLowerCase(),
84
+
85
+ i = lower.indexOf(lchr),
86
+ result = [];
87
+
88
+ while (i > -1) {
89
+ result.push({
90
+ before: string.slice(0, i),
91
+ chr: string.charAt(i),
92
+ after: string.slice(i + 1)
93
+ });
94
+
95
+ i = lower.indexOf(lchr, i + 1);
96
+ }
97
+ return result;
98
+ }
99
+
100
+ /**
101
+ * Escapes a string so that it can be interpreted as HTML node content.
102
+ *
103
+ * WARNING: The output isn't safe for including in attributes, and I
104
+ * haven't considered other HTML contexts.
105
+ * NOTE: This really is worth it compared to using $('<div>').text(foo).html().
106
+ *
107
+ * @param string, the string to escape
108
+ * @return string, the escaped version.
109
+ */
110
+ function htmlEscape(string) {
111
+ return string.replace(/&/g, '&amp;')
112
+ .replace(/</g, '&lt;')
113
+ .replace(/>/g, '&gt;');
114
+ }
115
+
116
+ /**
117
+ * Generates a case-insensitive match of the abbreviation against the string
118
+ *
119
+ * @param string, a canonical string to be matched against.
120
+ * @param abbreviation, an abbreviation that a user may have typed
121
+ * in order to specify that string.
122
+ *
123
+ * @cache (private), a cache that reduces the expected running time of the
124
+ * algorithm in the case there are many repeated characters.
125
+ *
126
+ * @return {
127
+ * score: A score (0 <= score <= 1) that indicates how likely it is that
128
+ * the abbreviation matches the string.
129
+ *
130
+ * The score is 0 if the characters in the abbreviation do not
131
+ * all appear in order in the string.
132
+ *
133
+ * The score is 1 if the user typed the exact string.
134
+ *
135
+ * Scores are designed to be comparable when many different
136
+ * strings are matched against the same abbreviation, for example
137
+ * for autocompleting.
138
+ *
139
+ * html: A copy of the input string html-escaped, with matching letters
140
+ * surrounded by <b> and </b>.
141
+ *
142
+ * }
143
+ **/
144
+ $.fuzzyMatch = function (string, abbreviation, cache) {
145
+ if (abbreviation === "") {
146
+ return {
147
+ score: string === "" ? SCORE_CONTINUE_MATCH : PENALTY_NOT_COMPLETE,
148
+ html: htmlEscape(string)
149
+ };
150
+ }
151
+
152
+ if (cache && cache[string] && cache[string][abbreviation]) {
153
+ return $.extend({}, cache[string][abbreviation]);
154
+ }
155
+
156
+ cache = cache || {};
157
+ cache[string] = cache[string] || {};
158
+ cache[string][abbreviation] =
159
+
160
+ $(allCaseInsensitiveSplits(string, abbreviation.charAt(0)))
161
+ .map(function (i, split) {
162
+ var result = $.fuzzyMatch(split.after, abbreviation.slice(1), cache),
163
+ preceding_char = split.before.charAt(split.before.length - 1);
164
+
165
+ if (split.before === "") {
166
+ result.score *= SCORE_CONTINUE_MATCH;
167
+
168
+ } else if (preceding_char.match(/[\\\/\-_+.# \t"@\[\(\{&]/) ||
169
+ (split.chr.toLowerCase() !== split.chr && preceding_char.toLowerCase() === preceding_char)) {
170
+
171
+ result.score *= SCORE_START_WORD;
172
+ } else {
173
+ result.score *= SCORE_OK;
174
+ }
175
+
176
+ if (split.chr !== abbreviation.charAt(0)) {
177
+ result.score *= PENALTY_CASE_MISMATCH;
178
+ }
179
+
180
+ result.score *= Math.pow(PENALTY_SKIPPED, split.before.length);
181
+ result.html = htmlEscape(split.before) + '<b>' + htmlEscape(split.chr) + '</b>' + result.html;
182
+
183
+ return result;
184
+ })
185
+ .sort(function (a, b) {
186
+ return a.score < b.score ? 1 : a.score === b.score ? 0 : -1;
187
+ })[0] ||
188
+
189
+ // No matches for the next character in the abbreviation, abort!
190
+ {
191
+ score: 0, // This 0 will multiply up to the top, giving a total of 0
192
+ html: htmlEscape(string)
193
+ };
194
+
195
+ return $.extend({}, cache[string][abbreviation]);
196
+ };
197
+ /*global jQuery */
198
+ }(jQuery));
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jquery-plugins-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-16 00:00:00.000000000 Z
12
+ date: 2012-06-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: railties
16
- requirement: &20547000 !ruby/object:Gem::Requirement
16
+ requirement: &4698280 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '3.0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *20547000
24
+ version_requirements: *4698280
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: jquery-rails
27
- requirement: &20545920 !ruby/object:Gem::Requirement
27
+ requirement: &4697840 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *20545920
35
+ version_requirements: *4697840
36
36
  description: jQuery plugins for Rails 3.x asset pipeline
37
37
  email:
38
38
  - bb@xnull.de
@@ -53,6 +53,7 @@ files:
53
53
  - lib/jquery-plugins/rails/version.rb
54
54
  - vendor/assets/javascripts/jquery/event/drag.js
55
55
  - vendor/assets/javascripts/jquery/event/drop.js
56
+ - vendor/assets/javascripts/jquery/fuzzymatch.js
56
57
  - vendor/assets/javascripts/jquery/livequery.js
57
58
  - vendor/assets/javascripts/jquery/metadata.js
58
59
  homepage: https://github.com/zenops/jquery-plugins-rails
@@ -75,7 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
75
76
  version: '0'
76
77
  requirements: []
77
78
  rubyforge_project:
78
- rubygems_version: 1.8.10
79
+ rubygems_version: 1.8.17
79
80
  signing_key:
80
81
  specification_version: 3
81
82
  summary: jQuery plugins for Rails 3.x asset pipeline