esphinx-rails 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/Rakefile +21 -0
  4. data/config/environments/production.rb +1 -0
  5. data/config/environments/staging.rb +1 -0
  6. data/config/initializers/assets.rb +7 -0
  7. data/esphinx.gemspec +19 -0
  8. data/lib/assets/javascripts/esphinx/element.js +256 -0
  9. data/lib/assets/javascripts/esphinx/event.js +227 -0
  10. data/lib/assets/javascripts/esphinx/index.js +3 -0
  11. data/lib/assets/javascripts/esphinx/lib/collection.js +51 -0
  12. data/lib/assets/javascripts/esphinx/lib/comparable.js +54 -0
  13. data/lib/assets/javascripts/esphinx/lib/extensions/array.js +541 -0
  14. data/lib/assets/javascripts/esphinx/lib/extensions/function.js +46 -0
  15. data/lib/assets/javascripts/esphinx/lib/extensions/index.js +1 -0
  16. data/lib/assets/javascripts/esphinx/lib/extensions/location.js +111 -0
  17. data/lib/assets/javascripts/esphinx/lib/extensions/map.js +29 -0
  18. data/lib/assets/javascripts/esphinx/lib/extensions/number.js +42 -0
  19. data/lib/assets/javascripts/esphinx/lib/extensions/object.js +502 -0
  20. data/lib/assets/javascripts/esphinx/lib/extensions/string.js +130 -0
  21. data/lib/assets/javascripts/esphinx/lib/extensions/x_path_result.js +31 -0
  22. data/lib/assets/javascripts/esphinx/lib/patterns/gof/flyweight/factory.js +115 -0
  23. data/lib/assets/javascripts/esphinx/lib/patterns/gof/flyweight/flyweight.js +12 -0
  24. data/lib/assets/javascripts/esphinx/lib/patterns/gof/iterator.js +332 -0
  25. data/lib/assets/javascripts/esphinx/lib/patterns/gof/strategies/context.js +42 -0
  26. data/lib/assets/javascripts/esphinx/lib/patterns/gof/strategies/search/graphs/bfs/element.js +78 -0
  27. data/lib/assets/javascripts/esphinx/lib/patterns/gof/strategies/search/graphs/bfs/object.js +83 -0
  28. data/lib/assets/javascripts/esphinx/lib/patterns/gof/strategies/search/graphs/bfs.js +19 -0
  29. data/lib/assets/javascripts/esphinx/lib/patterns/gof/strategies/search/search.js +24 -0
  30. data/lib/assets/javascripts/esphinx/lib/patterns/gof/strategies/search/search_proxy.js +52 -0
  31. data/lib/assets/javascripts/esphinx/lib/patterns/index.js +1 -0
  32. data/lib/assets/javascripts/esphinx/main.js +361 -0
  33. data/lib/assets/javascripts/esphinx/node.js +276 -0
  34. data/lib/assets/javascripts/esphinx/properties/forms.js +161 -0
  35. data/lib/assets/javascripts/esphinx/properties/inputs/text.js +29 -0
  36. data/lib/assets/javascripts/esphinx/property.js +308 -0
  37. data/lib/assets/javascripts/esphinx/query.js +347 -0
  38. data/lib/assets/javascripts/esphinx/samples/sort.js +30 -0
  39. data/lib/assets/javascripts/esphinx/style.js +342 -0
  40. data/lib/assets/javascripts/esphinx/util/ajax.js +152 -0
  41. data/lib/assets/javascripts/esphinx/util/autocomplete.js +356 -0
  42. data/lib/assets/javascripts/esphinx/util/browser.js +66 -0
  43. data/lib/assets/javascripts/esphinx/util/cookie.js +167 -0
  44. data/lib/assets/javascripts/esphinx/util/keyboard.js +110 -0
  45. data/lib/assets/javascripts/esphinx/util/loader.js +84 -0
  46. data/lib/assets/javascripts/esphinx/util/observer.js +58 -0
  47. data/lib/assets/javascripts/esphinx/util/promise.js +127 -0
  48. data/lib/assets/javascripts/esphinx/util/protector.js +142 -0
  49. data/lib/assets/javascripts/esphinx/util/range.js +6 -0
  50. data/lib/assets/javascripts/esphinx/util/scrollbar.js +22 -0
  51. data/lib/esphinx/rails/engine.rb +7 -0
  52. data/lib/esphinx/rails/version.rb +5 -0
  53. data/lib/esphinx-rails.rb +1 -0
  54. data/vendor/assets/javascripts/jquery-2.2.2.min.js +1 -0
  55. metadata +99 -0
@@ -0,0 +1,356 @@
1
+ var
2
+ esPhinx,
3
+ Iterable;
4
+
5
+
6
+ (function($) {
7
+ "use strict";
8
+
9
+ $.prototype.extend({
10
+
11
+ autocomplete: function(elementsList, options, callback) {
12
+ var
13
+ completeOften,
14
+ searchTextBox = this,
15
+ nonCharacterKeysPattern = new RegExp($
16
+ .nonCharacterKeysPattern()),
17
+ inline = false,
18
+ elements2Recovery = [],
19
+ afterAmountCharacters = options.afterAmountCharacters,
20
+
21
+ complete2Recovery = function(object, times) {
22
+ var
23
+ i = 0;
24
+
25
+ while (i++ < times) {
26
+ elements2Recovery.push(object);
27
+ }
28
+ },
29
+
30
+ resolveArguments = function(options) {
31
+ if (!Object.belongToClass(options, Object)) {
32
+ options = {};
33
+ }
34
+
35
+ if (typeof options.caseSensitive != "boolean") {
36
+ options.caseSensitive = false;
37
+ }
38
+
39
+ if (typeof options.orderlySearch != "boolean") {
40
+ options.orderlySearch = false;
41
+ }
42
+
43
+ if (typeof afterAmountCharacters != "number") {
44
+ afterAmountCharacters = 1;
45
+ }
46
+
47
+ },
48
+
49
+ inlineSearch = function(element, options) {
50
+ var
51
+ eventListenerMethod,
52
+ previousSearchText = searchTextBox.value();
53
+
54
+ if (typeof eventListenerMethod == "function") {
55
+ searchTextBox.off("input", eventListenerMethod);
56
+ }
57
+
58
+ eventListenerMethod = function(e) {
59
+ var
60
+ resolvedList,
61
+ foundElements,
62
+ startingIndex,
63
+ finalIndex,
64
+ foundElement,
65
+ previousElement = element,
66
+ parent = element.clone(),
67
+ searchTextLength = searchTextBox.value().length,
68
+ searchTextDifference = previousSearchText.length -
69
+ searchTextLength,
70
+ searchTextAmount = (searchTextLength -
71
+ afterAmountCharacters) + 1,
72
+
73
+ replaceLast = function(object) {
74
+ elements2Recovery.pop();
75
+ complete2Recovery(object);
76
+ };
77
+
78
+ if (searchTextBox.value()) {
79
+ startingIndex = searchTextBox.cursorPosition() - 2;
80
+
81
+ if (startingIndex < 0) {
82
+ startingIndex = 0;
83
+ }
84
+ finalIndex = startingIndex + searchTextDifference -
85
+ 1;
86
+
87
+ // when delete
88
+ if (searchTextLength < previousSearchText.length &&
89
+ searchTextLength >= afterAmountCharacters) {
90
+
91
+ if (startingIndex === 0) {
92
+ elements2Recovery.deleteAt(startingIndex,
93
+ finalIndex);
94
+ } else {
95
+ elements2Recovery.deleteAt(startingIndex,
96
+ elements2Recovery.lastIndex());
97
+ }
98
+
99
+ previousElement = elements2Recovery[
100
+ elements2Recovery.lastIndex()];
101
+ }
102
+
103
+ resolvedList = resolveList(previousElement,
104
+ options.order);
105
+ foundElements = resolvedList.elements;
106
+
107
+ if (foundElements.some() ||
108
+ elements2Recovery.length < searchTextAmount) {
109
+ if (searchTextDifference < 0) {
110
+ completeOften = Math
111
+ .abs(searchTextDifference);
112
+ } else {
113
+ completeOften = searchTextAmount -
114
+ elements2Recovery.length;
115
+ }
116
+
117
+ if (foundElements.some()) {
118
+ foundElement = parent.append(foundElements);
119
+ previousElement = foundElement;
120
+ }
121
+
122
+ complete2Recovery(previousElement,
123
+ completeOften);
124
+ } else {
125
+ replaceLast(previousElement);
126
+ }
127
+
128
+ previousSearchText = searchTextBox.value();
129
+ callback.call($(this), foundElements, resolvedList
130
+ .maps, e);
131
+ } else {
132
+ // reset
133
+ elements2Recovery = [];
134
+ previousSearchText = "";
135
+ previousElement = element;
136
+ callback.call($(this), $(), e);
137
+ }
138
+
139
+ };
140
+
141
+ searchTextBox.on("input", eventListenerMethod);
142
+ },
143
+
144
+ remoteSearch = function(options) {
145
+ var
146
+ word,
147
+ prevText,
148
+ nextText,
149
+ element,
150
+ URLParameters,
151
+ resolvedList,
152
+ clipboardData,
153
+
154
+ request = function(e) {
155
+ if (options.remote.URLParameters) {
156
+ URLParameters = options.remote.URLParameters
157
+ .call(searchTextBox);
158
+ }
159
+
160
+ $.Ajax.new(options.remote.url.call(searchTextBox))
161
+ .get({
162
+ URLParameters: URLParameters,
163
+ progress: function(xhr) {
164
+ if (options.remote.loading) {
165
+ options.remote
166
+ .loading(xhr, e);
167
+ }
168
+ },
169
+ complete: function() {
170
+ $(e.target).off("keypress");
171
+ },
172
+ success: function(r) {
173
+ element = $(r);
174
+
175
+ if (element.some()) {
176
+ completeOften = (searchTextBox
177
+ .value().length -
178
+ afterAmountCharacters) + 1;
179
+
180
+ complete2Recovery(element,
181
+ completeOften);
182
+ }
183
+
184
+ resolvedList = resolveList(element,
185
+ options.order);
186
+ callback.call(searchTextBox,
187
+ resolvedList.elements,
188
+ resolvedList.maps, e);
189
+ if (element.length) {
190
+ inlineSearch(element, options);
191
+ }
192
+ }
193
+ });
194
+ };
195
+
196
+ searchTextBox.on("keyup", function(e) {
197
+ word = searchTextBox.value();
198
+
199
+ if (word.length > afterAmountCharacters) {
200
+ inline = true;
201
+ } else if (word.length < afterAmountCharacters) {
202
+ inline = false;
203
+ }
204
+
205
+ if (word.length == afterAmountCharacters &&
206
+ !nonCharacterKeysPattern.test(e.key) &&
207
+ !inline &&
208
+ options.remote) {
209
+ $(e.target).on("keypress", function(e) {
210
+ e.preventDefault();
211
+ });
212
+
213
+ request(e);
214
+ }
215
+
216
+ });
217
+
218
+ searchTextBox.on("paste", function(e) {
219
+ word = searchTextBox.value();
220
+ prevText = word
221
+ .slice(0, searchTextBox.cursorPosition());
222
+ nextText = word
223
+ .slice(searchTextBox.selectionEnd(), word.length);
224
+
225
+ clipboardData = e.clipboardData.getData("text");
226
+
227
+ if (word.length >= afterAmountCharacters) {
228
+ inline = true;
229
+ } else {
230
+ inline = false;
231
+ }
232
+
233
+ word = prevText + clipboardData + nextText;
234
+
235
+ if (word.length >= afterAmountCharacters &&
236
+ !inline &&
237
+ options.remote) {
238
+ searchTextBox.value(word);
239
+
240
+ request(e);
241
+ e.preventDefault();
242
+ }
243
+ });
244
+
245
+ },
246
+
247
+ mapIf = function(searchTextAsArray, textNodeAsArray) {
248
+ var
249
+ iterator,
250
+ sliceIndex,
251
+ regexp,
252
+ textNodeHashSet = Object
253
+ .asCountableLiteral(textNodeAsArray),
254
+ mapped = {},
255
+ amount = 0,
256
+ index = 0,
257
+ previousIndex = -1,
258
+
259
+ callback = function(slice) {
260
+ slice = slice.trim();
261
+ index = Object.firstFromASlice(textNodeHashSet,
262
+ slice, index,
263
+ options
264
+ .caseSensitive);
265
+
266
+ if (index && ((options.orderlySearch &&
267
+ index > previousIndex) ||
268
+ !options.orderlySearch) &&
269
+ textNodeAsArray.countSlice(slice,
270
+ options.caseSensitive) >=
271
+ searchTextAsArray.amount(slice)) {
272
+
273
+ previousIndex = index;
274
+
275
+ if (options.caseSensitive) {
276
+ regexp = new RegExp(slice);
277
+ } else {
278
+ regexp = new RegExp(slice, "i");
279
+ }
280
+
281
+ sliceIndex = textNodeAsArray[index]
282
+ .search(regexp);
283
+ mapped[index] = textNodeAsArray[index]
284
+ .slice(sliceIndex, sliceIndex + slice
285
+ .length);
286
+ Object.delete(index, textNodeHashSet);
287
+ amount += 1;
288
+ } else {
289
+ this.finalize();
290
+ }
291
+ };
292
+
293
+ if (textNodeHashSet.length >= searchTextAsArray.length) {
294
+ iterator = Iterable.Proxy.new(searchTextAsArray);
295
+ iterator.each(callback);
296
+
297
+ if (amount == searchTextAsArray.length) {
298
+ return mapped;
299
+ }
300
+ }
301
+
302
+ return false;
303
+ },
304
+
305
+ // resolveList = function(list, order = "desc") {
306
+ resolveList = function(list, order) {
307
+ if (order != "asc") {order = "desc";}
308
+ var
309
+ textNode,
310
+ mapped,
311
+ textNodeAsArray,
312
+ sorted,
313
+ found = {elements: $(), maps: []},
314
+ textBoxContentArr = searchTextBox.value().split(" ")
315
+ .compact(),
316
+
317
+ callback = function(element) {
318
+ textNode = $(element).textContent().trim();
319
+ textNodeAsArray = textNode.split(" ");
320
+ mapped = mapIf(textBoxContentArr, textNodeAsArray);
321
+ if (mapped) {
322
+ found.elements.push(element);
323
+ found.maps.push(mapped);
324
+ }
325
+ };
326
+
327
+ if (list.elements().amount() == 1 &&
328
+ list.isA(window.Element)) {
329
+ list = list.childElements().clone(true);
330
+ }
331
+
332
+ if (order == "desc") {
333
+ sorted = list.orderTextNodeByDesc();
334
+ } else {
335
+ sorted = list.orderTextNodeByAsc();
336
+ }
337
+
338
+ sorted.each(callback);
339
+
340
+ return found;
341
+ };
342
+
343
+ resolveArguments(options);
344
+
345
+ // init
346
+ if (!Object.belongToClass(elementsList, Object)) {
347
+ inlineSearch(elementsList, options);
348
+ } else {
349
+ options = elementsList;
350
+ remoteSearch(options);
351
+ }
352
+ }
353
+
354
+ });
355
+
356
+ })(esPhinx);
@@ -0,0 +1,66 @@
1
+ var
2
+ esPhinx,
3
+ window;
4
+
5
+ (function($) {
6
+ "use strict";
7
+
8
+ var init = function() {
9
+
10
+ var
11
+ nav = window.navigator.userAgent,
12
+ out = {};
13
+
14
+ if (/OPR\//gi.test(nav)) {
15
+ out.name = "Opera";
16
+ out.codeName = null;
17
+ out.fullVersion = nav.match(/OPR\/[0-9]+[\.\[0-9]+\]*/)
18
+ .toString().match(/[0-9]+[\.\[0-9]+\]*/).toString();
19
+ } else if (/Opera\//gi.test(nav)) {
20
+ out.name = "Opera";
21
+ out.codeName = null;
22
+ out.fullVersion = nav.match(/Version\/[0-9]+[\.\[0-9]+\]*/)
23
+ .toString().match(/[0-9]+[\.\[0-9]+\]*/).toString();
24
+ } else if (/(Firefox\/[0-9]+[\.\[0-9]+\]*)$/gi.test(nav)) {
25
+ out.name = "Firefox";
26
+ out.codeName = "FF";
27
+ out.fullVersion = nav.match(/[Firefox\/\[0-9]+[\.\[0-9]+\]*$/gi)
28
+ .toString().match("[0-9]+[\\.[0-9]+]*").toString();
29
+ } else if (/Chrome\/[0-9]+[\.\[0-9]+\]*/gi.test(nav)) {
30
+ out.name = "Google Chrome";
31
+ out.codeName = "GC";
32
+ out.fullVersion = nav.match(/Chrome\/[0-9]+[\.\[0-9]+\]*/)
33
+ .toString().match(/[0-9]+[\.\[0-9]+\]*/).toString();
34
+ } else if (/MSIE\//gi.test(nav)) {
35
+ out.name = "Internet Explorer";
36
+ out.codeName = "IE";
37
+ out.fullVersion = nav.match(/MSIE [0-9]+[\.\[0-9]+\]*/)
38
+ .toString().match(/[0-9]+[\.\[0-9]+\]*/).toString();
39
+ } else if (/\.NET\//gi.test(nav)) {
40
+ out.name = "Internet Explorer";
41
+ out.codeName = "IE";
42
+ } else if (/Safari\//gi.test(nav) && /Version\//gi.test(nav)) {
43
+ out.name = "Safari";
44
+ }
45
+
46
+ return out;
47
+ };
48
+
49
+ $.extend(true, {
50
+ Browser: {
51
+ fullVersion: function() {
52
+ return init().fullVersion;
53
+ },
54
+
55
+ name: function() {
56
+ return init().name;
57
+ },
58
+
59
+ codeName: function() {
60
+ return init().codeName;
61
+ }
62
+ }
63
+
64
+ });
65
+
66
+ })(esPhinx);
@@ -0,0 +1,167 @@
1
+ var
2
+ esPhinx;
3
+
4
+
5
+ (function($) {
6
+ "use strict";
7
+
8
+ $.extend({
9
+ Cookie: {}
10
+ });
11
+
12
+ $.Extender.extend($.Cookie, true, {
13
+
14
+ set: function(key, value, options) {
15
+ var
16
+ expiresAt,
17
+
18
+ getResolvedOptions = function(options) {
19
+ var
20
+ duration;
21
+
22
+ if (!options || !Object.belongToClass(options, Object)) {
23
+ options = {};
24
+ }
25
+
26
+ // duration
27
+ if (!options.duration ||
28
+ Object.belongToClass(options.duration, Object)) {
29
+ options.duration = {};
30
+ }
31
+
32
+ duration = options.duration;
33
+
34
+ if (!duration.seconds) {
35
+ duration.seconds = 0;
36
+ }
37
+
38
+ if (!duration.minutes) {
39
+ duration.minutes = 0;
40
+ }
41
+
42
+ if (!duration.hours) {
43
+ duration.hours = 0;
44
+ }
45
+
46
+ if (!duration.days) {
47
+ duration.days = 0;
48
+ }
49
+
50
+ if (!duration.months) {
51
+ duration.months = 0;
52
+ }
53
+
54
+ if (!duration.years) {
55
+ duration.years = 0;
56
+ }
57
+
58
+ // path
59
+ if (!options.path) {
60
+ options.path = "/";
61
+ }
62
+
63
+ // max-age
64
+ if (!options.maxAge) {
65
+ if (duration.seconds) {
66
+ options.maxAge = duration.seconds;
67
+ } else if (duration.minutes) {
68
+ options.maxAge = duration.minutes * 60;
69
+ } else if (duration.hours) {
70
+ options.maxAge = optdurationons.hours * 60 * 60;
71
+ } else if (duration.days) {
72
+ options.maxAge = duration.days * 24 * 60 * 60;
73
+ }
74
+ }
75
+
76
+ if (typeof options.secure != "boolean") {
77
+ options.secure = false;
78
+ }
79
+
80
+ return options;
81
+ },
82
+
83
+ getDuration = function(durationOptions) {
84
+ var
85
+ date = new Date();
86
+
87
+ date.setSeconds(date.getSeconds() +
88
+ durationOptions.seconds);
89
+ date.setMinutes(date.getMinutes() +
90
+ durationOptions.minutes);
91
+ date.setHours(date.getHours() + durationOptions.hours);
92
+ date.setDate(date.getDate() + durationOptions.days);
93
+ date.setMonth(date.getMonth() + durationOptions.months);
94
+ date.setFullYear(date.getFullYear() +
95
+ durationOptions.years);
96
+
97
+ return date.toString();
98
+ },
99
+
100
+ getCompost = function(options) {
101
+ var
102
+ compost = "";
103
+
104
+ compost += key + "=" + value +
105
+ ";path=" + options.path;
106
+
107
+ if (options.domain) {
108
+ // test woth document.location.host
109
+ compost += ";domain=" + options.domain;
110
+ }
111
+
112
+ if (options.maxAge) {
113
+ compost += ";max-age=" + options.maxAge;
114
+ }
115
+
116
+ if (options.expires) {
117
+ expiresAt = getDuration(options.duration);
118
+ compost += ";expires=" + expiresAt;
119
+ }
120
+
121
+ if (options.secure) {
122
+ compost += ";secure";
123
+ }
124
+
125
+ return compost;
126
+ };
127
+
128
+ options = getResolvedOptions(options);
129
+
130
+ document.cookie = getCompost(options);
131
+
132
+ return this;
133
+ },
134
+
135
+ get: function(key) {
136
+ var
137
+ collection,
138
+ length,
139
+ pattern = new RegExp("(?:;*)" + key + "=([^;]*)", "g");
140
+
141
+ if (document.cookie) {
142
+ collection = pattern.exec(document.cookie);
143
+ length = collection.length;
144
+
145
+ if (length) {
146
+ return collection[1];
147
+ }
148
+ }
149
+
150
+ return "";
151
+ },
152
+
153
+ reset: function(key, durationOptions) {
154
+
155
+ },
156
+
157
+ delete: function(key) {
158
+
159
+ },
160
+
161
+ restart: function(key) {
162
+
163
+ }
164
+
165
+ });
166
+
167
+ }(esPhinx));