vendor/assets/javascripts/algolia/v2/algoliasearch.js in algoliasearch-rails-1.16.3 vs vendor/assets/javascripts/algolia/v2/algoliasearch.js in algoliasearch-rails-1.17.0
- old
+ new
@@ -19,11 +19,11 @@
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
-var ALGOLIA_VERSION = '2.9.4';
+var ALGOLIA_VERSION = '2.9.7';
/*
* Copyright (c) 2013 Algolia
* http://www.algolia.com/
*
@@ -104,32 +104,26 @@
}
}
// If hosts is undefined, initialize it with applicationID
if (this._isUndefined(hosts)) {
hosts = [
- this.applicationID + '-1.algolia.' + tld,
- this.applicationID + '-2.algolia.' + tld,
- this.applicationID + '-3.algolia.' + tld
+ this.applicationID + '-1.algolianet.com',
+ this.applicationID + '-2.algolianet.com',
+ this.applicationID + '-3.algolianet.com'
];
}
// detect is we use http or https
this.host_protocol = 'http://';
if (this._isUndefined(method) || method === null) {
this.host_protocol = ('https:' == document.location.protocol ? 'https' : 'http') + '://';
} else if (method === 'https' || method === 'HTTPS') {
this.host_protocol = 'https://';
}
- // Add hosts in random order
+ // Add protocol to hosts
for (var i = 0; i < hosts.length; ++i) {
- if (Math.random() > 0.5) {
- this.hosts.reverse();
- }
this.hosts.push(this.host_protocol + hosts[i]);
}
- if (Math.random() > 0.5) {
- this.hosts.reverse();
- }
// then add Distributed Search Network host if there is one
if (this.dsn || this.dsnHost != null) {
if (this.dsnHost) {
this.hosts.unshift(this.host_protocol + this.dsnHost);
} else {
@@ -141,10 +135,12 @@
this.options.angular.$injector.invoke(['$http', '$q', function ($http, $q) {
self.options.angular.$q = $q;
self.options.angular.$http = $http;
}]);
}
+
+ this._ua = this.options._ua || 'Algolia for vanilla JavaScript ' + window.ALGOLIA_VERSION;
};
// This holds the number of JSONP requests done accross clients
// It's used as part of the ?callback=JSONP_$JSONPCounter when we do JSONP requests
AlgoliaSearch.JSONPCounter = 0;
@@ -593,10 +589,11 @@
}
}
opts.successiveRetryCount = 0;
var impl = function() {
+
if (opts.successiveRetryCount >= self.hosts.length) {
var error = { message: 'Cannot connect the Algolia\'s Search API. Please send an email to support@algolia.com to report the issue.' };
if (!self._isUndefined(callback) && callback) {
opts.successiveRetryCount = 0;
callback(false, error);
@@ -663,10 +660,11 @@
url += '&X-Algolia-UserToken=' + encodeURIComponent(this.userToken);
}
if (this.tagFilters) {
url += '&X-Algolia-TagFilters=' + encodeURIComponent(this.tagFilters);
}
+ url += '&X-Algolia-Agent=' + encodeURIComponent(this._ua);
for (var i = 0; i < this.extraHeaders.length; ++i) {
url += '&' + this.extraHeaders[i].key + '=' + this.extraHeaders[i].value;
}
this.options.angular.$http({
url: url,
@@ -709,10 +707,11 @@
url += '&X-Algolia-UserToken=' + encodeURIComponent(this.userToken);
}
if (this.tagFilters) {
url += '&X-Algolia-TagFilters=' + encodeURIComponent(this.tagFilters);
}
+ url += '&X-Algolia-Agent=' + encodeURIComponent(this._ua);
for (var i = 0; i < this.extraHeaders.length; ++i) {
url += '&' + this.extraHeaders[i].key + '=' + this.extraHeaders[i].value;
}
this.options.jQuery.$.ajax(url, {
type: opts.method,
@@ -784,10 +783,12 @@
if (this.userToken) {
url += '&X-Algolia-UserToken=' + encodeURIComponent(this.userToken);
}
+ url += '&X-Algolia-Agent=' + encodeURIComponent(this._ua);
+
for (var i = 0; i < this.extraHeaders.length; ++i) {
url += '&' + this.extraHeaders[i].key + '=' + this.extraHeaders[i].value;
}
if (opts.body && opts.body.params) {
@@ -797,11 +798,11 @@
ontimeout = setTimeout(function() {
timedOut = true;
clean();
opts.callback(true, false, { 'message': 'Timeout - Failed to load JSONP script.' });
- }, this.requestTimeoutInMs);
+ }, this.requestTimeoutInMs * (opts.successiveRetryCount + 1));
success = function() {
if (done || timedOut) {
return;
}
@@ -894,10 +895,12 @@
if (this.tagFilters) {
url += '&X-Algolia-TagFilters=' + encodeURIComponent(this.tagFilters);
}
+ url += '&X-Algolia-Agent=' + encodeURIComponent(this._ua);
+
for (var i = 0; i < this.extraHeaders.length; ++i) {
url += '&' + this.extraHeaders[i].key + '=' + this.extraHeaders[i].value;
}
timeoutListener = function() {
@@ -955,9 +958,16 @@
var success = status === 200 || status === 201;
var retry = !success && status !== 400 && status !== 403 && status !== 404;
opts.callback(retry, success, response);
};
+
+ // we set an empty onprogress listener
+ // so that XDomainRequest on IE9 is not aborted
+ // refs:
+ // - https://github.com/algolia/algoliasearch-client-js/issues/76
+ // - https://social.msdn.microsoft.com/Forums/ie/en-US/30ef3add-767c-4436-b8a9-f1ca19b4812e/ie9-rtm-xdomainrequest-issued-requests-may-abort-if-all-event-handlers-not-specified?forum=iewebdevelopment
+ request.onprogress = function noop() {};
if (this._support.timeout) {
// .timeout supported by both XHR and XDR,
// we do receive timeout event, tested
request.timeout = this.requestTimeoutInMs * (opts.successiveRetryCount + 1);