algoliasearch-rails 1.1.8 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: afae0699f5d2896166af630b192195d06a257e25
4
- data.tar.gz: 0f4424fe70d89538c30fb951b816f68e0263826f
3
+ metadata.gz: e861f8af6b6f733a8683d965250821966fee0c1a
4
+ data.tar.gz: 22c2fd2805cc3491614c531486259087261ee27e
5
5
  SHA512:
6
- metadata.gz: 219fa0a2ed1f52b76de052c60f827651c380b1259d13d863df5476915033afef1d26eee49655d09b78a53bdbcd8566151d764a870c04e7bab23b502e2ca148b5
7
- data.tar.gz: 59f48f606327aaf035353456efc05bed35a1be5eed4f7bd035abf8b8793608e640256513da06548fb640c135a38a96e11453f7f6c0a5e6667cf794128ddfb739
6
+ metadata.gz: c32d9099ad97cb11c5528a6513ec6f7fee3d9da5722a2b9c33ff4a3703896b29c60dd5058df047398365308ffe0060a5bbf7982922cbc6650661c6130c7924a2
7
+ data.tar.gz: f663ccb499505f61c5fe37d84a22663fd42bdf5d2db3235640fe6e810133029de698579bd6fdca2481ec147829f99087fbf55d4b14f8e0f999f13b4f35530404
data/README.md CHANGED
@@ -16,6 +16,7 @@ Table of Content
16
16
  1. [Options](#options)
17
17
  1. [Indexing](#indexing)
18
18
  1. [Search settings](#search-settings)
19
+ 1. [Typeahead UI](#typeahead-ui)
19
20
  1. [Note on testing](#note-on-testing)
20
21
 
21
22
  Install
@@ -176,6 +177,41 @@ end
176
177
  p Contact.search("jon doe", hitsPerPage: 5, page: 2)
177
178
  ```
178
179
 
180
+ Typeahead UI
181
+ -------------
182
+
183
+ Require ```algolia/algoliasearch.min``` (see [algoliasearch-client-js](https://github.com/algolia/algoliasearch-client-js)) and ```algolia/typeahead.js``` (a modified version of typeahead.js with custom transports, see the [pull request](https://github.com/twitter/typeahead.js/pull/473)) somewhere in your JavaScript manifest, for example in application.js if you are using Rails 3.1+:
184
+
185
+ ```javascript
186
+ //= require algolia/algoliasearch.min
187
+ //= require algolia/typeahead.min
188
+ ```
189
+
190
+ We recommend the usage of [hogan](http://twitter.github.io/hogan.js/), a JavaScript templating engine from Twitter.
191
+
192
+ ```javascript
193
+ //= require hogan
194
+ ```
195
+
196
+ Turns any ```input[type="text"]``` element into a typeahead, for example:
197
+
198
+ ```javascript
199
+ <input name="email" placeholder="test@example.org" id="user_email" />
200
+ <script type="text/javascript">
201
+ $(document).ready(function() {
202
+ var client = new AlgoliaSearch('YourApplicationID', 'ReadOnlyApplicationKey');
203
+ $('input#user_email').typeahead({
204
+ name: 'emails',
205
+ remote: client.initIndex('YourIndex').getTypeaheadTransport(),
206
+ engine: Hogan,
207
+ template: '{{{_highlightResult.email.value}}} ({{{_highlightResult.first_name.value}}} {{{_highlightResult.last_name.value}}})',
208
+ valueKey: 'email'
209
+ });
210
+ });
211
+ </script>
212
+ ```
213
+
214
+
179
215
  Note on testing
180
216
  -----------------
181
217
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.8
1
+ 1.2.0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "algoliasearch-rails"
8
- s.version = "1.1.8"
8
+ s.version = "1.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Algolia"]
12
- s.date = "2013-10-04"
12
+ s.date = "2013-10-14"
13
13
  s.description = "AlgoliaSearch integration to your favorite ORM"
14
14
  s.email = "contact@algolia.com"
15
15
  s.extra_rdoc_files = [
@@ -36,7 +36,10 @@ Gem::Specification.new do |s|
36
36
  "lib/algoliasearch/tasks/algoliasearch.rake",
37
37
  "lib/algoliasearch/utilities.rb",
38
38
  "spec/spec_helper.rb",
39
- "spec/utilities_spec.rb"
39
+ "spec/utilities_spec.rb",
40
+ "vendor/assets/javascripts/algolia/algoliasearch.js",
41
+ "vendor/assets/javascripts/algolia/algoliasearch.min.js",
42
+ "vendor/assets/javascripts/algolia/typeahead.min.js"
40
43
  ]
41
44
  s.homepage = "http://github.com/algolia/algoliasearch-rails"
42
45
  s.licenses = ["MIT"]
@@ -45,8 +45,8 @@ module AlgoliaSearch
45
45
  class IndexOptions
46
46
 
47
47
  # AlgoliaSearch settings
48
- OPTIONS = [:attributesToIndex, :minWordSizeForApprox1,
49
- :minWordSizeForApprox2, :hitsPerPage, :attributesToRetrieve,
48
+ OPTIONS = [:attributesToIndex, :minWordSizefor1Typo,
49
+ :minWordSizefor2Typos, :hitsPerPage, :attributesToRetrieve,
50
50
  :attributesToHighlight, :attributesToSnippet, :attributesToIndex,
51
51
  :ranking, :customRanking, :queryType]
52
52
  OPTIONS.each do |k|
@@ -6,4 +6,6 @@ module AlgoliaSearch
6
6
  load "algoliasearch/tasks/algoliasearch.rake"
7
7
  end
8
8
  end
9
+ class Engine < Rails::Engine
10
+ end
9
11
  end
@@ -0,0 +1,544 @@
1
+ /*!
2
+ * algoliasearch 2.0.1
3
+ * https://github.com/algolia/algoliasearch-client-js
4
+ * Copyright 2013 Algolia SAS; Licensed MIT
5
+ */
6
+
7
+ var VERSION = "2.0.1";
8
+
9
+ var AlgoliaSearch = function(applicationID, apiKey, method, resolveDNS, hostsArray) {
10
+ this.applicationID = applicationID;
11
+ this.apiKey = apiKey;
12
+ if (this._isUndefined(hostsArray)) {
13
+ hostsArray = [ applicationID + "-1.algolia.io", applicationID + "-2.algolia.io", applicationID + "-3.algolia.io" ];
14
+ }
15
+ this.hosts = [];
16
+ for (var i = 0; i < hostsArray.length; ++i) {
17
+ if (Math.random() > .5) {
18
+ this.hosts.reverse();
19
+ }
20
+ if (!this._isUndefined(method) && (method === "https" || method === "HTTPS")) {
21
+ this.hosts.push("https://" + hostsArray[i]);
22
+ } else {
23
+ this.hosts.push("http://" + hostsArray[i]);
24
+ }
25
+ }
26
+ if (Math.random() > .5) {
27
+ this.hosts.reverse();
28
+ }
29
+ if (this._isUndefined(resolveDNS) || resolveDNS) {
30
+ this._jsonRequest({
31
+ method: "GET",
32
+ url: "/1/isalive"
33
+ });
34
+ }
35
+ };
36
+
37
+ AlgoliaSearch.prototype = {
38
+ deleteIndex: function(indexName, callback) {
39
+ this._jsonRequest({
40
+ method: "DELETE",
41
+ url: "/1/indexes/" + encodeURIComponent(indexName),
42
+ callback: callback
43
+ });
44
+ },
45
+ moveIndex: function(srcIndexName, dstIndexName, callback) {
46
+ var postObj = {
47
+ operation: "move",
48
+ destination: dstIndexName
49
+ };
50
+ this._jsonRequest({
51
+ method: "POST",
52
+ url: "/1/indexes/" + encodeURIComponent(indexName) + "/operation",
53
+ body: postObj,
54
+ callback: callback
55
+ });
56
+ },
57
+ copyIndex: function(srcIndexName, dstIndexName, callback) {
58
+ var postObj = {
59
+ operation: "copy",
60
+ destination: dstIndexName
61
+ };
62
+ this._jsonRequest({
63
+ method: "POST",
64
+ url: "/1/indexes/" + encodeURIComponent(indexName) + "/operation",
65
+ body: postObj,
66
+ callback: callback
67
+ });
68
+ },
69
+ getLogs: function(callback, offset, length) {
70
+ if (this._isUndefined(offset)) {
71
+ offset = 0;
72
+ }
73
+ if (this._isUndefined(length)) {
74
+ length = 10;
75
+ }
76
+ this._jsonRequest({
77
+ method: "GET",
78
+ url: "/1/logs?offset=" + offset + "&length=" + length,
79
+ callback: callback
80
+ });
81
+ },
82
+ listIndexes: function(callback) {
83
+ this._jsonRequest({
84
+ method: "GET",
85
+ url: "/1/indexes/",
86
+ callback: callback
87
+ });
88
+ },
89
+ initIndex: function(indexName) {
90
+ return new this.Index(this, indexName);
91
+ },
92
+ listUserKeys: function(callback) {
93
+ this._jsonRequest({
94
+ method: "GET",
95
+ url: "/1/keys",
96
+ callback: callback
97
+ });
98
+ },
99
+ getUserKeyACL: function(key, callback) {
100
+ this._jsonRequest({
101
+ method: "GET",
102
+ url: "/1/keys/" + key,
103
+ callback: callback
104
+ });
105
+ },
106
+ deleteUserKey: function(key, callback) {
107
+ this._jsonRequest({
108
+ method: "DELETE",
109
+ url: "/1/keys/" + key,
110
+ callback: callback
111
+ });
112
+ },
113
+ addUserKey: function(acls, callback) {
114
+ var aclsObject = {};
115
+ aclsObject.acl = acls;
116
+ this._jsonRequest({
117
+ method: "POST",
118
+ url: "/1/keys",
119
+ body: aclsObject,
120
+ callback: callback
121
+ });
122
+ },
123
+ addUserKeyWithValidity: function(acls, validity, callback) {
124
+ var indexObj = this;
125
+ var aclsObject = {};
126
+ aclsObject.acl = acls;
127
+ this._jsonRequest({
128
+ method: "POST",
129
+ url: "/1/indexes/" + indexObj.indexName + "/keys",
130
+ body: aclsObject,
131
+ callback: callback
132
+ });
133
+ },
134
+ startQueriesBatch: function() {
135
+ this.batch = [];
136
+ },
137
+ addQueryInBatch: function(indexName, query, args) {
138
+ var params = "query=" + query;
139
+ if (!this._isUndefined(args) && args != null) {
140
+ params = this._getSearchParams(args, params);
141
+ }
142
+ this.batch.push({
143
+ indexName: indexName,
144
+ params: params
145
+ });
146
+ },
147
+ clearCache: function() {
148
+ this.cache = {};
149
+ },
150
+ sendQueriesBatch: function(callback, delay) {
151
+ var as = this;
152
+ var params = {
153
+ requests: [],
154
+ apiKey: this.apiKey,
155
+ appID: this.applicationID
156
+ };
157
+ for (var i = 0; i < as.batch.length; ++i) {
158
+ params.requests.push(as.batch[i]);
159
+ }
160
+ window.clearTimeout(as.onDelayTrigger);
161
+ if (!this._isUndefined(delay) && delay != null && delay > 0) {
162
+ var onDelayTrigger = window.setTimeout(function() {
163
+ as._sendQueriesBatch(params, callback);
164
+ }, delay);
165
+ as.onDelayTrigger = onDelayTrigger;
166
+ } else {
167
+ this._sendQueriesBatch(params, callback);
168
+ }
169
+ },
170
+ Index: function(algoliasearch, indexName) {
171
+ this.indexName = indexName;
172
+ this.as = algoliasearch;
173
+ this.typeAheadArgs = null;
174
+ },
175
+ _sendQueriesBatch: function(params, callback) {
176
+ this._jsonRequest({
177
+ cache: this.cache,
178
+ method: "POST",
179
+ url: "/1/indexes/*/queries",
180
+ body: params,
181
+ callback: callback
182
+ });
183
+ },
184
+ _jsonRequest: function(opts) {
185
+ var self = this;
186
+ var callback = opts.callback;
187
+ var cache = null;
188
+ var cacheID = opts.url;
189
+ if (!this._isUndefined(opts.body)) {
190
+ cacheID = opts.url + "_body_" + JSON.stringify(opts.body);
191
+ }
192
+ if (!this._isUndefined(opts.cache)) {
193
+ cache = opts.cache;
194
+ if (!this._isUndefined(cache[cacheID])) {
195
+ if (!this._isUndefined(callback)) {
196
+ callback(true, cache[cacheID]);
197
+ }
198
+ return;
199
+ }
200
+ }
201
+ var impl = function(position) {
202
+ var idx = 0;
203
+ if (!self._isUndefined(position)) {
204
+ idx = position;
205
+ }
206
+ if (self.hosts.length <= idx) {
207
+ if (!self._isUndefined(callback)) {
208
+ callback(false, {
209
+ message: "Cannot contact server"
210
+ });
211
+ }
212
+ return;
213
+ }
214
+ opts.callback = function(retry, success, res, body) {
215
+ if (!success && !self._isUndefined(body)) {
216
+ console.log("Error: " + body.message);
217
+ }
218
+ if (success && !self._isUndefined(opts.cache)) {
219
+ cache[cacheID] = body;
220
+ }
221
+ if (!success && retry && idx + 1 < self.hosts.length) {
222
+ impl(idx + 1);
223
+ } else {
224
+ if (!self._isUndefined(callback)) {
225
+ callback(success, body);
226
+ }
227
+ }
228
+ };
229
+ opts.hostname = self.hosts[idx];
230
+ self._jsonRequestByHost(opts);
231
+ };
232
+ impl();
233
+ },
234
+ _jsonRequestByHost: function(opts) {
235
+ var body = null;
236
+ var self = this;
237
+ if (!this._isUndefined(opts.body)) {
238
+ body = JSON.stringify(opts.body);
239
+ }
240
+ var url = opts.hostname + opts.url;
241
+ var xmlHttp = null;
242
+ xmlHttp = new XMLHttpRequest();
243
+ if ("withCredentials" in xmlHttp) {
244
+ xmlHttp.open(opts.method, url, true);
245
+ xmlHttp.setRequestHeader("X-Algolia-API-Key", this.apiKey);
246
+ xmlHttp.setRequestHeader("X-Algolia-Application-Id", this.applicationID);
247
+ if (body != null) {
248
+ xmlHttp.setRequestHeader("Content-type", "application/json");
249
+ }
250
+ } else if (typeof XDomainRequest != "undefined") {
251
+ xmlHttp = new XDomainRequest();
252
+ xmlHttp.open(opts.method, url);
253
+ } else {
254
+ console.log("your browser is too old to support CORS requests");
255
+ }
256
+ xmlHttp.send(body);
257
+ xmlHttp.onload = function(event) {
258
+ if (!self._isUndefined(event)) {
259
+ var retry = event.target.status === 0 || event.target.status === 503;
260
+ var success = event.target.status === 200 || event.target.status === 201;
261
+ opts.callback(retry, success, event.target, event.target.response != null ? JSON.parse(event.target.response) : null);
262
+ } else {
263
+ opts.callback(false, true, event, JSON.parse(xmlHttp.responseText));
264
+ }
265
+ };
266
+ xmlHttp.onerror = function() {
267
+ opts.callback(true, false, null, {
268
+ message: "Could not connect to Host"
269
+ });
270
+ };
271
+ },
272
+ _getSearchParams: function(args, params) {
273
+ if (this._isUndefined(args) || args == null) {
274
+ return params;
275
+ }
276
+ for (var key in args) {
277
+ if (key != null && args.hasOwnProperty(key)) {
278
+ params += params.length === 0 ? "?" : "&";
279
+ params += key + "=" + encodeURIComponent(args[key]);
280
+ }
281
+ }
282
+ return params;
283
+ },
284
+ _isUndefined: function(obj) {
285
+ return obj === void 0;
286
+ },
287
+ applicationID: null,
288
+ apiKey: null,
289
+ hosts: [],
290
+ cache: {}
291
+ };
292
+
293
+ AlgoliaSearch.prototype.Index.prototype = {
294
+ clearCache: function() {
295
+ this.cache = {};
296
+ },
297
+ addObject: function(content, callback, objectID) {
298
+ var indexObj = this;
299
+ if (this.as._isUndefined(objectID)) {
300
+ this.as._jsonRequest({
301
+ method: "POST",
302
+ url: "/1/indexes/" + encodeURIComponent(indexObj.indexName),
303
+ body: content,
304
+ callback: callback
305
+ });
306
+ } else {
307
+ this.as._jsonRequest({
308
+ method: "PUT",
309
+ url: "/1/indexes/" + encodeURIComponent(indexObj.indexName) + "/" + encodeURIComponent(objectID),
310
+ body: content,
311
+ callback: callback
312
+ });
313
+ }
314
+ },
315
+ addObjects: function(objects, callback) {
316
+ var indexObj = this;
317
+ var postObj = {
318
+ requests: []
319
+ };
320
+ for (var i = 0; i < objects.length; ++i) {
321
+ var request = {
322
+ action: "addObject",
323
+ body: objects[i]
324
+ };
325
+ postObj.requests.push(request);
326
+ }
327
+ this.as._jsonRequest({
328
+ method: "POST",
329
+ url: "/1/indexes/" + encodeURIComponent(indexObj.indexName) + "/batch",
330
+ body: postObj,
331
+ callback: callback
332
+ });
333
+ },
334
+ getObject: function(objectID, callback, attributes) {
335
+ var indexObj = this;
336
+ var params = "";
337
+ if (!this.as._isUndefined(attributes)) {
338
+ params = "?attributes=";
339
+ for (var i = 0; i < attributes.length; ++i) {
340
+ if (i !== 0) {
341
+ params += ",";
342
+ }
343
+ params += attributes[i];
344
+ }
345
+ }
346
+ this.as._jsonRequest({
347
+ method: "GET",
348
+ url: "/1/indexes/" + encodeURIComponent(indexObj.indexName) + "/" + encodeURIComponent(objectID) + params,
349
+ callback: callback
350
+ });
351
+ },
352
+ partialUpdateObject: function(partialObject, callback) {
353
+ var indexObj = this;
354
+ this.as._jsonRequest({
355
+ method: "POST",
356
+ url: "/1/indexes/" + encodeURIComponent(indexObj.indexName) + "/" + encodeURIComponent(partialObject.objectID) + "/partial",
357
+ body: partialObject,
358
+ callback: callback
359
+ });
360
+ },
361
+ saveObject: function(object, callback) {
362
+ var indexObj = this;
363
+ this.as._jsonRequest({
364
+ method: "PUT",
365
+ url: "/1/indexes/" + encodeURIComponent(indexObj.indexName) + "/" + encodeURIComponent(object.objectID),
366
+ body: object,
367
+ callback: callback
368
+ });
369
+ },
370
+ saveObjects: function(objects, callback) {
371
+ var indexObj = this;
372
+ var postObj = {
373
+ requests: []
374
+ };
375
+ for (var i = 0; i < objects.length; ++i) {
376
+ var request = {
377
+ action: "updateObject",
378
+ objectID: encodeURIComponent(objects[i].objectID),
379
+ body: objects[i]
380
+ };
381
+ postObj.requests.push(request);
382
+ }
383
+ this.as._jsonRequest({
384
+ method: "POST",
385
+ url: "/1/indexes/" + encodeURIComponent(indexObj.indexName) + "/batch",
386
+ body: postObj,
387
+ callback: callback
388
+ });
389
+ },
390
+ deleteObject: function(objectID, callback) {
391
+ if (objectID == null || objectID.length === 0) {
392
+ callback(false, {
393
+ message: "empty objectID"
394
+ });
395
+ return;
396
+ }
397
+ var indexObj = this;
398
+ this.as._jsonRequest({
399
+ method: "DELETE",
400
+ url: "/1/indexes/" + encodeURIComponent(indexObj.indexName) + "/" + encodeURIComponent(objectID),
401
+ callback: callback
402
+ });
403
+ },
404
+ search: function(query, callback, args, delay) {
405
+ var indexObj = this;
406
+ var params = "query=" + encodeURIComponent(query);
407
+ if (!this.as._isUndefined(args) && args != null) {
408
+ params = this.as._getSearchParams(args, params);
409
+ }
410
+ window.clearTimeout(indexObj.onDelayTrigger);
411
+ if (!this.as._isUndefined(delay) && delay != null && delay > 0) {
412
+ var onDelayTrigger = window.setTimeout(function() {
413
+ indexObj._search(params, callback);
414
+ }, delay);
415
+ indexObj.onDelayTrigger = onDelayTrigger;
416
+ } else {
417
+ this._search(params, callback);
418
+ }
419
+ },
420
+ getTypeaheadTransport: function(args) {
421
+ this.typeAheadArgs = args;
422
+ return this;
423
+ },
424
+ get: function(query, processRemoteData, that, cb, suggestions) {
425
+ self = this;
426
+ this.search(query, function(success, content) {
427
+ if (success) {
428
+ for (var i = 0; i < content.hits.length; ++i) {
429
+ var obj = content.hits[i];
430
+ var found = false;
431
+ if (typeof obj.value === "undefined") {
432
+ for (var propertyName in obj) {
433
+ if (!found && obj.hasOwnProperty(propertyName) && typeof obj[propertyName] === "string") {
434
+ obj.value = obj[propertyName];
435
+ found = true;
436
+ }
437
+ }
438
+ }
439
+ suggestions.push(that._transformDatum(obj));
440
+ }
441
+ cb && cb(suggestions);
442
+ }
443
+ }, self.typeAheadArgs);
444
+ return true;
445
+ },
446
+ waitTask: function(taskID, callback) {
447
+ var indexObj = this;
448
+ this.as._jsonRequest({
449
+ method: "GET",
450
+ url: "/1/indexes/" + encodeURIComponent(indexObj.indexName) + "/task/" + taskID,
451
+ callback: function(success, body) {
452
+ if (success && body.status === "published") {
453
+ callback(true, body);
454
+ } else if (success && body.pendingTask) {
455
+ return indexObj.waitTask(taskID, callback);
456
+ } else {
457
+ callback(false, body);
458
+ }
459
+ }
460
+ });
461
+ },
462
+ getSettings: function(callback) {
463
+ var indexObj = this;
464
+ this.as._jsonRequest({
465
+ method: "GET",
466
+ url: "/1/indexes/" + encodeURIComponent(indexObj.indexName) + "/settings",
467
+ callback: callback
468
+ });
469
+ },
470
+ setSettings: function(settings, callback) {
471
+ var indexObj = this;
472
+ this.as._jsonRequest({
473
+ method: "PUT",
474
+ url: "/1/indexes/" + encodeURIComponent(indexObj.indexName) + "/settings",
475
+ body: settings,
476
+ callback: callback
477
+ });
478
+ },
479
+ listUserKeys: function(callback) {
480
+ var indexObj = this;
481
+ this.as._jsonRequest({
482
+ method: "GET",
483
+ url: "/1/indexes/" + encodeURIComponent(indexObj.indexName) + "/keys",
484
+ callback: callback
485
+ });
486
+ },
487
+ getUserKeyACL: function(key, callback) {
488
+ var indexObj = this;
489
+ this.as._jsonRequest({
490
+ method: "GET",
491
+ url: "/1/indexes/" + encodeURIComponent(indexObj.indexName) + "/keys/" + key,
492
+ callback: callback
493
+ });
494
+ },
495
+ deleteUserKey: function(key, callback) {
496
+ var indexObj = this;
497
+ this.as._jsonRequest({
498
+ method: "DELETE",
499
+ url: "/1/indexes/" + encodeURIComponent(indexObj.indexName) + "/keys/" + key,
500
+ callback: callback
501
+ });
502
+ },
503
+ addUserKey: function(acls, callback) {
504
+ var indexObj = this;
505
+ var aclsObject = {};
506
+ aclsObject.acl = acls;
507
+ this.as._jsonRequest({
508
+ method: "POST",
509
+ url: "/1/indexes/" + encodeURIComponent(indexObj.indexName) + "/keys",
510
+ body: aclsObject,
511
+ callback: callback
512
+ });
513
+ },
514
+ addUserKeyWithValidity: function(acls, validity, callback) {
515
+ var indexObj = this;
516
+ var aclsObject = {};
517
+ aclsObject.acl = acls;
518
+ aclsObject.validity = validity;
519
+ this.as._jsonRequest({
520
+ method: "POST",
521
+ url: "/1/indexes/" + encodeURIComponent(indexObj.indexName) + "/keys",
522
+ body: aclsObject,
523
+ callback: callback
524
+ });
525
+ },
526
+ _search: function(params, callback) {
527
+ this.as._jsonRequest({
528
+ cache: this.cache,
529
+ method: "POST",
530
+ url: "/1/indexes/" + encodeURIComponent(this.indexName) + "/query",
531
+ body: {
532
+ params: params,
533
+ apiKey: this.as.apiKey,
534
+ appID: this.as.applicationID
535
+ },
536
+ callback: callback
537
+ });
538
+ },
539
+ as: null,
540
+ indexName: null,
541
+ cache: {},
542
+ typeAheadArgs: null,
543
+ emptyConstructor: function() {}
544
+ };
@@ -0,0 +1,7 @@
1
+ /*!
2
+ * algoliasearch 2.0.1
3
+ * https://github.com/algolia/algoliasearch-client-js
4
+ * Copyright 2013 Algolia SAS; Licensed MIT
5
+ */
6
+
7
+ var VERSION="2.0.1",AlgoliaSearch=function(a,b,c,d,e){this.applicationID=a,this.apiKey=b,this._isUndefined(e)&&(e=[a+"-1.algolia.io",a+"-2.algolia.io",a+"-3.algolia.io"]),this.hosts=[];for(var f=0;f<e.length;++f)Math.random()>.5&&this.hosts.reverse(),this._isUndefined(c)||"https"!==c&&"HTTPS"!==c?this.hosts.push("http://"+e[f]):this.hosts.push("https://"+e[f]);Math.random()>.5&&this.hosts.reverse(),(this._isUndefined(d)||d)&&this._jsonRequest({method:"GET",url:"/1/isalive"})};AlgoliaSearch.prototype={deleteIndex:function(a,b){this._jsonRequest({method:"DELETE",url:"/1/indexes/"+encodeURIComponent(a),callback:b})},moveIndex:function(a,b,c){var d={operation:"move",destination:b};this._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(indexName)+"/operation",body:d,callback:c})},copyIndex:function(a,b,c){var d={operation:"copy",destination:b};this._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(indexName)+"/operation",body:d,callback:c})},getLogs:function(a,b,c){this._isUndefined(b)&&(b=0),this._isUndefined(c)&&(c=10),this._jsonRequest({method:"GET",url:"/1/logs?offset="+b+"&length="+c,callback:a})},listIndexes:function(a){this._jsonRequest({method:"GET",url:"/1/indexes/",callback:a})},initIndex:function(a){return new this.Index(this,a)},listUserKeys:function(a){this._jsonRequest({method:"GET",url:"/1/keys",callback:a})},getUserKeyACL:function(a,b){this._jsonRequest({method:"GET",url:"/1/keys/"+a,callback:b})},deleteUserKey:function(a,b){this._jsonRequest({method:"DELETE",url:"/1/keys/"+a,callback:b})},addUserKey:function(a,b){var c={};c.acl=a,this._jsonRequest({method:"POST",url:"/1/keys",body:c,callback:b})},addUserKeyWithValidity:function(a,b,c){var d=this,e={};e.acl=a,this._jsonRequest({method:"POST",url:"/1/indexes/"+d.indexName+"/keys",body:e,callback:c})},startQueriesBatch:function(){this.batch=[]},addQueryInBatch:function(a,b,c){var d="query="+b;this._isUndefined(c)||null==c||(d=this._getSearchParams(c,d)),this.batch.push({indexName:a,params:d})},clearCache:function(){this.cache={}},sendQueriesBatch:function(a,b){for(var c=this,d={requests:[],apiKey:this.apiKey,appID:this.applicationID},e=0;e<c.batch.length;++e)d.requests.push(c.batch[e]);if(window.clearTimeout(c.onDelayTrigger),!this._isUndefined(b)&&null!=b&&b>0){var f=window.setTimeout(function(){c._sendQueriesBatch(d,a)},b);c.onDelayTrigger=f}else this._sendQueriesBatch(d,a)},Index:function(a,b){this.indexName=b,this.as=a,this.typeAheadArgs=null},_sendQueriesBatch:function(a,b){this._jsonRequest({cache:this.cache,method:"POST",url:"/1/indexes/*/queries",body:a,callback:b})},_jsonRequest:function(a){var b=this,c=a.callback,d=null,e=a.url;if(this._isUndefined(a.body)||(e=a.url+"_body_"+JSON.stringify(a.body)),!this._isUndefined(a.cache)&&(d=a.cache,!this._isUndefined(d[e])))return this._isUndefined(c)||c(!0,d[e]),void 0;var f=function(g){var h=0;return b._isUndefined(g)||(h=g),b.hosts.length<=h?(b._isUndefined(c)||c(!1,{message:"Cannot contact server"}),void 0):(a.callback=function(g,i,j,k){i||b._isUndefined(k)||console.log("Error: "+k.message),i&&!b._isUndefined(a.cache)&&(d[e]=k),!i&&g&&h+1<b.hosts.length?f(h+1):b._isUndefined(c)||c(i,k)},a.hostname=b.hosts[h],b._jsonRequestByHost(a),void 0)};f()},_jsonRequestByHost:function(a){var b=null,c=this;this._isUndefined(a.body)||(b=JSON.stringify(a.body));var d=a.hostname+a.url,e=null;e=new XMLHttpRequest,"withCredentials"in e?(e.open(a.method,d,!0),e.setRequestHeader("X-Algolia-API-Key",this.apiKey),e.setRequestHeader("X-Algolia-Application-Id",this.applicationID),null!=b&&e.setRequestHeader("Content-type","application/json")):"undefined"!=typeof XDomainRequest?(e=new XDomainRequest,e.open(a.method,d)):console.log("your browser is too old to support CORS requests"),e.send(b),e.onload=function(b){if(c._isUndefined(b))a.callback(!1,!0,b,JSON.parse(e.responseText));else{var d=0===b.target.status||503===b.target.status,f=200===b.target.status||201===b.target.status;a.callback(d,f,b.target,null!=b.target.response?JSON.parse(b.target.response):null)}},e.onerror=function(){a.callback(!0,!1,null,{message:"Could not connect to Host"})}},_getSearchParams:function(a,b){if(this._isUndefined(a)||null==a)return b;for(var c in a)null!=c&&a.hasOwnProperty(c)&&(b+=0===b.length?"?":"&",b+=c+"="+encodeURIComponent(a[c]));return b},_isUndefined:function(a){return void 0===a},applicationID:null,apiKey:null,hosts:[],cache:{}},AlgoliaSearch.prototype.Index.prototype={clearCache:function(){this.cache={}},addObject:function(a,b,c){var d=this;this.as._isUndefined(c)?this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(d.indexName),body:a,callback:b}):this.as._jsonRequest({method:"PUT",url:"/1/indexes/"+encodeURIComponent(d.indexName)+"/"+encodeURIComponent(c),body:a,callback:b})},addObjects:function(a,b){for(var c=this,d={requests:[]},e=0;e<a.length;++e){var f={action:"addObject",body:a[e]};d.requests.push(f)}this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/batch",body:d,callback:b})},getObject:function(a,b,c){var d=this,e="";if(!this.as._isUndefined(c)){e="?attributes=";for(var f=0;f<c.length;++f)0!==f&&(e+=","),e+=c[f]}this.as._jsonRequest({method:"GET",url:"/1/indexes/"+encodeURIComponent(d.indexName)+"/"+encodeURIComponent(a)+e,callback:b})},partialUpdateObject:function(a,b){var c=this;this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/"+encodeURIComponent(a.objectID)+"/partial",body:a,callback:b})},saveObject:function(a,b){var c=this;this.as._jsonRequest({method:"PUT",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/"+encodeURIComponent(a.objectID),body:a,callback:b})},saveObjects:function(a,b){for(var c=this,d={requests:[]},e=0;e<a.length;++e){var f={action:"updateObject",objectID:encodeURIComponent(a[e].objectID),body:a[e]};d.requests.push(f)}this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/batch",body:d,callback:b})},deleteObject:function(a,b){if(null==a||0===a.length)return b(!1,{message:"empty objectID"}),void 0;var c=this;this.as._jsonRequest({method:"DELETE",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/"+encodeURIComponent(a),callback:b})},search:function(a,b,c,d){var e=this,f="query="+encodeURIComponent(a);if(this.as._isUndefined(c)||null==c||(f=this.as._getSearchParams(c,f)),window.clearTimeout(e.onDelayTrigger),!this.as._isUndefined(d)&&null!=d&&d>0){var g=window.setTimeout(function(){e._search(f,b)},d);e.onDelayTrigger=g}else this._search(f,b)},getTypeaheadTransport:function(a){return this.typeAheadArgs=a,this},get:function(a,b,c,d,e){return self=this,this.search(a,function(a,b){if(a){for(var f=0;f<b.hits.length;++f){var g=b.hits[f],h=!1;if("undefined"==typeof g.value)for(var i in g)!h&&g.hasOwnProperty(i)&&"string"==typeof g[i]&&(g.value=g[i],h=!0);e.push(c._transformDatum(g))}d&&d(e)}},self.typeAheadArgs),!0},waitTask:function(a,b){var c=this;this.as._jsonRequest({method:"GET",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/task/"+a,callback:function(d,e){if(d&&"published"===e.status)b(!0,e);else{if(d&&e.pendingTask)return c.waitTask(a,b);b(!1,e)}}})},getSettings:function(a){var b=this;this.as._jsonRequest({method:"GET",url:"/1/indexes/"+encodeURIComponent(b.indexName)+"/settings",callback:a})},setSettings:function(a,b){var c=this;this.as._jsonRequest({method:"PUT",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/settings",body:a,callback:b})},listUserKeys:function(a){var b=this;this.as._jsonRequest({method:"GET",url:"/1/indexes/"+encodeURIComponent(b.indexName)+"/keys",callback:a})},getUserKeyACL:function(a,b){var c=this;this.as._jsonRequest({method:"GET",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/keys/"+a,callback:b})},deleteUserKey:function(a,b){var c=this;this.as._jsonRequest({method:"DELETE",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/keys/"+a,callback:b})},addUserKey:function(a,b){var c=this,d={};d.acl=a,this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/keys",body:d,callback:b})},addUserKeyWithValidity:function(a,b,c){var d=this,e={};e.acl=a,e.validity=b,this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(d.indexName)+"/keys",body:e,callback:c})},_search:function(a,b){this.as._jsonRequest({cache:this.cache,method:"POST",url:"/1/indexes/"+encodeURIComponent(this.indexName)+"/query",body:{params:a,apiKey:this.as.apiKey,appID:this.as.applicationID},callback:b})},as:null,indexName:null,cache:{},typeAheadArgs:null,emptyConstructor:function(){}};
@@ -0,0 +1,7 @@
1
+ /*!
2
+ * typeahead.js 0.9.3
3
+ * https://github.com/twitter/typeahead
4
+ * Copyright 2013 Twitter, Inc. and other contributors; Licensed MIT
5
+ */
6
+
7
+ !function(a){var b="0.9.3",c={isMsie:function(){var a=/(msie) ([\w.]+)/i.exec(navigator.userAgent);return a?parseInt(a[2],10):!1},isBlankString:function(a){return!a||/^\s*$/.test(a)},escapeRegExChars:function(a){return a.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")},isString:function(a){return"string"==typeof a},isNumber:function(a){return"number"==typeof a},isArray:a.isArray,isFunction:a.isFunction,isObject:a.isPlainObject,isUndefined:function(a){return"undefined"==typeof a},bind:a.proxy,bindAll:function(b){var c;for(var d in b)a.isFunction(c=b[d])&&(b[d]=a.proxy(c,b))},indexOf:function(a,b){for(var c=0;c<a.length;c++)if(a[c]===b)return c;return-1},each:a.each,map:a.map,filter:a.grep,every:function(b,c){var d=!0;return b?(a.each(b,function(a,e){return(d=c.call(null,e,a,b))?void 0:!1}),!!d):d},some:function(b,c){var d=!1;return b?(a.each(b,function(a,e){return(d=c.call(null,e,a,b))?!1:void 0}),!!d):d},mixin:a.extend,getUniqueId:function(){var a=0;return function(){return a++}}(),defer:function(a){setTimeout(a,0)},debounce:function(a,b,c){var d,e;return function(){var f,g,h=this,i=arguments;return f=function(){d=null,c||(e=a.apply(h,i))},g=c&&!d,clearTimeout(d),d=setTimeout(f,b),g&&(e=a.apply(h,i)),e}},throttle:function(a,b){var c,d,e,f,g,h;return g=0,h=function(){g=new Date,e=null,f=a.apply(c,d)},function(){var i=new Date,j=b-(i-g);return c=this,d=arguments,0>=j?(clearTimeout(e),e=null,g=i,f=a.apply(c,d)):e||(e=setTimeout(h,j)),f}},tokenizeQuery:function(b){return a.trim(b).toLowerCase().split(/[\s]+/)},tokenizeText:function(b){return a.trim(b).toLowerCase().split(/[\s\-_]+/)},getProtocol:function(){return location.protocol},noop:function(){}},d=function(){var a=/\s+/;return{on:function(b,c){var d;if(!c)return this;for(this._callbacks=this._callbacks||{},b=b.split(a);d=b.shift();)this._callbacks[d]=this._callbacks[d]||[],this._callbacks[d].push(c);return this},trigger:function(b,c){var d,e;if(!this._callbacks)return this;for(b=b.split(a);d=b.shift();)if(e=this._callbacks[d])for(var f=0;f<e.length;f+=1)e[f].call(this,{type:d,data:c});return this}}}(),e=function(){function b(b){b&&b.el||a.error("EventBus initialized without el"),this.$el=a(b.el)}var d="typeahead:";return c.mixin(b.prototype,{trigger:function(a){var b=[].slice.call(arguments,1);this.$el.trigger(d+a,b)}}),b}(),f=function(){function a(a){this.prefix=["__",a,"__"].join(""),this.ttlKey="__ttl__",this.keyMatcher=new RegExp("^"+this.prefix)}function b(){return(new Date).getTime()}function d(a){return JSON.stringify(c.isUndefined(a)?null:a)}function e(a){return JSON.parse(a)}var f,g;try{f=window.localStorage,f.setItem("~~~","!"),f.removeItem("~~~")}catch(h){f=null}return g=f&&window.JSON?{_prefix:function(a){return this.prefix+a},_ttlKey:function(a){return this._prefix(a)+this.ttlKey},get:function(a){return this.isExpired(a)&&this.remove(a),e(f.getItem(this._prefix(a)))},set:function(a,e,g){return c.isNumber(g)?f.setItem(this._ttlKey(a),d(b()+g)):f.removeItem(this._ttlKey(a)),f.setItem(this._prefix(a),d(e))},remove:function(a){return f.removeItem(this._ttlKey(a)),f.removeItem(this._prefix(a)),this},clear:function(){var a,b,c=[],d=f.length;for(a=0;d>a;a++)(b=f.key(a)).match(this.keyMatcher)&&c.push(b.replace(this.keyMatcher,""));for(a=c.length;a--;)this.remove(c[a]);return this},isExpired:function(a){var d=e(f.getItem(this._ttlKey(a)));return c.isNumber(d)&&b()>d?!0:!1}}:{get:c.noop,set:c.noop,remove:c.noop,clear:c.noop,isExpired:c.noop},c.mixin(a.prototype,g),a}(),g=function(){function a(a){c.bindAll(this),a=a||{},this.sizeLimit=a.sizeLimit||10,this.cache={},this.cachedKeysByAge=[]}return c.mixin(a.prototype,{get:function(a){return this.cache[a]},set:function(a,b){var c;this.cachedKeysByAge.length===this.sizeLimit&&(c=this.cachedKeysByAge.shift(),delete this.cache[c]),this.cache[a]=b,this.cachedKeysByAge.push(a)}}),a}(),h=function(){function b(a){c.bindAll(this),a=c.isString(a)?{url:a}:a,i=i||new g,h=c.isNumber(a.maxParallelRequests)?a.maxParallelRequests:h||6,this.url=a.url,this.wildcard=a.wildcard||"%QUERY",this.filter=a.filter,this.replace=a.replace,this.ajaxSettings={type:"get",cache:a.cache,timeout:a.timeout,dataType:a.dataType||"json",beforeSend:a.beforeSend},this._get=(/^throttle$/i.test(a.rateLimitFn)?c.throttle:c.debounce)(this._get,a.rateLimitWait||300)}function d(){j++}function e(){j--}function f(){return h>j}var h,i,j=0,k={};return c.mixin(b.prototype,{_get:function(a,b){function c(c){var e=d.filter?d.filter(c):c;b&&b(e),i.set(a,c)}var d=this;f()?this._sendRequest(a).done(c):this.onDeckRequestArgs=[].slice.call(arguments,0)},_sendRequest:function(b){function c(){e(),k[b]=null,f.onDeckRequestArgs&&(f._get.apply(f,f.onDeckRequestArgs),f.onDeckRequestArgs=null)}var f=this,g=k[b];return g||(d(),g=k[b]=a.ajax(b,this.ajaxSettings).always(c)),g},get:function(a,b){var d,e,f=this,g=encodeURIComponent(a||"");return b=b||c.noop,d=this.replace?this.replace(this.url,g):this.url.replace(this.wildcard,g),(e=i.get(d))?c.defer(function(){b(f.filter?f.filter(e):e)}):this._get(d,b),!!e}}),b}(),i=function(){function d(b){c.bindAll(this),c.isString(b.template)&&!b.engine&&a.error("no template engine specified"),b.local||b.prefetch||b.remote||a.error("one of local, prefetch, or remote is required"),this.name=b.name||c.getUniqueId(),this.limit=b.limit||5,this.minLength=b.minLength||1,this.header=b.header,this.footer=b.footer,this.valueKey=b.valueKey||"value",this.template=e(b.template,b.engine,this.valueKey),this.local=b.local,this.prefetch=b.prefetch,this.remote=b.remote,this.itemHash={},this.adjacencyList={},this.storage=b.name?new f(b.name):null}function e(a,b,d){var e,f;return c.isFunction(a)?e=a:c.isString(a)?(f=b.compile(a),e=c.bind(f.render,f)):e=function(a){return"<p>"+a[d]+"</p>"},e}var g={thumbprint:"thumbprint",protocol:"protocol",itemHash:"itemHash",adjacencyList:"adjacencyList"};return c.mixin(d.prototype,{_processLocalData:function(a){this._mergeProcessedData(this._processData(a))},_loadPrefetchData:function(d){function e(a){var b=d.filter?d.filter(a):a,e=m._processData(b),f=e.itemHash,h=e.adjacencyList;m.storage&&(m.storage.set(g.itemHash,f,d.ttl),m.storage.set(g.adjacencyList,h,d.ttl),m.storage.set(g.thumbprint,n,d.ttl),m.storage.set(g.protocol,c.getProtocol(),d.ttl)),m._mergeProcessedData(e)}var f,h,i,j,k,l,m=this,n=b+(d.thumbprint||"");return this.storage&&(f=this.storage.get(g.thumbprint),h=this.storage.get(g.protocol),i=this.storage.get(g.itemHash),j=this.storage.get(g.adjacencyList)),k=f!==n||h!==c.getProtocol(),d=c.isString(d)?{url:d}:d,d.ttl=c.isNumber(d.ttl)?d.ttl:864e5,i&&j&&!k?(this._mergeProcessedData({itemHash:i,adjacencyList:j}),l=a.Deferred().resolve()):l=a.getJSON(d.url).done(e),l},_transformDatum:function(a){var b=c.isString(a)?a:a[this.valueKey],d=a.tokens||c.tokenizeText(b),e={value:b,tokens:d};return c.isString(a)?(e.datum={},e.datum[this.valueKey]=a):e.datum=a,e.tokens=c.filter(e.tokens,function(a){return!c.isBlankString(a)}),e.tokens=c.map(e.tokens,function(a){return a.toLowerCase()}),e},_processData:function(a){var b=this,d={},e={};return c.each(a,function(a,f){var g=b._transformDatum(f),h=c.getUniqueId(g.value);d[h]=g,c.each(g.tokens,function(a,b){var d=b.charAt(0),f=e[d]||(e[d]=[h]);!~c.indexOf(f,h)&&f.push(h)})}),{itemHash:d,adjacencyList:e}},_mergeProcessedData:function(a){var b=this;c.mixin(this.itemHash,a.itemHash),c.each(a.adjacencyList,function(a,c){var d=b.adjacencyList[a];b.adjacencyList[a]=d?d.concat(c):c})},_getLocalSuggestions:function(a){var b,d=this,e=[],f=[],g=[];return c.each(a,function(a,b){var d=b.charAt(0);!~c.indexOf(e,d)&&e.push(d)}),c.each(e,function(a,c){var e=d.adjacencyList[c];return e?(f.push(e),(!b||e.length<b.length)&&(b=e),void 0):!1}),f.length<e.length?[]:(c.each(b,function(b,e){var h,i,j=d.itemHash[e];h=c.every(f,function(a){return~c.indexOf(a,e)}),i=h&&c.every(a,function(a){return c.some(j.tokens,function(b){return 0===b.indexOf(a)})}),i&&g.push(j)}),g)},initialize:function(){var b;return this.local&&this._processLocalData(this.local),this.transport="undefined"==typeof this.remote?null:"string"==typeof this.remote?new h(this.remote):this.remote,b=this.prefetch?this._loadPrefetchData(this.prefetch):a.Deferred().resolve(),this.local=this.prefetch=this.remote=null,this.initialize=function(){return b},b},getSuggestions:function(a,b){function d(a){f=f.slice(0),c.each(a,function(a,b){var d,e=g._transformDatum(b);return d=c.some(f,function(a){return e.value===a.value}),!d&&f.push(e),f.length<g.limit}),b&&b(f)}var e,f,g=this,h=!1;a.length<this.minLength||(e=c.tokenizeQuery(a),f=this._getLocalSuggestions(e).slice(0,this.limit),f.length<this.limit&&this.transport&&(h=this.transport.get(a,d,g,b,f)),!h&&b&&b(f))}}),d}(),j=function(){function b(b){var d=this;c.bindAll(this),this.specialKeyCodeMap={9:"tab",27:"esc",37:"left",39:"right",13:"enter",38:"up",40:"down"},this.$hint=a(b.hint),this.$input=a(b.input).on("blur.tt",this._handleBlur).on("focus.tt",this._handleFocus).on("keydown.tt",this._handleSpecialKeyEvent),c.isMsie()?this.$input.on("keydown.tt keypress.tt cut.tt paste.tt",function(a){d.specialKeyCodeMap[a.which||a.keyCode]||c.defer(d._compareQueryToInputValue)}):this.$input.on("input.tt",this._compareQueryToInputValue),this.query=this.$input.val(),this.$overflowHelper=e(this.$input)}function e(b){return a("<span></span>").css({position:"absolute",left:"-9999px",visibility:"hidden",whiteSpace:"nowrap",fontFamily:b.css("font-family"),fontSize:b.css("font-size"),fontStyle:b.css("font-style"),fontVariant:b.css("font-variant"),fontWeight:b.css("font-weight"),wordSpacing:b.css("word-spacing"),letterSpacing:b.css("letter-spacing"),textIndent:b.css("text-indent"),textRendering:b.css("text-rendering"),textTransform:b.css("text-transform")}).insertAfter(b)}function f(a,b){return a=(a||"").replace(/^\s*/g,"").replace(/\s{2,}/g," "),b=(b||"").replace(/^\s*/g,"").replace(/\s{2,}/g," "),a===b}return c.mixin(b.prototype,d,{_handleFocus:function(){this.trigger("focused")},_handleBlur:function(){this.trigger("blured")},_handleSpecialKeyEvent:function(a){var b=this.specialKeyCodeMap[a.which||a.keyCode];b&&this.trigger(b+"Keyed",a)},_compareQueryToInputValue:function(){var a=this.getInputValue(),b=f(this.query,a),c=b?this.query.length!==a.length:!1;c?this.trigger("whitespaceChanged",{value:this.query}):b||this.trigger("queryChanged",{value:this.query=a})},destroy:function(){this.$hint.off(".tt"),this.$input.off(".tt"),this.$hint=this.$input=this.$overflowHelper=null},focus:function(){this.$input.focus()},blur:function(){this.$input.blur()},getQuery:function(){return this.query},setQuery:function(a){this.query=a},getInputValue:function(){return this.$input.val()},setInputValue:function(a,b){this.$input.val(a),!b&&this._compareQueryToInputValue()},getHintValue:function(){return this.$hint.val()},setHintValue:function(a){this.$hint.val(a)},getLanguageDirection:function(){return(this.$input.css("direction")||"ltr").toLowerCase()},isOverflow:function(){return this.$overflowHelper.text(this.getInputValue()),this.$overflowHelper.width()>this.$input.width()},isCursorAtEnd:function(){var a,b=this.$input.val().length,d=this.$input[0].selectionStart;return c.isNumber(d)?d===b:document.selection?(a=document.selection.createRange(),a.moveStart("character",-b),b===a.text.length):!0}}),b}(),k=function(){function b(b){c.bindAll(this),this.isOpen=!1,this.isEmpty=!0,this.isMouseOverDropdown=!1,this.$menu=a(b.menu).on("mouseenter.tt",this._handleMouseenter).on("mouseleave.tt",this._handleMouseleave).on("click.tt",".tt-suggestion",this._handleSelection).on("mouseover.tt",".tt-suggestion",this._handleMouseover)}function e(a){return a.data("suggestion")}var f={suggestionsList:'<span class="tt-suggestions"></span>'},g={suggestionsList:{display:"block"},suggestion:{whiteSpace:"nowrap",cursor:"pointer"},suggestionChild:{whiteSpace:"normal"}};return c.mixin(b.prototype,d,{_handleMouseenter:function(){this.isMouseOverDropdown=!0},_handleMouseleave:function(){this.isMouseOverDropdown=!1},_handleMouseover:function(b){var c=a(b.currentTarget);this._getSuggestions().removeClass("tt-is-under-cursor"),c.addClass("tt-is-under-cursor")},_handleSelection:function(b){var c=a(b.currentTarget);this.trigger("suggestionSelected",e(c))},_show:function(){this.$menu.css("display","block")},_hide:function(){this.$menu.hide()},_moveCursor:function(a){var b,c,d,f;if(this.isVisible()){if(b=this._getSuggestions(),c=b.filter(".tt-is-under-cursor"),c.removeClass("tt-is-under-cursor"),d=b.index(c)+a,d=(d+1)%(b.length+1)-1,-1===d)return this.trigger("cursorRemoved"),void 0;-1>d&&(d=b.length-1),f=b.eq(d).addClass("tt-is-under-cursor"),this._ensureVisibility(f),this.trigger("cursorMoved",e(f))}},_getSuggestions:function(){return this.$menu.find(".tt-suggestions > .tt-suggestion")},_ensureVisibility:function(a){var b=this.$menu.height()+parseInt(this.$menu.css("paddingTop"),10)+parseInt(this.$menu.css("paddingBottom"),10),c=this.$menu.scrollTop(),d=a.position().top,e=d+a.outerHeight(!0);0>d?this.$menu.scrollTop(c+d):e>b&&this.$menu.scrollTop(c+(e-b))},destroy:function(){this.$menu.off(".tt"),this.$menu=null},isVisible:function(){return this.isOpen&&!this.isEmpty},closeUnlessMouseIsOverDropdown:function(){this.isMouseOverDropdown||this.close()},close:function(){this.isOpen&&(this.isOpen=!1,this.isMouseOverDropdown=!1,this._hide(),this.$menu.find(".tt-suggestions > .tt-suggestion").removeClass("tt-is-under-cursor"),this.trigger("closed"))},open:function(){this.isOpen||(this.isOpen=!0,!this.isEmpty&&this._show(),this.trigger("opened"))},setLanguageDirection:function(a){var b={left:"0",right:"auto"},c={left:"auto",right:" 0"};"ltr"===a?this.$menu.css(b):this.$menu.css(c)},moveCursorUp:function(){this._moveCursor(-1)},moveCursorDown:function(){this._moveCursor(1)},getSuggestionUnderCursor:function(){var a=this._getSuggestions().filter(".tt-is-under-cursor").first();return a.length>0?e(a):null},getFirstSuggestion:function(){var a=this._getSuggestions().first();return a.length>0?e(a):null},renderSuggestions:function(b,d){var e,h,i,j,k,l="tt-dataset-"+b.name,m='<div class="tt-suggestion">%body</div>',n=this.$menu.find("."+l);0===n.length&&(h=a(f.suggestionsList).css(g.suggestionsList),n=a("<div></div>").addClass(l).append(b.header).append(h).append(b.footer).appendTo(this.$menu)),d.length>0?(this.isEmpty=!1,this.isOpen&&this._show(),i=document.createElement("div"),j=document.createDocumentFragment(),c.each(d,function(c,d){d.dataset=b.name,e=b.template(d.datum),i.innerHTML=m.replace("%body",e),k=a(i.firstChild).css(g.suggestion).data("suggestion",d),k.children().each(function(){a(this).css(g.suggestionChild)}),j.appendChild(k[0])}),n.show().find(".tt-suggestions").html(j)):this.clearSuggestions(b.name),this.trigger("suggestionsRendered")},clearSuggestions:function(a){var b=a?this.$menu.find(".tt-dataset-"+a):this.$menu.find('[class^="tt-dataset-"]'),c=b.find(".tt-suggestions");b.hide(),c.empty(),0===this._getSuggestions().length&&(this.isEmpty=!0,this._hide())}}),b}(),l=function(){function b(a){var b,d,f;c.bindAll(this),this.$node=e(a.input),this.datasets=a.datasets,this.dir=null,this.eventBus=a.eventBus,b=this.$node.find(".tt-dropdown-menu"),d=this.$node.find(".tt-query"),f=this.$node.find(".tt-hint"),this.dropdownView=new k({menu:b}).on("suggestionSelected",this._handleSelection).on("cursorMoved",this._clearHint).on("cursorMoved",this._setInputValueToSuggestionUnderCursor).on("cursorRemoved",this._setInputValueToQuery).on("cursorRemoved",this._updateHint).on("suggestionsRendered",this._updateHint).on("opened",this._updateHint).on("closed",this._clearHint).on("opened closed",this._propagateEvent),this.inputView=new j({input:d,hint:f}).on("focused",this._openDropdown).on("blured",this._closeDropdown).on("blured",this._setInputValueToQuery).on("enterKeyed tabKeyed",this._handleSelection).on("queryChanged",this._clearHint).on("queryChanged",this._clearSuggestions).on("queryChanged",this._getSuggestions).on("whitespaceChanged",this._updateHint).on("queryChanged whitespaceChanged",this._openDropdown).on("queryChanged whitespaceChanged",this._setLanguageDirection).on("escKeyed",this._closeDropdown).on("escKeyed",this._setInputValueToQuery).on("tabKeyed upKeyed downKeyed",this._managePreventDefault).on("upKeyed downKeyed",this._moveDropdownCursor).on("upKeyed downKeyed",this._openDropdown).on("tabKeyed leftKeyed rightKeyed",this._autocomplete)}function e(b){var c=a(g.wrapper),d=a(g.dropdown),e=a(b),f=a(g.hint);c=c.css(h.wrapper),d=d.css(h.dropdown),f.css(h.hint).css({backgroundAttachment:e.css("background-attachment"),backgroundClip:e.css("background-clip"),backgroundColor:e.css("background-color"),backgroundImage:e.css("background-image"),backgroundOrigin:e.css("background-origin"),backgroundPosition:e.css("background-position"),backgroundRepeat:e.css("background-repeat"),backgroundSize:e.css("background-size")}),e.data("ttAttrs",{dir:e.attr("dir"),autocomplete:e.attr("autocomplete"),spellcheck:e.attr("spellcheck"),style:e.attr("style")}),e.addClass("tt-query").attr({autocomplete:"off",spellcheck:!1}).css(h.query);try{!e.attr("dir")&&e.attr("dir","auto")}catch(i){}return e.wrap(c).parent().prepend(f).append(d)}function f(a){var b=a.find(".tt-query");c.each(b.data("ttAttrs"),function(a,d){c.isUndefined(d)?b.removeAttr(a):b.attr(a,d)}),b.detach().removeData("ttAttrs").removeClass("tt-query").insertAfter(a),a.remove()}var g={wrapper:'<span class="twitter-typeahead"></span>',hint:'<input class="tt-hint" type="text" autocomplete="off" spellcheck="off" disabled>',dropdown:'<span class="tt-dropdown-menu"></span>'},h={wrapper:{position:"relative",display:"inline-block"},hint:{position:"absolute",top:"0",left:"0",borderColor:"transparent",boxShadow:"none"},query:{position:"relative",verticalAlign:"top",backgroundColor:"transparent"},dropdown:{position:"absolute",top:"100%",left:"0",zIndex:"100",display:"none"}};return c.isMsie()&&c.mixin(h.query,{backgroundImage:"url(data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7)"}),c.isMsie()&&c.isMsie()<=7&&(c.mixin(h.wrapper,{display:"inline",zoom:"1"}),c.mixin(h.query,{marginTop:"-1px"})),c.mixin(b.prototype,d,{_managePreventDefault:function(a){var b,c,d=a.data,e=!1;switch(a.type){case"tabKeyed":b=this.inputView.getHintValue(),c=this.inputView.getInputValue(),e=b&&b!==c;break;case"upKeyed":case"downKeyed":e=!d.shiftKey&&!d.ctrlKey&&!d.metaKey}e&&d.preventDefault()},_setLanguageDirection:function(){var a=this.inputView.getLanguageDirection();a!==this.dir&&(this.dir=a,this.$node.css("direction",a),this.dropdownView.setLanguageDirection(a))},_updateHint:function(){var a,b,d,e,f,g=this.dropdownView.getFirstSuggestion(),h=g?g.value:null,i=this.dropdownView.isVisible(),j=this.inputView.isOverflow();h&&i&&!j&&(a=this.inputView.getInputValue(),b=a.replace(/\s{2,}/g," ").replace(/^\s+/g,""),d=c.escapeRegExChars(b),e=new RegExp("^(?:"+d+")(.*$)","i"),f=e.exec(h),this.inputView.setHintValue(a+(f?f[1]:"")))},_clearHint:function(){this.inputView.setHintValue("")},_clearSuggestions:function(){this.dropdownView.clearSuggestions()},_setInputValueToQuery:function(){this.inputView.setInputValue(this.inputView.getQuery())},_setInputValueToSuggestionUnderCursor:function(a){var b=a.data;this.inputView.setInputValue(b.value,!0)},_openDropdown:function(){this.dropdownView.open()},_closeDropdown:function(a){this.dropdownView["blured"===a.type?"closeUnlessMouseIsOverDropdown":"close"]()},_moveDropdownCursor:function(a){var b=a.data;b.shiftKey||b.ctrlKey||b.metaKey||this.dropdownView["upKeyed"===a.type?"moveCursorUp":"moveCursorDown"]()},_handleSelection:function(a){var b="suggestionSelected"===a.type,d=b?a.data:this.dropdownView.getSuggestionUnderCursor();d&&(this.inputView.setInputValue(d.value),b?this.inputView.focus():a.data.preventDefault(),b&&c.isMsie()?c.defer(this.dropdownView.close):this.dropdownView.close(),this.eventBus.trigger("selected",d.datum,d.dataset))},_getSuggestions:function(){var a=this,b=this.inputView.getQuery();c.isBlankString(b)||c.each(this.datasets,function(c,d){d.getSuggestions(b,function(c){b===a.inputView.getQuery()&&a.dropdownView.renderSuggestions(d,c)})})},_autocomplete:function(a){var b,c,d,e,f;("rightKeyed"!==a.type&&"leftKeyed"!==a.type||(b=this.inputView.isCursorAtEnd(),c="ltr"===this.inputView.getLanguageDirection()?"leftKeyed"===a.type:"rightKeyed"===a.type,b&&!c))&&(d=this.inputView.getQuery(),e=this.inputView.getHintValue(),""!==e&&d!==e&&(f=this.dropdownView.getFirstSuggestion(),this.inputView.setInputValue(f.value),this.eventBus.trigger("autocompleted",f.datum,f.dataset)))},_propagateEvent:function(a){this.eventBus.trigger(a.type)},destroy:function(){this.inputView.destroy(),this.dropdownView.destroy(),f(this.$node),this.$node=null},setQuery:function(a){this.inputView.setQuery(a),this.inputView.setInputValue(a),this._clearHint(),this._clearSuggestions(),this._getSuggestions()}}),b}();!function(){var b,d={},f="ttView";b={initialize:function(b){function g(){var b,d=a(this),g=new e({el:d});b=c.map(h,function(a){return a.initialize()}),d.data(f,new l({input:d,eventBus:g=new e({el:d}),datasets:h})),a.when.apply(a,b).always(function(){c.defer(function(){g.trigger("initialized")})})}var h;return b=c.isArray(b)?b:[b],0===b.length&&a.error("no datasets provided"),h=c.map(b,function(a){var b=d[a.name]?d[a.name]:new i(a);return a.name&&(d[a.name]=b),b}),this.each(g)},destroy:function(){function b(){var b=a(this),c=b.data(f);c&&(c.destroy(),b.removeData(f))}return this.each(b)},setQuery:function(b){function c(){var c=a(this).data(f);c&&c.setQuery(b)}return this.each(c)}},jQuery.fn.typeahead=function(a){return b[a]?b[a].apply(this,[].slice.call(arguments,1)):b.initialize.apply(this,arguments)}}()}(window.jQuery);
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: algoliasearch-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.8
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Algolia
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-04 00:00:00.000000000 Z
11
+ date: 2013-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -122,6 +122,9 @@ files:
122
122
  - lib/algoliasearch/utilities.rb
123
123
  - spec/spec_helper.rb
124
124
  - spec/utilities_spec.rb
125
+ - vendor/assets/javascripts/algolia/algoliasearch.js
126
+ - vendor/assets/javascripts/algolia/algoliasearch.min.js
127
+ - vendor/assets/javascripts/algolia/typeahead.min.js
125
128
  homepage: http://github.com/algolia/algoliasearch-rails
126
129
  licenses:
127
130
  - MIT