algoliasearch-rails 1.16.3 → 1.17.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ChangeLog +8 -0
- data/Gemfile +6 -1
- data/Gemfile.lock +3 -3
- data/README.md +153 -94
- data/VERSION +1 -1
- data/algoliasearch-rails.gemspec +1 -1
- data/lib/algoliasearch-rails.rb +75 -36
- data/spec/spec_helper.rb +7 -0
- data/vendor/assets/javascripts/algolia/algoliasearch.angular.js +23 -12
- data/vendor/assets/javascripts/algolia/algoliasearch.angular.min.js +2 -2
- data/vendor/assets/javascripts/algolia/algoliasearch.jquery.js +23 -12
- data/vendor/assets/javascripts/algolia/algoliasearch.jquery.min.js +2 -2
- data/vendor/assets/javascripts/algolia/algoliasearch.js +22 -12
- data/vendor/assets/javascripts/algolia/algoliasearch.min.js +2 -2
- data/vendor/assets/javascripts/algolia/v2/algoliasearch.angular.js +23 -12
- data/vendor/assets/javascripts/algolia/v2/algoliasearch.angular.min.js +2 -2
- data/vendor/assets/javascripts/algolia/v2/algoliasearch.jquery.js +23 -12
- data/vendor/assets/javascripts/algolia/v2/algoliasearch.jquery.min.js +2 -2
- data/vendor/assets/javascripts/algolia/v2/algoliasearch.js +22 -12
- data/vendor/assets/javascripts/algolia/v2/algoliasearch.min.js +2 -2
- data/vendor/assets/javascripts/algolia/v3/algoliasearch.angular.js +2020 -1301
- data/vendor/assets/javascripts/algolia/v3/algoliasearch.angular.min.js +3 -3
- data/vendor/assets/javascripts/algolia/v3/algoliasearch.jquery.js +2019 -1300
- data/vendor/assets/javascripts/algolia/v3/algoliasearch.jquery.min.js +3 -3
- data/vendor/assets/javascripts/algolia/v3/algoliasearch.js +2003 -1284
- data/vendor/assets/javascripts/algolia/v3/algoliasearch.min.js +3 -3
- metadata +5 -6
@@ -1,7 +1,7 @@
|
|
1
1
|
/*!
|
2
|
-
* algoliasearch 2.9.
|
2
|
+
* algoliasearch 2.9.7
|
3
3
|
* https://github.com/algolia/algoliasearch-client-js
|
4
4
|
* Copyright 2014 Algolia SAS; Licensed MIT
|
5
5
|
*/
|
6
6
|
|
7
|
-
function AlgoliaExplainResults(a,b,c){function d(a,b){var c=[];if("object"==typeof a&&"matchedWords"in a&&"value"in a){for(var e=!1,f=0;f<a.matchedWords.length;++f){var g=a.matchedWords[f];g in b||(b[g]=1,e=!0)}e&&c.push(a.value)}else if("[object Array]"===Object.prototype.toString.call(a))for(var h=0;h<a.length;++h){var i=d(a[h],b);c=c.concat(i)}else if("object"==typeof a)for(var j in a)a.hasOwnProperty(j)&&(c=c.concat(d(a[j],b)));return c}function e(a,b,c){var f=a._highlightResult||a;if(-1===c.indexOf("."))return c in f?d(f[c],b):[];for(var g=c.split("."),h=f,i=0;i<g.length;++i){if("[object Array]"===Object.prototype.toString.call(h)){for(var j=[],k=0;k<h.length;++k)j=j.concat(e(h[k],b,g.slice(i).join(".")));return j}if(!(g[i]in h))return[];h=h[g[i]]}return d(h,b)}var f={},g={},h=e(a,g,b);if(f.title=h.length>0?h[0]:"",f.subtitles=[],"undefined"!=typeof c)for(var i=0;i<c.length;++i)for(var j=e(a,g,c[i]),k=0;k<j.length;++k)f.subtitles.push({attr:c[i],value:j[k]});return f}var ALGOLIA_VERSION="2.9.4",AlgoliaSearch=function(a,b,c,d,e){var f=this;this.applicationID=a,this.apiKey=b,this.dsn=!0,this.dsnHost=null,this.hosts=[],this.currentHostIndex=0,this.requestTimeoutInMs=2e3,this.extraHeaders=[],this.jsonp=null,this.options={},this.cache={};var g,h="net";if("string"==typeof c)g=c;else{var i=c||{};this.options=i,this._isUndefined(i.method)||(g=i.method),this._isUndefined(i.tld)||(h=i.tld),this._isUndefined(i.dsn)||(this.dsn=i.dsn),this._isUndefined(i.hosts)||(e=i.hosts),this._isUndefined(i.dsnHost)||(this.dsnHost=i.dsnHost),this._isUndefined(i.requestTimeoutInMs)||(this.requestTimeoutInMs=+i.requestTimeoutInMs),this._isUndefined(i.jsonp)||(this.jsonp=i.jsonp)}this._isUndefined(e)&&(e=[this.applicationID+"-1.algolia."+h,this.applicationID+"-2.algolia."+h,this.applicationID+"-3.algolia."+h]),this.host_protocol="http://",this._isUndefined(g)||null===g?this.host_protocol=("https:"==document.location.protocol?"https":"http")+"://":("https"===g||"HTTPS"===g)&&(this.host_protocol="https://");for(var j=0;j<e.length;++j)Math.random()>.5&&this.hosts.reverse(),this.hosts.push(this.host_protocol+e[j]);Math.random()>.5&&this.hosts.reverse(),(this.dsn||null!=this.dsnHost)&&this.hosts.unshift(this.dsnHost?this.host_protocol+this.dsnHost:this.host_protocol+this.applicationID+"-dsn.algolia."+h),this.options.angular&&this.options.angular.$injector.invoke(["$http","$q",function(a,b){f.options.angular.$q=b,f.options.angular.$http=a}])};AlgoliaSearch.JSONPCounter=0,AlgoliaSearch.prototype={deleteIndex:function(a,b){return this._jsonRequest({method:"DELETE",url:"/1/indexes/"+encodeURIComponent(a),callback:b})},moveIndex:function(a,b,c){var d={operation:"move",destination:b};return this._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(a)+"/operation",body:d,callback:c})},copyIndex:function(a,b,c){var d={operation:"copy",destination:b};return this._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(a)+"/operation",body:d,callback:c})},getLogs:function(a,b,c){return 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,b){var c="undefined"!=typeof b?"?page="+b:"";return this._jsonRequest({method:"GET",url:"/1/indexes"+c,callback:a})},initIndex:function(a){return new this.Index(this,a)},listUserKeys:function(a){return this._jsonRequest({method:"GET",url:"/1/keys",callback:a})},getUserKeyACL:function(a,b){return this._jsonRequest({method:"GET",url:"/1/keys/"+a,callback:b})},deleteUserKey:function(a,b){return this._jsonRequest({method:"DELETE",url:"/1/keys/"+a,callback:b})},addUserKey:function(a,b){return this.addUserKeyWithValidity(a,0,0,0,b)},addUserKeyWithValidity:function(a,b,c,d,e){var f={};return f.acl=a,f.validity=b,f.maxQueriesPerIPPerHour=c,f.maxHitsPerQuery=d,this._jsonRequest({method:"POST",url:"/1/keys",body:f,callback:e})},setSecurityTags:function(a){if("[object Array]"===Object.prototype.toString.call(a)){for(var b=[],c=0;c<a.length;++c)if("[object Array]"===Object.prototype.toString.call(a[c])){for(var d=[],e=0;e<a[c].length;++e)d.push(a[c][e]);b.push("("+d.join(",")+")")}else b.push(a[c]);a=b.join(",")}this.tagFilters=a},setUserToken:function(a){this.userToken=a},startQueriesBatch:function(){this.batch=[]},addQueryInBatch:function(a,b,c){var d="query="+encodeURIComponent(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:[]},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))return this._sendQueriesBatch(d,a);var f=window.setTimeout(function(){c._sendQueriesBatch(d,a)},b);c.onDelayTrigger=f},setRequestTimeout:function(a){a&&(this.requestTimeoutInMs=parseInt(a,10))},Index:function(a,b){this.indexName=b,this.as=a,this.typeAheadArgs=null,this.typeAheadValueOption=null,this.cache={}},setExtraHeader:function(a,b){this.extraHeaders.push({key:a,value:b})},_sendQueriesBatch:function(a,b){if(null===this.jsonp){var c=this;return this._jsonRequest({cache:this.cache,method:"POST",url:"/1/indexes/*/queries",body:a,callback:function(d,e){d?(c.jsonp=!1,b&&b(d,e)):(c.jsonp=!0,c._sendQueriesBatch(a,b))}})}if(this.jsonp){for(var d="",e=0;e<a.requests.length;++e){var f="/1/indexes/"+encodeURIComponent(a.requests[e].indexName)+"?"+a.requests[e].params;d+=e+"="+encodeURIComponent(f)+"&"}var g={params:d};return this._jsonRequest({cache:this.cache,method:"GET",url:"/1/indexes/*",body:g,callback:b})}return 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,f=null;if(this.options.jQuery?(f=this.options.jQuery.$.Deferred(),f.promise=f.promise()):this.options.angular&&(f=this.options.angular.$q.defer()),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&&setTimeout(function(){c(!0,d[e])},1),f&&f.resolve(d[e]),f&&f.promise;a.successiveRetryCount=0;var g=function(){if(a.successiveRetryCount>=b.hosts.length){var h={message:"Cannot connect the Algolia's Search API. Please send an email to support@algolia.com to report the issue."};return!b._isUndefined(c)&&c&&(a.successiveRetryCount=0,c(!1,h)),void(f&&f.reject(h))}a.callback=function(h,i,j){i&&!b._isUndefined(a.cache)&&(d[e]=j),!i&&h?(b.currentHostIndex=++b.currentHostIndex%b.hosts.length,a.successiveRetryCount+=1,g()):(a.successiveRetryCount=0,f&&(i?f.resolve(j):f.reject(j)),!b._isUndefined(c)&&c&&c(i,j))},a.hostname=b.hosts[b.currentHostIndex],b._jsonRequestByHost(a)};return g(),f&&f.promise},_jsonRequestByHost:function(a){var b=a.hostname+a.url;this.jsonp?this._makeJsonpRequestByHost(b,a):this.options.jQuery?this._makejQueryRequestByHost(b,a):this.options.angular?this._makeAngularRequestByHost(b,a):this._makeXmlHttpRequestByHost(b,a)},_makeAngularRequestByHost:function(a,b){var c=null;this._isUndefined(b.body)||(c=JSON.stringify(b.body)),a+=(-1===a.indexOf("?")?"?":"&")+"X-Algolia-API-Key="+this.apiKey,a+="&X-Algolia-Application-Id="+this.applicationID,this.userToken&&(a+="&X-Algolia-UserToken="+encodeURIComponent(this.userToken)),this.tagFilters&&(a+="&X-Algolia-TagFilters="+encodeURIComponent(this.tagFilters));for(var d=0;d<this.extraHeaders.length;++d)a+="&"+this.extraHeaders[d].key+"="+this.extraHeaders[d].value;this.options.angular.$http({url:a,method:b.method,data:c,cache:!1,timeout:this.requestTimeoutInMs*(b.successiveRetryCount+1)}).then(function(a){b.callback(!1,!0,a.data)},function(a){0===a.status?b.callback(!0,!1,a.data):400==a.status||403===a.status||404===a.status?b.callback(!1,!1,a.data):b.callback(!0,!1,a.data)})},_makejQueryRequestByHost:function(a,b){var c=null;this._isUndefined(b.body)||(c=JSON.stringify(b.body)),a+=(-1===a.indexOf("?")?"?":"&")+"X-Algolia-API-Key="+this.apiKey,a+="&X-Algolia-Application-Id="+this.applicationID,this.userToken&&(a+="&X-Algolia-UserToken="+encodeURIComponent(this.userToken)),this.tagFilters&&(a+="&X-Algolia-TagFilters="+encodeURIComponent(this.tagFilters));for(var d=0;d<this.extraHeaders.length;++d)a+="&"+this.extraHeaders[d].key+"="+this.extraHeaders[d].value;this.options.jQuery.$.ajax(a,{type:b.method,timeout:this.requestTimeoutInMs*(b.successiveRetryCount+1),dataType:"json",data:c,error:function(c,d,e){"timeout"===d?b.callback(!0,!1,{message:"Timeout - Could not connect to endpoint "+a}):400===c.status||403===c.status||404===c.status?b.callback(!1,!1,c.responseJSON):b.callback(!0,!1,{message:e})},success:function(a){b.callback(!1,!0,a)}})},_makeJsonpRequestByHost:function(a,b){if("GET"!==b.method)return void b.callback(!0,!1,{message:"Method "+b.method+" "+a+" is not supported by JSONP."});var c=!1,d=!1;AlgoliaSearch.JSONPCounter+=1;var e,f,g,h=document.getElementsByTagName("head")[0],i=document.createElement("script"),j="algoliaJSONP_"+AlgoliaSearch.JSONPCounter,k=!1;window[j]=function(a){try{delete window[j]}catch(e){window[j]=void 0}if(!d){var f=a&&a.message&&a.status||a&&200,g=200===f,h=!g&&400!==f&&403!==f&&404!==f;c=!0,b.callback(h,g,a)}},i.type="text/javascript",a+="?callback="+j+"&X-Algolia-Application-Id="+this.applicationID+"&X-Algolia-API-Key="+this.apiKey,this.tagFilters&&(a+="&X-Algolia-TagFilters="+encodeURIComponent(this.tagFilters)),this.userToken&&(a+="&X-Algolia-UserToken="+encodeURIComponent(this.userToken));for(var l=0;l<this.extraHeaders.length;++l)a+="&"+this.extraHeaders[l].key+"="+this.extraHeaders[l].value;b.body&&b.body.params&&(a+="&"+b.body.params),e=setTimeout(function(){d=!0,g(),b.callback(!0,!1,{message:"Timeout - Failed to load JSONP script."})},this.requestTimeoutInMs),f=function(){k||d||(k=!0,g(),c||b.callback(!0,!1,{message:"Failed to load JSONP script."}))},g=function(){clearTimeout(e),i.onload=null,i.onreadystatechange=null,i.onerror=null,h.removeChild(i);try{delete window[j],delete window[j+"_loaded"]}catch(a){window[j]=null,window[j+"_loaded"]=null}},i.onreadystatechange=function(){("loaded"===this.readyState||"complete"===this.readyState)&&f()},i.onload=function(){f()},i.onerror=function(){k||d||(g(),b.callback(!0,!1,{message:"Failed to load JSONP script."}))},i.async=!0,i.defer=!0,i.src=a,h.appendChild(i)},_makeXmlHttpRequestByHost:function(a,b){if(!this._support.cors&&!this._support.hasXDomainRequest)return void b.callback(!1,!1,{message:"CORS not supported"});var c,d,e,f=null,g=this._support.cors?new XMLHttpRequest:new XDomainRequest,h=this;this._isUndefined(b.body)||(f=JSON.stringify(b.body)),a+=(-1===a.indexOf("?")?"?":"&")+"X-Algolia-API-Key="+this.apiKey,a+="&X-Algolia-Application-Id="+this.applicationID,this.userToken&&(a+="&X-Algolia-UserToken="+encodeURIComponent(this.userToken)),this.tagFilters&&(a+="&X-Algolia-TagFilters="+encodeURIComponent(this.tagFilters));for(var i=0;i<this.extraHeaders.length;++i)a+="&"+this.extraHeaders[i].key+"="+this.extraHeaders[i].value;e=function(){h._support.timeout||(d=!0,g.abort()),b.callback(!0,!1,{message:"Timeout - Could not connect to endpoint "+a})},g instanceof XMLHttpRequest?g.open(b.method,a,!0):g.open(b.method,a),this._support.cors&&null!==f&&"GET"!==b.method&&g.setRequestHeader("Content-type","application/x-www-form-urlencoded"),g.onload=function(){if(!d){h._support.timeout||clearTimeout(c);var a=null;try{a=JSON.parse(g.responseText)}catch(e){}var f=g.status||a&&a.message&&a.status||a&&200,i=200===f||201===f,j=!i&&400!==f&&403!==f&&404!==f;b.callback(j,i,a)}},this._support.timeout?(g.timeout=this.requestTimeoutInMs*(b.successiveRetryCount+1),g.ontimeout=e):c=setTimeout(e,this.requestTimeoutInMs*(b.successiveRetryCount+1)),g.onerror=function(a){d||(h._support.timeout||clearTimeout(c),b.callback(!0,!1,{message:"Could not connect to host",error:a}))},g.send(f)},_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("[object Array]"===Object.prototype.toString.call(a[c])?JSON.stringify(a[c]):a[c]));return b},_isUndefined:function(a){return void 0===a},_support:{hasXMLHttpRequest:"XMLHttpRequest"in window,hasXDomainRequest:"XDomainRequest"in window,cors:"withCredentials"in new XMLHttpRequest,timeout:"timeout"in new XMLHttpRequest}},AlgoliaSearch.prototype.Index.prototype={clearCache:function(){this.cache={}},addObject:function(a,b,c){var d=this;return this.as._jsonRequest(this.as._isUndefined(c)?{method:"POST",url:"/1/indexes/"+encodeURIComponent(d.indexName),body:a,callback:b}:{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)}return this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/batch",body:d,callback:b})},getObject:function(a,b,c){"[object Array]"!==Object.prototype.toString.call(b)||c||(c=b,b=null);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]}return this.as._jsonRequest({method:"GET",url:"/1/indexes/"+encodeURIComponent(d.indexName)+"/"+encodeURIComponent(a)+e,callback:b})},partialUpdateObject:function(a,b){var c=this;return this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/"+encodeURIComponent(a.objectID)+"/partial",body:a,callback:b})},partialUpdateObjects:function(a,b){for(var c=this,d={requests:[]},e=0;e<a.length;++e){var f={action:"partialUpdateObject",objectID:a[e].objectID,body:a[e]};d.requests.push(f)}return this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/batch",body:d,callback:b})},saveObject:function(a,b){var c=this;return 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:a[e].objectID,body:a[e]};d.requests.push(f)}return 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 void b(!1,{message:"empty objectID"});var c=this;return this.as._jsonRequest({method:"DELETE",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/"+encodeURIComponent(a),callback:b})},search:function(a,b,c,d){(void 0===a||null===a)&&(a=""),"function"==typeof a&&(b=a,a=""),"object"!=typeof b||!this.as._isUndefined(c)&&c||(c=b,b=null);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))return this._search(f,b);var g=window.setTimeout(function(){e._search(f,b)},d);e.onDelayTrigger=g},browse:function(a,b,c){+b>0&&(this.as._isUndefined(c)||!c)&&(c=b,b=null);var d=this,e="?page="+a;return this.as._isUndefined(c)||(e+="&hitsPerPage="+c),this.as._jsonRequest({method:"GET",url:"/1/indexes/"+encodeURIComponent(d.indexName)+"/browse"+e,callback:b})},ttAdapter:function(a){var b=this;return function(c,d){b.search(c,function(a,b){d(a?b.hits:b&&b.message)},a)}},waitTask:function(a,b){var c=this;return this.as._jsonRequest({method:"GET",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/task/"+a,callback:function(d,e){d?"published"===e.status?b(!0,e):setTimeout(function(){c.waitTask(a,b)},100):b(!1,e)}})},clearIndex:function(a){var b=this;return this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(b.indexName)+"/clear",callback:a})},getSettings:function(a){var b=this;return this.as._jsonRequest({method:"GET",url:"/1/indexes/"+encodeURIComponent(b.indexName)+"/settings",callback:a})},setSettings:function(a,b){var c=this;return this.as._jsonRequest({method:"PUT",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/settings",body:a,callback:b})},listUserKeys:function(a){var b=this;return this.as._jsonRequest({method:"GET",url:"/1/indexes/"+encodeURIComponent(b.indexName)+"/keys",callback:a})},getUserKeyACL:function(a,b){var c=this;return this.as._jsonRequest({method:"GET",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/keys/"+a,callback:b})},deleteUserKey:function(a,b){var c=this;return this.as._jsonRequest({method:"DELETE",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/keys/"+a,callback:b})},addUserKey:function(a,b){var c=this,d={};return d.acl=a,this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/keys",body:d,callback:b})},addUserKeyWithValidity:function(a,b,c,d,e){var f=this,g={};return g.acl=a,g.validity=b,g.maxQueriesPerIPPerHour=c,g.maxHitsPerQuery=d,this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(f.indexName)+"/keys",body:g,callback:e})},_search:function(a,b){var c={params:a};if(null===this.as.jsonp){var d=this;return this.as._jsonRequest({cache:this.cache,method:"POST",url:"/1/indexes/"+encodeURIComponent(this.indexName)+"/query",body:c,callback:function(c,e){var f=e&&e.status;c||f&&4===Math.floor(f/100)||1===Math.floor(f/100)?(d.as.jsonp=!1,b&&b(c,e)):(d.as.jsonp=!0,d._search(a,b))}})}return this.as._jsonRequest(this.as.jsonp?{cache:this.cache,method:"GET",url:"/1/indexes/"+encodeURIComponent(this.indexName),body:c,callback:b}:{cache:this.cache,method:"POST",url:"/1/indexes/"+encodeURIComponent(this.indexName)+"/query",body:c,callback:b})},as:null,indexName:null,typeAheadArgs:null,typeAheadValueOption:null},function(){var a=function(a){a=a||{};for(var b=1;b<arguments.length;b++)if(arguments[b])for(var c in arguments[b])arguments[b].hasOwnProperty(c)&&(a[c]=arguments[b][c]);return a};window.AlgoliaSearchHelper=function(b,c,d){var e={facets:[],disjunctiveFacets:[],hitsPerPage:20,defaultFacetFilters:[]};this.init(b,c,a({},e,d))},AlgoliaSearchHelper.prototype={init:function(a,b,c){this.client=a,this.index=b,this.options=c,this.page=0,this.refinements={},this.excludes={},this.disjunctiveRefinements={},this.extraQueries=[]},search:function(a,b,c){this.q=a,this.searchCallback=b,this.searchParams=c||{},this.page=this.page||0,this.refinements=this.refinements||{},this.disjunctiveRefinements=this.disjunctiveRefinements||{},this._search()},clearRefinements:function(){this.disjunctiveRefinements={},this.refinements={}},addDisjunctiveRefine:function(a,b){this.disjunctiveRefinements=this.disjunctiveRefinements||{},this.disjunctiveRefinements[a]=this.disjunctiveRefinements[a]||{},this.disjunctiveRefinements[a][b]=!0},removeDisjunctiveRefine:function(a,b){this.disjunctiveRefinements=this.disjunctiveRefinements||{},this.disjunctiveRefinements[a]=this.disjunctiveRefinements[a]||{};try{delete this.disjunctiveRefinements[a][b]}catch(c){this.disjunctiveRefinements[a][b]=void 0}},addRefine:function(a,b){var c=a+":"+b;this.refinements=this.refinements||{},this.refinements[c]=!0},removeRefine:function(a,b){var c=a+":"+b;this.refinements=this.refinements||{},this.refinements[c]=!1},addExclude:function(a,b){var c=a+":-"+b;this.excludes=this.excludes||{},this.excludes[c]=!0},removeExclude:function(a,b){var c=a+":-"+b;this.excludes=this.excludes||{},this.excludes[c]=!1},toggleExclude:function(a,b){for(var c=0;c<this.options.facets.length;++c)if(this.options.facets[c]==a){var d=a+":-"+b;return this.excludes[d]=!this.excludes[d],this.page=0,this._search(),!0}return!1},toggleRefine:function(a,b){for(var c=0;c<this.options.facets.length;++c)if(this.options.facets[c]==a){var d=a+":"+b;return this.refinements[d]=!this.refinements[d],this.page=0,this._search(),!0}this.disjunctiveRefinements[a]=this.disjunctiveRefinements[a]||{};for(var e=0;e<this.options.disjunctiveFacets.length;++e)if(this.options.disjunctiveFacets[e]==a)return this.disjunctiveRefinements[a][b]=!this.disjunctiveRefinements[a][b],this.page=0,this._search(),!0;return!1},isRefined:function(a,b){var c=a+":"+b;return this.refinements[c]?!0:this.disjunctiveRefinements[a]&&this.disjunctiveRefinements[a][b]?!0:!1},isExcluded:function(a,b){var c=a+":-"+b;return this.excludes[c]?!0:!1},nextPage:function(){this._gotoPage(this.page+1)},previousPage:function(){this.page>0&&this._gotoPage(this.page-1)},gotoPage:function(a){this._gotoPage(a)},setPage:function(a){this.page=a},setIndex:function(a){this.index=a},getIndex:function(){return this.index},clearExtraQueries:function(){this.extraQueries=[]},addExtraQuery:function(a,b,c){this.extraQueries.push({index:a,query:b,params:c||{}})},_gotoPage:function(a){this.page=a,this._search()},_search:function(){this.client.startQueriesBatch(),this.client.addQueryInBatch(this.index,this.q,this._getHitsSearchParams());var a=[],b={},c=0;for(c=0;c<this.options.disjunctiveFacets.length;++c){var d=this.options.disjunctiveFacets[c];this._hasDisjunctiveRefinements(d)?a.push(d):b[d]=!0}for(c=0;c<a.length;++c)this.client.addQueryInBatch(this.index,this.q,this._getDisjunctiveFacetSearchParams(a[c]));for(c=0;c<this.extraQueries.length;++c)this.client.addQueryInBatch(this.extraQueries[c].index,this.extraQueries[c].query,this.extraQueries[c].params);var e=this;this.client.sendQueriesBatch(function(d,f){if(!d)return void e.searchCallback(!1,f);var g=f.results[0];g.disjunctiveFacets=g.disjunctiveFacets||{},g.facets_stats=g.facets_stats||{};for(var h in b)if(g.facets[h]&&!g.disjunctiveFacets[h]){g.disjunctiveFacets[h]=g.facets[h];try{delete g.facets[h]}catch(i){g.facets[h]=void 0}}for(c=0;c<a.length;++c){for(var j in f.results[c+1].facets)if(g.disjunctiveFacets[j]=f.results[c+1].facets[j],e.disjunctiveRefinements[j])for(var k in e.disjunctiveRefinements[j])!g.disjunctiveFacets[j][k]&&e.disjunctiveRefinements[j][k]&&(g.disjunctiveFacets[j][k]=0);for(var l in f.results[c+1].facets_stats)g.facets_stats[l]=f.results[c+1].facets_stats[l]}g.facetStats=g.facets_stats;for(var m in e.excludes)if(e.excludes[m]){var i=m.indexOf(":-"),h=m.slice(0,i),k=m.slice(i+2);g.facets[h]=g.facets[h]||{},g.facets[h][k]||(g.facets[h][k]=0)}if(0===e.extraQueries.length)e.searchCallback(!0,g);else{var n={results:[g]};for(c=0;c<e.extraQueries.length;++c)n.results.push(f.results[1+a.length+c]);e.searchCallback(!0,n)}})},_getHitsSearchParams:function(){var b=[],c=0;for(c=0;c<this.options.facets.length;++c)b.push(this.options.facets[c]);for(c=0;c<this.options.disjunctiveFacets.length;++c){var d=this.options.disjunctiveFacets[c];this._hasDisjunctiveRefinements(d)||b.push(d)}return a({},{hitsPerPage:this.options.hitsPerPage,page:this.page,facets:b,facetFilters:this._getFacetFilters()},this.searchParams)},_getDisjunctiveFacetSearchParams:function(b){return a({},this.searchParams,{hitsPerPage:1,page:0,attributesToRetrieve:[],attributesToHighlight:[],attributesToSnippet:[],facets:b,facetFilters:this._getFacetFilters(b),analytics:!1})},_hasDisjunctiveRefinements:function(a){for(var b in this.disjunctiveRefinements[a])if(this.disjunctiveRefinements[a][b])return!0;return!1},_getFacetFilters:function(a){var b=[];if(this.options.defaultFacetFilters)for(var c=0;c<this.options.defaultFacetFilters.length;++c)b.push(this.options.defaultFacetFilters[c]);for(var d in this.refinements)this.refinements[d]&&b.push(d);for(var d in this.excludes)this.excludes[d]&&b.push(d);for(var e in this.disjunctiveRefinements)if(e!=a){var f=[];for(var g in this.disjunctiveRefinements[e])this.disjunctiveRefinements[e][g]&&f.push(e+":"+g);f.length>0&&b.push(f)}return b}}}(),function(){window.AlgoliaPlaces=function(a,b){this.init(a,b)},AlgoliaPlaces.prototype={init:function(a,b){this.client=new AlgoliaSearch(a,b,"http",!0,["places-1.algolia.io","places-2.algolia.io","places-3.algolia.io"]),this.cache={}},search:function(a,b,c){var d="query="+encodeURIComponent(a);this.client._isUndefined(c)||null==c||(d=this.client._getSearchParams(c,d));var e={params:d,apiKey:this.client.apiKey,appID:this.client.applicationID};this.client._jsonRequest({cache:this.cache,method:"POST",url:"/1/places/query",body:e,callback:b,removeCustomHTTPHeaders:!0})}}}(),"object"!=typeof JSON&&(JSON={}),function(){"use strict";function f(a){return 10>a?"0"+a:a}function quote(a){return escapable.lastIndex=0,escapable.test(a)?'"'+a.replace(escapable,function(a){var b=meta[a];return"string"==typeof b?b:"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+a+'"'}function str(a,b){var c,d,e,f,g,h=gap,i=b[a];switch(i&&"object"==typeof i&&"function"==typeof i.toJSON&&(i=i.toJSON(a)),"function"==typeof rep&&(i=rep.call(b,a,i)),typeof i){case"string":return quote(i);case"number":return isFinite(i)?String(i):"null";case"boolean":case"null":return String(i);case"object":if(!i)return"null";if(gap+=indent,g=[],"[object Array]"===Object.prototype.toString.apply(i)){for(f=i.length,c=0;f>c;c+=1)g[c]=str(c,i)||"null";return e=0===g.length?"[]":gap?"[\n"+gap+g.join(",\n"+gap)+"\n"+h+"]":"["+g.join(",")+"]",gap=h,e}if(rep&&"object"==typeof rep)for(f=rep.length,c=0;f>c;c+=1)"string"==typeof rep[c]&&(d=rep[c],e=str(d,i),e&&g.push(quote(d)+(gap?": ":":")+e));else for(d in i)Object.prototype.hasOwnProperty.call(i,d)&&(e=str(d,i),e&&g.push(quote(d)+(gap?": ":":")+e));return e=0===g.length?"{}":gap?"{\n"+gap+g.join(",\n"+gap)+"\n"+h+"}":"{"+g.join(",")+"}",gap=h,e}}"function"!=typeof Date.prototype.toJSON&&(Date.prototype.toJSON=function(){return isFinite(this.valueOf())?this.getUTCFullYear()+"-"+f(this.getUTCMonth()+1)+"-"+f(this.getUTCDate())+"T"+f(this.getUTCHours())+":"+f(this.getUTCMinutes())+":"+f(this.getUTCSeconds())+"Z":null},String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(){return this.valueOf()});var cx,escapable,gap,indent,meta,rep;"function"!=typeof JSON.stringify&&(escapable=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,meta={"\b":"\\b"," ":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},JSON.stringify=function(a,b,c){var d;if(gap="",indent="","number"==typeof c)for(d=0;c>d;d+=1)indent+=" ";else"string"==typeof c&&(indent=c);if(rep=b,b&&"function"!=typeof b&&("object"!=typeof b||"number"!=typeof b.length))throw new Error("JSON.stringify");return str("",{"":a})}),"function"!=typeof JSON.parse&&(cx=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,JSON.parse=function(text,reviver){function walk(a,b){var c,d,e=a[b];if(e&&"object"==typeof e)for(c in e)Object.prototype.hasOwnProperty.call(e,c)&&(d=walk(e,c),void 0!==d?e[c]=d:delete e[c]);return reviver.call(a,b,e)}var j;if(text=String(text),cx.lastIndex=0,cx.test(text)&&(text=text.replace(cx,function(a){return"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)})),/^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,"@").replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,"]").replace(/(?:^|:|,)(?:\s*\[)+/g,"")))return j=eval("("+text+")"),"function"==typeof reviver?walk({"":j},""):j;throw new SyntaxError("JSON.parse")})}(),function(a){a.algolia={},a.algolia.Client=function(b,c,d){return d=d||{},d.jQuery={$:a},new AlgoliaSearch(b,c,d)}}(jQuery);
|
7
|
+
function AlgoliaExplainResults(a,b,c){function d(a,b){var c=[];if("object"==typeof a&&"matchedWords"in a&&"value"in a){for(var e=!1,f=0;f<a.matchedWords.length;++f){var g=a.matchedWords[f];g in b||(b[g]=1,e=!0)}e&&c.push(a.value)}else if("[object Array]"===Object.prototype.toString.call(a))for(var h=0;h<a.length;++h){var i=d(a[h],b);c=c.concat(i)}else if("object"==typeof a)for(var j in a)a.hasOwnProperty(j)&&(c=c.concat(d(a[j],b)));return c}function e(a,b,c){var f=a._highlightResult||a;if(-1===c.indexOf("."))return c in f?d(f[c],b):[];for(var g=c.split("."),h=f,i=0;i<g.length;++i){if("[object Array]"===Object.prototype.toString.call(h)){for(var j=[],k=0;k<h.length;++k)j=j.concat(e(h[k],b,g.slice(i).join(".")));return j}if(!(g[i]in h))return[];h=h[g[i]]}return d(h,b)}var f={},g={},h=e(a,g,b);if(f.title=h.length>0?h[0]:"",f.subtitles=[],"undefined"!=typeof c)for(var i=0;i<c.length;++i)for(var j=e(a,g,c[i]),k=0;k<j.length;++k)f.subtitles.push({attr:c[i],value:j[k]});return f}var ALGOLIA_VERSION="2.9.7",AlgoliaSearch=function(a,b,c,d,e){var f=this;this.applicationID=a,this.apiKey=b,this.dsn=!0,this.dsnHost=null,this.hosts=[],this.currentHostIndex=0,this.requestTimeoutInMs=2e3,this.extraHeaders=[],this.jsonp=null,this.options={},this.cache={};var g,h="net";if("string"==typeof c)g=c;else{var i=c||{};this.options=i,this._isUndefined(i.method)||(g=i.method),this._isUndefined(i.tld)||(h=i.tld),this._isUndefined(i.dsn)||(this.dsn=i.dsn),this._isUndefined(i.hosts)||(e=i.hosts),this._isUndefined(i.dsnHost)||(this.dsnHost=i.dsnHost),this._isUndefined(i.requestTimeoutInMs)||(this.requestTimeoutInMs=+i.requestTimeoutInMs),this._isUndefined(i.jsonp)||(this.jsonp=i.jsonp)}this._isUndefined(e)&&(e=[this.applicationID+"-1.algolianet.com",this.applicationID+"-2.algolianet.com",this.applicationID+"-3.algolianet.com"]),this.host_protocol="http://",this._isUndefined(g)||null===g?this.host_protocol=("https:"==document.location.protocol?"https":"http")+"://":("https"===g||"HTTPS"===g)&&(this.host_protocol="https://");for(var j=0;j<e.length;++j)this.hosts.push(this.host_protocol+e[j]);(this.dsn||null!=this.dsnHost)&&(this.dsnHost?this.hosts.unshift(this.host_protocol+this.dsnHost):this.hosts.unshift(this.host_protocol+this.applicationID+"-dsn.algolia."+h)),this.options.angular&&this.options.angular.$injector.invoke(["$http","$q",function(a,b){f.options.angular.$q=b,f.options.angular.$http=a}]),this._ua=this.options._ua||"Algolia for vanilla JavaScript "+window.ALGOLIA_VERSION};AlgoliaSearch.JSONPCounter=0,AlgoliaSearch.prototype={deleteIndex:function(a,b){return this._jsonRequest({method:"DELETE",url:"/1/indexes/"+encodeURIComponent(a),callback:b})},moveIndex:function(a,b,c){var d={operation:"move",destination:b};return this._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(a)+"/operation",body:d,callback:c})},copyIndex:function(a,b,c){var d={operation:"copy",destination:b};return this._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(a)+"/operation",body:d,callback:c})},getLogs:function(a,b,c){return 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,b){var c="undefined"!=typeof b?"?page="+b:"";return this._jsonRequest({method:"GET",url:"/1/indexes"+c,callback:a})},initIndex:function(a){return new this.Index(this,a)},listUserKeys:function(a){return this._jsonRequest({method:"GET",url:"/1/keys",callback:a})},getUserKeyACL:function(a,b){return this._jsonRequest({method:"GET",url:"/1/keys/"+a,callback:b})},deleteUserKey:function(a,b){return this._jsonRequest({method:"DELETE",url:"/1/keys/"+a,callback:b})},addUserKey:function(a,b){return this.addUserKeyWithValidity(a,0,0,0,b)},addUserKeyWithValidity:function(a,b,c,d,e){var f={};return f.acl=a,f.validity=b,f.maxQueriesPerIPPerHour=c,f.maxHitsPerQuery=d,this._jsonRequest({method:"POST",url:"/1/keys",body:f,callback:e})},setSecurityTags:function(a){if("[object Array]"===Object.prototype.toString.call(a)){for(var b=[],c=0;c<a.length;++c)if("[object Array]"===Object.prototype.toString.call(a[c])){for(var d=[],e=0;e<a[c].length;++e)d.push(a[c][e]);b.push("("+d.join(",")+")")}else b.push(a[c]);a=b.join(",")}this.tagFilters=a},setUserToken:function(a){this.userToken=a},startQueriesBatch:function(){this.batch=[]},addQueryInBatch:function(a,b,c){var d="query="+encodeURIComponent(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:[]},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))return this._sendQueriesBatch(d,a);var f=window.setTimeout(function(){c._sendQueriesBatch(d,a)},b);c.onDelayTrigger=f},setRequestTimeout:function(a){a&&(this.requestTimeoutInMs=parseInt(a,10))},Index:function(a,b){this.indexName=b,this.as=a,this.typeAheadArgs=null,this.typeAheadValueOption=null,this.cache={}},setExtraHeader:function(a,b){this.extraHeaders.push({key:a,value:b})},_sendQueriesBatch:function(a,b){if(null===this.jsonp){var c=this;return this._jsonRequest({cache:this.cache,method:"POST",url:"/1/indexes/*/queries",body:a,callback:function(d,e){d?(c.jsonp=!1,b&&b(d,e)):(c.jsonp=!0,c._sendQueriesBatch(a,b))}})}if(this.jsonp){for(var d="",e=0;e<a.requests.length;++e){var f="/1/indexes/"+encodeURIComponent(a.requests[e].indexName)+"?"+a.requests[e].params;d+=e+"="+encodeURIComponent(f)+"&"}var g={params:d};return this._jsonRequest({cache:this.cache,method:"GET",url:"/1/indexes/*",body:g,callback:b})}return 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,f=null;if(this.options.jQuery?(f=this.options.jQuery.$.Deferred(),f.promise=f.promise()):this.options.angular&&(f=this.options.angular.$q.defer()),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&&setTimeout(function(){c(!0,d[e])},1),f&&f.resolve(d[e]),f&&f.promise;a.successiveRetryCount=0;var g=function(){if(a.successiveRetryCount>=b.hosts.length){var h={message:"Cannot connect the Algolia's Search API. Please send an email to support@algolia.com to report the issue."};return!b._isUndefined(c)&&c&&(a.successiveRetryCount=0,c(!1,h)),void(f&&f.reject(h))}a.callback=function(h,i,j){i&&!b._isUndefined(a.cache)&&(d[e]=j),!i&&h?(b.currentHostIndex=++b.currentHostIndex%b.hosts.length,a.successiveRetryCount+=1,g()):(a.successiveRetryCount=0,f&&(i?f.resolve(j):f.reject(j)),!b._isUndefined(c)&&c&&c(i,j))},a.hostname=b.hosts[b.currentHostIndex],b._jsonRequestByHost(a)};return g(),f&&f.promise},_jsonRequestByHost:function(a){var b=a.hostname+a.url;this.jsonp?this._makeJsonpRequestByHost(b,a):this.options.jQuery?this._makejQueryRequestByHost(b,a):this.options.angular?this._makeAngularRequestByHost(b,a):this._makeXmlHttpRequestByHost(b,a)},_makeAngularRequestByHost:function(a,b){var c=null;this._isUndefined(b.body)||(c=JSON.stringify(b.body)),a+=(-1===a.indexOf("?")?"?":"&")+"X-Algolia-API-Key="+this.apiKey,a+="&X-Algolia-Application-Id="+this.applicationID,this.userToken&&(a+="&X-Algolia-UserToken="+encodeURIComponent(this.userToken)),this.tagFilters&&(a+="&X-Algolia-TagFilters="+encodeURIComponent(this.tagFilters)),a+="&X-Algolia-Agent="+encodeURIComponent(this._ua);for(var d=0;d<this.extraHeaders.length;++d)a+="&"+this.extraHeaders[d].key+"="+this.extraHeaders[d].value;this.options.angular.$http({url:a,method:b.method,data:c,cache:!1,timeout:this.requestTimeoutInMs*(b.successiveRetryCount+1)}).then(function(a){b.callback(!1,!0,a.data)},function(a){0===a.status?b.callback(!0,!1,a.data):400==a.status||403===a.status||404===a.status?b.callback(!1,!1,a.data):b.callback(!0,!1,a.data)})},_makejQueryRequestByHost:function(a,b){var c=null;this._isUndefined(b.body)||(c=JSON.stringify(b.body)),a+=(-1===a.indexOf("?")?"?":"&")+"X-Algolia-API-Key="+this.apiKey,a+="&X-Algolia-Application-Id="+this.applicationID,this.userToken&&(a+="&X-Algolia-UserToken="+encodeURIComponent(this.userToken)),this.tagFilters&&(a+="&X-Algolia-TagFilters="+encodeURIComponent(this.tagFilters)),a+="&X-Algolia-Agent="+encodeURIComponent(this._ua);for(var d=0;d<this.extraHeaders.length;++d)a+="&"+this.extraHeaders[d].key+"="+this.extraHeaders[d].value;this.options.jQuery.$.ajax(a,{type:b.method,timeout:this.requestTimeoutInMs*(b.successiveRetryCount+1),dataType:"json",data:c,error:function(c,d,e){"timeout"===d?b.callback(!0,!1,{message:"Timeout - Could not connect to endpoint "+a}):400===c.status||403===c.status||404===c.status?b.callback(!1,!1,c.responseJSON):b.callback(!0,!1,{message:e})},success:function(a,c,d){b.callback(!1,!0,a)}})},_makeJsonpRequestByHost:function(a,b){if("GET"!==b.method)return void b.callback(!0,!1,{message:"Method "+b.method+" "+a+" is not supported by JSONP."});var c=!1,d=!1;AlgoliaSearch.JSONPCounter+=1;var e,f,g,h=document.getElementsByTagName("head")[0],i=document.createElement("script"),j="algoliaJSONP_"+AlgoliaSearch.JSONPCounter,k=!1;window[j]=function(a){try{delete window[j]}catch(e){window[j]=void 0}if(!d){var f=a&&a.message&&a.status||a&&200,g=200===f,h=!g&&400!==f&&403!==f&&404!==f;c=!0,b.callback(h,g,a)}},i.type="text/javascript",a+="?callback="+j+"&X-Algolia-Application-Id="+this.applicationID+"&X-Algolia-API-Key="+this.apiKey,this.tagFilters&&(a+="&X-Algolia-TagFilters="+encodeURIComponent(this.tagFilters)),this.userToken&&(a+="&X-Algolia-UserToken="+encodeURIComponent(this.userToken)),a+="&X-Algolia-Agent="+encodeURIComponent(this._ua);for(var l=0;l<this.extraHeaders.length;++l)a+="&"+this.extraHeaders[l].key+"="+this.extraHeaders[l].value;b.body&&b.body.params&&(a+="&"+b.body.params),e=setTimeout(function(){d=!0,g(),b.callback(!0,!1,{message:"Timeout - Failed to load JSONP script."})},this.requestTimeoutInMs*(b.successiveRetryCount+1)),f=function(){k||d||(k=!0,g(),c||b.callback(!0,!1,{message:"Failed to load JSONP script."}))},g=function(){clearTimeout(e),i.onload=null,i.onreadystatechange=null,i.onerror=null,h.removeChild(i);try{delete window[j],delete window[j+"_loaded"]}catch(a){window[j]=null,window[j+"_loaded"]=null}},i.onreadystatechange=function(){("loaded"===this.readyState||"complete"===this.readyState)&&f()},i.onload=function(){f()},i.onerror=function(){k||d||(g(),b.callback(!0,!1,{message:"Failed to load JSONP script."}))},i.async=!0,i.defer=!0,i.src=a,h.appendChild(i)},_makeXmlHttpRequestByHost:function(a,b){if(!this._support.cors&&!this._support.hasXDomainRequest)return void b.callback(!1,!1,{message:"CORS not supported"});var c,d,e,f=null,g=this._support.cors?new XMLHttpRequest:new XDomainRequest,h=this;this._isUndefined(b.body)||(f=JSON.stringify(b.body)),a+=(-1===a.indexOf("?")?"?":"&")+"X-Algolia-API-Key="+this.apiKey,a+="&X-Algolia-Application-Id="+this.applicationID,this.userToken&&(a+="&X-Algolia-UserToken="+encodeURIComponent(this.userToken)),this.tagFilters&&(a+="&X-Algolia-TagFilters="+encodeURIComponent(this.tagFilters)),a+="&X-Algolia-Agent="+encodeURIComponent(this._ua);for(var i=0;i<this.extraHeaders.length;++i)a+="&"+this.extraHeaders[i].key+"="+this.extraHeaders[i].value;e=function(){h._support.timeout||(d=!0,g.abort()),b.callback(!0,!1,{message:"Timeout - Could not connect to endpoint "+a})},g instanceof XMLHttpRequest?g.open(b.method,a,!0):g.open(b.method,a),this._support.cors&&null!==f&&"GET"!==b.method&&g.setRequestHeader("Content-type","application/x-www-form-urlencoded"),g.onload=function(){if(!d){h._support.timeout||clearTimeout(c);var a=null;try{a=JSON.parse(g.responseText)}catch(e){}var f=g.status||a&&a.message&&a.status||a&&200,i=200===f||201===f,j=!i&&400!==f&&403!==f&&404!==f;b.callback(j,i,a)}},g.onprogress=function(){},this._support.timeout?(g.timeout=this.requestTimeoutInMs*(b.successiveRetryCount+1),g.ontimeout=e):c=setTimeout(e,this.requestTimeoutInMs*(b.successiveRetryCount+1)),g.onerror=function(a){d||(h._support.timeout||clearTimeout(c),b.callback(!0,!1,{message:"Could not connect to host",error:a}))},g.send(f)},_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("[object Array]"===Object.prototype.toString.call(a[c])?JSON.stringify(a[c]):a[c]));return b},_isUndefined:function(a){return void 0===a},_support:{hasXMLHttpRequest:"XMLHttpRequest"in window,hasXDomainRequest:"XDomainRequest"in window,cors:"withCredentials"in new XMLHttpRequest,timeout:"timeout"in new XMLHttpRequest}},AlgoliaSearch.prototype.Index.prototype={clearCache:function(){this.cache={}},addObject:function(a,b,c){var d=this;return 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)}return this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/batch",body:d,callback:b})},getObject:function(a,b,c){"[object Array]"!==Object.prototype.toString.call(b)||c||(c=b,b=null);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]}return this.as._jsonRequest({method:"GET",url:"/1/indexes/"+encodeURIComponent(d.indexName)+"/"+encodeURIComponent(a)+e,callback:b})},partialUpdateObject:function(a,b){var c=this;return this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/"+encodeURIComponent(a.objectID)+"/partial",body:a,callback:b})},partialUpdateObjects:function(a,b){for(var c=this,d={requests:[]},e=0;e<a.length;++e){var f={action:"partialUpdateObject",objectID:a[e].objectID,body:a[e]};d.requests.push(f)}return this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/batch",body:d,callback:b})},saveObject:function(a,b){var c=this;return 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:a[e].objectID,body:a[e]};d.requests.push(f)}return 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 void b(!1,{message:"empty objectID"});var c=this;return this.as._jsonRequest({method:"DELETE",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/"+encodeURIComponent(a),callback:b})},search:function(a,b,c,d){(void 0===a||null===a)&&(a=""),"function"==typeof a&&(b=a,a=""),"object"!=typeof b||!this.as._isUndefined(c)&&c||(c=b,b=null);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))return this._search(f,b);var g=window.setTimeout(function(){e._search(f,b)},d);e.onDelayTrigger=g},browse:function(a,b,c){+b>0&&(this.as._isUndefined(c)||!c)&&(c=b,b=null);var d=this,e="?page="+a;return this.as._isUndefined(c)||(e+="&hitsPerPage="+c),this.as._jsonRequest({method:"GET",url:"/1/indexes/"+encodeURIComponent(d.indexName)+"/browse"+e,callback:b})},ttAdapter:function(a){var b=this;return function(c,d){b.search(c,function(a,b){d(a?b.hits:b&&b.message)},a)}},waitTask:function(a,b){var c=this;return this.as._jsonRequest({method:"GET",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/task/"+a,callback:function(d,e){d?"published"===e.status?b(!0,e):setTimeout(function(){c.waitTask(a,b)},100):b(!1,e)}})},clearIndex:function(a){var b=this;return this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(b.indexName)+"/clear",callback:a})},getSettings:function(a){var b=this;return this.as._jsonRequest({method:"GET",url:"/1/indexes/"+encodeURIComponent(b.indexName)+"/settings",callback:a})},setSettings:function(a,b){var c=this;return this.as._jsonRequest({method:"PUT",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/settings",body:a,callback:b})},listUserKeys:function(a){var b=this;return this.as._jsonRequest({method:"GET",url:"/1/indexes/"+encodeURIComponent(b.indexName)+"/keys",callback:a})},getUserKeyACL:function(a,b){var c=this;return this.as._jsonRequest({method:"GET",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/keys/"+a,callback:b})},deleteUserKey:function(a,b){var c=this;return this.as._jsonRequest({method:"DELETE",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/keys/"+a,callback:b})},addUserKey:function(a,b){var c=this,d={};return d.acl=a,this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/keys",body:d,callback:b})},addUserKeyWithValidity:function(a,b,c,d,e){var f=this,g={};return g.acl=a,g.validity=b,g.maxQueriesPerIPPerHour=c,g.maxHitsPerQuery=d,this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(f.indexName)+"/keys",body:g,callback:e})},_search:function(a,b){var c={params:a};if(null===this.as.jsonp){var d=this;return this.as._jsonRequest({cache:this.cache,method:"POST",url:"/1/indexes/"+encodeURIComponent(this.indexName)+"/query",body:c,callback:function(c,e){var f=e&&e.status;c||f&&4===Math.floor(f/100)||1===Math.floor(f/100)?(d.as.jsonp=!1,b&&b(c,e)):(d.as.jsonp=!0,d._search(a,b))}})}return this.as.jsonp?this.as._jsonRequest({cache:this.cache,method:"GET",url:"/1/indexes/"+encodeURIComponent(this.indexName),body:c,callback:b}):this.as._jsonRequest({cache:this.cache,method:"POST",url:"/1/indexes/"+encodeURIComponent(this.indexName)+"/query",body:c,callback:b})},as:null,indexName:null,typeAheadArgs:null,typeAheadValueOption:null},function(a){var b=function(a){a=a||{};for(var b=1;b<arguments.length;b++)if(arguments[b])for(var c in arguments[b])arguments[b].hasOwnProperty(c)&&(a[c]=arguments[b][c]);return a};window.AlgoliaSearchHelper=function(a,c,d){var e={facets:[],disjunctiveFacets:[],hitsPerPage:20,defaultFacetFilters:[]};this.init(a,c,b({},e,d))},AlgoliaSearchHelper.prototype={init:function(a,b,c){this.client=a,this.index=b,this.options=c,this.page=0,this.refinements={},this.excludes={},this.disjunctiveRefinements={},this.extraQueries=[]},search:function(a,b,c){this.q=a,this.searchCallback=b,this.searchParams=c||{},this.page=this.page||0,this.refinements=this.refinements||{},this.disjunctiveRefinements=this.disjunctiveRefinements||{},this._search()},clearRefinements:function(){this.disjunctiveRefinements={},this.refinements={}},addDisjunctiveRefine:function(a,b){this.disjunctiveRefinements=this.disjunctiveRefinements||{},this.disjunctiveRefinements[a]=this.disjunctiveRefinements[a]||{},this.disjunctiveRefinements[a][b]=!0},removeDisjunctiveRefine:function(a,b){this.disjunctiveRefinements=this.disjunctiveRefinements||{},this.disjunctiveRefinements[a]=this.disjunctiveRefinements[a]||{};try{delete this.disjunctiveRefinements[a][b]}catch(c){this.disjunctiveRefinements[a][b]=void 0}},addRefine:function(a,b){var c=a+":"+b;this.refinements=this.refinements||{},this.refinements[c]=!0},removeRefine:function(a,b){var c=a+":"+b;this.refinements=this.refinements||{},this.refinements[c]=!1},addExclude:function(a,b){var c=a+":-"+b;this.excludes=this.excludes||{},this.excludes[c]=!0},removeExclude:function(a,b){var c=a+":-"+b;this.excludes=this.excludes||{},this.excludes[c]=!1},toggleExclude:function(a,b){for(var c=0;c<this.options.facets.length;++c)if(this.options.facets[c]==a){var d=a+":-"+b;return this.excludes[d]=!this.excludes[d],this.page=0,this._search(),!0}return!1},toggleRefine:function(a,b){for(var c=0;c<this.options.facets.length;++c)if(this.options.facets[c]==a){var d=a+":"+b;return this.refinements[d]=!this.refinements[d],this.page=0,this._search(),!0}this.disjunctiveRefinements[a]=this.disjunctiveRefinements[a]||{};for(var e=0;e<this.options.disjunctiveFacets.length;++e)if(this.options.disjunctiveFacets[e]==a)return this.disjunctiveRefinements[a][b]=!this.disjunctiveRefinements[a][b],this.page=0,this._search(),!0;return!1},isRefined:function(a,b){var c=a+":"+b;return this.refinements[c]?!0:this.disjunctiveRefinements[a]&&this.disjunctiveRefinements[a][b]?!0:!1},isExcluded:function(a,b){var c=a+":-"+b;return this.excludes[c]?!0:!1},nextPage:function(){this._gotoPage(this.page+1)},previousPage:function(){this.page>0&&this._gotoPage(this.page-1)},gotoPage:function(a){this._gotoPage(a)},setPage:function(a){this.page=a},setIndex:function(a){this.index=a},getIndex:function(){return this.index},clearExtraQueries:function(){this.extraQueries=[]},addExtraQuery:function(a,b,c){this.extraQueries.push({index:a,query:b,params:c||{}})},_gotoPage:function(a){this.page=a,this._search()},_search:function(){this.client.startQueriesBatch(),this.client.addQueryInBatch(this.index,this.q,this._getHitsSearchParams());var a=[],b={},c=0;for(c=0;c<this.options.disjunctiveFacets.length;++c){var d=this.options.disjunctiveFacets[c];this._hasDisjunctiveRefinements(d)?a.push(d):b[d]=!0}for(c=0;c<a.length;++c)this.client.addQueryInBatch(this.index,this.q,this._getDisjunctiveFacetSearchParams(a[c]));for(c=0;c<this.extraQueries.length;++c)this.client.addQueryInBatch(this.extraQueries[c].index,this.extraQueries[c].query,this.extraQueries[c].params);var e=this;this.client.sendQueriesBatch(function(d,f){if(!d)return void e.searchCallback(!1,f);var g=f.results[0];g.disjunctiveFacets=g.disjunctiveFacets||{},g.facets_stats=g.facets_stats||{};for(var h in b)if(g.facets[h]&&!g.disjunctiveFacets[h]){g.disjunctiveFacets[h]=g.facets[h];try{delete g.facets[h]}catch(i){g.facets[h]=void 0}}for(c=0;c<a.length;++c){for(var j in f.results[c+1].facets)if(g.disjunctiveFacets[j]=f.results[c+1].facets[j],e.disjunctiveRefinements[j])for(var k in e.disjunctiveRefinements[j])!g.disjunctiveFacets[j][k]&&e.disjunctiveRefinements[j][k]&&(g.disjunctiveFacets[j][k]=0);for(var l in f.results[c+1].facets_stats)g.facets_stats[l]=f.results[c+1].facets_stats[l]}g.facetStats=g.facets_stats;for(var m in e.excludes)if(e.excludes[m]){var i=m.indexOf(":-"),h=m.slice(0,i),k=m.slice(i+2);g.facets[h]=g.facets[h]||{},g.facets[h][k]||(g.facets[h][k]=0)}if(0===e.extraQueries.length)e.searchCallback(!0,g);else{var n={results:[g]};for(c=0;c<e.extraQueries.length;++c)n.results.push(f.results[1+a.length+c]);e.searchCallback(!0,n)}})},_getHitsSearchParams:function(){var a=[],c=0;for(c=0;c<this.options.facets.length;++c)a.push(this.options.facets[c]);for(c=0;c<this.options.disjunctiveFacets.length;++c){var d=this.options.disjunctiveFacets[c];this._hasDisjunctiveRefinements(d)||a.push(d)}return b({},{hitsPerPage:this.options.hitsPerPage,page:this.page,facets:a,facetFilters:this._getFacetFilters()},this.searchParams)},_getDisjunctiveFacetSearchParams:function(a){return b({},this.searchParams,{hitsPerPage:1,page:0,attributesToRetrieve:[],attributesToHighlight:[],attributesToSnippet:[],facets:a,facetFilters:this._getFacetFilters(a),analytics:!1})},_hasDisjunctiveRefinements:function(a){for(var b in this.disjunctiveRefinements[a])if(this.disjunctiveRefinements[a][b])return!0;return!1},_getFacetFilters:function(a){var b=[];if(this.options.defaultFacetFilters)for(var c=0;c<this.options.defaultFacetFilters.length;++c)b.push(this.options.defaultFacetFilters[c]);for(var d in this.refinements)this.refinements[d]&&b.push(d);for(var d in this.excludes)this.excludes[d]&&b.push(d);for(var e in this.disjunctiveRefinements)if(e!=a){var f=[];for(var g in this.disjunctiveRefinements[e])this.disjunctiveRefinements[e][g]&&f.push(e+":"+g);f.length>0&&b.push(f)}return b}}}(),function(a){window.AlgoliaPlaces=function(a,b){this.init(a,b)},AlgoliaPlaces.prototype={init:function(a,b){this.client=new AlgoliaSearch(a,b,"http",!0,["places-1.algolia.io","places-2.algolia.io","places-3.algolia.io"]),this.cache={}},search:function(a,b,c){var d="query="+encodeURIComponent(a);this.client._isUndefined(c)||null==c||(d=this.client._getSearchParams(c,d));var e={params:d,apiKey:this.client.apiKey,appID:this.client.applicationID};this.client._jsonRequest({cache:this.cache,method:"POST",url:"/1/places/query",body:e,callback:b,removeCustomHTTPHeaders:!0})}}}(),"object"!=typeof JSON&&(JSON={}),function(){"use strict";function f(a){return 10>a?"0"+a:a}function quote(a){return escapable.lastIndex=0,escapable.test(a)?'"'+a.replace(escapable,function(a){var b=meta[a];return"string"==typeof b?b:"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+a+'"'}function str(a,b){var c,d,e,f,g,h=gap,i=b[a];switch(i&&"object"==typeof i&&"function"==typeof i.toJSON&&(i=i.toJSON(a)),"function"==typeof rep&&(i=rep.call(b,a,i)),typeof i){case"string":return quote(i);case"number":return isFinite(i)?String(i):"null";case"boolean":case"null":return String(i);case"object":if(!i)return"null";if(gap+=indent,g=[],"[object Array]"===Object.prototype.toString.apply(i)){for(f=i.length,c=0;f>c;c+=1)g[c]=str(c,i)||"null";return e=0===g.length?"[]":gap?"[\n"+gap+g.join(",\n"+gap)+"\n"+h+"]":"["+g.join(",")+"]",gap=h,e}if(rep&&"object"==typeof rep)for(f=rep.length,c=0;f>c;c+=1)"string"==typeof rep[c]&&(d=rep[c],e=str(d,i),e&&g.push(quote(d)+(gap?": ":":")+e));else for(d in i)Object.prototype.hasOwnProperty.call(i,d)&&(e=str(d,i),e&&g.push(quote(d)+(gap?": ":":")+e));return e=0===g.length?"{}":gap?"{\n"+gap+g.join(",\n"+gap)+"\n"+h+"}":"{"+g.join(",")+"}",gap=h,e}}"function"!=typeof Date.prototype.toJSON&&(Date.prototype.toJSON=function(){return isFinite(this.valueOf())?this.getUTCFullYear()+"-"+f(this.getUTCMonth()+1)+"-"+f(this.getUTCDate())+"T"+f(this.getUTCHours())+":"+f(this.getUTCMinutes())+":"+f(this.getUTCSeconds())+"Z":null},String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(){return this.valueOf()});var cx,escapable,gap,indent,meta,rep;"function"!=typeof JSON.stringify&&(escapable=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,meta={"\b":"\\b"," ":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},JSON.stringify=function(a,b,c){var d;if(gap="",indent="","number"==typeof c)for(d=0;c>d;d+=1)indent+=" ";else"string"==typeof c&&(indent=c);if(rep=b,b&&"function"!=typeof b&&("object"!=typeof b||"number"!=typeof b.length))throw new Error("JSON.stringify");return str("",{"":a})}),"function"!=typeof JSON.parse&&(cx=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,JSON.parse=function(text,reviver){function walk(a,b){var c,d,e=a[b];if(e&&"object"==typeof e)for(c in e)Object.prototype.hasOwnProperty.call(e,c)&&(d=walk(e,c),void 0!==d?e[c]=d:delete e[c]);return reviver.call(a,b,e)}var j;if(text=String(text),cx.lastIndex=0,cx.test(text)&&(text=text.replace(cx,function(a){return"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)})),/^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,"@").replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,"]").replace(/(?:^|:|,)(?:\s*\[)+/g,"")))return j=eval("("+text+")"),"function"==typeof reviver?walk({"":j},""):j;throw new SyntaxError("JSON.parse")})}(),function(a){a.algolia={},a.algolia.Client=function(b,c,d){return d=d||{},d.jQuery={$:a},d._ua="Algolia for jQuery "+window.ALGOLIA_VERSION,new AlgoliaSearch(b,c,d)}}(jQuery);
|
@@ -21,7 +21,7 @@
|
|
21
21
|
* THE SOFTWARE.
|
22
22
|
*/
|
23
23
|
|
24
|
-
var ALGOLIA_VERSION = '2.9.
|
24
|
+
var ALGOLIA_VERSION = '2.9.7';
|
25
25
|
|
26
26
|
/*
|
27
27
|
* Copyright (c) 2013 Algolia
|
@@ -106,9 +106,9 @@ var AlgoliaSearch = function(applicationID, apiKey, methodOrOptions, resolveDNS,
|
|
106
106
|
// If hosts is undefined, initialize it with applicationID
|
107
107
|
if (this._isUndefined(hosts)) {
|
108
108
|
hosts = [
|
109
|
-
this.applicationID + '-1.
|
110
|
-
this.applicationID + '-2.
|
111
|
-
this.applicationID + '-3.
|
109
|
+
this.applicationID + '-1.algolianet.com',
|
110
|
+
this.applicationID + '-2.algolianet.com',
|
111
|
+
this.applicationID + '-3.algolianet.com'
|
112
112
|
];
|
113
113
|
}
|
114
114
|
// detect is we use http or https
|
@@ -118,16 +118,10 @@ var AlgoliaSearch = function(applicationID, apiKey, methodOrOptions, resolveDNS,
|
|
118
118
|
} else if (method === 'https' || method === 'HTTPS') {
|
119
119
|
this.host_protocol = 'https://';
|
120
120
|
}
|
121
|
-
// Add
|
121
|
+
// Add protocol to hosts
|
122
122
|
for (var i = 0; i < hosts.length; ++i) {
|
123
|
-
if (Math.random() > 0.5) {
|
124
|
-
this.hosts.reverse();
|
125
|
-
}
|
126
123
|
this.hosts.push(this.host_protocol + hosts[i]);
|
127
124
|
}
|
128
|
-
if (Math.random() > 0.5) {
|
129
|
-
this.hosts.reverse();
|
130
|
-
}
|
131
125
|
// then add Distributed Search Network host if there is one
|
132
126
|
if (this.dsn || this.dsnHost != null) {
|
133
127
|
if (this.dsnHost) {
|
@@ -143,6 +137,8 @@ var AlgoliaSearch = function(applicationID, apiKey, methodOrOptions, resolveDNS,
|
|
143
137
|
self.options.angular.$http = $http;
|
144
138
|
}]);
|
145
139
|
}
|
140
|
+
|
141
|
+
this._ua = this.options._ua || 'Algolia for vanilla JavaScript ' + window.ALGOLIA_VERSION;
|
146
142
|
};
|
147
143
|
|
148
144
|
// This holds the number of JSONP requests done accross clients
|
@@ -595,6 +591,7 @@ AlgoliaSearch.prototype = {
|
|
595
591
|
|
596
592
|
opts.successiveRetryCount = 0;
|
597
593
|
var impl = function() {
|
594
|
+
|
598
595
|
if (opts.successiveRetryCount >= self.hosts.length) {
|
599
596
|
var error = { message: 'Cannot connect the Algolia\'s Search API. Please send an email to support@algolia.com to report the issue.' };
|
600
597
|
if (!self._isUndefined(callback) && callback) {
|
@@ -665,6 +662,7 @@ AlgoliaSearch.prototype = {
|
|
665
662
|
if (this.tagFilters) {
|
666
663
|
url += '&X-Algolia-TagFilters=' + encodeURIComponent(this.tagFilters);
|
667
664
|
}
|
665
|
+
url += '&X-Algolia-Agent=' + encodeURIComponent(this._ua);
|
668
666
|
for (var i = 0; i < this.extraHeaders.length; ++i) {
|
669
667
|
url += '&' + this.extraHeaders[i].key + '=' + this.extraHeaders[i].value;
|
670
668
|
}
|
@@ -711,6 +709,7 @@ AlgoliaSearch.prototype = {
|
|
711
709
|
if (this.tagFilters) {
|
712
710
|
url += '&X-Algolia-TagFilters=' + encodeURIComponent(this.tagFilters);
|
713
711
|
}
|
712
|
+
url += '&X-Algolia-Agent=' + encodeURIComponent(this._ua);
|
714
713
|
for (var i = 0; i < this.extraHeaders.length; ++i) {
|
715
714
|
url += '&' + this.extraHeaders[i].key + '=' + this.extraHeaders[i].value;
|
716
715
|
}
|
@@ -786,6 +785,8 @@ AlgoliaSearch.prototype = {
|
|
786
785
|
url += '&X-Algolia-UserToken=' + encodeURIComponent(this.userToken);
|
787
786
|
}
|
788
787
|
|
788
|
+
url += '&X-Algolia-Agent=' + encodeURIComponent(this._ua);
|
789
|
+
|
789
790
|
for (var i = 0; i < this.extraHeaders.length; ++i) {
|
790
791
|
url += '&' + this.extraHeaders[i].key + '=' + this.extraHeaders[i].value;
|
791
792
|
}
|
@@ -799,7 +800,7 @@ AlgoliaSearch.prototype = {
|
|
799
800
|
clean();
|
800
801
|
|
801
802
|
opts.callback(true, false, { 'message': 'Timeout - Failed to load JSONP script.' });
|
802
|
-
}, this.requestTimeoutInMs);
|
803
|
+
}, this.requestTimeoutInMs * (opts.successiveRetryCount + 1));
|
803
804
|
|
804
805
|
success = function() {
|
805
806
|
if (done || timedOut) {
|
@@ -896,6 +897,8 @@ AlgoliaSearch.prototype = {
|
|
896
897
|
url += '&X-Algolia-TagFilters=' + encodeURIComponent(this.tagFilters);
|
897
898
|
}
|
898
899
|
|
900
|
+
url += '&X-Algolia-Agent=' + encodeURIComponent(this._ua);
|
901
|
+
|
899
902
|
for (var i = 0; i < this.extraHeaders.length; ++i) {
|
900
903
|
url += '&' + this.extraHeaders[i].key + '=' + this.extraHeaders[i].value;
|
901
904
|
}
|
@@ -958,6 +961,13 @@ AlgoliaSearch.prototype = {
|
|
958
961
|
opts.callback(retry, success, response);
|
959
962
|
};
|
960
963
|
|
964
|
+
// we set an empty onprogress listener
|
965
|
+
// so that XDomainRequest on IE9 is not aborted
|
966
|
+
// refs:
|
967
|
+
// - https://github.com/algolia/algoliasearch-client-js/issues/76
|
968
|
+
// - 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
|
969
|
+
request.onprogress = function noop() {};
|
970
|
+
|
961
971
|
if (this._support.timeout) {
|
962
972
|
// .timeout supported by both XHR and XDR,
|
963
973
|
// we do receive timeout event, tested
|
@@ -1,7 +1,7 @@
|
|
1
1
|
/*!
|
2
|
-
* algoliasearch 2.9.
|
2
|
+
* algoliasearch 2.9.7
|
3
3
|
* https://github.com/algolia/algoliasearch-client-js
|
4
4
|
* Copyright 2014 Algolia SAS; Licensed MIT
|
5
5
|
*/
|
6
6
|
|
7
|
-
function AlgoliaExplainResults(a,b,c){function d(a,b){var c=[];if("object"==typeof a&&"matchedWords"in a&&"value"in a){for(var e=!1,f=0;f<a.matchedWords.length;++f){var g=a.matchedWords[f];g in b||(b[g]=1,e=!0)}e&&c.push(a.value)}else if("[object Array]"===Object.prototype.toString.call(a))for(var h=0;h<a.length;++h){var i=d(a[h],b);c=c.concat(i)}else if("object"==typeof a)for(var j in a)a.hasOwnProperty(j)&&(c=c.concat(d(a[j],b)));return c}function e(a,b,c){var f=a._highlightResult||a;if(-1===c.indexOf("."))return c in f?d(f[c],b):[];for(var g=c.split("."),h=f,i=0;i<g.length;++i){if("[object Array]"===Object.prototype.toString.call(h)){for(var j=[],k=0;k<h.length;++k)j=j.concat(e(h[k],b,g.slice(i).join(".")));return j}if(!(g[i]in h))return[];h=h[g[i]]}return d(h,b)}var f={},g={},h=e(a,g,b);if(f.title=h.length>0?h[0]:"",f.subtitles=[],"undefined"!=typeof c)for(var i=0;i<c.length;++i)for(var j=e(a,g,c[i]),k=0;k<j.length;++k)f.subtitles.push({attr:c[i],value:j[k]});return f}var ALGOLIA_VERSION="2.9.4",AlgoliaSearch=function(a,b,c,d,e){var f=this;this.applicationID=a,this.apiKey=b,this.dsn=!0,this.dsnHost=null,this.hosts=[],this.currentHostIndex=0,this.requestTimeoutInMs=2e3,this.extraHeaders=[],this.jsonp=null,this.options={},this.cache={};var g,h="net";if("string"==typeof c)g=c;else{var i=c||{};this.options=i,this._isUndefined(i.method)||(g=i.method),this._isUndefined(i.tld)||(h=i.tld),this._isUndefined(i.dsn)||(this.dsn=i.dsn),this._isUndefined(i.hosts)||(e=i.hosts),this._isUndefined(i.dsnHost)||(this.dsnHost=i.dsnHost),this._isUndefined(i.requestTimeoutInMs)||(this.requestTimeoutInMs=+i.requestTimeoutInMs),this._isUndefined(i.jsonp)||(this.jsonp=i.jsonp)}this._isUndefined(e)&&(e=[this.applicationID+"-1.algolia."+h,this.applicationID+"-2.algolia."+h,this.applicationID+"-3.algolia."+h]),this.host_protocol="http://",this._isUndefined(g)||null===g?this.host_protocol=("https:"==document.location.protocol?"https":"http")+"://":("https"===g||"HTTPS"===g)&&(this.host_protocol="https://");for(var j=0;j<e.length;++j)Math.random()>.5&&this.hosts.reverse(),this.hosts.push(this.host_protocol+e[j]);Math.random()>.5&&this.hosts.reverse(),(this.dsn||null!=this.dsnHost)&&this.hosts.unshift(this.dsnHost?this.host_protocol+this.dsnHost:this.host_protocol+this.applicationID+"-dsn.algolia."+h),this.options.angular&&this.options.angular.$injector.invoke(["$http","$q",function(a,b){f.options.angular.$q=b,f.options.angular.$http=a}])};AlgoliaSearch.JSONPCounter=0,AlgoliaSearch.prototype={deleteIndex:function(a,b){return this._jsonRequest({method:"DELETE",url:"/1/indexes/"+encodeURIComponent(a),callback:b})},moveIndex:function(a,b,c){var d={operation:"move",destination:b};return this._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(a)+"/operation",body:d,callback:c})},copyIndex:function(a,b,c){var d={operation:"copy",destination:b};return this._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(a)+"/operation",body:d,callback:c})},getLogs:function(a,b,c){return 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,b){var c="undefined"!=typeof b?"?page="+b:"";return this._jsonRequest({method:"GET",url:"/1/indexes"+c,callback:a})},initIndex:function(a){return new this.Index(this,a)},listUserKeys:function(a){return this._jsonRequest({method:"GET",url:"/1/keys",callback:a})},getUserKeyACL:function(a,b){return this._jsonRequest({method:"GET",url:"/1/keys/"+a,callback:b})},deleteUserKey:function(a,b){return this._jsonRequest({method:"DELETE",url:"/1/keys/"+a,callback:b})},addUserKey:function(a,b){return this.addUserKeyWithValidity(a,0,0,0,b)},addUserKeyWithValidity:function(a,b,c,d,e){var f={};return f.acl=a,f.validity=b,f.maxQueriesPerIPPerHour=c,f.maxHitsPerQuery=d,this._jsonRequest({method:"POST",url:"/1/keys",body:f,callback:e})},setSecurityTags:function(a){if("[object Array]"===Object.prototype.toString.call(a)){for(var b=[],c=0;c<a.length;++c)if("[object Array]"===Object.prototype.toString.call(a[c])){for(var d=[],e=0;e<a[c].length;++e)d.push(a[c][e]);b.push("("+d.join(",")+")")}else b.push(a[c]);a=b.join(",")}this.tagFilters=a},setUserToken:function(a){this.userToken=a},startQueriesBatch:function(){this.batch=[]},addQueryInBatch:function(a,b,c){var d="query="+encodeURIComponent(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:[]},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))return this._sendQueriesBatch(d,a);var f=window.setTimeout(function(){c._sendQueriesBatch(d,a)},b);c.onDelayTrigger=f},setRequestTimeout:function(a){a&&(this.requestTimeoutInMs=parseInt(a,10))},Index:function(a,b){this.indexName=b,this.as=a,this.typeAheadArgs=null,this.typeAheadValueOption=null,this.cache={}},setExtraHeader:function(a,b){this.extraHeaders.push({key:a,value:b})},_sendQueriesBatch:function(a,b){if(null===this.jsonp){var c=this;return this._jsonRequest({cache:this.cache,method:"POST",url:"/1/indexes/*/queries",body:a,callback:function(d,e){d?(c.jsonp=!1,b&&b(d,e)):(c.jsonp=!0,c._sendQueriesBatch(a,b))}})}if(this.jsonp){for(var d="",e=0;e<a.requests.length;++e){var f="/1/indexes/"+encodeURIComponent(a.requests[e].indexName)+"?"+a.requests[e].params;d+=e+"="+encodeURIComponent(f)+"&"}var g={params:d};return this._jsonRequest({cache:this.cache,method:"GET",url:"/1/indexes/*",body:g,callback:b})}return 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,f=null;if(this.options.jQuery?(f=this.options.jQuery.$.Deferred(),f.promise=f.promise()):this.options.angular&&(f=this.options.angular.$q.defer()),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&&setTimeout(function(){c(!0,d[e])},1),f&&f.resolve(d[e]),f&&f.promise;a.successiveRetryCount=0;var g=function(){if(a.successiveRetryCount>=b.hosts.length){var h={message:"Cannot connect the Algolia's Search API. Please send an email to support@algolia.com to report the issue."};return!b._isUndefined(c)&&c&&(a.successiveRetryCount=0,c(!1,h)),void(f&&f.reject(h))}a.callback=function(h,i,j){i&&!b._isUndefined(a.cache)&&(d[e]=j),!i&&h?(b.currentHostIndex=++b.currentHostIndex%b.hosts.length,a.successiveRetryCount+=1,g()):(a.successiveRetryCount=0,f&&(i?f.resolve(j):f.reject(j)),!b._isUndefined(c)&&c&&c(i,j))},a.hostname=b.hosts[b.currentHostIndex],b._jsonRequestByHost(a)};return g(),f&&f.promise},_jsonRequestByHost:function(a){var b=a.hostname+a.url;this.jsonp?this._makeJsonpRequestByHost(b,a):this.options.jQuery?this._makejQueryRequestByHost(b,a):this.options.angular?this._makeAngularRequestByHost(b,a):this._makeXmlHttpRequestByHost(b,a)},_makeAngularRequestByHost:function(a,b){var c=null;this._isUndefined(b.body)||(c=JSON.stringify(b.body)),a+=(-1===a.indexOf("?")?"?":"&")+"X-Algolia-API-Key="+this.apiKey,a+="&X-Algolia-Application-Id="+this.applicationID,this.userToken&&(a+="&X-Algolia-UserToken="+encodeURIComponent(this.userToken)),this.tagFilters&&(a+="&X-Algolia-TagFilters="+encodeURIComponent(this.tagFilters));for(var d=0;d<this.extraHeaders.length;++d)a+="&"+this.extraHeaders[d].key+"="+this.extraHeaders[d].value;this.options.angular.$http({url:a,method:b.method,data:c,cache:!1,timeout:this.requestTimeoutInMs*(b.successiveRetryCount+1)}).then(function(a){b.callback(!1,!0,a.data)},function(a){0===a.status?b.callback(!0,!1,a.data):400==a.status||403===a.status||404===a.status?b.callback(!1,!1,a.data):b.callback(!0,!1,a.data)})},_makejQueryRequestByHost:function(a,b){var c=null;this._isUndefined(b.body)||(c=JSON.stringify(b.body)),a+=(-1===a.indexOf("?")?"?":"&")+"X-Algolia-API-Key="+this.apiKey,a+="&X-Algolia-Application-Id="+this.applicationID,this.userToken&&(a+="&X-Algolia-UserToken="+encodeURIComponent(this.userToken)),this.tagFilters&&(a+="&X-Algolia-TagFilters="+encodeURIComponent(this.tagFilters));for(var d=0;d<this.extraHeaders.length;++d)a+="&"+this.extraHeaders[d].key+"="+this.extraHeaders[d].value;this.options.jQuery.$.ajax(a,{type:b.method,timeout:this.requestTimeoutInMs*(b.successiveRetryCount+1),dataType:"json",data:c,error:function(c,d,e){"timeout"===d?b.callback(!0,!1,{message:"Timeout - Could not connect to endpoint "+a}):400===c.status||403===c.status||404===c.status?b.callback(!1,!1,c.responseJSON):b.callback(!0,!1,{message:e})},success:function(a){b.callback(!1,!0,a)}})},_makeJsonpRequestByHost:function(a,b){if("GET"!==b.method)return void b.callback(!0,!1,{message:"Method "+b.method+" "+a+" is not supported by JSONP."});var c=!1,d=!1;AlgoliaSearch.JSONPCounter+=1;var e,f,g,h=document.getElementsByTagName("head")[0],i=document.createElement("script"),j="algoliaJSONP_"+AlgoliaSearch.JSONPCounter,k=!1;window[j]=function(a){try{delete window[j]}catch(e){window[j]=void 0}if(!d){var f=a&&a.message&&a.status||a&&200,g=200===f,h=!g&&400!==f&&403!==f&&404!==f;c=!0,b.callback(h,g,a)}},i.type="text/javascript",a+="?callback="+j+"&X-Algolia-Application-Id="+this.applicationID+"&X-Algolia-API-Key="+this.apiKey,this.tagFilters&&(a+="&X-Algolia-TagFilters="+encodeURIComponent(this.tagFilters)),this.userToken&&(a+="&X-Algolia-UserToken="+encodeURIComponent(this.userToken));for(var l=0;l<this.extraHeaders.length;++l)a+="&"+this.extraHeaders[l].key+"="+this.extraHeaders[l].value;b.body&&b.body.params&&(a+="&"+b.body.params),e=setTimeout(function(){d=!0,g(),b.callback(!0,!1,{message:"Timeout - Failed to load JSONP script."})},this.requestTimeoutInMs),f=function(){k||d||(k=!0,g(),c||b.callback(!0,!1,{message:"Failed to load JSONP script."}))},g=function(){clearTimeout(e),i.onload=null,i.onreadystatechange=null,i.onerror=null,h.removeChild(i);try{delete window[j],delete window[j+"_loaded"]}catch(a){window[j]=null,window[j+"_loaded"]=null}},i.onreadystatechange=function(){("loaded"===this.readyState||"complete"===this.readyState)&&f()},i.onload=function(){f()},i.onerror=function(){k||d||(g(),b.callback(!0,!1,{message:"Failed to load JSONP script."}))},i.async=!0,i.defer=!0,i.src=a,h.appendChild(i)},_makeXmlHttpRequestByHost:function(a,b){if(!this._support.cors&&!this._support.hasXDomainRequest)return void b.callback(!1,!1,{message:"CORS not supported"});var c,d,e,f=null,g=this._support.cors?new XMLHttpRequest:new XDomainRequest,h=this;this._isUndefined(b.body)||(f=JSON.stringify(b.body)),a+=(-1===a.indexOf("?")?"?":"&")+"X-Algolia-API-Key="+this.apiKey,a+="&X-Algolia-Application-Id="+this.applicationID,this.userToken&&(a+="&X-Algolia-UserToken="+encodeURIComponent(this.userToken)),this.tagFilters&&(a+="&X-Algolia-TagFilters="+encodeURIComponent(this.tagFilters));for(var i=0;i<this.extraHeaders.length;++i)a+="&"+this.extraHeaders[i].key+"="+this.extraHeaders[i].value;e=function(){h._support.timeout||(d=!0,g.abort()),b.callback(!0,!1,{message:"Timeout - Could not connect to endpoint "+a})},g instanceof XMLHttpRequest?g.open(b.method,a,!0):g.open(b.method,a),this._support.cors&&null!==f&&"GET"!==b.method&&g.setRequestHeader("Content-type","application/x-www-form-urlencoded"),g.onload=function(){if(!d){h._support.timeout||clearTimeout(c);var a=null;try{a=JSON.parse(g.responseText)}catch(e){}var f=g.status||a&&a.message&&a.status||a&&200,i=200===f||201===f,j=!i&&400!==f&&403!==f&&404!==f;b.callback(j,i,a)}},this._support.timeout?(g.timeout=this.requestTimeoutInMs*(b.successiveRetryCount+1),g.ontimeout=e):c=setTimeout(e,this.requestTimeoutInMs*(b.successiveRetryCount+1)),g.onerror=function(a){d||(h._support.timeout||clearTimeout(c),b.callback(!0,!1,{message:"Could not connect to host",error:a}))},g.send(f)},_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("[object Array]"===Object.prototype.toString.call(a[c])?JSON.stringify(a[c]):a[c]));return b},_isUndefined:function(a){return void 0===a},_support:{hasXMLHttpRequest:"XMLHttpRequest"in window,hasXDomainRequest:"XDomainRequest"in window,cors:"withCredentials"in new XMLHttpRequest,timeout:"timeout"in new XMLHttpRequest}},AlgoliaSearch.prototype.Index.prototype={clearCache:function(){this.cache={}},addObject:function(a,b,c){var d=this;return this.as._jsonRequest(this.as._isUndefined(c)?{method:"POST",url:"/1/indexes/"+encodeURIComponent(d.indexName),body:a,callback:b}:{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)}return this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/batch",body:d,callback:b})},getObject:function(a,b,c){"[object Array]"!==Object.prototype.toString.call(b)||c||(c=b,b=null);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]}return this.as._jsonRequest({method:"GET",url:"/1/indexes/"+encodeURIComponent(d.indexName)+"/"+encodeURIComponent(a)+e,callback:b})},partialUpdateObject:function(a,b){var c=this;return this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/"+encodeURIComponent(a.objectID)+"/partial",body:a,callback:b})},partialUpdateObjects:function(a,b){for(var c=this,d={requests:[]},e=0;e<a.length;++e){var f={action:"partialUpdateObject",objectID:a[e].objectID,body:a[e]};d.requests.push(f)}return this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/batch",body:d,callback:b})},saveObject:function(a,b){var c=this;return 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:a[e].objectID,body:a[e]};d.requests.push(f)}return 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 void b(!1,{message:"empty objectID"});var c=this;return this.as._jsonRequest({method:"DELETE",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/"+encodeURIComponent(a),callback:b})},search:function(a,b,c,d){(void 0===a||null===a)&&(a=""),"function"==typeof a&&(b=a,a=""),"object"!=typeof b||!this.as._isUndefined(c)&&c||(c=b,b=null);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))return this._search(f,b);var g=window.setTimeout(function(){e._search(f,b)},d);e.onDelayTrigger=g},browse:function(a,b,c){+b>0&&(this.as._isUndefined(c)||!c)&&(c=b,b=null);var d=this,e="?page="+a;return this.as._isUndefined(c)||(e+="&hitsPerPage="+c),this.as._jsonRequest({method:"GET",url:"/1/indexes/"+encodeURIComponent(d.indexName)+"/browse"+e,callback:b})},ttAdapter:function(a){var b=this;return function(c,d){b.search(c,function(a,b){d(a?b.hits:b&&b.message)},a)}},waitTask:function(a,b){var c=this;return this.as._jsonRequest({method:"GET",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/task/"+a,callback:function(d,e){d?"published"===e.status?b(!0,e):setTimeout(function(){c.waitTask(a,b)},100):b(!1,e)}})},clearIndex:function(a){var b=this;return this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(b.indexName)+"/clear",callback:a})},getSettings:function(a){var b=this;return this.as._jsonRequest({method:"GET",url:"/1/indexes/"+encodeURIComponent(b.indexName)+"/settings",callback:a})},setSettings:function(a,b){var c=this;return this.as._jsonRequest({method:"PUT",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/settings",body:a,callback:b})},listUserKeys:function(a){var b=this;return this.as._jsonRequest({method:"GET",url:"/1/indexes/"+encodeURIComponent(b.indexName)+"/keys",callback:a})},getUserKeyACL:function(a,b){var c=this;return this.as._jsonRequest({method:"GET",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/keys/"+a,callback:b})},deleteUserKey:function(a,b){var c=this;return this.as._jsonRequest({method:"DELETE",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/keys/"+a,callback:b})},addUserKey:function(a,b){var c=this,d={};return d.acl=a,this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/keys",body:d,callback:b})},addUserKeyWithValidity:function(a,b,c,d,e){var f=this,g={};return g.acl=a,g.validity=b,g.maxQueriesPerIPPerHour=c,g.maxHitsPerQuery=d,this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(f.indexName)+"/keys",body:g,callback:e})},_search:function(a,b){var c={params:a};if(null===this.as.jsonp){var d=this;return this.as._jsonRequest({cache:this.cache,method:"POST",url:"/1/indexes/"+encodeURIComponent(this.indexName)+"/query",body:c,callback:function(c,e){var f=e&&e.status;c||f&&4===Math.floor(f/100)||1===Math.floor(f/100)?(d.as.jsonp=!1,b&&b(c,e)):(d.as.jsonp=!0,d._search(a,b))}})}return this.as._jsonRequest(this.as.jsonp?{cache:this.cache,method:"GET",url:"/1/indexes/"+encodeURIComponent(this.indexName),body:c,callback:b}:{cache:this.cache,method:"POST",url:"/1/indexes/"+encodeURIComponent(this.indexName)+"/query",body:c,callback:b})},as:null,indexName:null,typeAheadArgs:null,typeAheadValueOption:null},function(){var a=function(a){a=a||{};for(var b=1;b<arguments.length;b++)if(arguments[b])for(var c in arguments[b])arguments[b].hasOwnProperty(c)&&(a[c]=arguments[b][c]);return a};window.AlgoliaSearchHelper=function(b,c,d){var e={facets:[],disjunctiveFacets:[],hitsPerPage:20,defaultFacetFilters:[]};this.init(b,c,a({},e,d))},AlgoliaSearchHelper.prototype={init:function(a,b,c){this.client=a,this.index=b,this.options=c,this.page=0,this.refinements={},this.excludes={},this.disjunctiveRefinements={},this.extraQueries=[]},search:function(a,b,c){this.q=a,this.searchCallback=b,this.searchParams=c||{},this.page=this.page||0,this.refinements=this.refinements||{},this.disjunctiveRefinements=this.disjunctiveRefinements||{},this._search()},clearRefinements:function(){this.disjunctiveRefinements={},this.refinements={}},addDisjunctiveRefine:function(a,b){this.disjunctiveRefinements=this.disjunctiveRefinements||{},this.disjunctiveRefinements[a]=this.disjunctiveRefinements[a]||{},this.disjunctiveRefinements[a][b]=!0},removeDisjunctiveRefine:function(a,b){this.disjunctiveRefinements=this.disjunctiveRefinements||{},this.disjunctiveRefinements[a]=this.disjunctiveRefinements[a]||{};try{delete this.disjunctiveRefinements[a][b]}catch(c){this.disjunctiveRefinements[a][b]=void 0}},addRefine:function(a,b){var c=a+":"+b;this.refinements=this.refinements||{},this.refinements[c]=!0},removeRefine:function(a,b){var c=a+":"+b;this.refinements=this.refinements||{},this.refinements[c]=!1},addExclude:function(a,b){var c=a+":-"+b;this.excludes=this.excludes||{},this.excludes[c]=!0},removeExclude:function(a,b){var c=a+":-"+b;this.excludes=this.excludes||{},this.excludes[c]=!1},toggleExclude:function(a,b){for(var c=0;c<this.options.facets.length;++c)if(this.options.facets[c]==a){var d=a+":-"+b;return this.excludes[d]=!this.excludes[d],this.page=0,this._search(),!0}return!1},toggleRefine:function(a,b){for(var c=0;c<this.options.facets.length;++c)if(this.options.facets[c]==a){var d=a+":"+b;return this.refinements[d]=!this.refinements[d],this.page=0,this._search(),!0}this.disjunctiveRefinements[a]=this.disjunctiveRefinements[a]||{};for(var e=0;e<this.options.disjunctiveFacets.length;++e)if(this.options.disjunctiveFacets[e]==a)return this.disjunctiveRefinements[a][b]=!this.disjunctiveRefinements[a][b],this.page=0,this._search(),!0;return!1},isRefined:function(a,b){var c=a+":"+b;return this.refinements[c]?!0:this.disjunctiveRefinements[a]&&this.disjunctiveRefinements[a][b]?!0:!1},isExcluded:function(a,b){var c=a+":-"+b;return this.excludes[c]?!0:!1},nextPage:function(){this._gotoPage(this.page+1)},previousPage:function(){this.page>0&&this._gotoPage(this.page-1)},gotoPage:function(a){this._gotoPage(a)},setPage:function(a){this.page=a},setIndex:function(a){this.index=a},getIndex:function(){return this.index},clearExtraQueries:function(){this.extraQueries=[]},addExtraQuery:function(a,b,c){this.extraQueries.push({index:a,query:b,params:c||{}})},_gotoPage:function(a){this.page=a,this._search()},_search:function(){this.client.startQueriesBatch(),this.client.addQueryInBatch(this.index,this.q,this._getHitsSearchParams());var a=[],b={},c=0;for(c=0;c<this.options.disjunctiveFacets.length;++c){var d=this.options.disjunctiveFacets[c];this._hasDisjunctiveRefinements(d)?a.push(d):b[d]=!0}for(c=0;c<a.length;++c)this.client.addQueryInBatch(this.index,this.q,this._getDisjunctiveFacetSearchParams(a[c]));for(c=0;c<this.extraQueries.length;++c)this.client.addQueryInBatch(this.extraQueries[c].index,this.extraQueries[c].query,this.extraQueries[c].params);var e=this;this.client.sendQueriesBatch(function(d,f){if(!d)return void e.searchCallback(!1,f);var g=f.results[0];g.disjunctiveFacets=g.disjunctiveFacets||{},g.facets_stats=g.facets_stats||{};for(var h in b)if(g.facets[h]&&!g.disjunctiveFacets[h]){g.disjunctiveFacets[h]=g.facets[h];try{delete g.facets[h]}catch(i){g.facets[h]=void 0}}for(c=0;c<a.length;++c){for(var j in f.results[c+1].facets)if(g.disjunctiveFacets[j]=f.results[c+1].facets[j],e.disjunctiveRefinements[j])for(var k in e.disjunctiveRefinements[j])!g.disjunctiveFacets[j][k]&&e.disjunctiveRefinements[j][k]&&(g.disjunctiveFacets[j][k]=0);for(var l in f.results[c+1].facets_stats)g.facets_stats[l]=f.results[c+1].facets_stats[l]}g.facetStats=g.facets_stats;for(var m in e.excludes)if(e.excludes[m]){var i=m.indexOf(":-"),h=m.slice(0,i),k=m.slice(i+2);g.facets[h]=g.facets[h]||{},g.facets[h][k]||(g.facets[h][k]=0)}if(0===e.extraQueries.length)e.searchCallback(!0,g);else{var n={results:[g]};for(c=0;c<e.extraQueries.length;++c)n.results.push(f.results[1+a.length+c]);e.searchCallback(!0,n)}})},_getHitsSearchParams:function(){var b=[],c=0;for(c=0;c<this.options.facets.length;++c)b.push(this.options.facets[c]);for(c=0;c<this.options.disjunctiveFacets.length;++c){var d=this.options.disjunctiveFacets[c];this._hasDisjunctiveRefinements(d)||b.push(d)}return a({},{hitsPerPage:this.options.hitsPerPage,page:this.page,facets:b,facetFilters:this._getFacetFilters()},this.searchParams)},_getDisjunctiveFacetSearchParams:function(b){return a({},this.searchParams,{hitsPerPage:1,page:0,attributesToRetrieve:[],attributesToHighlight:[],attributesToSnippet:[],facets:b,facetFilters:this._getFacetFilters(b),analytics:!1})},_hasDisjunctiveRefinements:function(a){for(var b in this.disjunctiveRefinements[a])if(this.disjunctiveRefinements[a][b])return!0;return!1},_getFacetFilters:function(a){var b=[];if(this.options.defaultFacetFilters)for(var c=0;c<this.options.defaultFacetFilters.length;++c)b.push(this.options.defaultFacetFilters[c]);for(var d in this.refinements)this.refinements[d]&&b.push(d);for(var d in this.excludes)this.excludes[d]&&b.push(d);for(var e in this.disjunctiveRefinements)if(e!=a){var f=[];for(var g in this.disjunctiveRefinements[e])this.disjunctiveRefinements[e][g]&&f.push(e+":"+g);f.length>0&&b.push(f)}return b}}}(),function(){window.AlgoliaPlaces=function(a,b){this.init(a,b)},AlgoliaPlaces.prototype={init:function(a,b){this.client=new AlgoliaSearch(a,b,"http",!0,["places-1.algolia.io","places-2.algolia.io","places-3.algolia.io"]),this.cache={}},search:function(a,b,c){var d="query="+encodeURIComponent(a);this.client._isUndefined(c)||null==c||(d=this.client._getSearchParams(c,d));var e={params:d,apiKey:this.client.apiKey,appID:this.client.applicationID};this.client._jsonRequest({cache:this.cache,method:"POST",url:"/1/places/query",body:e,callback:b,removeCustomHTTPHeaders:!0})}}}(),"object"!=typeof JSON&&(JSON={}),function(){"use strict";function f(a){return 10>a?"0"+a:a}function quote(a){return escapable.lastIndex=0,escapable.test(a)?'"'+a.replace(escapable,function(a){var b=meta[a];return"string"==typeof b?b:"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+a+'"'}function str(a,b){var c,d,e,f,g,h=gap,i=b[a];switch(i&&"object"==typeof i&&"function"==typeof i.toJSON&&(i=i.toJSON(a)),"function"==typeof rep&&(i=rep.call(b,a,i)),typeof i){case"string":return quote(i);case"number":return isFinite(i)?String(i):"null";case"boolean":case"null":return String(i);case"object":if(!i)return"null";if(gap+=indent,g=[],"[object Array]"===Object.prototype.toString.apply(i)){for(f=i.length,c=0;f>c;c+=1)g[c]=str(c,i)||"null";return e=0===g.length?"[]":gap?"[\n"+gap+g.join(",\n"+gap)+"\n"+h+"]":"["+g.join(",")+"]",gap=h,e}if(rep&&"object"==typeof rep)for(f=rep.length,c=0;f>c;c+=1)"string"==typeof rep[c]&&(d=rep[c],e=str(d,i),e&&g.push(quote(d)+(gap?": ":":")+e));else for(d in i)Object.prototype.hasOwnProperty.call(i,d)&&(e=str(d,i),e&&g.push(quote(d)+(gap?": ":":")+e));return e=0===g.length?"{}":gap?"{\n"+gap+g.join(",\n"+gap)+"\n"+h+"}":"{"+g.join(",")+"}",gap=h,e}}"function"!=typeof Date.prototype.toJSON&&(Date.prototype.toJSON=function(){return isFinite(this.valueOf())?this.getUTCFullYear()+"-"+f(this.getUTCMonth()+1)+"-"+f(this.getUTCDate())+"T"+f(this.getUTCHours())+":"+f(this.getUTCMinutes())+":"+f(this.getUTCSeconds())+"Z":null},String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(){return this.valueOf()});var cx,escapable,gap,indent,meta,rep;"function"!=typeof JSON.stringify&&(escapable=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,meta={"\b":"\\b"," ":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},JSON.stringify=function(a,b,c){var d;if(gap="",indent="","number"==typeof c)for(d=0;c>d;d+=1)indent+=" ";else"string"==typeof c&&(indent=c);if(rep=b,b&&"function"!=typeof b&&("object"!=typeof b||"number"!=typeof b.length))throw new Error("JSON.stringify");return str("",{"":a})}),"function"!=typeof JSON.parse&&(cx=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,JSON.parse=function(text,reviver){function walk(a,b){var c,d,e=a[b];if(e&&"object"==typeof e)for(c in e)Object.prototype.hasOwnProperty.call(e,c)&&(d=walk(e,c),void 0!==d?e[c]=d:delete e[c]);return reviver.call(a,b,e)}var j;if(text=String(text),cx.lastIndex=0,cx.test(text)&&(text=text.replace(cx,function(a){return"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)})),/^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,"@").replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,"]").replace(/(?:^|:|,)(?:\s*\[)+/g,"")))return j=eval("("+text+")"),"function"==typeof reviver?walk({"":j},""):j;throw new SyntaxError("JSON.parse")})}();
|
7
|
+
function AlgoliaExplainResults(a,b,c){function d(a,b){var c=[];if("object"==typeof a&&"matchedWords"in a&&"value"in a){for(var e=!1,f=0;f<a.matchedWords.length;++f){var g=a.matchedWords[f];g in b||(b[g]=1,e=!0)}e&&c.push(a.value)}else if("[object Array]"===Object.prototype.toString.call(a))for(var h=0;h<a.length;++h){var i=d(a[h],b);c=c.concat(i)}else if("object"==typeof a)for(var j in a)a.hasOwnProperty(j)&&(c=c.concat(d(a[j],b)));return c}function e(a,b,c){var f=a._highlightResult||a;if(-1===c.indexOf("."))return c in f?d(f[c],b):[];for(var g=c.split("."),h=f,i=0;i<g.length;++i){if("[object Array]"===Object.prototype.toString.call(h)){for(var j=[],k=0;k<h.length;++k)j=j.concat(e(h[k],b,g.slice(i).join(".")));return j}if(!(g[i]in h))return[];h=h[g[i]]}return d(h,b)}var f={},g={},h=e(a,g,b);if(f.title=h.length>0?h[0]:"",f.subtitles=[],"undefined"!=typeof c)for(var i=0;i<c.length;++i)for(var j=e(a,g,c[i]),k=0;k<j.length;++k)f.subtitles.push({attr:c[i],value:j[k]});return f}var ALGOLIA_VERSION="2.9.7",AlgoliaSearch=function(a,b,c,d,e){var f=this;this.applicationID=a,this.apiKey=b,this.dsn=!0,this.dsnHost=null,this.hosts=[],this.currentHostIndex=0,this.requestTimeoutInMs=2e3,this.extraHeaders=[],this.jsonp=null,this.options={},this.cache={};var g,h="net";if("string"==typeof c)g=c;else{var i=c||{};this.options=i,this._isUndefined(i.method)||(g=i.method),this._isUndefined(i.tld)||(h=i.tld),this._isUndefined(i.dsn)||(this.dsn=i.dsn),this._isUndefined(i.hosts)||(e=i.hosts),this._isUndefined(i.dsnHost)||(this.dsnHost=i.dsnHost),this._isUndefined(i.requestTimeoutInMs)||(this.requestTimeoutInMs=+i.requestTimeoutInMs),this._isUndefined(i.jsonp)||(this.jsonp=i.jsonp)}this._isUndefined(e)&&(e=[this.applicationID+"-1.algolianet.com",this.applicationID+"-2.algolianet.com",this.applicationID+"-3.algolianet.com"]),this.host_protocol="http://",this._isUndefined(g)||null===g?this.host_protocol=("https:"==document.location.protocol?"https":"http")+"://":("https"===g||"HTTPS"===g)&&(this.host_protocol="https://");for(var j=0;j<e.length;++j)this.hosts.push(this.host_protocol+e[j]);(this.dsn||null!=this.dsnHost)&&(this.dsnHost?this.hosts.unshift(this.host_protocol+this.dsnHost):this.hosts.unshift(this.host_protocol+this.applicationID+"-dsn.algolia."+h)),this.options.angular&&this.options.angular.$injector.invoke(["$http","$q",function(a,b){f.options.angular.$q=b,f.options.angular.$http=a}]),this._ua=this.options._ua||"Algolia for vanilla JavaScript "+window.ALGOLIA_VERSION};AlgoliaSearch.JSONPCounter=0,AlgoliaSearch.prototype={deleteIndex:function(a,b){return this._jsonRequest({method:"DELETE",url:"/1/indexes/"+encodeURIComponent(a),callback:b})},moveIndex:function(a,b,c){var d={operation:"move",destination:b};return this._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(a)+"/operation",body:d,callback:c})},copyIndex:function(a,b,c){var d={operation:"copy",destination:b};return this._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(a)+"/operation",body:d,callback:c})},getLogs:function(a,b,c){return 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,b){var c="undefined"!=typeof b?"?page="+b:"";return this._jsonRequest({method:"GET",url:"/1/indexes"+c,callback:a})},initIndex:function(a){return new this.Index(this,a)},listUserKeys:function(a){return this._jsonRequest({method:"GET",url:"/1/keys",callback:a})},getUserKeyACL:function(a,b){return this._jsonRequest({method:"GET",url:"/1/keys/"+a,callback:b})},deleteUserKey:function(a,b){return this._jsonRequest({method:"DELETE",url:"/1/keys/"+a,callback:b})},addUserKey:function(a,b){return this.addUserKeyWithValidity(a,0,0,0,b)},addUserKeyWithValidity:function(a,b,c,d,e){var f={};return f.acl=a,f.validity=b,f.maxQueriesPerIPPerHour=c,f.maxHitsPerQuery=d,this._jsonRequest({method:"POST",url:"/1/keys",body:f,callback:e})},setSecurityTags:function(a){if("[object Array]"===Object.prototype.toString.call(a)){for(var b=[],c=0;c<a.length;++c)if("[object Array]"===Object.prototype.toString.call(a[c])){for(var d=[],e=0;e<a[c].length;++e)d.push(a[c][e]);b.push("("+d.join(",")+")")}else b.push(a[c]);a=b.join(",")}this.tagFilters=a},setUserToken:function(a){this.userToken=a},startQueriesBatch:function(){this.batch=[]},addQueryInBatch:function(a,b,c){var d="query="+encodeURIComponent(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:[]},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))return this._sendQueriesBatch(d,a);var f=window.setTimeout(function(){c._sendQueriesBatch(d,a)},b);c.onDelayTrigger=f},setRequestTimeout:function(a){a&&(this.requestTimeoutInMs=parseInt(a,10))},Index:function(a,b){this.indexName=b,this.as=a,this.typeAheadArgs=null,this.typeAheadValueOption=null,this.cache={}},setExtraHeader:function(a,b){this.extraHeaders.push({key:a,value:b})},_sendQueriesBatch:function(a,b){if(null===this.jsonp){var c=this;return this._jsonRequest({cache:this.cache,method:"POST",url:"/1/indexes/*/queries",body:a,callback:function(d,e){d?(c.jsonp=!1,b&&b(d,e)):(c.jsonp=!0,c._sendQueriesBatch(a,b))}})}if(this.jsonp){for(var d="",e=0;e<a.requests.length;++e){var f="/1/indexes/"+encodeURIComponent(a.requests[e].indexName)+"?"+a.requests[e].params;d+=e+"="+encodeURIComponent(f)+"&"}var g={params:d};return this._jsonRequest({cache:this.cache,method:"GET",url:"/1/indexes/*",body:g,callback:b})}return 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,f=null;if(this.options.jQuery?(f=this.options.jQuery.$.Deferred(),f.promise=f.promise()):this.options.angular&&(f=this.options.angular.$q.defer()),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&&setTimeout(function(){c(!0,d[e])},1),f&&f.resolve(d[e]),f&&f.promise;a.successiveRetryCount=0;var g=function(){if(a.successiveRetryCount>=b.hosts.length){var h={message:"Cannot connect the Algolia's Search API. Please send an email to support@algolia.com to report the issue."};return!b._isUndefined(c)&&c&&(a.successiveRetryCount=0,c(!1,h)),void(f&&f.reject(h))}a.callback=function(h,i,j){i&&!b._isUndefined(a.cache)&&(d[e]=j),!i&&h?(b.currentHostIndex=++b.currentHostIndex%b.hosts.length,a.successiveRetryCount+=1,g()):(a.successiveRetryCount=0,f&&(i?f.resolve(j):f.reject(j)),!b._isUndefined(c)&&c&&c(i,j))},a.hostname=b.hosts[b.currentHostIndex],b._jsonRequestByHost(a)};return g(),f&&f.promise},_jsonRequestByHost:function(a){var b=a.hostname+a.url;this.jsonp?this._makeJsonpRequestByHost(b,a):this.options.jQuery?this._makejQueryRequestByHost(b,a):this.options.angular?this._makeAngularRequestByHost(b,a):this._makeXmlHttpRequestByHost(b,a)},_makeAngularRequestByHost:function(a,b){var c=null;this._isUndefined(b.body)||(c=JSON.stringify(b.body)),a+=(-1===a.indexOf("?")?"?":"&")+"X-Algolia-API-Key="+this.apiKey,a+="&X-Algolia-Application-Id="+this.applicationID,this.userToken&&(a+="&X-Algolia-UserToken="+encodeURIComponent(this.userToken)),this.tagFilters&&(a+="&X-Algolia-TagFilters="+encodeURIComponent(this.tagFilters)),a+="&X-Algolia-Agent="+encodeURIComponent(this._ua);for(var d=0;d<this.extraHeaders.length;++d)a+="&"+this.extraHeaders[d].key+"="+this.extraHeaders[d].value;this.options.angular.$http({url:a,method:b.method,data:c,cache:!1,timeout:this.requestTimeoutInMs*(b.successiveRetryCount+1)}).then(function(a){b.callback(!1,!0,a.data)},function(a){0===a.status?b.callback(!0,!1,a.data):400==a.status||403===a.status||404===a.status?b.callback(!1,!1,a.data):b.callback(!0,!1,a.data)})},_makejQueryRequestByHost:function(a,b){var c=null;this._isUndefined(b.body)||(c=JSON.stringify(b.body)),a+=(-1===a.indexOf("?")?"?":"&")+"X-Algolia-API-Key="+this.apiKey,a+="&X-Algolia-Application-Id="+this.applicationID,this.userToken&&(a+="&X-Algolia-UserToken="+encodeURIComponent(this.userToken)),this.tagFilters&&(a+="&X-Algolia-TagFilters="+encodeURIComponent(this.tagFilters)),a+="&X-Algolia-Agent="+encodeURIComponent(this._ua);for(var d=0;d<this.extraHeaders.length;++d)a+="&"+this.extraHeaders[d].key+"="+this.extraHeaders[d].value;this.options.jQuery.$.ajax(a,{type:b.method,timeout:this.requestTimeoutInMs*(b.successiveRetryCount+1),dataType:"json",data:c,error:function(c,d,e){"timeout"===d?b.callback(!0,!1,{message:"Timeout - Could not connect to endpoint "+a}):400===c.status||403===c.status||404===c.status?b.callback(!1,!1,c.responseJSON):b.callback(!0,!1,{message:e})},success:function(a,c,d){b.callback(!1,!0,a)}})},_makeJsonpRequestByHost:function(a,b){if("GET"!==b.method)return void b.callback(!0,!1,{message:"Method "+b.method+" "+a+" is not supported by JSONP."});var c=!1,d=!1;AlgoliaSearch.JSONPCounter+=1;var e,f,g,h=document.getElementsByTagName("head")[0],i=document.createElement("script"),j="algoliaJSONP_"+AlgoliaSearch.JSONPCounter,k=!1;window[j]=function(a){try{delete window[j]}catch(e){window[j]=void 0}if(!d){var f=a&&a.message&&a.status||a&&200,g=200===f,h=!g&&400!==f&&403!==f&&404!==f;c=!0,b.callback(h,g,a)}},i.type="text/javascript",a+="?callback="+j+"&X-Algolia-Application-Id="+this.applicationID+"&X-Algolia-API-Key="+this.apiKey,this.tagFilters&&(a+="&X-Algolia-TagFilters="+encodeURIComponent(this.tagFilters)),this.userToken&&(a+="&X-Algolia-UserToken="+encodeURIComponent(this.userToken)),a+="&X-Algolia-Agent="+encodeURIComponent(this._ua);for(var l=0;l<this.extraHeaders.length;++l)a+="&"+this.extraHeaders[l].key+"="+this.extraHeaders[l].value;b.body&&b.body.params&&(a+="&"+b.body.params),e=setTimeout(function(){d=!0,g(),b.callback(!0,!1,{message:"Timeout - Failed to load JSONP script."})},this.requestTimeoutInMs*(b.successiveRetryCount+1)),f=function(){k||d||(k=!0,g(),c||b.callback(!0,!1,{message:"Failed to load JSONP script."}))},g=function(){clearTimeout(e),i.onload=null,i.onreadystatechange=null,i.onerror=null,h.removeChild(i);try{delete window[j],delete window[j+"_loaded"]}catch(a){window[j]=null,window[j+"_loaded"]=null}},i.onreadystatechange=function(){("loaded"===this.readyState||"complete"===this.readyState)&&f()},i.onload=function(){f()},i.onerror=function(){k||d||(g(),b.callback(!0,!1,{message:"Failed to load JSONP script."}))},i.async=!0,i.defer=!0,i.src=a,h.appendChild(i)},_makeXmlHttpRequestByHost:function(a,b){if(!this._support.cors&&!this._support.hasXDomainRequest)return void b.callback(!1,!1,{message:"CORS not supported"});var c,d,e,f=null,g=this._support.cors?new XMLHttpRequest:new XDomainRequest,h=this;this._isUndefined(b.body)||(f=JSON.stringify(b.body)),a+=(-1===a.indexOf("?")?"?":"&")+"X-Algolia-API-Key="+this.apiKey,a+="&X-Algolia-Application-Id="+this.applicationID,this.userToken&&(a+="&X-Algolia-UserToken="+encodeURIComponent(this.userToken)),this.tagFilters&&(a+="&X-Algolia-TagFilters="+encodeURIComponent(this.tagFilters)),a+="&X-Algolia-Agent="+encodeURIComponent(this._ua);for(var i=0;i<this.extraHeaders.length;++i)a+="&"+this.extraHeaders[i].key+"="+this.extraHeaders[i].value;e=function(){h._support.timeout||(d=!0,g.abort()),b.callback(!0,!1,{message:"Timeout - Could not connect to endpoint "+a})},g instanceof XMLHttpRequest?g.open(b.method,a,!0):g.open(b.method,a),this._support.cors&&null!==f&&"GET"!==b.method&&g.setRequestHeader("Content-type","application/x-www-form-urlencoded"),g.onload=function(){if(!d){h._support.timeout||clearTimeout(c);var a=null;try{a=JSON.parse(g.responseText)}catch(e){}var f=g.status||a&&a.message&&a.status||a&&200,i=200===f||201===f,j=!i&&400!==f&&403!==f&&404!==f;b.callback(j,i,a)}},g.onprogress=function(){},this._support.timeout?(g.timeout=this.requestTimeoutInMs*(b.successiveRetryCount+1),g.ontimeout=e):c=setTimeout(e,this.requestTimeoutInMs*(b.successiveRetryCount+1)),g.onerror=function(a){d||(h._support.timeout||clearTimeout(c),b.callback(!0,!1,{message:"Could not connect to host",error:a}))},g.send(f)},_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("[object Array]"===Object.prototype.toString.call(a[c])?JSON.stringify(a[c]):a[c]));return b},_isUndefined:function(a){return void 0===a},_support:{hasXMLHttpRequest:"XMLHttpRequest"in window,hasXDomainRequest:"XDomainRequest"in window,cors:"withCredentials"in new XMLHttpRequest,timeout:"timeout"in new XMLHttpRequest}},AlgoliaSearch.prototype.Index.prototype={clearCache:function(){this.cache={}},addObject:function(a,b,c){var d=this;return 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)}return this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/batch",body:d,callback:b})},getObject:function(a,b,c){"[object Array]"!==Object.prototype.toString.call(b)||c||(c=b,b=null);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]}return this.as._jsonRequest({method:"GET",url:"/1/indexes/"+encodeURIComponent(d.indexName)+"/"+encodeURIComponent(a)+e,callback:b})},partialUpdateObject:function(a,b){var c=this;return this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/"+encodeURIComponent(a.objectID)+"/partial",body:a,callback:b})},partialUpdateObjects:function(a,b){for(var c=this,d={requests:[]},e=0;e<a.length;++e){var f={action:"partialUpdateObject",objectID:a[e].objectID,body:a[e]};d.requests.push(f)}return this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/batch",body:d,callback:b})},saveObject:function(a,b){var c=this;return 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:a[e].objectID,body:a[e]};d.requests.push(f)}return 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 void b(!1,{message:"empty objectID"});var c=this;return this.as._jsonRequest({method:"DELETE",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/"+encodeURIComponent(a),callback:b})},search:function(a,b,c,d){(void 0===a||null===a)&&(a=""),"function"==typeof a&&(b=a,a=""),"object"!=typeof b||!this.as._isUndefined(c)&&c||(c=b,b=null);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))return this._search(f,b);var g=window.setTimeout(function(){e._search(f,b)},d);e.onDelayTrigger=g},browse:function(a,b,c){+b>0&&(this.as._isUndefined(c)||!c)&&(c=b,b=null);var d=this,e="?page="+a;return this.as._isUndefined(c)||(e+="&hitsPerPage="+c),this.as._jsonRequest({method:"GET",url:"/1/indexes/"+encodeURIComponent(d.indexName)+"/browse"+e,callback:b})},ttAdapter:function(a){var b=this;return function(c,d){b.search(c,function(a,b){d(a?b.hits:b&&b.message)},a)}},waitTask:function(a,b){var c=this;return this.as._jsonRequest({method:"GET",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/task/"+a,callback:function(d,e){d?"published"===e.status?b(!0,e):setTimeout(function(){c.waitTask(a,b)},100):b(!1,e)}})},clearIndex:function(a){var b=this;return this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(b.indexName)+"/clear",callback:a})},getSettings:function(a){var b=this;return this.as._jsonRequest({method:"GET",url:"/1/indexes/"+encodeURIComponent(b.indexName)+"/settings",callback:a})},setSettings:function(a,b){var c=this;return this.as._jsonRequest({method:"PUT",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/settings",body:a,callback:b})},listUserKeys:function(a){var b=this;return this.as._jsonRequest({method:"GET",url:"/1/indexes/"+encodeURIComponent(b.indexName)+"/keys",callback:a})},getUserKeyACL:function(a,b){var c=this;return this.as._jsonRequest({method:"GET",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/keys/"+a,callback:b})},deleteUserKey:function(a,b){var c=this;return this.as._jsonRequest({method:"DELETE",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/keys/"+a,callback:b})},addUserKey:function(a,b){var c=this,d={};return d.acl=a,this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(c.indexName)+"/keys",body:d,callback:b})},addUserKeyWithValidity:function(a,b,c,d,e){var f=this,g={};return g.acl=a,g.validity=b,g.maxQueriesPerIPPerHour=c,g.maxHitsPerQuery=d,this.as._jsonRequest({method:"POST",url:"/1/indexes/"+encodeURIComponent(f.indexName)+"/keys",body:g,callback:e})},_search:function(a,b){var c={params:a};if(null===this.as.jsonp){var d=this;return this.as._jsonRequest({cache:this.cache,method:"POST",url:"/1/indexes/"+encodeURIComponent(this.indexName)+"/query",body:c,callback:function(c,e){var f=e&&e.status;c||f&&4===Math.floor(f/100)||1===Math.floor(f/100)?(d.as.jsonp=!1,b&&b(c,e)):(d.as.jsonp=!0,d._search(a,b))}})}return this.as.jsonp?this.as._jsonRequest({cache:this.cache,method:"GET",url:"/1/indexes/"+encodeURIComponent(this.indexName),body:c,callback:b}):this.as._jsonRequest({cache:this.cache,method:"POST",url:"/1/indexes/"+encodeURIComponent(this.indexName)+"/query",body:c,callback:b})},as:null,indexName:null,typeAheadArgs:null,typeAheadValueOption:null},function(a){var b=function(a){a=a||{};for(var b=1;b<arguments.length;b++)if(arguments[b])for(var c in arguments[b])arguments[b].hasOwnProperty(c)&&(a[c]=arguments[b][c]);return a};window.AlgoliaSearchHelper=function(a,c,d){var e={facets:[],disjunctiveFacets:[],hitsPerPage:20,defaultFacetFilters:[]};this.init(a,c,b({},e,d))},AlgoliaSearchHelper.prototype={init:function(a,b,c){this.client=a,this.index=b,this.options=c,this.page=0,this.refinements={},this.excludes={},this.disjunctiveRefinements={},this.extraQueries=[]},search:function(a,b,c){this.q=a,this.searchCallback=b,this.searchParams=c||{},this.page=this.page||0,this.refinements=this.refinements||{},this.disjunctiveRefinements=this.disjunctiveRefinements||{},this._search()},clearRefinements:function(){this.disjunctiveRefinements={},this.refinements={}},addDisjunctiveRefine:function(a,b){this.disjunctiveRefinements=this.disjunctiveRefinements||{},this.disjunctiveRefinements[a]=this.disjunctiveRefinements[a]||{},this.disjunctiveRefinements[a][b]=!0},removeDisjunctiveRefine:function(a,b){this.disjunctiveRefinements=this.disjunctiveRefinements||{},this.disjunctiveRefinements[a]=this.disjunctiveRefinements[a]||{};try{delete this.disjunctiveRefinements[a][b]}catch(c){this.disjunctiveRefinements[a][b]=void 0}},addRefine:function(a,b){var c=a+":"+b;this.refinements=this.refinements||{},this.refinements[c]=!0},removeRefine:function(a,b){var c=a+":"+b;this.refinements=this.refinements||{},this.refinements[c]=!1},addExclude:function(a,b){var c=a+":-"+b;this.excludes=this.excludes||{},this.excludes[c]=!0},removeExclude:function(a,b){var c=a+":-"+b;this.excludes=this.excludes||{},this.excludes[c]=!1},toggleExclude:function(a,b){for(var c=0;c<this.options.facets.length;++c)if(this.options.facets[c]==a){var d=a+":-"+b;return this.excludes[d]=!this.excludes[d],this.page=0,this._search(),!0}return!1},toggleRefine:function(a,b){for(var c=0;c<this.options.facets.length;++c)if(this.options.facets[c]==a){var d=a+":"+b;return this.refinements[d]=!this.refinements[d],this.page=0,this._search(),!0}this.disjunctiveRefinements[a]=this.disjunctiveRefinements[a]||{};for(var e=0;e<this.options.disjunctiveFacets.length;++e)if(this.options.disjunctiveFacets[e]==a)return this.disjunctiveRefinements[a][b]=!this.disjunctiveRefinements[a][b],this.page=0,this._search(),!0;return!1},isRefined:function(a,b){var c=a+":"+b;return this.refinements[c]?!0:this.disjunctiveRefinements[a]&&this.disjunctiveRefinements[a][b]?!0:!1},isExcluded:function(a,b){var c=a+":-"+b;return this.excludes[c]?!0:!1},nextPage:function(){this._gotoPage(this.page+1)},previousPage:function(){this.page>0&&this._gotoPage(this.page-1)},gotoPage:function(a){this._gotoPage(a)},setPage:function(a){this.page=a},setIndex:function(a){this.index=a},getIndex:function(){return this.index},clearExtraQueries:function(){this.extraQueries=[]},addExtraQuery:function(a,b,c){this.extraQueries.push({index:a,query:b,params:c||{}})},_gotoPage:function(a){this.page=a,this._search()},_search:function(){this.client.startQueriesBatch(),this.client.addQueryInBatch(this.index,this.q,this._getHitsSearchParams());var a=[],b={},c=0;for(c=0;c<this.options.disjunctiveFacets.length;++c){var d=this.options.disjunctiveFacets[c];this._hasDisjunctiveRefinements(d)?a.push(d):b[d]=!0}for(c=0;c<a.length;++c)this.client.addQueryInBatch(this.index,this.q,this._getDisjunctiveFacetSearchParams(a[c]));for(c=0;c<this.extraQueries.length;++c)this.client.addQueryInBatch(this.extraQueries[c].index,this.extraQueries[c].query,this.extraQueries[c].params);var e=this;this.client.sendQueriesBatch(function(d,f){if(!d)return void e.searchCallback(!1,f);var g=f.results[0];g.disjunctiveFacets=g.disjunctiveFacets||{},g.facets_stats=g.facets_stats||{};for(var h in b)if(g.facets[h]&&!g.disjunctiveFacets[h]){g.disjunctiveFacets[h]=g.facets[h];try{delete g.facets[h]}catch(i){g.facets[h]=void 0}}for(c=0;c<a.length;++c){for(var j in f.results[c+1].facets)if(g.disjunctiveFacets[j]=f.results[c+1].facets[j],e.disjunctiveRefinements[j])for(var k in e.disjunctiveRefinements[j])!g.disjunctiveFacets[j][k]&&e.disjunctiveRefinements[j][k]&&(g.disjunctiveFacets[j][k]=0);for(var l in f.results[c+1].facets_stats)g.facets_stats[l]=f.results[c+1].facets_stats[l]}g.facetStats=g.facets_stats;for(var m in e.excludes)if(e.excludes[m]){var i=m.indexOf(":-"),h=m.slice(0,i),k=m.slice(i+2);g.facets[h]=g.facets[h]||{},g.facets[h][k]||(g.facets[h][k]=0)}if(0===e.extraQueries.length)e.searchCallback(!0,g);else{var n={results:[g]};for(c=0;c<e.extraQueries.length;++c)n.results.push(f.results[1+a.length+c]);e.searchCallback(!0,n)}})},_getHitsSearchParams:function(){var a=[],c=0;for(c=0;c<this.options.facets.length;++c)a.push(this.options.facets[c]);for(c=0;c<this.options.disjunctiveFacets.length;++c){var d=this.options.disjunctiveFacets[c];this._hasDisjunctiveRefinements(d)||a.push(d)}return b({},{hitsPerPage:this.options.hitsPerPage,page:this.page,facets:a,facetFilters:this._getFacetFilters()},this.searchParams)},_getDisjunctiveFacetSearchParams:function(a){return b({},this.searchParams,{hitsPerPage:1,page:0,attributesToRetrieve:[],attributesToHighlight:[],attributesToSnippet:[],facets:a,facetFilters:this._getFacetFilters(a),analytics:!1})},_hasDisjunctiveRefinements:function(a){for(var b in this.disjunctiveRefinements[a])if(this.disjunctiveRefinements[a][b])return!0;return!1},_getFacetFilters:function(a){var b=[];if(this.options.defaultFacetFilters)for(var c=0;c<this.options.defaultFacetFilters.length;++c)b.push(this.options.defaultFacetFilters[c]);for(var d in this.refinements)this.refinements[d]&&b.push(d);for(var d in this.excludes)this.excludes[d]&&b.push(d);for(var e in this.disjunctiveRefinements)if(e!=a){var f=[];for(var g in this.disjunctiveRefinements[e])this.disjunctiveRefinements[e][g]&&f.push(e+":"+g);f.length>0&&b.push(f)}return b}}}(),function(a){window.AlgoliaPlaces=function(a,b){this.init(a,b)},AlgoliaPlaces.prototype={init:function(a,b){this.client=new AlgoliaSearch(a,b,"http",!0,["places-1.algolia.io","places-2.algolia.io","places-3.algolia.io"]),this.cache={}},search:function(a,b,c){var d="query="+encodeURIComponent(a);this.client._isUndefined(c)||null==c||(d=this.client._getSearchParams(c,d));var e={params:d,apiKey:this.client.apiKey,appID:this.client.applicationID};this.client._jsonRequest({cache:this.cache,method:"POST",url:"/1/places/query",body:e,callback:b,removeCustomHTTPHeaders:!0})}}}(),"object"!=typeof JSON&&(JSON={}),function(){"use strict";function f(a){return 10>a?"0"+a:a}function quote(a){return escapable.lastIndex=0,escapable.test(a)?'"'+a.replace(escapable,function(a){var b=meta[a];return"string"==typeof b?b:"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+a+'"'}function str(a,b){var c,d,e,f,g,h=gap,i=b[a];switch(i&&"object"==typeof i&&"function"==typeof i.toJSON&&(i=i.toJSON(a)),"function"==typeof rep&&(i=rep.call(b,a,i)),typeof i){case"string":return quote(i);case"number":return isFinite(i)?String(i):"null";case"boolean":case"null":return String(i);case"object":if(!i)return"null";if(gap+=indent,g=[],"[object Array]"===Object.prototype.toString.apply(i)){for(f=i.length,c=0;f>c;c+=1)g[c]=str(c,i)||"null";return e=0===g.length?"[]":gap?"[\n"+gap+g.join(",\n"+gap)+"\n"+h+"]":"["+g.join(",")+"]",gap=h,e}if(rep&&"object"==typeof rep)for(f=rep.length,c=0;f>c;c+=1)"string"==typeof rep[c]&&(d=rep[c],e=str(d,i),e&&g.push(quote(d)+(gap?": ":":")+e));else for(d in i)Object.prototype.hasOwnProperty.call(i,d)&&(e=str(d,i),e&&g.push(quote(d)+(gap?": ":":")+e));return e=0===g.length?"{}":gap?"{\n"+gap+g.join(",\n"+gap)+"\n"+h+"}":"{"+g.join(",")+"}",gap=h,e}}"function"!=typeof Date.prototype.toJSON&&(Date.prototype.toJSON=function(){return isFinite(this.valueOf())?this.getUTCFullYear()+"-"+f(this.getUTCMonth()+1)+"-"+f(this.getUTCDate())+"T"+f(this.getUTCHours())+":"+f(this.getUTCMinutes())+":"+f(this.getUTCSeconds())+"Z":null},String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(){return this.valueOf()});var cx,escapable,gap,indent,meta,rep;"function"!=typeof JSON.stringify&&(escapable=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,meta={"\b":"\\b"," ":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},JSON.stringify=function(a,b,c){var d;if(gap="",indent="","number"==typeof c)for(d=0;c>d;d+=1)indent+=" ";else"string"==typeof c&&(indent=c);if(rep=b,b&&"function"!=typeof b&&("object"!=typeof b||"number"!=typeof b.length))throw new Error("JSON.stringify");return str("",{"":a})}),"function"!=typeof JSON.parse&&(cx=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,JSON.parse=function(text,reviver){function walk(a,b){var c,d,e=a[b];if(e&&"object"==typeof e)for(c in e)Object.prototype.hasOwnProperty.call(e,c)&&(d=walk(e,c),void 0!==d?e[c]=d:delete e[c]);return reviver.call(a,b,e)}var j;if(text=String(text),cx.lastIndex=0,cx.test(text)&&(text=text.replace(cx,function(a){return"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4)})),/^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,"@").replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,"]").replace(/(?:^|:|,)(?:\s*\[)+/g,"")))return j=eval("("+text+")"),"function"==typeof reviver?walk({"":j},""):j;throw new SyntaxError("JSON.parse")})}();
|
@@ -1,4 +1,4 @@
|
|
1
|
-
/*! algoliasearch 3.
|
1
|
+
/*! algoliasearch 3.20.3 | © 2014, 2015 Algolia SAS | github.com/algolia/algoliasearch-client-js */
|
2
2
|
(function(f){var g;if(typeof window!=='undefined'){g=window}else if(typeof self!=='undefined'){g=self}g.ALGOLIA_MIGRATION_LAYER=f()})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
|
3
3
|
|
4
4
|
module.exports = function load (src, opts, cb) {
|
@@ -200,258 +200,7 @@ function migrationLayer(buildName) {
|
|
200
200
|
|
201
201
|
},{"2":2,"3":3,"4":4}]},{},[5])(5)
|
202
202
|
});(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
|
203
|
-
|
204
|
-
* Helpers.
|
205
|
-
*/
|
206
|
-
|
207
|
-
var s = 1000;
|
208
|
-
var m = s * 60;
|
209
|
-
var h = m * 60;
|
210
|
-
var d = h * 24;
|
211
|
-
var y = d * 365.25;
|
212
|
-
|
213
|
-
/**
|
214
|
-
* Parse or format the given `val`.
|
215
|
-
*
|
216
|
-
* Options:
|
217
|
-
*
|
218
|
-
* - `long` verbose formatting [false]
|
219
|
-
*
|
220
|
-
* @param {String|Number} val
|
221
|
-
* @param {Object} options
|
222
|
-
* @return {String|Number}
|
223
|
-
* @api public
|
224
|
-
*/
|
225
|
-
|
226
|
-
module.exports = function(val, options){
|
227
|
-
options = options || {};
|
228
|
-
if ('string' == typeof val) return parse(val);
|
229
|
-
// long, short were "future reserved words in js", YUI compressor fail on them
|
230
|
-
// https://github.com/algolia/algoliasearch-client-js/issues/113#issuecomment-111978606
|
231
|
-
// https://github.com/yui/yuicompressor/issues/47
|
232
|
-
// https://github.com/rauchg/ms.js/pull/40
|
233
|
-
return options['long']
|
234
|
-
? _long(val)
|
235
|
-
: _short(val);
|
236
|
-
};
|
237
|
-
|
238
|
-
/**
|
239
|
-
* Parse the given `str` and return milliseconds.
|
240
|
-
*
|
241
|
-
* @param {String} str
|
242
|
-
* @return {Number}
|
243
|
-
* @api private
|
244
|
-
*/
|
245
|
-
|
246
|
-
function parse(str) {
|
247
|
-
str = '' + str;
|
248
|
-
if (str.length > 10000) return;
|
249
|
-
var match = /^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(str);
|
250
|
-
if (!match) return;
|
251
|
-
var n = parseFloat(match[1]);
|
252
|
-
var type = (match[2] || 'ms').toLowerCase();
|
253
|
-
switch (type) {
|
254
|
-
case 'years':
|
255
|
-
case 'year':
|
256
|
-
case 'yrs':
|
257
|
-
case 'yr':
|
258
|
-
case 'y':
|
259
|
-
return n * y;
|
260
|
-
case 'days':
|
261
|
-
case 'day':
|
262
|
-
case 'd':
|
263
|
-
return n * d;
|
264
|
-
case 'hours':
|
265
|
-
case 'hour':
|
266
|
-
case 'hrs':
|
267
|
-
case 'hr':
|
268
|
-
case 'h':
|
269
|
-
return n * h;
|
270
|
-
case 'minutes':
|
271
|
-
case 'minute':
|
272
|
-
case 'mins':
|
273
|
-
case 'min':
|
274
|
-
case 'm':
|
275
|
-
return n * m;
|
276
|
-
case 'seconds':
|
277
|
-
case 'second':
|
278
|
-
case 'secs':
|
279
|
-
case 'sec':
|
280
|
-
case 's':
|
281
|
-
return n * s;
|
282
|
-
case 'milliseconds':
|
283
|
-
case 'millisecond':
|
284
|
-
case 'msecs':
|
285
|
-
case 'msec':
|
286
|
-
case 'ms':
|
287
|
-
return n;
|
288
|
-
}
|
289
|
-
}
|
290
|
-
|
291
|
-
/**
|
292
|
-
* Short format for `ms`.
|
293
|
-
*
|
294
|
-
* @param {Number} ms
|
295
|
-
* @return {String}
|
296
|
-
* @api private
|
297
|
-
*/
|
298
|
-
|
299
|
-
function _short(ms) {
|
300
|
-
if (ms >= d) return Math.round(ms / d) + 'd';
|
301
|
-
if (ms >= h) return Math.round(ms / h) + 'h';
|
302
|
-
if (ms >= m) return Math.round(ms / m) + 'm';
|
303
|
-
if (ms >= s) return Math.round(ms / s) + 's';
|
304
|
-
return ms + 'ms';
|
305
|
-
}
|
306
|
-
|
307
|
-
/**
|
308
|
-
* Long format for `ms`.
|
309
|
-
*
|
310
|
-
* @param {Number} ms
|
311
|
-
* @return {String}
|
312
|
-
* @api private
|
313
|
-
*/
|
314
|
-
|
315
|
-
function _long(ms) {
|
316
|
-
return plural(ms, d, 'day')
|
317
|
-
|| plural(ms, h, 'hour')
|
318
|
-
|| plural(ms, m, 'minute')
|
319
|
-
|| plural(ms, s, 'second')
|
320
|
-
|| ms + ' ms';
|
321
|
-
}
|
322
|
-
|
323
|
-
/**
|
324
|
-
* Pluralization helper.
|
325
|
-
*/
|
326
|
-
|
327
|
-
function plural(ms, n, name) {
|
328
|
-
if (ms < n) return;
|
329
|
-
if (ms < n * 1.5) return Math.floor(ms / n) + ' ' + name;
|
330
|
-
return Math.ceil(ms / n) + ' ' + name + 's';
|
331
|
-
}
|
332
|
-
|
333
|
-
},{}],2:[function(require,module,exports){
|
334
|
-
// shim for using process in browser
|
335
|
-
|
336
|
-
var process = module.exports = {};
|
337
|
-
|
338
|
-
// cached from whatever global is present so that test runners that stub it
|
339
|
-
// don't break things. But we need to wrap it in a try catch in case it is
|
340
|
-
// wrapped in strict mode code which doesn't define any globals. It's inside a
|
341
|
-
// function because try/catches deoptimize in certain engines.
|
342
|
-
|
343
|
-
var cachedSetTimeout;
|
344
|
-
var cachedClearTimeout;
|
345
|
-
|
346
|
-
(function () {
|
347
|
-
try {
|
348
|
-
cachedSetTimeout = setTimeout;
|
349
|
-
} catch (e) {
|
350
|
-
cachedSetTimeout = function () {
|
351
|
-
throw new Error('setTimeout is not defined');
|
352
|
-
}
|
353
|
-
}
|
354
|
-
try {
|
355
|
-
cachedClearTimeout = clearTimeout;
|
356
|
-
} catch (e) {
|
357
|
-
cachedClearTimeout = function () {
|
358
|
-
throw new Error('clearTimeout is not defined');
|
359
|
-
}
|
360
|
-
}
|
361
|
-
} ())
|
362
|
-
var queue = [];
|
363
|
-
var draining = false;
|
364
|
-
var currentQueue;
|
365
|
-
var queueIndex = -1;
|
366
|
-
|
367
|
-
function cleanUpNextTick() {
|
368
|
-
if (!draining || !currentQueue) {
|
369
|
-
return;
|
370
|
-
}
|
371
|
-
draining = false;
|
372
|
-
if (currentQueue.length) {
|
373
|
-
queue = currentQueue.concat(queue);
|
374
|
-
} else {
|
375
|
-
queueIndex = -1;
|
376
|
-
}
|
377
|
-
if (queue.length) {
|
378
|
-
drainQueue();
|
379
|
-
}
|
380
|
-
}
|
381
|
-
|
382
|
-
function drainQueue() {
|
383
|
-
if (draining) {
|
384
|
-
return;
|
385
|
-
}
|
386
|
-
var timeout = cachedSetTimeout(cleanUpNextTick);
|
387
|
-
draining = true;
|
388
|
-
|
389
|
-
var len = queue.length;
|
390
|
-
while(len) {
|
391
|
-
currentQueue = queue;
|
392
|
-
queue = [];
|
393
|
-
while (++queueIndex < len) {
|
394
|
-
if (currentQueue) {
|
395
|
-
currentQueue[queueIndex].run();
|
396
|
-
}
|
397
|
-
}
|
398
|
-
queueIndex = -1;
|
399
|
-
len = queue.length;
|
400
|
-
}
|
401
|
-
currentQueue = null;
|
402
|
-
draining = false;
|
403
|
-
cachedClearTimeout(timeout);
|
404
|
-
}
|
405
|
-
|
406
|
-
process.nextTick = function (fun) {
|
407
|
-
var args = new Array(arguments.length - 1);
|
408
|
-
if (arguments.length > 1) {
|
409
|
-
for (var i = 1; i < arguments.length; i++) {
|
410
|
-
args[i - 1] = arguments[i];
|
411
|
-
}
|
412
|
-
}
|
413
|
-
queue.push(new Item(fun, args));
|
414
|
-
if (queue.length === 1 && !draining) {
|
415
|
-
cachedSetTimeout(drainQueue, 0);
|
416
|
-
}
|
417
|
-
};
|
418
|
-
|
419
|
-
// v8 likes predictible objects
|
420
|
-
function Item(fun, array) {
|
421
|
-
this.fun = fun;
|
422
|
-
this.array = array;
|
423
|
-
}
|
424
|
-
Item.prototype.run = function () {
|
425
|
-
this.fun.apply(null, this.array);
|
426
|
-
};
|
427
|
-
process.title = 'browser';
|
428
|
-
process.browser = true;
|
429
|
-
process.env = {};
|
430
|
-
process.argv = [];
|
431
|
-
process.version = ''; // empty string to avoid regexp issues
|
432
|
-
process.versions = {};
|
433
|
-
|
434
|
-
function noop() {}
|
435
|
-
|
436
|
-
process.on = noop;
|
437
|
-
process.addListener = noop;
|
438
|
-
process.once = noop;
|
439
|
-
process.off = noop;
|
440
|
-
process.removeListener = noop;
|
441
|
-
process.removeAllListeners = noop;
|
442
|
-
process.emit = noop;
|
443
|
-
|
444
|
-
process.binding = function (name) {
|
445
|
-
throw new Error('process.binding is not supported');
|
446
|
-
};
|
447
|
-
|
448
|
-
process.cwd = function () { return '/' };
|
449
|
-
process.chdir = function (dir) {
|
450
|
-
throw new Error('process.chdir is not supported');
|
451
|
-
};
|
452
|
-
process.umask = function() { return 0; };
|
453
|
-
|
454
|
-
},{}],3:[function(require,module,exports){
|
203
|
+
(function (process){
|
455
204
|
|
456
205
|
/**
|
457
206
|
* This is the web browser implementation of `debug()`.
|
@@ -459,7 +208,7 @@ process.umask = function() { return 0; };
|
|
459
208
|
* Expose `debug()` as the module.
|
460
209
|
*/
|
461
210
|
|
462
|
-
exports = module.exports = require(
|
211
|
+
exports = module.exports = require(2);
|
463
212
|
exports.log = log;
|
464
213
|
exports.formatArgs = formatArgs;
|
465
214
|
exports.save = save;
|
@@ -493,7 +242,8 @@ exports.colors = [
|
|
493
242
|
|
494
243
|
function useColors() {
|
495
244
|
// is webkit? http://stackoverflow.com/a/16459606/376773
|
496
|
-
|
245
|
+
// document is undefined in react-native: https://github.com/facebook/react-native/pull/1632
|
246
|
+
return (typeof document !== 'undefined' && 'WebkitAppearance' in document.documentElement.style) ||
|
497
247
|
// is firebug? http://stackoverflow.com/a/398120/376773
|
498
248
|
(window.console && (console.firebug || (console.exception && console.table))) ||
|
499
249
|
// is firefox >= v31?
|
@@ -506,7 +256,11 @@ function useColors() {
|
|
506
256
|
*/
|
507
257
|
|
508
258
|
exports.formatters.j = function(v) {
|
509
|
-
|
259
|
+
try {
|
260
|
+
return JSON.stringify(v);
|
261
|
+
} catch (err) {
|
262
|
+
return '[UnexpectedJSONParseError]: ' + err.message;
|
263
|
+
}
|
510
264
|
};
|
511
265
|
|
512
266
|
|
@@ -593,9 +347,13 @@ function save(namespaces) {
|
|
593
347
|
function load() {
|
594
348
|
var r;
|
595
349
|
try {
|
596
|
-
|
350
|
+
return exports.storage.debug;
|
597
351
|
} catch(e) {}
|
598
|
-
|
352
|
+
|
353
|
+
// If debug isn't set in LS, and we're in Electron, try to load $DEBUG
|
354
|
+
if (typeof process !== 'undefined' && 'env' in process) {
|
355
|
+
return process.env.DEBUG;
|
356
|
+
}
|
599
357
|
}
|
600
358
|
|
601
359
|
/**
|
@@ -621,7 +379,8 @@ function localstorage(){
|
|
621
379
|
} catch (e) {}
|
622
380
|
}
|
623
381
|
|
624
|
-
},
|
382
|
+
}).call(this,require(12))
|
383
|
+
},{"12":12,"2":2}],2:[function(require,module,exports){
|
625
384
|
|
626
385
|
/**
|
627
386
|
* This is the common logic for both the Node.js and web browser
|
@@ -630,12 +389,12 @@ function localstorage(){
|
|
630
389
|
* Expose `debug()` as the module.
|
631
390
|
*/
|
632
391
|
|
633
|
-
exports = module.exports = debug;
|
392
|
+
exports = module.exports = debug.debug = debug;
|
634
393
|
exports.coerce = coerce;
|
635
394
|
exports.disable = disable;
|
636
395
|
exports.enable = enable;
|
637
396
|
exports.enabled = enabled;
|
638
|
-
exports.humanize = require(
|
397
|
+
exports.humanize = require(9);
|
639
398
|
|
640
399
|
/**
|
641
400
|
* The currently active debug mode names, and names to skip.
|
@@ -707,7 +466,10 @@ function debug(namespace) {
|
|
707
466
|
if (null == self.useColors) self.useColors = exports.useColors();
|
708
467
|
if (null == self.color && self.useColors) self.color = selectColor();
|
709
468
|
|
710
|
-
var args = Array
|
469
|
+
var args = new Array(arguments.length);
|
470
|
+
for (var i = 0; i < args.length; i++) {
|
471
|
+
args[i] = arguments[i];
|
472
|
+
}
|
711
473
|
|
712
474
|
args[0] = exports.coerce(args[0]);
|
713
475
|
|
@@ -734,9 +496,9 @@ function debug(namespace) {
|
|
734
496
|
return match;
|
735
497
|
});
|
736
498
|
|
737
|
-
|
738
|
-
|
739
|
-
|
499
|
+
// apply env-specific formatting
|
500
|
+
args = exports.formatArgs.apply(self, args);
|
501
|
+
|
740
502
|
var logFn = enabled.log || exports.log || console.log.bind(console);
|
741
503
|
logFn.apply(self, args);
|
742
504
|
}
|
@@ -765,7 +527,7 @@ function enable(namespaces) {
|
|
765
527
|
|
766
528
|
for (var i = 0; i < len; i++) {
|
767
529
|
if (!split[i]) continue; // ignore empty strings
|
768
|
-
namespaces = split[i].replace(/\*/g, '.*?');
|
530
|
+
namespaces = split[i].replace(/[\\^$+?.()|[\]{}]/g, '\\$&').replace(/\*/g, '.*?');
|
769
531
|
if (namespaces[0] === '-') {
|
770
532
|
exports.skips.push(new RegExp('^' + namespaces.substr(1) + '$'));
|
771
533
|
} else {
|
@@ -820,970 +582,1167 @@ function coerce(val) {
|
|
820
582
|
return val;
|
821
583
|
}
|
822
584
|
|
823
|
-
},{"
|
585
|
+
},{"9":9}],3:[function(require,module,exports){
|
824
586
|
(function (process,global){
|
825
587
|
/*!
|
826
588
|
* @overview es6-promise - a tiny implementation of Promises/A+.
|
827
589
|
* @copyright Copyright (c) 2014 Yehuda Katz, Tom Dale, Stefan Penner and contributors (Conversion to ES6 API by Jake Archibald)
|
828
590
|
* @license Licensed under MIT license
|
829
|
-
* See https://raw.githubusercontent.com/
|
830
|
-
* @version
|
591
|
+
* See https://raw.githubusercontent.com/stefanpenner/es6-promise/master/LICENSE
|
592
|
+
* @version 4.0.5
|
831
593
|
*/
|
832
594
|
|
833
|
-
(function() {
|
834
|
-
|
835
|
-
function
|
836
|
-
|
837
|
-
|
595
|
+
(function (global, factory) {
|
596
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
597
|
+
typeof define === 'function' && define.amd ? define(factory) :
|
598
|
+
(global.ES6Promise = factory());
|
599
|
+
}(this, (function () { 'use strict';
|
838
600
|
|
839
|
-
|
840
|
-
|
841
|
-
|
601
|
+
function objectOrFunction(x) {
|
602
|
+
return typeof x === 'function' || typeof x === 'object' && x !== null;
|
603
|
+
}
|
842
604
|
|
843
|
-
|
844
|
-
|
845
|
-
|
605
|
+
function isFunction(x) {
|
606
|
+
return typeof x === 'function';
|
607
|
+
}
|
846
608
|
|
847
|
-
|
848
|
-
|
849
|
-
|
850
|
-
|
851
|
-
|
609
|
+
var _isArray = undefined;
|
610
|
+
if (!Array.isArray) {
|
611
|
+
_isArray = function (x) {
|
612
|
+
return Object.prototype.toString.call(x) === '[object Array]';
|
613
|
+
};
|
614
|
+
} else {
|
615
|
+
_isArray = Array.isArray;
|
616
|
+
}
|
617
|
+
|
618
|
+
var isArray = _isArray;
|
619
|
+
|
620
|
+
var len = 0;
|
621
|
+
var vertxNext = undefined;
|
622
|
+
var customSchedulerFn = undefined;
|
623
|
+
|
624
|
+
var asap = function asap(callback, arg) {
|
625
|
+
queue[len] = callback;
|
626
|
+
queue[len + 1] = arg;
|
627
|
+
len += 2;
|
628
|
+
if (len === 2) {
|
629
|
+
// If len is 2, that means that we need to schedule an async flush.
|
630
|
+
// If additional callbacks are queued before the queue is flushed, they
|
631
|
+
// will be processed by this flush that we are scheduling.
|
632
|
+
if (customSchedulerFn) {
|
633
|
+
customSchedulerFn(flush);
|
852
634
|
} else {
|
853
|
-
|
635
|
+
scheduleFlush();
|
854
636
|
}
|
637
|
+
}
|
638
|
+
};
|
855
639
|
|
856
|
-
|
857
|
-
|
858
|
-
|
859
|
-
var lib$es6$promise$asap$$customSchedulerFn;
|
860
|
-
|
861
|
-
var lib$es6$promise$asap$$asap = function asap(callback, arg) {
|
862
|
-
lib$es6$promise$asap$$queue[lib$es6$promise$asap$$len] = callback;
|
863
|
-
lib$es6$promise$asap$$queue[lib$es6$promise$asap$$len + 1] = arg;
|
864
|
-
lib$es6$promise$asap$$len += 2;
|
865
|
-
if (lib$es6$promise$asap$$len === 2) {
|
866
|
-
// If len is 2, that means that we need to schedule an async flush.
|
867
|
-
// If additional callbacks are queued before the queue is flushed, they
|
868
|
-
// will be processed by this flush that we are scheduling.
|
869
|
-
if (lib$es6$promise$asap$$customSchedulerFn) {
|
870
|
-
lib$es6$promise$asap$$customSchedulerFn(lib$es6$promise$asap$$flush);
|
871
|
-
} else {
|
872
|
-
lib$es6$promise$asap$$scheduleFlush();
|
873
|
-
}
|
874
|
-
}
|
875
|
-
}
|
640
|
+
function setScheduler(scheduleFn) {
|
641
|
+
customSchedulerFn = scheduleFn;
|
642
|
+
}
|
876
643
|
|
877
|
-
|
878
|
-
|
879
|
-
|
644
|
+
function setAsap(asapFn) {
|
645
|
+
asap = asapFn;
|
646
|
+
}
|
880
647
|
|
881
|
-
|
882
|
-
|
883
|
-
|
648
|
+
var browserWindow = typeof window !== 'undefined' ? window : undefined;
|
649
|
+
var browserGlobal = browserWindow || {};
|
650
|
+
var BrowserMutationObserver = browserGlobal.MutationObserver || browserGlobal.WebKitMutationObserver;
|
651
|
+
var isNode = typeof self === 'undefined' && typeof process !== 'undefined' && ({}).toString.call(process) === '[object process]';
|
884
652
|
|
885
|
-
|
886
|
-
|
887
|
-
var lib$es6$promise$asap$$BrowserMutationObserver = lib$es6$promise$asap$$browserGlobal.MutationObserver || lib$es6$promise$asap$$browserGlobal.WebKitMutationObserver;
|
888
|
-
var lib$es6$promise$asap$$isNode = typeof self === 'undefined' && typeof process !== 'undefined' && {}.toString.call(process) === '[object process]';
|
889
|
-
|
890
|
-
// test for web worker but not in IE10
|
891
|
-
var lib$es6$promise$asap$$isWorker = typeof Uint8ClampedArray !== 'undefined' &&
|
892
|
-
typeof importScripts !== 'undefined' &&
|
893
|
-
typeof MessageChannel !== 'undefined';
|
894
|
-
|
895
|
-
// node
|
896
|
-
function lib$es6$promise$asap$$useNextTick() {
|
897
|
-
// node version 0.10.x displays a deprecation warning when nextTick is used recursively
|
898
|
-
// see https://github.com/cujojs/when/issues/410 for details
|
899
|
-
return function() {
|
900
|
-
process.nextTick(lib$es6$promise$asap$$flush);
|
901
|
-
};
|
902
|
-
}
|
653
|
+
// test for web worker but not in IE10
|
654
|
+
var isWorker = typeof Uint8ClampedArray !== 'undefined' && typeof importScripts !== 'undefined' && typeof MessageChannel !== 'undefined';
|
903
655
|
|
904
|
-
|
905
|
-
|
906
|
-
|
907
|
-
|
908
|
-
|
909
|
-
|
656
|
+
// node
|
657
|
+
function useNextTick() {
|
658
|
+
// node version 0.10.x displays a deprecation warning when nextTick is used recursively
|
659
|
+
// see https://github.com/cujojs/when/issues/410 for details
|
660
|
+
return function () {
|
661
|
+
return process.nextTick(flush);
|
662
|
+
};
|
663
|
+
}
|
910
664
|
|
911
|
-
|
912
|
-
|
913
|
-
|
914
|
-
|
915
|
-
|
665
|
+
// vertx
|
666
|
+
function useVertxTimer() {
|
667
|
+
if (typeof vertxNext !== 'undefined') {
|
668
|
+
return function () {
|
669
|
+
vertxNext(flush);
|
670
|
+
};
|
671
|
+
}
|
916
672
|
|
917
|
-
|
918
|
-
|
919
|
-
};
|
920
|
-
}
|
673
|
+
return useSetTimeout();
|
674
|
+
}
|
921
675
|
|
922
|
-
|
923
|
-
|
924
|
-
|
925
|
-
|
926
|
-
|
927
|
-
channel.port2.postMessage(0);
|
928
|
-
};
|
929
|
-
}
|
676
|
+
function useMutationObserver() {
|
677
|
+
var iterations = 0;
|
678
|
+
var observer = new BrowserMutationObserver(flush);
|
679
|
+
var node = document.createTextNode('');
|
680
|
+
observer.observe(node, { characterData: true });
|
930
681
|
|
931
|
-
|
932
|
-
|
933
|
-
|
934
|
-
|
935
|
-
}
|
682
|
+
return function () {
|
683
|
+
node.data = iterations = ++iterations % 2;
|
684
|
+
};
|
685
|
+
}
|
936
686
|
|
937
|
-
|
938
|
-
|
939
|
-
|
940
|
-
|
941
|
-
|
687
|
+
// web worker
|
688
|
+
function useMessageChannel() {
|
689
|
+
var channel = new MessageChannel();
|
690
|
+
channel.port1.onmessage = flush;
|
691
|
+
return function () {
|
692
|
+
return channel.port2.postMessage(0);
|
693
|
+
};
|
694
|
+
}
|
942
695
|
|
943
|
-
|
696
|
+
function useSetTimeout() {
|
697
|
+
// Store setTimeout reference so es6-promise will be unaffected by
|
698
|
+
// other code modifying setTimeout (like sinon.useFakeTimers())
|
699
|
+
var globalSetTimeout = setTimeout;
|
700
|
+
return function () {
|
701
|
+
return globalSetTimeout(flush, 1);
|
702
|
+
};
|
703
|
+
}
|
944
704
|
|
945
|
-
|
946
|
-
|
947
|
-
|
705
|
+
var queue = new Array(1000);
|
706
|
+
function flush() {
|
707
|
+
for (var i = 0; i < len; i += 2) {
|
708
|
+
var callback = queue[i];
|
709
|
+
var arg = queue[i + 1];
|
948
710
|
|
949
|
-
|
950
|
-
}
|
711
|
+
callback(arg);
|
951
712
|
|
952
|
-
|
953
|
-
|
954
|
-
|
955
|
-
var vertx = r('vertx');
|
956
|
-
lib$es6$promise$asap$$vertxNext = vertx.runOnLoop || vertx.runOnContext;
|
957
|
-
return lib$es6$promise$asap$$useVertxTimer();
|
958
|
-
} catch(e) {
|
959
|
-
return lib$es6$promise$asap$$useSetTimeout();
|
960
|
-
}
|
961
|
-
}
|
713
|
+
queue[i] = undefined;
|
714
|
+
queue[i + 1] = undefined;
|
715
|
+
}
|
962
716
|
|
963
|
-
|
964
|
-
|
965
|
-
if (lib$es6$promise$asap$$isNode) {
|
966
|
-
lib$es6$promise$asap$$scheduleFlush = lib$es6$promise$asap$$useNextTick();
|
967
|
-
} else if (lib$es6$promise$asap$$BrowserMutationObserver) {
|
968
|
-
lib$es6$promise$asap$$scheduleFlush = lib$es6$promise$asap$$useMutationObserver();
|
969
|
-
} else if (lib$es6$promise$asap$$isWorker) {
|
970
|
-
lib$es6$promise$asap$$scheduleFlush = lib$es6$promise$asap$$useMessageChannel();
|
971
|
-
} else if (lib$es6$promise$asap$$browserWindow === undefined && typeof require === 'function') {
|
972
|
-
lib$es6$promise$asap$$scheduleFlush = lib$es6$promise$asap$$attemptVertx();
|
973
|
-
} else {
|
974
|
-
lib$es6$promise$asap$$scheduleFlush = lib$es6$promise$asap$$useSetTimeout();
|
975
|
-
}
|
976
|
-
function lib$es6$promise$then$$then(onFulfillment, onRejection) {
|
977
|
-
var parent = this;
|
717
|
+
len = 0;
|
718
|
+
}
|
978
719
|
|
979
|
-
|
720
|
+
function attemptVertx() {
|
721
|
+
try {
|
722
|
+
var r = require;
|
723
|
+
var vertx = r('vertx');
|
724
|
+
vertxNext = vertx.runOnLoop || vertx.runOnContext;
|
725
|
+
return useVertxTimer();
|
726
|
+
} catch (e) {
|
727
|
+
return useSetTimeout();
|
728
|
+
}
|
729
|
+
}
|
980
730
|
|
981
|
-
|
982
|
-
|
983
|
-
|
731
|
+
var scheduleFlush = undefined;
|
732
|
+
// Decide what async method to use to triggering processing of queued callbacks:
|
733
|
+
if (isNode) {
|
734
|
+
scheduleFlush = useNextTick();
|
735
|
+
} else if (BrowserMutationObserver) {
|
736
|
+
scheduleFlush = useMutationObserver();
|
737
|
+
} else if (isWorker) {
|
738
|
+
scheduleFlush = useMessageChannel();
|
739
|
+
} else if (browserWindow === undefined && typeof require === 'function') {
|
740
|
+
scheduleFlush = attemptVertx();
|
741
|
+
} else {
|
742
|
+
scheduleFlush = useSetTimeout();
|
743
|
+
}
|
984
744
|
|
985
|
-
|
745
|
+
function then(onFulfillment, onRejection) {
|
746
|
+
var _arguments = arguments;
|
986
747
|
|
987
|
-
|
988
|
-
var callback = arguments[state - 1];
|
989
|
-
lib$es6$promise$asap$$asap(function(){
|
990
|
-
lib$es6$promise$$internal$$invokeCallback(state, child, callback, parent._result);
|
991
|
-
});
|
992
|
-
} else {
|
993
|
-
lib$es6$promise$$internal$$subscribe(parent, child, onFulfillment, onRejection);
|
994
|
-
}
|
748
|
+
var parent = this;
|
995
749
|
|
996
|
-
|
997
|
-
}
|
998
|
-
var lib$es6$promise$then$$default = lib$es6$promise$then$$then;
|
999
|
-
function lib$es6$promise$promise$resolve$$resolve(object) {
|
1000
|
-
/*jshint validthis:true */
|
1001
|
-
var Constructor = this;
|
750
|
+
var child = new this.constructor(noop);
|
1002
751
|
|
1003
|
-
|
1004
|
-
|
1005
|
-
|
752
|
+
if (child[PROMISE_ID] === undefined) {
|
753
|
+
makePromise(child);
|
754
|
+
}
|
1006
755
|
|
1007
|
-
|
1008
|
-
lib$es6$promise$$internal$$resolve(promise, object);
|
1009
|
-
return promise;
|
1010
|
-
}
|
1011
|
-
var lib$es6$promise$promise$resolve$$default = lib$es6$promise$promise$resolve$$resolve;
|
1012
|
-
var lib$es6$promise$$internal$$PROMISE_ID = Math.random().toString(36).substring(16);
|
756
|
+
var _state = parent._state;
|
1013
757
|
|
1014
|
-
|
758
|
+
if (_state) {
|
759
|
+
(function () {
|
760
|
+
var callback = _arguments[_state - 1];
|
761
|
+
asap(function () {
|
762
|
+
return invokeCallback(_state, child, callback, parent._result);
|
763
|
+
});
|
764
|
+
})();
|
765
|
+
} else {
|
766
|
+
subscribe(parent, child, onFulfillment, onRejection);
|
767
|
+
}
|
1015
768
|
|
1016
|
-
|
1017
|
-
|
1018
|
-
var lib$es6$promise$$internal$$REJECTED = 2;
|
769
|
+
return child;
|
770
|
+
}
|
1019
771
|
|
1020
|
-
|
772
|
+
/**
|
773
|
+
`Promise.resolve` returns a promise that will become resolved with the
|
774
|
+
passed `value`. It is shorthand for the following:
|
1021
775
|
|
1022
|
-
|
1023
|
-
|
1024
|
-
|
776
|
+
```javascript
|
777
|
+
let promise = new Promise(function(resolve, reject){
|
778
|
+
resolve(1);
|
779
|
+
});
|
1025
780
|
|
1026
|
-
|
1027
|
-
|
1028
|
-
|
781
|
+
promise.then(function(value){
|
782
|
+
// value === 1
|
783
|
+
});
|
784
|
+
```
|
1029
785
|
|
1030
|
-
|
1031
|
-
try {
|
1032
|
-
return promise.then;
|
1033
|
-
} catch(error) {
|
1034
|
-
lib$es6$promise$$internal$$GET_THEN_ERROR.error = error;
|
1035
|
-
return lib$es6$promise$$internal$$GET_THEN_ERROR;
|
1036
|
-
}
|
1037
|
-
}
|
786
|
+
Instead of writing the above, your code now simply becomes the following:
|
1038
787
|
|
1039
|
-
|
1040
|
-
|
1041
|
-
then.call(value, fulfillmentHandler, rejectionHandler);
|
1042
|
-
} catch(e) {
|
1043
|
-
return e;
|
1044
|
-
}
|
1045
|
-
}
|
788
|
+
```javascript
|
789
|
+
let promise = Promise.resolve(1);
|
1046
790
|
|
1047
|
-
|
1048
|
-
|
1049
|
-
|
1050
|
-
|
1051
|
-
|
1052
|
-
|
1053
|
-
|
1054
|
-
|
1055
|
-
|
1056
|
-
|
1057
|
-
|
1058
|
-
|
1059
|
-
|
1060
|
-
|
791
|
+
promise.then(function(value){
|
792
|
+
// value === 1
|
793
|
+
});
|
794
|
+
```
|
795
|
+
|
796
|
+
@method resolve
|
797
|
+
@static
|
798
|
+
@param {Any} value value that the returned promise will be resolved with
|
799
|
+
Useful for tooling.
|
800
|
+
@return {Promise} a promise that will become fulfilled with the given
|
801
|
+
`value`
|
802
|
+
*/
|
803
|
+
function resolve(object) {
|
804
|
+
/*jshint validthis:true */
|
805
|
+
var Constructor = this;
|
1061
806
|
|
1062
|
-
|
1063
|
-
|
807
|
+
if (object && typeof object === 'object' && object.constructor === Constructor) {
|
808
|
+
return object;
|
809
|
+
}
|
1064
810
|
|
1065
|
-
|
1066
|
-
|
1067
|
-
|
1068
|
-
|
1069
|
-
}, promise);
|
1070
|
-
}
|
811
|
+
var promise = new Constructor(noop);
|
812
|
+
_resolve(promise, object);
|
813
|
+
return promise;
|
814
|
+
}
|
1071
815
|
|
1072
|
-
|
1073
|
-
if (thenable._state === lib$es6$promise$$internal$$FULFILLED) {
|
1074
|
-
lib$es6$promise$$internal$$fulfill(promise, thenable._result);
|
1075
|
-
} else if (thenable._state === lib$es6$promise$$internal$$REJECTED) {
|
1076
|
-
lib$es6$promise$$internal$$reject(promise, thenable._result);
|
1077
|
-
} else {
|
1078
|
-
lib$es6$promise$$internal$$subscribe(thenable, undefined, function(value) {
|
1079
|
-
lib$es6$promise$$internal$$resolve(promise, value);
|
1080
|
-
}, function(reason) {
|
1081
|
-
lib$es6$promise$$internal$$reject(promise, reason);
|
1082
|
-
});
|
1083
|
-
}
|
1084
|
-
}
|
816
|
+
var PROMISE_ID = Math.random().toString(36).substring(16);
|
1085
817
|
|
1086
|
-
|
1087
|
-
if (maybeThenable.constructor === promise.constructor &&
|
1088
|
-
then === lib$es6$promise$then$$default &&
|
1089
|
-
constructor.resolve === lib$es6$promise$promise$resolve$$default) {
|
1090
|
-
lib$es6$promise$$internal$$handleOwnThenable(promise, maybeThenable);
|
1091
|
-
} else {
|
1092
|
-
if (then === lib$es6$promise$$internal$$GET_THEN_ERROR) {
|
1093
|
-
lib$es6$promise$$internal$$reject(promise, lib$es6$promise$$internal$$GET_THEN_ERROR.error);
|
1094
|
-
} else if (then === undefined) {
|
1095
|
-
lib$es6$promise$$internal$$fulfill(promise, maybeThenable);
|
1096
|
-
} else if (lib$es6$promise$utils$$isFunction(then)) {
|
1097
|
-
lib$es6$promise$$internal$$handleForeignThenable(promise, maybeThenable, then);
|
1098
|
-
} else {
|
1099
|
-
lib$es6$promise$$internal$$fulfill(promise, maybeThenable);
|
1100
|
-
}
|
1101
|
-
}
|
1102
|
-
}
|
818
|
+
function noop() {}
|
1103
819
|
|
1104
|
-
|
1105
|
-
|
1106
|
-
|
1107
|
-
} else if (lib$es6$promise$utils$$objectOrFunction(value)) {
|
1108
|
-
lib$es6$promise$$internal$$handleMaybeThenable(promise, value, lib$es6$promise$$internal$$getThen(value));
|
1109
|
-
} else {
|
1110
|
-
lib$es6$promise$$internal$$fulfill(promise, value);
|
1111
|
-
}
|
1112
|
-
}
|
820
|
+
var PENDING = void 0;
|
821
|
+
var FULFILLED = 1;
|
822
|
+
var REJECTED = 2;
|
1113
823
|
|
1114
|
-
|
1115
|
-
if (promise._onerror) {
|
1116
|
-
promise._onerror(promise._result);
|
1117
|
-
}
|
824
|
+
var GET_THEN_ERROR = new ErrorObject();
|
1118
825
|
|
1119
|
-
|
1120
|
-
|
826
|
+
function selfFulfillment() {
|
827
|
+
return new TypeError("You cannot resolve a promise with itself");
|
828
|
+
}
|
829
|
+
|
830
|
+
function cannotReturnOwn() {
|
831
|
+
return new TypeError('A promises callback cannot return that same promise.');
|
832
|
+
}
|
1121
833
|
|
1122
|
-
|
1123
|
-
|
834
|
+
function getThen(promise) {
|
835
|
+
try {
|
836
|
+
return promise.then;
|
837
|
+
} catch (error) {
|
838
|
+
GET_THEN_ERROR.error = error;
|
839
|
+
return GET_THEN_ERROR;
|
840
|
+
}
|
841
|
+
}
|
1124
842
|
|
1125
|
-
|
1126
|
-
|
843
|
+
function tryThen(then, value, fulfillmentHandler, rejectionHandler) {
|
844
|
+
try {
|
845
|
+
then.call(value, fulfillmentHandler, rejectionHandler);
|
846
|
+
} catch (e) {
|
847
|
+
return e;
|
848
|
+
}
|
849
|
+
}
|
1127
850
|
|
1128
|
-
|
1129
|
-
|
851
|
+
function handleForeignThenable(promise, thenable, then) {
|
852
|
+
asap(function (promise) {
|
853
|
+
var sealed = false;
|
854
|
+
var error = tryThen(then, thenable, function (value) {
|
855
|
+
if (sealed) {
|
856
|
+
return;
|
1130
857
|
}
|
1131
|
-
|
858
|
+
sealed = true;
|
859
|
+
if (thenable !== value) {
|
860
|
+
_resolve(promise, value);
|
861
|
+
} else {
|
862
|
+
fulfill(promise, value);
|
863
|
+
}
|
864
|
+
}, function (reason) {
|
865
|
+
if (sealed) {
|
866
|
+
return;
|
867
|
+
}
|
868
|
+
sealed = true;
|
1132
869
|
|
1133
|
-
|
1134
|
-
|
1135
|
-
promise._state = lib$es6$promise$$internal$$REJECTED;
|
1136
|
-
promise._result = reason;
|
870
|
+
_reject(promise, reason);
|
871
|
+
}, 'Settle: ' + (promise._label || ' unknown promise'));
|
1137
872
|
|
1138
|
-
|
873
|
+
if (!sealed && error) {
|
874
|
+
sealed = true;
|
875
|
+
_reject(promise, error);
|
1139
876
|
}
|
877
|
+
}, promise);
|
878
|
+
}
|
1140
879
|
|
1141
|
-
|
1142
|
-
|
1143
|
-
|
880
|
+
function handleOwnThenable(promise, thenable) {
|
881
|
+
if (thenable._state === FULFILLED) {
|
882
|
+
fulfill(promise, thenable._result);
|
883
|
+
} else if (thenable._state === REJECTED) {
|
884
|
+
_reject(promise, thenable._result);
|
885
|
+
} else {
|
886
|
+
subscribe(thenable, undefined, function (value) {
|
887
|
+
return _resolve(promise, value);
|
888
|
+
}, function (reason) {
|
889
|
+
return _reject(promise, reason);
|
890
|
+
});
|
891
|
+
}
|
892
|
+
}
|
1144
893
|
|
1145
|
-
|
894
|
+
function handleMaybeThenable(promise, maybeThenable, then$$) {
|
895
|
+
if (maybeThenable.constructor === promise.constructor && then$$ === then && maybeThenable.constructor.resolve === resolve) {
|
896
|
+
handleOwnThenable(promise, maybeThenable);
|
897
|
+
} else {
|
898
|
+
if (then$$ === GET_THEN_ERROR) {
|
899
|
+
_reject(promise, GET_THEN_ERROR.error);
|
900
|
+
} else if (then$$ === undefined) {
|
901
|
+
fulfill(promise, maybeThenable);
|
902
|
+
} else if (isFunction(then$$)) {
|
903
|
+
handleForeignThenable(promise, maybeThenable, then$$);
|
904
|
+
} else {
|
905
|
+
fulfill(promise, maybeThenable);
|
906
|
+
}
|
907
|
+
}
|
908
|
+
}
|
1146
909
|
|
1147
|
-
|
1148
|
-
|
1149
|
-
|
910
|
+
function _resolve(promise, value) {
|
911
|
+
if (promise === value) {
|
912
|
+
_reject(promise, selfFulfillment());
|
913
|
+
} else if (objectOrFunction(value)) {
|
914
|
+
handleMaybeThenable(promise, value, getThen(value));
|
915
|
+
} else {
|
916
|
+
fulfill(promise, value);
|
917
|
+
}
|
918
|
+
}
|
1150
919
|
|
1151
|
-
|
1152
|
-
|
1153
|
-
|
1154
|
-
|
920
|
+
function publishRejection(promise) {
|
921
|
+
if (promise._onerror) {
|
922
|
+
promise._onerror(promise._result);
|
923
|
+
}
|
1155
924
|
|
1156
|
-
|
1157
|
-
|
1158
|
-
var settled = promise._state;
|
925
|
+
publish(promise);
|
926
|
+
}
|
1159
927
|
|
1160
|
-
|
928
|
+
function fulfill(promise, value) {
|
929
|
+
if (promise._state !== PENDING) {
|
930
|
+
return;
|
931
|
+
}
|
1161
932
|
|
1162
|
-
|
933
|
+
promise._result = value;
|
934
|
+
promise._state = FULFILLED;
|
1163
935
|
|
1164
|
-
|
1165
|
-
|
1166
|
-
|
936
|
+
if (promise._subscribers.length !== 0) {
|
937
|
+
asap(publish, promise);
|
938
|
+
}
|
939
|
+
}
|
1167
940
|
|
1168
|
-
|
1169
|
-
|
1170
|
-
|
1171
|
-
|
1172
|
-
|
1173
|
-
|
941
|
+
function _reject(promise, reason) {
|
942
|
+
if (promise._state !== PENDING) {
|
943
|
+
return;
|
944
|
+
}
|
945
|
+
promise._state = REJECTED;
|
946
|
+
promise._result = reason;
|
1174
947
|
|
1175
|
-
|
1176
|
-
|
948
|
+
asap(publishRejection, promise);
|
949
|
+
}
|
1177
950
|
|
1178
|
-
|
1179
|
-
|
1180
|
-
|
951
|
+
function subscribe(parent, child, onFulfillment, onRejection) {
|
952
|
+
var _subscribers = parent._subscribers;
|
953
|
+
var length = _subscribers.length;
|
1181
954
|
|
1182
|
-
|
955
|
+
parent._onerror = null;
|
1183
956
|
|
1184
|
-
|
1185
|
-
|
1186
|
-
|
1187
|
-
} catch(e) {
|
1188
|
-
lib$es6$promise$$internal$$TRY_CATCH_ERROR.error = e;
|
1189
|
-
return lib$es6$promise$$internal$$TRY_CATCH_ERROR;
|
1190
|
-
}
|
1191
|
-
}
|
957
|
+
_subscribers[length] = child;
|
958
|
+
_subscribers[length + FULFILLED] = onFulfillment;
|
959
|
+
_subscribers[length + REJECTED] = onRejection;
|
1192
960
|
|
1193
|
-
|
1194
|
-
|
1195
|
-
|
961
|
+
if (length === 0 && parent._state) {
|
962
|
+
asap(publish, parent);
|
963
|
+
}
|
964
|
+
}
|
1196
965
|
|
1197
|
-
|
1198
|
-
|
966
|
+
function publish(promise) {
|
967
|
+
var subscribers = promise._subscribers;
|
968
|
+
var settled = promise._state;
|
1199
969
|
|
1200
|
-
|
1201
|
-
|
1202
|
-
|
1203
|
-
value = null;
|
1204
|
-
} else {
|
1205
|
-
succeeded = true;
|
1206
|
-
}
|
970
|
+
if (subscribers.length === 0) {
|
971
|
+
return;
|
972
|
+
}
|
1207
973
|
|
1208
|
-
|
1209
|
-
|
1210
|
-
|
1211
|
-
}
|
974
|
+
var child = undefined,
|
975
|
+
callback = undefined,
|
976
|
+
detail = promise._result;
|
1212
977
|
|
1213
|
-
|
1214
|
-
|
1215
|
-
|
1216
|
-
}
|
978
|
+
for (var i = 0; i < subscribers.length; i += 3) {
|
979
|
+
child = subscribers[i];
|
980
|
+
callback = subscribers[i + settled];
|
1217
981
|
|
1218
|
-
|
1219
|
-
|
1220
|
-
|
1221
|
-
|
1222
|
-
} else if (failed) {
|
1223
|
-
lib$es6$promise$$internal$$reject(promise, error);
|
1224
|
-
} else if (settled === lib$es6$promise$$internal$$FULFILLED) {
|
1225
|
-
lib$es6$promise$$internal$$fulfill(promise, value);
|
1226
|
-
} else if (settled === lib$es6$promise$$internal$$REJECTED) {
|
1227
|
-
lib$es6$promise$$internal$$reject(promise, value);
|
1228
|
-
}
|
982
|
+
if (child) {
|
983
|
+
invokeCallback(settled, child, callback, detail);
|
984
|
+
} else {
|
985
|
+
callback(detail);
|
1229
986
|
}
|
987
|
+
}
|
1230
988
|
|
1231
|
-
|
1232
|
-
|
1233
|
-
resolver(function resolvePromise(value){
|
1234
|
-
lib$es6$promise$$internal$$resolve(promise, value);
|
1235
|
-
}, function rejectPromise(reason) {
|
1236
|
-
lib$es6$promise$$internal$$reject(promise, reason);
|
1237
|
-
});
|
1238
|
-
} catch(e) {
|
1239
|
-
lib$es6$promise$$internal$$reject(promise, e);
|
1240
|
-
}
|
1241
|
-
}
|
989
|
+
promise._subscribers.length = 0;
|
990
|
+
}
|
1242
991
|
|
1243
|
-
|
1244
|
-
|
1245
|
-
|
1246
|
-
}
|
992
|
+
function ErrorObject() {
|
993
|
+
this.error = null;
|
994
|
+
}
|
1247
995
|
|
1248
|
-
|
1249
|
-
promise[lib$es6$promise$$internal$$PROMISE_ID] = lib$es6$promise$$internal$$id++;
|
1250
|
-
promise._state = undefined;
|
1251
|
-
promise._result = undefined;
|
1252
|
-
promise._subscribers = [];
|
1253
|
-
}
|
996
|
+
var TRY_CATCH_ERROR = new ErrorObject();
|
1254
997
|
|
1255
|
-
|
1256
|
-
|
1257
|
-
|
1258
|
-
|
1259
|
-
|
1260
|
-
|
1261
|
-
|
1262
|
-
|
1263
|
-
if (!lib$es6$promise$utils$$isArray(entries)) {
|
1264
|
-
return new Constructor(function(resolve, reject) {
|
1265
|
-
reject(new TypeError('You must pass an array to race.'));
|
1266
|
-
});
|
1267
|
-
} else {
|
1268
|
-
return new Constructor(function(resolve, reject) {
|
1269
|
-
var length = entries.length;
|
1270
|
-
for (var i = 0; i < length; i++) {
|
1271
|
-
Constructor.resolve(entries[i]).then(resolve, reject);
|
1272
|
-
}
|
1273
|
-
});
|
1274
|
-
}
|
1275
|
-
}
|
1276
|
-
var lib$es6$promise$promise$race$$default = lib$es6$promise$promise$race$$race;
|
1277
|
-
function lib$es6$promise$promise$reject$$reject(reason) {
|
1278
|
-
/*jshint validthis:true */
|
1279
|
-
var Constructor = this;
|
1280
|
-
var promise = new Constructor(lib$es6$promise$$internal$$noop);
|
1281
|
-
lib$es6$promise$$internal$$reject(promise, reason);
|
1282
|
-
return promise;
|
1283
|
-
}
|
1284
|
-
var lib$es6$promise$promise$reject$$default = lib$es6$promise$promise$reject$$reject;
|
998
|
+
function tryCatch(callback, detail) {
|
999
|
+
try {
|
1000
|
+
return callback(detail);
|
1001
|
+
} catch (e) {
|
1002
|
+
TRY_CATCH_ERROR.error = e;
|
1003
|
+
return TRY_CATCH_ERROR;
|
1004
|
+
}
|
1005
|
+
}
|
1285
1006
|
|
1007
|
+
function invokeCallback(settled, promise, callback, detail) {
|
1008
|
+
var hasCallback = isFunction(callback),
|
1009
|
+
value = undefined,
|
1010
|
+
error = undefined,
|
1011
|
+
succeeded = undefined,
|
1012
|
+
failed = undefined;
|
1286
1013
|
|
1287
|
-
|
1288
|
-
|
1014
|
+
if (hasCallback) {
|
1015
|
+
value = tryCatch(callback, detail);
|
1016
|
+
|
1017
|
+
if (value === TRY_CATCH_ERROR) {
|
1018
|
+
failed = true;
|
1019
|
+
error = value.error;
|
1020
|
+
value = null;
|
1021
|
+
} else {
|
1022
|
+
succeeded = true;
|
1289
1023
|
}
|
1290
1024
|
|
1291
|
-
|
1292
|
-
|
1025
|
+
if (promise === value) {
|
1026
|
+
_reject(promise, cannotReturnOwn());
|
1027
|
+
return;
|
1293
1028
|
}
|
1029
|
+
} else {
|
1030
|
+
value = detail;
|
1031
|
+
succeeded = true;
|
1032
|
+
}
|
1294
1033
|
|
1295
|
-
|
1296
|
-
|
1297
|
-
|
1298
|
-
|
1299
|
-
|
1300
|
-
|
1034
|
+
if (promise._state !== PENDING) {
|
1035
|
+
// noop
|
1036
|
+
} else if (hasCallback && succeeded) {
|
1037
|
+
_resolve(promise, value);
|
1038
|
+
} else if (failed) {
|
1039
|
+
_reject(promise, error);
|
1040
|
+
} else if (settled === FULFILLED) {
|
1041
|
+
fulfill(promise, value);
|
1042
|
+
} else if (settled === REJECTED) {
|
1043
|
+
_reject(promise, value);
|
1044
|
+
}
|
1045
|
+
}
|
1301
1046
|
|
1302
|
-
|
1303
|
-
|
1047
|
+
function initializePromise(promise, resolver) {
|
1048
|
+
try {
|
1049
|
+
resolver(function resolvePromise(value) {
|
1050
|
+
_resolve(promise, value);
|
1051
|
+
}, function rejectPromise(reason) {
|
1052
|
+
_reject(promise, reason);
|
1053
|
+
});
|
1054
|
+
} catch (e) {
|
1055
|
+
_reject(promise, e);
|
1056
|
+
}
|
1057
|
+
}
|
1304
1058
|
|
1305
|
-
|
1306
|
-
|
1307
|
-
|
1308
|
-
|
1309
|
-
- `reason` is a value that indicates why a promise was rejected.
|
1310
|
-
- `settled` the final resting state of a promise, fulfilled or rejected.
|
1059
|
+
var id = 0;
|
1060
|
+
function nextId() {
|
1061
|
+
return id++;
|
1062
|
+
}
|
1311
1063
|
|
1312
|
-
|
1064
|
+
function makePromise(promise) {
|
1065
|
+
promise[PROMISE_ID] = id++;
|
1066
|
+
promise._state = undefined;
|
1067
|
+
promise._result = undefined;
|
1068
|
+
promise._subscribers = [];
|
1069
|
+
}
|
1313
1070
|
|
1314
|
-
|
1315
|
-
|
1316
|
-
|
1071
|
+
function Enumerator(Constructor, input) {
|
1072
|
+
this._instanceConstructor = Constructor;
|
1073
|
+
this.promise = new Constructor(noop);
|
1317
1074
|
|
1318
|
-
|
1319
|
-
|
1320
|
-
|
1321
|
-
itself reject, and a promise that *resolves* a promise that fulfills will
|
1322
|
-
itself fulfill.
|
1075
|
+
if (!this.promise[PROMISE_ID]) {
|
1076
|
+
makePromise(this.promise);
|
1077
|
+
}
|
1323
1078
|
|
1079
|
+
if (isArray(input)) {
|
1080
|
+
this._input = input;
|
1081
|
+
this.length = input.length;
|
1082
|
+
this._remaining = input.length;
|
1324
1083
|
|
1325
|
-
|
1326
|
-
------------
|
1084
|
+
this._result = new Array(this.length);
|
1327
1085
|
|
1328
|
-
|
1329
|
-
|
1330
|
-
|
1331
|
-
|
1086
|
+
if (this.length === 0) {
|
1087
|
+
fulfill(this.promise, this._result);
|
1088
|
+
} else {
|
1089
|
+
this.length = this.length || 0;
|
1090
|
+
this._enumerate();
|
1091
|
+
if (this._remaining === 0) {
|
1092
|
+
fulfill(this.promise, this._result);
|
1093
|
+
}
|
1094
|
+
}
|
1095
|
+
} else {
|
1096
|
+
_reject(this.promise, validationError());
|
1097
|
+
}
|
1098
|
+
}
|
1332
1099
|
|
1333
|
-
|
1334
|
-
|
1335
|
-
|
1100
|
+
function validationError() {
|
1101
|
+
return new Error('Array Methods must be provided an Array');
|
1102
|
+
};
|
1336
1103
|
|
1337
|
-
|
1338
|
-
|
1339
|
-
|
1340
|
-
// on rejection
|
1341
|
-
});
|
1342
|
-
```
|
1343
|
-
|
1344
|
-
Advanced Usage:
|
1345
|
-
---------------
|
1346
|
-
|
1347
|
-
Promises shine when abstracting away asynchronous interactions such as
|
1348
|
-
`XMLHttpRequest`s.
|
1349
|
-
|
1350
|
-
```js
|
1351
|
-
function getJSON(url) {
|
1352
|
-
return new Promise(function(resolve, reject){
|
1353
|
-
var xhr = new XMLHttpRequest();
|
1354
|
-
|
1355
|
-
xhr.open('GET', url);
|
1356
|
-
xhr.onreadystatechange = handler;
|
1357
|
-
xhr.responseType = 'json';
|
1358
|
-
xhr.setRequestHeader('Accept', 'application/json');
|
1359
|
-
xhr.send();
|
1360
|
-
|
1361
|
-
function handler() {
|
1362
|
-
if (this.readyState === this.DONE) {
|
1363
|
-
if (this.status === 200) {
|
1364
|
-
resolve(this.response);
|
1365
|
-
} else {
|
1366
|
-
reject(new Error('getJSON: `' + url + '` failed with status: [' + this.status + ']'));
|
1367
|
-
}
|
1368
|
-
}
|
1369
|
-
};
|
1370
|
-
});
|
1371
|
-
}
|
1104
|
+
Enumerator.prototype._enumerate = function () {
|
1105
|
+
var length = this.length;
|
1106
|
+
var _input = this._input;
|
1372
1107
|
|
1373
|
-
|
1374
|
-
|
1375
|
-
|
1376
|
-
|
1377
|
-
});
|
1378
|
-
```
|
1108
|
+
for (var i = 0; this._state === PENDING && i < length; i++) {
|
1109
|
+
this._eachEntry(_input[i], i);
|
1110
|
+
}
|
1111
|
+
};
|
1379
1112
|
|
1380
|
-
|
1113
|
+
Enumerator.prototype._eachEntry = function (entry, i) {
|
1114
|
+
var c = this._instanceConstructor;
|
1115
|
+
var resolve$$ = c.resolve;
|
1116
|
+
|
1117
|
+
if (resolve$$ === resolve) {
|
1118
|
+
var _then = getThen(entry);
|
1119
|
+
|
1120
|
+
if (_then === then && entry._state !== PENDING) {
|
1121
|
+
this._settledAt(entry._state, i, entry._result);
|
1122
|
+
} else if (typeof _then !== 'function') {
|
1123
|
+
this._remaining--;
|
1124
|
+
this._result[i] = entry;
|
1125
|
+
} else if (c === Promise) {
|
1126
|
+
var promise = new c(noop);
|
1127
|
+
handleMaybeThenable(promise, entry, _then);
|
1128
|
+
this._willSettleAt(promise, i);
|
1129
|
+
} else {
|
1130
|
+
this._willSettleAt(new c(function (resolve$$) {
|
1131
|
+
return resolve$$(entry);
|
1132
|
+
}), i);
|
1133
|
+
}
|
1134
|
+
} else {
|
1135
|
+
this._willSettleAt(resolve$$(entry), i);
|
1136
|
+
}
|
1137
|
+
};
|
1381
1138
|
|
1382
|
-
|
1383
|
-
|
1384
|
-
getJSON('/posts'),
|
1385
|
-
getJSON('/comments')
|
1386
|
-
]).then(function(values){
|
1387
|
-
values[0] // => postsJSON
|
1388
|
-
values[1] // => commentsJSON
|
1139
|
+
Enumerator.prototype._settledAt = function (state, i, value) {
|
1140
|
+
var promise = this.promise;
|
1389
1141
|
|
1390
|
-
|
1391
|
-
|
1392
|
-
|
1393
|
-
|
1394
|
-
|
1395
|
-
|
1396
|
-
|
1397
|
-
@constructor
|
1398
|
-
*/
|
1399
|
-
function lib$es6$promise$promise$$Promise(resolver) {
|
1400
|
-
this[lib$es6$promise$$internal$$PROMISE_ID] = lib$es6$promise$$internal$$nextId();
|
1401
|
-
this._result = this._state = undefined;
|
1402
|
-
this._subscribers = [];
|
1403
|
-
|
1404
|
-
if (lib$es6$promise$$internal$$noop !== resolver) {
|
1405
|
-
typeof resolver !== 'function' && lib$es6$promise$promise$$needsResolver();
|
1406
|
-
this instanceof lib$es6$promise$promise$$Promise ? lib$es6$promise$$internal$$initializePromise(this, resolver) : lib$es6$promise$promise$$needsNew();
|
1407
|
-
}
|
1142
|
+
if (promise._state === PENDING) {
|
1143
|
+
this._remaining--;
|
1144
|
+
|
1145
|
+
if (state === REJECTED) {
|
1146
|
+
_reject(promise, value);
|
1147
|
+
} else {
|
1148
|
+
this._result[i] = value;
|
1408
1149
|
}
|
1150
|
+
}
|
1409
1151
|
|
1410
|
-
|
1411
|
-
|
1412
|
-
|
1413
|
-
|
1414
|
-
lib$es6$promise$promise$$Promise._setScheduler = lib$es6$promise$asap$$setScheduler;
|
1415
|
-
lib$es6$promise$promise$$Promise._setAsap = lib$es6$promise$asap$$setAsap;
|
1416
|
-
lib$es6$promise$promise$$Promise._asap = lib$es6$promise$asap$$asap;
|
1417
|
-
|
1418
|
-
lib$es6$promise$promise$$Promise.prototype = {
|
1419
|
-
constructor: lib$es6$promise$promise$$Promise,
|
1420
|
-
|
1421
|
-
/**
|
1422
|
-
The primary way of interacting with a promise is through its `then` method,
|
1423
|
-
which registers callbacks to receive either a promise's eventual value or the
|
1424
|
-
reason why the promise cannot be fulfilled.
|
1425
|
-
|
1426
|
-
```js
|
1427
|
-
findUser().then(function(user){
|
1428
|
-
// user is available
|
1429
|
-
}, function(reason){
|
1430
|
-
// user is unavailable, and you are given the reason why
|
1431
|
-
});
|
1432
|
-
```
|
1433
|
-
|
1434
|
-
Chaining
|
1435
|
-
--------
|
1436
|
-
|
1437
|
-
The return value of `then` is itself a promise. This second, 'downstream'
|
1438
|
-
promise is resolved with the return value of the first promise's fulfillment
|
1439
|
-
or rejection handler, or rejected if the handler throws an exception.
|
1440
|
-
|
1441
|
-
```js
|
1442
|
-
findUser().then(function (user) {
|
1443
|
-
return user.name;
|
1444
|
-
}, function (reason) {
|
1445
|
-
return 'default name';
|
1446
|
-
}).then(function (userName) {
|
1447
|
-
// If `findUser` fulfilled, `userName` will be the user's name, otherwise it
|
1448
|
-
// will be `'default name'`
|
1449
|
-
});
|
1152
|
+
if (this._remaining === 0) {
|
1153
|
+
fulfill(promise, this._result);
|
1154
|
+
}
|
1155
|
+
};
|
1450
1156
|
|
1451
|
-
|
1452
|
-
|
1453
|
-
}, function (reason) {
|
1454
|
-
throw new Error('`findUser` rejected and we're unhappy');
|
1455
|
-
}).then(function (value) {
|
1456
|
-
// never reached
|
1457
|
-
}, function (reason) {
|
1458
|
-
// if `findUser` fulfilled, `reason` will be 'Found user, but still unhappy'.
|
1459
|
-
// If `findUser` rejected, `reason` will be '`findUser` rejected and we're unhappy'.
|
1460
|
-
});
|
1461
|
-
```
|
1462
|
-
If the downstream promise does not specify a rejection handler, rejection reasons will be propagated further downstream.
|
1463
|
-
|
1464
|
-
```js
|
1465
|
-
findUser().then(function (user) {
|
1466
|
-
throw new PedagogicalException('Upstream error');
|
1467
|
-
}).then(function (value) {
|
1468
|
-
// never reached
|
1469
|
-
}).then(function (value) {
|
1470
|
-
// never reached
|
1471
|
-
}, function (reason) {
|
1472
|
-
// The `PedgagocialException` is propagated all the way down to here
|
1473
|
-
});
|
1474
|
-
```
|
1157
|
+
Enumerator.prototype._willSettleAt = function (promise, i) {
|
1158
|
+
var enumerator = this;
|
1475
1159
|
|
1476
|
-
|
1477
|
-
|
1160
|
+
subscribe(promise, undefined, function (value) {
|
1161
|
+
return enumerator._settledAt(FULFILLED, i, value);
|
1162
|
+
}, function (reason) {
|
1163
|
+
return enumerator._settledAt(REJECTED, i, reason);
|
1164
|
+
});
|
1165
|
+
};
|
1478
1166
|
|
1479
|
-
|
1480
|
-
|
1481
|
-
|
1482
|
-
|
1167
|
+
/**
|
1168
|
+
`Promise.all` accepts an array of promises, and returns a new promise which
|
1169
|
+
is fulfilled with an array of fulfillment values for the passed promises, or
|
1170
|
+
rejected with the reason of the first passed promise to be rejected. It casts all
|
1171
|
+
elements of the passed iterable to promises as it runs this algorithm.
|
1483
1172
|
|
1484
|
-
|
1485
|
-
findUser().then(function (user) {
|
1486
|
-
return findCommentsByAuthor(user);
|
1487
|
-
}).then(function (comments) {
|
1488
|
-
// The user's comments are now available
|
1489
|
-
});
|
1490
|
-
```
|
1173
|
+
Example:
|
1491
1174
|
|
1492
|
-
|
1175
|
+
```javascript
|
1176
|
+
let promise1 = resolve(1);
|
1177
|
+
let promise2 = resolve(2);
|
1178
|
+
let promise3 = resolve(3);
|
1179
|
+
let promises = [ promise1, promise2, promise3 ];
|
1493
1180
|
|
1494
|
-
|
1495
|
-
|
1496
|
-
|
1497
|
-
|
1498
|
-
// If `findCommentsByAuthor` fulfills, we'll have the value here
|
1499
|
-
}, function (reason) {
|
1500
|
-
// If `findCommentsByAuthor` rejects, we'll have the reason here
|
1501
|
-
});
|
1502
|
-
```
|
1181
|
+
Promise.all(promises).then(function(array){
|
1182
|
+
// The array here would be [ 1, 2, 3 ];
|
1183
|
+
});
|
1184
|
+
```
|
1503
1185
|
|
1504
|
-
|
1505
|
-
|
1186
|
+
If any of the `promises` given to `all` are rejected, the first promise
|
1187
|
+
that is rejected will be given as an argument to the returned promises's
|
1188
|
+
rejection handler. For example:
|
1506
1189
|
|
1507
|
-
|
1190
|
+
Example:
|
1508
1191
|
|
1509
|
-
|
1510
|
-
|
1192
|
+
```javascript
|
1193
|
+
let promise1 = resolve(1);
|
1194
|
+
let promise2 = reject(new Error("2"));
|
1195
|
+
let promise3 = reject(new Error("3"));
|
1196
|
+
let promises = [ promise1, promise2, promise3 ];
|
1511
1197
|
|
1512
|
-
|
1513
|
-
|
1514
|
-
|
1515
|
-
|
1516
|
-
|
1517
|
-
|
1518
|
-
|
1198
|
+
Promise.all(promises).then(function(array){
|
1199
|
+
// Code here never runs because there are rejected promises!
|
1200
|
+
}, function(error) {
|
1201
|
+
// error.message === "2"
|
1202
|
+
});
|
1203
|
+
```
|
1204
|
+
|
1205
|
+
@method all
|
1206
|
+
@static
|
1207
|
+
@param {Array} entries array of promises
|
1208
|
+
@param {String} label optional string for labeling the promise.
|
1209
|
+
Useful for tooling.
|
1210
|
+
@return {Promise} promise that is fulfilled when all `promises` have been
|
1211
|
+
fulfilled, or rejected if any of them become rejected.
|
1212
|
+
@static
|
1213
|
+
*/
|
1214
|
+
function all(entries) {
|
1215
|
+
return new Enumerator(this, entries).promise;
|
1216
|
+
}
|
1519
1217
|
|
1520
|
-
|
1218
|
+
/**
|
1219
|
+
`Promise.race` returns a new promise which is settled in the same way as the
|
1220
|
+
first passed promise to settle.
|
1521
1221
|
|
1522
|
-
|
1523
|
-
findResult(function(result, err){
|
1524
|
-
if (err) {
|
1525
|
-
// failure
|
1526
|
-
} else {
|
1527
|
-
// success
|
1528
|
-
}
|
1529
|
-
});
|
1530
|
-
```
|
1222
|
+
Example:
|
1531
1223
|
|
1532
|
-
|
1224
|
+
```javascript
|
1225
|
+
let promise1 = new Promise(function(resolve, reject){
|
1226
|
+
setTimeout(function(){
|
1227
|
+
resolve('promise 1');
|
1228
|
+
}, 200);
|
1229
|
+
});
|
1533
1230
|
|
1534
|
-
|
1535
|
-
|
1536
|
-
|
1537
|
-
|
1538
|
-
|
1539
|
-
});
|
1540
|
-
```
|
1231
|
+
let promise2 = new Promise(function(resolve, reject){
|
1232
|
+
setTimeout(function(){
|
1233
|
+
resolve('promise 2');
|
1234
|
+
}, 100);
|
1235
|
+
});
|
1541
1236
|
|
1542
|
-
|
1543
|
-
|
1237
|
+
Promise.race([promise1, promise2]).then(function(result){
|
1238
|
+
// result === 'promise 2' because it was resolved before promise1
|
1239
|
+
// was resolved.
|
1240
|
+
});
|
1241
|
+
```
|
1242
|
+
|
1243
|
+
`Promise.race` is deterministic in that only the state of the first
|
1244
|
+
settled promise matters. For example, even if other promises given to the
|
1245
|
+
`promises` array argument are resolved, but the first settled promise has
|
1246
|
+
become rejected before the other promises became fulfilled, the returned
|
1247
|
+
promise will become rejected:
|
1248
|
+
|
1249
|
+
```javascript
|
1250
|
+
let promise1 = new Promise(function(resolve, reject){
|
1251
|
+
setTimeout(function(){
|
1252
|
+
resolve('promise 1');
|
1253
|
+
}, 200);
|
1254
|
+
});
|
1544
1255
|
|
1545
|
-
|
1256
|
+
let promise2 = new Promise(function(resolve, reject){
|
1257
|
+
setTimeout(function(){
|
1258
|
+
reject(new Error('promise 2'));
|
1259
|
+
}, 100);
|
1260
|
+
});
|
1546
1261
|
|
1547
|
-
|
1548
|
-
|
1262
|
+
Promise.race([promise1, promise2]).then(function(result){
|
1263
|
+
// Code here never runs
|
1264
|
+
}, function(reason){
|
1265
|
+
// reason.message === 'promise 2' because promise 2 became rejected before
|
1266
|
+
// promise 1 became fulfilled
|
1267
|
+
});
|
1268
|
+
```
|
1549
1269
|
|
1550
|
-
|
1551
|
-
|
1552
|
-
|
1553
|
-
|
1554
|
-
|
1555
|
-
|
1270
|
+
An example real-world use case is implementing timeouts:
|
1271
|
+
|
1272
|
+
```javascript
|
1273
|
+
Promise.race([ajax('foo.json'), timeout(5000)])
|
1274
|
+
```
|
1275
|
+
|
1276
|
+
@method race
|
1277
|
+
@static
|
1278
|
+
@param {Array} promises array of promises to observe
|
1279
|
+
Useful for tooling.
|
1280
|
+
@return {Promise} a promise which settles in the same way as the first passed
|
1281
|
+
promise to settle.
|
1282
|
+
*/
|
1283
|
+
function race(entries) {
|
1284
|
+
/*jshint validthis:true */
|
1285
|
+
var Constructor = this;
|
1286
|
+
|
1287
|
+
if (!isArray(entries)) {
|
1288
|
+
return new Constructor(function (_, reject) {
|
1289
|
+
return reject(new TypeError('You must pass an array to race.'));
|
1290
|
+
});
|
1291
|
+
} else {
|
1292
|
+
return new Constructor(function (resolve, reject) {
|
1293
|
+
var length = entries.length;
|
1294
|
+
for (var i = 0; i < length; i++) {
|
1295
|
+
Constructor.resolve(entries[i]).then(resolve, reject);
|
1556
1296
|
}
|
1557
|
-
|
1297
|
+
});
|
1298
|
+
}
|
1299
|
+
}
|
1558
1300
|
|
1559
|
-
|
1301
|
+
/**
|
1302
|
+
`Promise.reject` returns a promise rejected with the passed `reason`.
|
1303
|
+
It is shorthand for the following:
|
1560
1304
|
|
1561
|
-
|
1305
|
+
```javascript
|
1306
|
+
let promise = new Promise(function(resolve, reject){
|
1307
|
+
reject(new Error('WHOOPS'));
|
1308
|
+
});
|
1562
1309
|
|
1563
|
-
|
1310
|
+
promise.then(function(value){
|
1311
|
+
// Code here doesn't run because the promise is rejected!
|
1312
|
+
}, function(reason){
|
1313
|
+
// reason.message === 'WHOOPS'
|
1314
|
+
});
|
1315
|
+
```
|
1564
1316
|
|
1565
|
-
|
1317
|
+
Instead of writing the above, your code now simply becomes the following:
|
1566
1318
|
|
1567
|
-
|
1319
|
+
```javascript
|
1320
|
+
let promise = Promise.reject(new Error('WHOOPS'));
|
1568
1321
|
|
1569
|
-
|
1322
|
+
promise.then(function(value){
|
1323
|
+
// Code here doesn't run because the promise is rejected!
|
1324
|
+
}, function(reason){
|
1325
|
+
// reason.message === 'WHOOPS'
|
1326
|
+
});
|
1327
|
+
```
|
1570
1328
|
|
1571
|
-
|
1572
|
-
|
1573
|
-
|
1574
|
-
|
1575
|
-
|
1576
|
-
|
1577
|
-
|
1578
|
-
|
1579
|
-
|
1580
|
-
|
1581
|
-
|
1582
|
-
|
1583
|
-
|
1584
|
-
failure(reason);
|
1585
|
-
}
|
1586
|
-
}
|
1587
|
-
});
|
1588
|
-
} catch(error) {
|
1589
|
-
failure(err);
|
1590
|
-
}
|
1591
|
-
// success
|
1592
|
-
}
|
1593
|
-
});
|
1594
|
-
```
|
1329
|
+
@method reject
|
1330
|
+
@static
|
1331
|
+
@param {Any} reason value that the returned promise will be rejected with.
|
1332
|
+
Useful for tooling.
|
1333
|
+
@return {Promise} a promise rejected with the given `reason`.
|
1334
|
+
*/
|
1335
|
+
function reject(reason) {
|
1336
|
+
/*jshint validthis:true */
|
1337
|
+
var Constructor = this;
|
1338
|
+
var promise = new Constructor(noop);
|
1339
|
+
_reject(promise, reason);
|
1340
|
+
return promise;
|
1341
|
+
}
|
1595
1342
|
|
1596
|
-
|
1343
|
+
function needsResolver() {
|
1344
|
+
throw new TypeError('You must pass a resolver function as the first argument to the promise constructor');
|
1345
|
+
}
|
1597
1346
|
|
1598
|
-
|
1599
|
-
|
1600
|
-
|
1601
|
-
then(function(books){
|
1602
|
-
// found books
|
1603
|
-
}).catch(function(reason){
|
1604
|
-
// something went wrong
|
1605
|
-
});
|
1606
|
-
```
|
1607
|
-
|
1608
|
-
@method then
|
1609
|
-
@param {Function} onFulfilled
|
1610
|
-
@param {Function} onRejected
|
1611
|
-
Useful for tooling.
|
1612
|
-
@return {Promise}
|
1613
|
-
*/
|
1614
|
-
then: lib$es6$promise$then$$default,
|
1615
|
-
|
1616
|
-
/**
|
1617
|
-
`catch` is simply sugar for `then(undefined, onRejection)` which makes it the same
|
1618
|
-
as the catch block of a try/catch statement.
|
1619
|
-
|
1620
|
-
```js
|
1621
|
-
function findAuthor(){
|
1622
|
-
throw new Error('couldn't find that author');
|
1623
|
-
}
|
1347
|
+
function needsNew() {
|
1348
|
+
throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.");
|
1349
|
+
}
|
1624
1350
|
|
1625
|
-
|
1626
|
-
|
1627
|
-
|
1628
|
-
|
1629
|
-
|
1630
|
-
}
|
1351
|
+
/**
|
1352
|
+
Promise objects represent the eventual result of an asynchronous operation. The
|
1353
|
+
primary way of interacting with a promise is through its `then` method, which
|
1354
|
+
registers callbacks to receive either a promise's eventual value or the reason
|
1355
|
+
why the promise cannot be fulfilled.
|
1631
1356
|
|
1632
|
-
|
1633
|
-
|
1634
|
-
// something went wrong
|
1635
|
-
});
|
1636
|
-
```
|
1637
|
-
|
1638
|
-
@method catch
|
1639
|
-
@param {Function} onRejection
|
1640
|
-
Useful for tooling.
|
1641
|
-
@return {Promise}
|
1642
|
-
*/
|
1643
|
-
'catch': function(onRejection) {
|
1644
|
-
return this.then(null, onRejection);
|
1645
|
-
}
|
1646
|
-
};
|
1647
|
-
var lib$es6$promise$enumerator$$default = lib$es6$promise$enumerator$$Enumerator;
|
1648
|
-
function lib$es6$promise$enumerator$$Enumerator(Constructor, input) {
|
1649
|
-
this._instanceConstructor = Constructor;
|
1650
|
-
this.promise = new Constructor(lib$es6$promise$$internal$$noop);
|
1357
|
+
Terminology
|
1358
|
+
-----------
|
1651
1359
|
|
1652
|
-
|
1653
|
-
|
1654
|
-
|
1360
|
+
- `promise` is an object or function with a `then` method whose behavior conforms to this specification.
|
1361
|
+
- `thenable` is an object or function that defines a `then` method.
|
1362
|
+
- `value` is any legal JavaScript value (including undefined, a thenable, or a promise).
|
1363
|
+
- `exception` is a value that is thrown using the throw statement.
|
1364
|
+
- `reason` is a value that indicates why a promise was rejected.
|
1365
|
+
- `settled` the final resting state of a promise, fulfilled or rejected.
|
1655
1366
|
|
1656
|
-
|
1657
|
-
this._input = input;
|
1658
|
-
this.length = input.length;
|
1659
|
-
this._remaining = input.length;
|
1367
|
+
A promise can be in one of three states: pending, fulfilled, or rejected.
|
1660
1368
|
|
1661
|
-
|
1369
|
+
Promises that are fulfilled have a fulfillment value and are in the fulfilled
|
1370
|
+
state. Promises that are rejected have a rejection reason and are in the
|
1371
|
+
rejected state. A fulfillment value is never a thenable.
|
1662
1372
|
|
1663
|
-
|
1664
|
-
|
1665
|
-
|
1666
|
-
|
1667
|
-
|
1668
|
-
if (this._remaining === 0) {
|
1669
|
-
lib$es6$promise$$internal$$fulfill(this.promise, this._result);
|
1670
|
-
}
|
1671
|
-
}
|
1672
|
-
} else {
|
1673
|
-
lib$es6$promise$$internal$$reject(this.promise, lib$es6$promise$enumerator$$validationError());
|
1674
|
-
}
|
1675
|
-
}
|
1373
|
+
Promises can also be said to *resolve* a value. If this value is also a
|
1374
|
+
promise, then the original promise's settled state will match the value's
|
1375
|
+
settled state. So a promise that *resolves* a promise that rejects will
|
1376
|
+
itself reject, and a promise that *resolves* a promise that fulfills will
|
1377
|
+
itself fulfill.
|
1676
1378
|
|
1677
|
-
function lib$es6$promise$enumerator$$validationError() {
|
1678
|
-
return new Error('Array Methods must be provided an Array');
|
1679
|
-
}
|
1680
1379
|
|
1681
|
-
|
1682
|
-
|
1683
|
-
var input = this._input;
|
1380
|
+
Basic Usage:
|
1381
|
+
------------
|
1684
1382
|
|
1685
|
-
|
1686
|
-
|
1687
|
-
|
1688
|
-
|
1383
|
+
```js
|
1384
|
+
let promise = new Promise(function(resolve, reject) {
|
1385
|
+
// on success
|
1386
|
+
resolve(value);
|
1689
1387
|
|
1690
|
-
|
1691
|
-
|
1692
|
-
|
1693
|
-
|
1694
|
-
if (resolve === lib$es6$promise$promise$resolve$$default) {
|
1695
|
-
var then = lib$es6$promise$$internal$$getThen(entry);
|
1696
|
-
|
1697
|
-
if (then === lib$es6$promise$then$$default &&
|
1698
|
-
entry._state !== lib$es6$promise$$internal$$PENDING) {
|
1699
|
-
this._settledAt(entry._state, i, entry._result);
|
1700
|
-
} else if (typeof then !== 'function') {
|
1701
|
-
this._remaining--;
|
1702
|
-
this._result[i] = entry;
|
1703
|
-
} else if (c === lib$es6$promise$promise$$default) {
|
1704
|
-
var promise = new c(lib$es6$promise$$internal$$noop);
|
1705
|
-
lib$es6$promise$$internal$$handleMaybeThenable(promise, entry, then);
|
1706
|
-
this._willSettleAt(promise, i);
|
1707
|
-
} else {
|
1708
|
-
this._willSettleAt(new c(function(resolve) { resolve(entry); }), i);
|
1709
|
-
}
|
1710
|
-
} else {
|
1711
|
-
this._willSettleAt(resolve(entry), i);
|
1712
|
-
}
|
1713
|
-
};
|
1388
|
+
// on failure
|
1389
|
+
reject(reason);
|
1390
|
+
});
|
1714
1391
|
|
1715
|
-
|
1716
|
-
|
1392
|
+
promise.then(function(value) {
|
1393
|
+
// on fulfillment
|
1394
|
+
}, function(reason) {
|
1395
|
+
// on rejection
|
1396
|
+
});
|
1397
|
+
```
|
1717
1398
|
|
1718
|
-
|
1719
|
-
|
1399
|
+
Advanced Usage:
|
1400
|
+
---------------
|
1720
1401
|
|
1721
|
-
|
1722
|
-
|
1723
|
-
|
1724
|
-
|
1402
|
+
Promises shine when abstracting away asynchronous interactions such as
|
1403
|
+
`XMLHttpRequest`s.
|
1404
|
+
|
1405
|
+
```js
|
1406
|
+
function getJSON(url) {
|
1407
|
+
return new Promise(function(resolve, reject){
|
1408
|
+
let xhr = new XMLHttpRequest();
|
1409
|
+
|
1410
|
+
xhr.open('GET', url);
|
1411
|
+
xhr.onreadystatechange = handler;
|
1412
|
+
xhr.responseType = 'json';
|
1413
|
+
xhr.setRequestHeader('Accept', 'application/json');
|
1414
|
+
xhr.send();
|
1415
|
+
|
1416
|
+
function handler() {
|
1417
|
+
if (this.readyState === this.DONE) {
|
1418
|
+
if (this.status === 200) {
|
1419
|
+
resolve(this.response);
|
1420
|
+
} else {
|
1421
|
+
reject(new Error('getJSON: `' + url + '` failed with status: [' + this.status + ']'));
|
1422
|
+
}
|
1725
1423
|
}
|
1726
|
-
}
|
1424
|
+
};
|
1425
|
+
});
|
1426
|
+
}
|
1727
1427
|
|
1728
|
-
|
1729
|
-
|
1730
|
-
|
1731
|
-
|
1428
|
+
getJSON('/posts.json').then(function(json) {
|
1429
|
+
// on fulfillment
|
1430
|
+
}, function(reason) {
|
1431
|
+
// on rejection
|
1432
|
+
});
|
1433
|
+
```
|
1732
1434
|
|
1733
|
-
|
1734
|
-
var enumerator = this;
|
1435
|
+
Unlike callbacks, promises are great composable primitives.
|
1735
1436
|
|
1736
|
-
|
1737
|
-
|
1738
|
-
|
1739
|
-
|
1740
|
-
|
1741
|
-
|
1742
|
-
|
1743
|
-
|
1437
|
+
```js
|
1438
|
+
Promise.all([
|
1439
|
+
getJSON('/posts'),
|
1440
|
+
getJSON('/comments')
|
1441
|
+
]).then(function(values){
|
1442
|
+
values[0] // => postsJSON
|
1443
|
+
values[1] // => commentsJSON
|
1444
|
+
|
1445
|
+
return values;
|
1446
|
+
});
|
1447
|
+
```
|
1448
|
+
|
1449
|
+
@class Promise
|
1450
|
+
@param {function} resolver
|
1451
|
+
Useful for tooling.
|
1452
|
+
@constructor
|
1453
|
+
*/
|
1454
|
+
function Promise(resolver) {
|
1455
|
+
this[PROMISE_ID] = nextId();
|
1456
|
+
this._result = this._state = undefined;
|
1457
|
+
this._subscribers = [];
|
1458
|
+
|
1459
|
+
if (noop !== resolver) {
|
1460
|
+
typeof resolver !== 'function' && needsResolver();
|
1461
|
+
this instanceof Promise ? initializePromise(this, resolver) : needsNew();
|
1462
|
+
}
|
1463
|
+
}
|
1744
1464
|
|
1745
|
-
|
1746
|
-
|
1747
|
-
|
1748
|
-
|
1465
|
+
Promise.all = all;
|
1466
|
+
Promise.race = race;
|
1467
|
+
Promise.resolve = resolve;
|
1468
|
+
Promise.reject = reject;
|
1469
|
+
Promise._setScheduler = setScheduler;
|
1470
|
+
Promise._setAsap = setAsap;
|
1471
|
+
Promise._asap = asap;
|
1472
|
+
|
1473
|
+
Promise.prototype = {
|
1474
|
+
constructor: Promise,
|
1475
|
+
|
1476
|
+
/**
|
1477
|
+
The primary way of interacting with a promise is through its `then` method,
|
1478
|
+
which registers callbacks to receive either a promise's eventual value or the
|
1479
|
+
reason why the promise cannot be fulfilled.
|
1480
|
+
|
1481
|
+
```js
|
1482
|
+
findUser().then(function(user){
|
1483
|
+
// user is available
|
1484
|
+
}, function(reason){
|
1485
|
+
// user is unavailable, and you are given the reason why
|
1486
|
+
});
|
1487
|
+
```
|
1488
|
+
|
1489
|
+
Chaining
|
1490
|
+
--------
|
1491
|
+
|
1492
|
+
The return value of `then` is itself a promise. This second, 'downstream'
|
1493
|
+
promise is resolved with the return value of the first promise's fulfillment
|
1494
|
+
or rejection handler, or rejected if the handler throws an exception.
|
1495
|
+
|
1496
|
+
```js
|
1497
|
+
findUser().then(function (user) {
|
1498
|
+
return user.name;
|
1499
|
+
}, function (reason) {
|
1500
|
+
return 'default name';
|
1501
|
+
}).then(function (userName) {
|
1502
|
+
// If `findUser` fulfilled, `userName` will be the user's name, otherwise it
|
1503
|
+
// will be `'default name'`
|
1504
|
+
});
|
1505
|
+
|
1506
|
+
findUser().then(function (user) {
|
1507
|
+
throw new Error('Found user, but still unhappy');
|
1508
|
+
}, function (reason) {
|
1509
|
+
throw new Error('`findUser` rejected and we're unhappy');
|
1510
|
+
}).then(function (value) {
|
1511
|
+
// never reached
|
1512
|
+
}, function (reason) {
|
1513
|
+
// if `findUser` fulfilled, `reason` will be 'Found user, but still unhappy'.
|
1514
|
+
// If `findUser` rejected, `reason` will be '`findUser` rejected and we're unhappy'.
|
1515
|
+
});
|
1516
|
+
```
|
1517
|
+
If the downstream promise does not specify a rejection handler, rejection reasons will be propagated further downstream.
|
1518
|
+
|
1519
|
+
```js
|
1520
|
+
findUser().then(function (user) {
|
1521
|
+
throw new PedagogicalException('Upstream error');
|
1522
|
+
}).then(function (value) {
|
1523
|
+
// never reached
|
1524
|
+
}).then(function (value) {
|
1525
|
+
// never reached
|
1526
|
+
}, function (reason) {
|
1527
|
+
// The `PedgagocialException` is propagated all the way down to here
|
1528
|
+
});
|
1529
|
+
```
|
1530
|
+
|
1531
|
+
Assimilation
|
1532
|
+
------------
|
1533
|
+
|
1534
|
+
Sometimes the value you want to propagate to a downstream promise can only be
|
1535
|
+
retrieved asynchronously. This can be achieved by returning a promise in the
|
1536
|
+
fulfillment or rejection handler. The downstream promise will then be pending
|
1537
|
+
until the returned promise is settled. This is called *assimilation*.
|
1538
|
+
|
1539
|
+
```js
|
1540
|
+
findUser().then(function (user) {
|
1541
|
+
return findCommentsByAuthor(user);
|
1542
|
+
}).then(function (comments) {
|
1543
|
+
// The user's comments are now available
|
1544
|
+
});
|
1545
|
+
```
|
1546
|
+
|
1547
|
+
If the assimliated promise rejects, then the downstream promise will also reject.
|
1548
|
+
|
1549
|
+
```js
|
1550
|
+
findUser().then(function (user) {
|
1551
|
+
return findCommentsByAuthor(user);
|
1552
|
+
}).then(function (comments) {
|
1553
|
+
// If `findCommentsByAuthor` fulfills, we'll have the value here
|
1554
|
+
}, function (reason) {
|
1555
|
+
// If `findCommentsByAuthor` rejects, we'll have the reason here
|
1556
|
+
});
|
1557
|
+
```
|
1558
|
+
|
1559
|
+
Simple Example
|
1560
|
+
--------------
|
1561
|
+
|
1562
|
+
Synchronous Example
|
1563
|
+
|
1564
|
+
```javascript
|
1565
|
+
let result;
|
1566
|
+
|
1567
|
+
try {
|
1568
|
+
result = findResult();
|
1569
|
+
// success
|
1570
|
+
} catch(reason) {
|
1571
|
+
// failure
|
1572
|
+
}
|
1573
|
+
```
|
1574
|
+
|
1575
|
+
Errback Example
|
1576
|
+
|
1577
|
+
```js
|
1578
|
+
findResult(function(result, err){
|
1579
|
+
if (err) {
|
1580
|
+
// failure
|
1749
1581
|
} else {
|
1750
|
-
|
1751
|
-
|
1752
|
-
|
1753
|
-
|
1754
|
-
|
1582
|
+
// success
|
1583
|
+
}
|
1584
|
+
});
|
1585
|
+
```
|
1586
|
+
|
1587
|
+
Promise Example;
|
1588
|
+
|
1589
|
+
```javascript
|
1590
|
+
findResult().then(function(result){
|
1591
|
+
// success
|
1592
|
+
}, function(reason){
|
1593
|
+
// failure
|
1594
|
+
});
|
1595
|
+
```
|
1596
|
+
|
1597
|
+
Advanced Example
|
1598
|
+
--------------
|
1599
|
+
|
1600
|
+
Synchronous Example
|
1601
|
+
|
1602
|
+
```javascript
|
1603
|
+
let author, books;
|
1604
|
+
|
1605
|
+
try {
|
1606
|
+
author = findAuthor();
|
1607
|
+
books = findBooksByAuthor(author);
|
1608
|
+
// success
|
1609
|
+
} catch(reason) {
|
1610
|
+
// failure
|
1611
|
+
}
|
1612
|
+
```
|
1613
|
+
|
1614
|
+
Errback Example
|
1615
|
+
|
1616
|
+
```js
|
1617
|
+
|
1618
|
+
function foundBooks(books) {
|
1619
|
+
|
1620
|
+
}
|
1621
|
+
|
1622
|
+
function failure(reason) {
|
1623
|
+
|
1624
|
+
}
|
1625
|
+
|
1626
|
+
findAuthor(function(author, err){
|
1627
|
+
if (err) {
|
1628
|
+
failure(err);
|
1629
|
+
// failure
|
1630
|
+
} else {
|
1631
|
+
try {
|
1632
|
+
findBoooksByAuthor(author, function(books, err) {
|
1633
|
+
if (err) {
|
1634
|
+
failure(err);
|
1635
|
+
} else {
|
1636
|
+
try {
|
1637
|
+
foundBooks(books);
|
1638
|
+
} catch(reason) {
|
1639
|
+
failure(reason);
|
1640
|
+
}
|
1641
|
+
}
|
1642
|
+
});
|
1643
|
+
} catch(error) {
|
1644
|
+
failure(err);
|
1645
|
+
}
|
1646
|
+
// success
|
1755
1647
|
}
|
1648
|
+
});
|
1649
|
+
```
|
1650
|
+
|
1651
|
+
Promise Example;
|
1652
|
+
|
1653
|
+
```javascript
|
1654
|
+
findAuthor().
|
1655
|
+
then(findBooksByAuthor).
|
1656
|
+
then(function(books){
|
1657
|
+
// found books
|
1658
|
+
}).catch(function(reason){
|
1659
|
+
// something went wrong
|
1660
|
+
});
|
1661
|
+
```
|
1662
|
+
|
1663
|
+
@method then
|
1664
|
+
@param {Function} onFulfilled
|
1665
|
+
@param {Function} onRejected
|
1666
|
+
Useful for tooling.
|
1667
|
+
@return {Promise}
|
1668
|
+
*/
|
1669
|
+
then: then,
|
1670
|
+
|
1671
|
+
/**
|
1672
|
+
`catch` is simply sugar for `then(undefined, onRejection)` which makes it the same
|
1673
|
+
as the catch block of a try/catch statement.
|
1674
|
+
|
1675
|
+
```js
|
1676
|
+
function findAuthor(){
|
1677
|
+
throw new Error('couldn't find that author');
|
1678
|
+
}
|
1679
|
+
|
1680
|
+
// synchronous
|
1681
|
+
try {
|
1682
|
+
findAuthor();
|
1683
|
+
} catch(reason) {
|
1684
|
+
// something went wrong
|
1685
|
+
}
|
1686
|
+
|
1687
|
+
// async with promises
|
1688
|
+
findAuthor().catch(function(reason){
|
1689
|
+
// something went wrong
|
1690
|
+
});
|
1691
|
+
```
|
1692
|
+
|
1693
|
+
@method catch
|
1694
|
+
@param {Function} onRejection
|
1695
|
+
Useful for tooling.
|
1696
|
+
@return {Promise}
|
1697
|
+
*/
|
1698
|
+
'catch': function _catch(onRejection) {
|
1699
|
+
return this.then(null, onRejection);
|
1700
|
+
}
|
1701
|
+
};
|
1756
1702
|
|
1757
|
-
|
1703
|
+
function polyfill() {
|
1704
|
+
var local = undefined;
|
1758
1705
|
|
1759
|
-
|
1760
|
-
|
1761
|
-
|
1706
|
+
if (typeof global !== 'undefined') {
|
1707
|
+
local = global;
|
1708
|
+
} else if (typeof self !== 'undefined') {
|
1709
|
+
local = self;
|
1710
|
+
} else {
|
1711
|
+
try {
|
1712
|
+
local = Function('return this')();
|
1713
|
+
} catch (e) {
|
1714
|
+
throw new Error('polyfill failed because global object is unavailable in this environment');
|
1715
|
+
}
|
1716
|
+
}
|
1717
|
+
|
1718
|
+
var P = local.Promise;
|
1762
1719
|
|
1763
|
-
|
1720
|
+
if (P) {
|
1721
|
+
var promiseToString = null;
|
1722
|
+
try {
|
1723
|
+
promiseToString = Object.prototype.toString.call(P.resolve());
|
1724
|
+
} catch (e) {
|
1725
|
+
// silently ignored
|
1726
|
+
}
|
1727
|
+
|
1728
|
+
if (promiseToString === '[object Promise]' && !P.cast) {
|
1729
|
+
return;
|
1730
|
+
}
|
1764
1731
|
}
|
1765
|
-
var lib$es6$promise$polyfill$$default = lib$es6$promise$polyfill$$polyfill;
|
1766
1732
|
|
1767
|
-
|
1768
|
-
|
1769
|
-
'polyfill': lib$es6$promise$polyfill$$default
|
1770
|
-
};
|
1733
|
+
local.Promise = Promise;
|
1734
|
+
}
|
1771
1735
|
|
1772
|
-
|
1773
|
-
|
1774
|
-
|
1775
|
-
} else if (typeof module !== 'undefined' && module['exports']) {
|
1776
|
-
module['exports'] = lib$es6$promise$umd$$ES6Promise;
|
1777
|
-
} else if (typeof this !== 'undefined') {
|
1778
|
-
this['ES6Promise'] = lib$es6$promise$umd$$ES6Promise;
|
1779
|
-
}
|
1736
|
+
// Strange compat..
|
1737
|
+
Promise.polyfill = polyfill;
|
1738
|
+
Promise.Promise = Promise;
|
1780
1739
|
|
1781
|
-
|
1782
|
-
}).call(this);
|
1740
|
+
return Promise;
|
1783
1741
|
|
1742
|
+
})));
|
1784
1743
|
|
1785
|
-
}).call(this,require(
|
1786
|
-
},{"
|
1744
|
+
}).call(this,require(12),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
1745
|
+
},{"12":12}],4:[function(require,module,exports){
|
1787
1746
|
// Copyright Joyent, Inc. and other Node contributors.
|
1788
1747
|
//
|
1789
1748
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
@@ -2087,76 +2046,570 @@ function isUndefined(arg) {
|
|
2087
2046
|
return arg === void 0;
|
2088
2047
|
}
|
2089
2048
|
|
2090
|
-
},{}],
|
2091
|
-
|
2092
|
-
var hasOwn = Object.prototype.hasOwnProperty;
|
2093
|
-
var toString = Object.prototype.toString;
|
2094
|
-
|
2095
|
-
module.exports = function forEach (obj, fn, ctx) {
|
2096
|
-
if (toString.call(fn) !== '[object Function]') {
|
2097
|
-
throw new TypeError('iterator must be a function');
|
2049
|
+
},{}],5:[function(require,module,exports){
|
2050
|
+
|
2051
|
+
var hasOwn = Object.prototype.hasOwnProperty;
|
2052
|
+
var toString = Object.prototype.toString;
|
2053
|
+
|
2054
|
+
module.exports = function forEach (obj, fn, ctx) {
|
2055
|
+
if (toString.call(fn) !== '[object Function]') {
|
2056
|
+
throw new TypeError('iterator must be a function');
|
2057
|
+
}
|
2058
|
+
var l = obj.length;
|
2059
|
+
if (l === +l) {
|
2060
|
+
for (var i = 0; i < l; i++) {
|
2061
|
+
fn.call(ctx, obj[i], i, obj);
|
2062
|
+
}
|
2063
|
+
} else {
|
2064
|
+
for (var k in obj) {
|
2065
|
+
if (hasOwn.call(obj, k)) {
|
2066
|
+
fn.call(ctx, obj[k], k, obj);
|
2067
|
+
}
|
2068
|
+
}
|
2069
|
+
}
|
2070
|
+
};
|
2071
|
+
|
2072
|
+
|
2073
|
+
},{}],6:[function(require,module,exports){
|
2074
|
+
(function (global){
|
2075
|
+
if (typeof window !== "undefined") {
|
2076
|
+
module.exports = window;
|
2077
|
+
} else if (typeof global !== "undefined") {
|
2078
|
+
module.exports = global;
|
2079
|
+
} else if (typeof self !== "undefined"){
|
2080
|
+
module.exports = self;
|
2081
|
+
} else {
|
2082
|
+
module.exports = {};
|
2083
|
+
}
|
2084
|
+
|
2085
|
+
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
2086
|
+
},{}],7:[function(require,module,exports){
|
2087
|
+
if (typeof Object.create === 'function') {
|
2088
|
+
// implementation from standard node.js 'util' module
|
2089
|
+
module.exports = function inherits(ctor, superCtor) {
|
2090
|
+
ctor.super_ = superCtor
|
2091
|
+
ctor.prototype = Object.create(superCtor.prototype, {
|
2092
|
+
constructor: {
|
2093
|
+
value: ctor,
|
2094
|
+
enumerable: false,
|
2095
|
+
writable: true,
|
2096
|
+
configurable: true
|
2097
|
+
}
|
2098
|
+
});
|
2099
|
+
};
|
2100
|
+
} else {
|
2101
|
+
// old school shim for old browsers
|
2102
|
+
module.exports = function inherits(ctor, superCtor) {
|
2103
|
+
ctor.super_ = superCtor
|
2104
|
+
var TempCtor = function () {}
|
2105
|
+
TempCtor.prototype = superCtor.prototype
|
2106
|
+
ctor.prototype = new TempCtor()
|
2107
|
+
ctor.prototype.constructor = ctor
|
2108
|
+
}
|
2109
|
+
}
|
2110
|
+
|
2111
|
+
},{}],8:[function(require,module,exports){
|
2112
|
+
var toString = {}.toString;
|
2113
|
+
|
2114
|
+
module.exports = Array.isArray || function (arr) {
|
2115
|
+
return toString.call(arr) == '[object Array]';
|
2116
|
+
};
|
2117
|
+
|
2118
|
+
},{}],9:[function(require,module,exports){
|
2119
|
+
/**
|
2120
|
+
* Helpers.
|
2121
|
+
*/
|
2122
|
+
|
2123
|
+
var s = 1000
|
2124
|
+
var m = s * 60
|
2125
|
+
var h = m * 60
|
2126
|
+
var d = h * 24
|
2127
|
+
var y = d * 365.25
|
2128
|
+
|
2129
|
+
/**
|
2130
|
+
* Parse or format the given `val`.
|
2131
|
+
*
|
2132
|
+
* Options:
|
2133
|
+
*
|
2134
|
+
* - `long` verbose formatting [false]
|
2135
|
+
*
|
2136
|
+
* @param {String|Number} val
|
2137
|
+
* @param {Object} options
|
2138
|
+
* @throws {Error} throw an error if val is not a non-empty string or a number
|
2139
|
+
* @return {String|Number}
|
2140
|
+
* @api public
|
2141
|
+
*/
|
2142
|
+
|
2143
|
+
module.exports = function (val, options) {
|
2144
|
+
options = options || {}
|
2145
|
+
var type = typeof val
|
2146
|
+
if (type === 'string' && val.length > 0) {
|
2147
|
+
return parse(val)
|
2148
|
+
} else if (type === 'number' && isNaN(val) === false) {
|
2149
|
+
return options.long ?
|
2150
|
+
fmtLong(val) :
|
2151
|
+
fmtShort(val)
|
2152
|
+
}
|
2153
|
+
throw new Error('val is not a non-empty string or a valid number. val=' + JSON.stringify(val))
|
2154
|
+
}
|
2155
|
+
|
2156
|
+
/**
|
2157
|
+
* Parse the given `str` and return milliseconds.
|
2158
|
+
*
|
2159
|
+
* @param {String} str
|
2160
|
+
* @return {Number}
|
2161
|
+
* @api private
|
2162
|
+
*/
|
2163
|
+
|
2164
|
+
function parse(str) {
|
2165
|
+
str = String(str)
|
2166
|
+
if (str.length > 10000) {
|
2167
|
+
return
|
2168
|
+
}
|
2169
|
+
var match = /^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(str)
|
2170
|
+
if (!match) {
|
2171
|
+
return
|
2172
|
+
}
|
2173
|
+
var n = parseFloat(match[1])
|
2174
|
+
var type = (match[2] || 'ms').toLowerCase()
|
2175
|
+
switch (type) {
|
2176
|
+
case 'years':
|
2177
|
+
case 'year':
|
2178
|
+
case 'yrs':
|
2179
|
+
case 'yr':
|
2180
|
+
case 'y':
|
2181
|
+
return n * y
|
2182
|
+
case 'days':
|
2183
|
+
case 'day':
|
2184
|
+
case 'd':
|
2185
|
+
return n * d
|
2186
|
+
case 'hours':
|
2187
|
+
case 'hour':
|
2188
|
+
case 'hrs':
|
2189
|
+
case 'hr':
|
2190
|
+
case 'h':
|
2191
|
+
return n * h
|
2192
|
+
case 'minutes':
|
2193
|
+
case 'minute':
|
2194
|
+
case 'mins':
|
2195
|
+
case 'min':
|
2196
|
+
case 'm':
|
2197
|
+
return n * m
|
2198
|
+
case 'seconds':
|
2199
|
+
case 'second':
|
2200
|
+
case 'secs':
|
2201
|
+
case 'sec':
|
2202
|
+
case 's':
|
2203
|
+
return n * s
|
2204
|
+
case 'milliseconds':
|
2205
|
+
case 'millisecond':
|
2206
|
+
case 'msecs':
|
2207
|
+
case 'msec':
|
2208
|
+
case 'ms':
|
2209
|
+
return n
|
2210
|
+
default:
|
2211
|
+
return undefined
|
2212
|
+
}
|
2213
|
+
}
|
2214
|
+
|
2215
|
+
/**
|
2216
|
+
* Short format for `ms`.
|
2217
|
+
*
|
2218
|
+
* @param {Number} ms
|
2219
|
+
* @return {String}
|
2220
|
+
* @api private
|
2221
|
+
*/
|
2222
|
+
|
2223
|
+
function fmtShort(ms) {
|
2224
|
+
if (ms >= d) {
|
2225
|
+
return Math.round(ms / d) + 'd'
|
2226
|
+
}
|
2227
|
+
if (ms >= h) {
|
2228
|
+
return Math.round(ms / h) + 'h'
|
2229
|
+
}
|
2230
|
+
if (ms >= m) {
|
2231
|
+
return Math.round(ms / m) + 'm'
|
2232
|
+
}
|
2233
|
+
if (ms >= s) {
|
2234
|
+
return Math.round(ms / s) + 's'
|
2235
|
+
}
|
2236
|
+
return ms + 'ms'
|
2237
|
+
}
|
2238
|
+
|
2239
|
+
/**
|
2240
|
+
* Long format for `ms`.
|
2241
|
+
*
|
2242
|
+
* @param {Number} ms
|
2243
|
+
* @return {String}
|
2244
|
+
* @api private
|
2245
|
+
*/
|
2246
|
+
|
2247
|
+
function fmtLong(ms) {
|
2248
|
+
return plural(ms, d, 'day') ||
|
2249
|
+
plural(ms, h, 'hour') ||
|
2250
|
+
plural(ms, m, 'minute') ||
|
2251
|
+
plural(ms, s, 'second') ||
|
2252
|
+
ms + ' ms'
|
2253
|
+
}
|
2254
|
+
|
2255
|
+
/**
|
2256
|
+
* Pluralization helper.
|
2257
|
+
*/
|
2258
|
+
|
2259
|
+
function plural(ms, n, name) {
|
2260
|
+
if (ms < n) {
|
2261
|
+
return
|
2262
|
+
}
|
2263
|
+
if (ms < n * 1.5) {
|
2264
|
+
return Math.floor(ms / n) + ' ' + name
|
2265
|
+
}
|
2266
|
+
return Math.ceil(ms / n) + ' ' + name + 's'
|
2267
|
+
}
|
2268
|
+
|
2269
|
+
},{}],10:[function(require,module,exports){
|
2270
|
+
'use strict';
|
2271
|
+
|
2272
|
+
// modified from https://github.com/es-shims/es5-shim
|
2273
|
+
var has = Object.prototype.hasOwnProperty;
|
2274
|
+
var toStr = Object.prototype.toString;
|
2275
|
+
var slice = Array.prototype.slice;
|
2276
|
+
var isArgs = require(11);
|
2277
|
+
var isEnumerable = Object.prototype.propertyIsEnumerable;
|
2278
|
+
var hasDontEnumBug = !isEnumerable.call({ toString: null }, 'toString');
|
2279
|
+
var hasProtoEnumBug = isEnumerable.call(function () {}, 'prototype');
|
2280
|
+
var dontEnums = [
|
2281
|
+
'toString',
|
2282
|
+
'toLocaleString',
|
2283
|
+
'valueOf',
|
2284
|
+
'hasOwnProperty',
|
2285
|
+
'isPrototypeOf',
|
2286
|
+
'propertyIsEnumerable',
|
2287
|
+
'constructor'
|
2288
|
+
];
|
2289
|
+
var equalsConstructorPrototype = function (o) {
|
2290
|
+
var ctor = o.constructor;
|
2291
|
+
return ctor && ctor.prototype === o;
|
2292
|
+
};
|
2293
|
+
var excludedKeys = {
|
2294
|
+
$console: true,
|
2295
|
+
$external: true,
|
2296
|
+
$frame: true,
|
2297
|
+
$frameElement: true,
|
2298
|
+
$frames: true,
|
2299
|
+
$innerHeight: true,
|
2300
|
+
$innerWidth: true,
|
2301
|
+
$outerHeight: true,
|
2302
|
+
$outerWidth: true,
|
2303
|
+
$pageXOffset: true,
|
2304
|
+
$pageYOffset: true,
|
2305
|
+
$parent: true,
|
2306
|
+
$scrollLeft: true,
|
2307
|
+
$scrollTop: true,
|
2308
|
+
$scrollX: true,
|
2309
|
+
$scrollY: true,
|
2310
|
+
$self: true,
|
2311
|
+
$webkitIndexedDB: true,
|
2312
|
+
$webkitStorageInfo: true,
|
2313
|
+
$window: true
|
2314
|
+
};
|
2315
|
+
var hasAutomationEqualityBug = (function () {
|
2316
|
+
/* global window */
|
2317
|
+
if (typeof window === 'undefined') { return false; }
|
2318
|
+
for (var k in window) {
|
2319
|
+
try {
|
2320
|
+
if (!excludedKeys['$' + k] && has.call(window, k) && window[k] !== null && typeof window[k] === 'object') {
|
2321
|
+
try {
|
2322
|
+
equalsConstructorPrototype(window[k]);
|
2323
|
+
} catch (e) {
|
2324
|
+
return true;
|
2325
|
+
}
|
2326
|
+
}
|
2327
|
+
} catch (e) {
|
2328
|
+
return true;
|
2329
|
+
}
|
2330
|
+
}
|
2331
|
+
return false;
|
2332
|
+
}());
|
2333
|
+
var equalsConstructorPrototypeIfNotBuggy = function (o) {
|
2334
|
+
/* global window */
|
2335
|
+
if (typeof window === 'undefined' || !hasAutomationEqualityBug) {
|
2336
|
+
return equalsConstructorPrototype(o);
|
2337
|
+
}
|
2338
|
+
try {
|
2339
|
+
return equalsConstructorPrototype(o);
|
2340
|
+
} catch (e) {
|
2341
|
+
return false;
|
2342
|
+
}
|
2343
|
+
};
|
2344
|
+
|
2345
|
+
var keysShim = function keys(object) {
|
2346
|
+
var isObject = object !== null && typeof object === 'object';
|
2347
|
+
var isFunction = toStr.call(object) === '[object Function]';
|
2348
|
+
var isArguments = isArgs(object);
|
2349
|
+
var isString = isObject && toStr.call(object) === '[object String]';
|
2350
|
+
var theKeys = [];
|
2351
|
+
|
2352
|
+
if (!isObject && !isFunction && !isArguments) {
|
2353
|
+
throw new TypeError('Object.keys called on a non-object');
|
2354
|
+
}
|
2355
|
+
|
2356
|
+
var skipProto = hasProtoEnumBug && isFunction;
|
2357
|
+
if (isString && object.length > 0 && !has.call(object, 0)) {
|
2358
|
+
for (var i = 0; i < object.length; ++i) {
|
2359
|
+
theKeys.push(String(i));
|
2360
|
+
}
|
2361
|
+
}
|
2362
|
+
|
2363
|
+
if (isArguments && object.length > 0) {
|
2364
|
+
for (var j = 0; j < object.length; ++j) {
|
2365
|
+
theKeys.push(String(j));
|
2366
|
+
}
|
2367
|
+
} else {
|
2368
|
+
for (var name in object) {
|
2369
|
+
if (!(skipProto && name === 'prototype') && has.call(object, name)) {
|
2370
|
+
theKeys.push(String(name));
|
2371
|
+
}
|
2372
|
+
}
|
2373
|
+
}
|
2374
|
+
|
2375
|
+
if (hasDontEnumBug) {
|
2376
|
+
var skipConstructor = equalsConstructorPrototypeIfNotBuggy(object);
|
2377
|
+
|
2378
|
+
for (var k = 0; k < dontEnums.length; ++k) {
|
2379
|
+
if (!(skipConstructor && dontEnums[k] === 'constructor') && has.call(object, dontEnums[k])) {
|
2380
|
+
theKeys.push(dontEnums[k]);
|
2381
|
+
}
|
2382
|
+
}
|
2383
|
+
}
|
2384
|
+
return theKeys;
|
2385
|
+
};
|
2386
|
+
|
2387
|
+
keysShim.shim = function shimObjectKeys() {
|
2388
|
+
if (Object.keys) {
|
2389
|
+
var keysWorksWithArguments = (function () {
|
2390
|
+
// Safari 5.0 bug
|
2391
|
+
return (Object.keys(arguments) || '').length === 2;
|
2392
|
+
}(1, 2));
|
2393
|
+
if (!keysWorksWithArguments) {
|
2394
|
+
var originalKeys = Object.keys;
|
2395
|
+
Object.keys = function keys(object) {
|
2396
|
+
if (isArgs(object)) {
|
2397
|
+
return originalKeys(slice.call(object));
|
2398
|
+
} else {
|
2399
|
+
return originalKeys(object);
|
2400
|
+
}
|
2401
|
+
};
|
2402
|
+
}
|
2403
|
+
} else {
|
2404
|
+
Object.keys = keysShim;
|
2405
|
+
}
|
2406
|
+
return Object.keys || keysShim;
|
2407
|
+
};
|
2408
|
+
|
2409
|
+
module.exports = keysShim;
|
2410
|
+
|
2411
|
+
},{"11":11}],11:[function(require,module,exports){
|
2412
|
+
'use strict';
|
2413
|
+
|
2414
|
+
var toStr = Object.prototype.toString;
|
2415
|
+
|
2416
|
+
module.exports = function isArguments(value) {
|
2417
|
+
var str = toStr.call(value);
|
2418
|
+
var isArgs = str === '[object Arguments]';
|
2419
|
+
if (!isArgs) {
|
2420
|
+
isArgs = str !== '[object Array]' &&
|
2421
|
+
value !== null &&
|
2422
|
+
typeof value === 'object' &&
|
2423
|
+
typeof value.length === 'number' &&
|
2424
|
+
value.length >= 0 &&
|
2425
|
+
toStr.call(value.callee) === '[object Function]';
|
2426
|
+
}
|
2427
|
+
return isArgs;
|
2428
|
+
};
|
2429
|
+
|
2430
|
+
},{}],12:[function(require,module,exports){
|
2431
|
+
// shim for using process in browser
|
2432
|
+
var process = module.exports = {};
|
2433
|
+
|
2434
|
+
// cached from whatever global is present so that test runners that stub it
|
2435
|
+
// don't break things. But we need to wrap it in a try catch in case it is
|
2436
|
+
// wrapped in strict mode code which doesn't define any globals. It's inside a
|
2437
|
+
// function because try/catches deoptimize in certain engines.
|
2438
|
+
|
2439
|
+
var cachedSetTimeout;
|
2440
|
+
var cachedClearTimeout;
|
2441
|
+
|
2442
|
+
function defaultSetTimout() {
|
2443
|
+
throw new Error('setTimeout has not been defined');
|
2444
|
+
}
|
2445
|
+
function defaultClearTimeout () {
|
2446
|
+
throw new Error('clearTimeout has not been defined');
|
2447
|
+
}
|
2448
|
+
(function () {
|
2449
|
+
try {
|
2450
|
+
if (typeof setTimeout === 'function') {
|
2451
|
+
cachedSetTimeout = setTimeout;
|
2452
|
+
} else {
|
2453
|
+
cachedSetTimeout = defaultSetTimout;
|
2454
|
+
}
|
2455
|
+
} catch (e) {
|
2456
|
+
cachedSetTimeout = defaultSetTimout;
|
2457
|
+
}
|
2458
|
+
try {
|
2459
|
+
if (typeof clearTimeout === 'function') {
|
2460
|
+
cachedClearTimeout = clearTimeout;
|
2461
|
+
} else {
|
2462
|
+
cachedClearTimeout = defaultClearTimeout;
|
2463
|
+
}
|
2464
|
+
} catch (e) {
|
2465
|
+
cachedClearTimeout = defaultClearTimeout;
|
2466
|
+
}
|
2467
|
+
} ())
|
2468
|
+
function runTimeout(fun) {
|
2469
|
+
if (cachedSetTimeout === setTimeout) {
|
2470
|
+
//normal enviroments in sane situations
|
2471
|
+
return setTimeout(fun, 0);
|
2472
|
+
}
|
2473
|
+
// if setTimeout wasn't available but was latter defined
|
2474
|
+
if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
|
2475
|
+
cachedSetTimeout = setTimeout;
|
2476
|
+
return setTimeout(fun, 0);
|
2477
|
+
}
|
2478
|
+
try {
|
2479
|
+
// when when somebody has screwed with setTimeout but no I.E. maddness
|
2480
|
+
return cachedSetTimeout(fun, 0);
|
2481
|
+
} catch(e){
|
2482
|
+
try {
|
2483
|
+
// When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
|
2484
|
+
return cachedSetTimeout.call(null, fun, 0);
|
2485
|
+
} catch(e){
|
2486
|
+
// same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
|
2487
|
+
return cachedSetTimeout.call(this, fun, 0);
|
2488
|
+
}
|
2489
|
+
}
|
2490
|
+
|
2491
|
+
|
2492
|
+
}
|
2493
|
+
function runClearTimeout(marker) {
|
2494
|
+
if (cachedClearTimeout === clearTimeout) {
|
2495
|
+
//normal enviroments in sane situations
|
2496
|
+
return clearTimeout(marker);
|
2497
|
+
}
|
2498
|
+
// if clearTimeout wasn't available but was latter defined
|
2499
|
+
if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
|
2500
|
+
cachedClearTimeout = clearTimeout;
|
2501
|
+
return clearTimeout(marker);
|
2502
|
+
}
|
2503
|
+
try {
|
2504
|
+
// when when somebody has screwed with setTimeout but no I.E. maddness
|
2505
|
+
return cachedClearTimeout(marker);
|
2506
|
+
} catch (e){
|
2507
|
+
try {
|
2508
|
+
// When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
|
2509
|
+
return cachedClearTimeout.call(null, marker);
|
2510
|
+
} catch (e){
|
2511
|
+
// same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
|
2512
|
+
// Some versions of I.E. have different rules for clearTimeout vs setTimeout
|
2513
|
+
return cachedClearTimeout.call(this, marker);
|
2514
|
+
}
|
2515
|
+
}
|
2516
|
+
|
2517
|
+
|
2518
|
+
|
2519
|
+
}
|
2520
|
+
var queue = [];
|
2521
|
+
var draining = false;
|
2522
|
+
var currentQueue;
|
2523
|
+
var queueIndex = -1;
|
2524
|
+
|
2525
|
+
function cleanUpNextTick() {
|
2526
|
+
if (!draining || !currentQueue) {
|
2527
|
+
return;
|
2528
|
+
}
|
2529
|
+
draining = false;
|
2530
|
+
if (currentQueue.length) {
|
2531
|
+
queue = currentQueue.concat(queue);
|
2532
|
+
} else {
|
2533
|
+
queueIndex = -1;
|
2534
|
+
}
|
2535
|
+
if (queue.length) {
|
2536
|
+
drainQueue();
|
2537
|
+
}
|
2538
|
+
}
|
2539
|
+
|
2540
|
+
function drainQueue() {
|
2541
|
+
if (draining) {
|
2542
|
+
return;
|
2098
2543
|
}
|
2099
|
-
var
|
2100
|
-
|
2101
|
-
|
2102
|
-
|
2103
|
-
|
2104
|
-
|
2105
|
-
|
2106
|
-
|
2107
|
-
|
2544
|
+
var timeout = runTimeout(cleanUpNextTick);
|
2545
|
+
draining = true;
|
2546
|
+
|
2547
|
+
var len = queue.length;
|
2548
|
+
while(len) {
|
2549
|
+
currentQueue = queue;
|
2550
|
+
queue = [];
|
2551
|
+
while (++queueIndex < len) {
|
2552
|
+
if (currentQueue) {
|
2553
|
+
currentQueue[queueIndex].run();
|
2108
2554
|
}
|
2109
2555
|
}
|
2556
|
+
queueIndex = -1;
|
2557
|
+
len = queue.length;
|
2558
|
+
}
|
2559
|
+
currentQueue = null;
|
2560
|
+
draining = false;
|
2561
|
+
runClearTimeout(timeout);
|
2562
|
+
}
|
2563
|
+
|
2564
|
+
process.nextTick = function (fun) {
|
2565
|
+
var args = new Array(arguments.length - 1);
|
2566
|
+
if (arguments.length > 1) {
|
2567
|
+
for (var i = 1; i < arguments.length; i++) {
|
2568
|
+
args[i - 1] = arguments[i];
|
2569
|
+
}
|
2570
|
+
}
|
2571
|
+
queue.push(new Item(fun, args));
|
2572
|
+
if (queue.length === 1 && !draining) {
|
2573
|
+
runTimeout(drainQueue);
|
2110
2574
|
}
|
2111
2575
|
};
|
2112
2576
|
|
2113
|
-
|
2114
|
-
|
2115
|
-
|
2116
|
-
|
2117
|
-
module.exports = window;
|
2118
|
-
} else if (typeof global !== "undefined") {
|
2119
|
-
module.exports = global;
|
2120
|
-
} else if (typeof self !== "undefined"){
|
2121
|
-
module.exports = self;
|
2122
|
-
} else {
|
2123
|
-
module.exports = {};
|
2577
|
+
// v8 likes predictible objects
|
2578
|
+
function Item(fun, array) {
|
2579
|
+
this.fun = fun;
|
2580
|
+
this.array = array;
|
2124
2581
|
}
|
2582
|
+
Item.prototype.run = function () {
|
2583
|
+
this.fun.apply(null, this.array);
|
2584
|
+
};
|
2585
|
+
process.title = 'browser';
|
2586
|
+
process.browser = true;
|
2587
|
+
process.env = {};
|
2588
|
+
process.argv = [];
|
2589
|
+
process.version = ''; // empty string to avoid regexp issues
|
2590
|
+
process.versions = {};
|
2125
2591
|
|
2126
|
-
|
2127
|
-
},{}],9:[function(require,module,exports){
|
2128
|
-
if (typeof Object.create === 'function') {
|
2129
|
-
// implementation from standard node.js 'util' module
|
2130
|
-
module.exports = function inherits(ctor, superCtor) {
|
2131
|
-
ctor.super_ = superCtor
|
2132
|
-
ctor.prototype = Object.create(superCtor.prototype, {
|
2133
|
-
constructor: {
|
2134
|
-
value: ctor,
|
2135
|
-
enumerable: false,
|
2136
|
-
writable: true,
|
2137
|
-
configurable: true
|
2138
|
-
}
|
2139
|
-
});
|
2140
|
-
};
|
2141
|
-
} else {
|
2142
|
-
// old school shim for old browsers
|
2143
|
-
module.exports = function inherits(ctor, superCtor) {
|
2144
|
-
ctor.super_ = superCtor
|
2145
|
-
var TempCtor = function () {}
|
2146
|
-
TempCtor.prototype = superCtor.prototype
|
2147
|
-
ctor.prototype = new TempCtor()
|
2148
|
-
ctor.prototype.constructor = ctor
|
2149
|
-
}
|
2150
|
-
}
|
2592
|
+
function noop() {}
|
2151
2593
|
|
2152
|
-
|
2153
|
-
|
2594
|
+
process.on = noop;
|
2595
|
+
process.addListener = noop;
|
2596
|
+
process.once = noop;
|
2597
|
+
process.off = noop;
|
2598
|
+
process.removeListener = noop;
|
2599
|
+
process.removeAllListeners = noop;
|
2600
|
+
process.emit = noop;
|
2154
2601
|
|
2155
|
-
|
2156
|
-
|
2602
|
+
process.binding = function (name) {
|
2603
|
+
throw new Error('process.binding is not supported');
|
2604
|
+
};
|
2605
|
+
|
2606
|
+
process.cwd = function () { return '/' };
|
2607
|
+
process.chdir = function (dir) {
|
2608
|
+
throw new Error('process.chdir is not supported');
|
2157
2609
|
};
|
2610
|
+
process.umask = function() { return 0; };
|
2158
2611
|
|
2159
|
-
},{}],
|
2612
|
+
},{}],13:[function(require,module,exports){
|
2160
2613
|
// Copyright Joyent, Inc. and other Node contributors.
|
2161
2614
|
//
|
2162
2615
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
@@ -2243,15 +2696,15 @@ var objectKeys = Object.keys || function (obj) {
|
|
2243
2696
|
return res;
|
2244
2697
|
};
|
2245
2698
|
|
2246
|
-
},{}],
|
2699
|
+
},{}],14:[function(require,module,exports){
|
2247
2700
|
module.exports = AlgoliaSearch;
|
2248
2701
|
|
2249
|
-
var Index = require(
|
2250
|
-
var deprecate = require(
|
2251
|
-
var deprecatedMessage = require(
|
2252
|
-
var AlgoliaSearchCore = require(
|
2253
|
-
var inherits = require(
|
2254
|
-
var errors = require(
|
2702
|
+
var Index = require(16);
|
2703
|
+
var deprecate = require(27);
|
2704
|
+
var deprecatedMessage = require(28);
|
2705
|
+
var AlgoliaSearchCore = require(15);
|
2706
|
+
var inherits = require(7);
|
2707
|
+
var errors = require(29);
|
2255
2708
|
|
2256
2709
|
function AlgoliaSearch() {
|
2257
2710
|
AlgoliaSearchCore.apply(this, arguments);
|
@@ -2332,7 +2785,7 @@ AlgoliaSearch.prototype.copyIndex = function(srcIndexName, dstIndexName, callbac
|
|
2332
2785
|
* content: the server answer that contains the task ID
|
2333
2786
|
*/
|
2334
2787
|
AlgoliaSearch.prototype.getLogs = function(offset, length, callback) {
|
2335
|
-
var clone = require(
|
2788
|
+
var clone = require(26);
|
2336
2789
|
var params = {};
|
2337
2790
|
if (typeof offset === 'object') {
|
2338
2791
|
// getLogs(params)
|
@@ -2484,7 +2937,7 @@ AlgoliaSearch.prototype.deleteUserKey = function(key, callback) {
|
|
2484
2937
|
* @see {@link https://www.algolia.com/doc/rest_api#AddKey|Algolia REST API Documentation}
|
2485
2938
|
*/
|
2486
2939
|
AlgoliaSearch.prototype.addUserKey = function(acls, params, callback) {
|
2487
|
-
var isArray = require(
|
2940
|
+
var isArray = require(8);
|
2488
2941
|
var usage = 'Usage: client.addUserKey(arrayOfAcls[, params, callback])';
|
2489
2942
|
|
2490
2943
|
if (!isArray(acls)) {
|
@@ -2569,7 +3022,7 @@ AlgoliaSearch.prototype.addUserKeyWithValidity = deprecate(function(acls, params
|
|
2569
3022
|
* @see {@link https://www.algolia.com/doc/rest_api#UpdateIndexKey|Algolia REST API Documentation}
|
2570
3023
|
*/
|
2571
3024
|
AlgoliaSearch.prototype.updateUserKey = function(key, acls, params, callback) {
|
2572
|
-
var isArray = require(
|
3025
|
+
var isArray = require(8);
|
2573
3026
|
var usage = 'Usage: client.updateUserKey(key, arrayOfAcls[, params, callback])';
|
2574
3027
|
|
2575
3028
|
if (!isArray(acls)) {
|
@@ -2670,7 +3123,7 @@ AlgoliaSearch.prototype.sendQueriesBatch = deprecate(function sendQueriesBatchDe
|
|
2670
3123
|
* }], cb)
|
2671
3124
|
*/
|
2672
3125
|
AlgoliaSearch.prototype.batch = function(operations, callback) {
|
2673
|
-
var isArray = require(
|
3126
|
+
var isArray = require(8);
|
2674
3127
|
var usage = 'Usage: client.batch(operations[, callback])';
|
2675
3128
|
|
2676
3129
|
if (!isArray(operations)) {
|
@@ -2703,15 +3156,22 @@ function notImplemented() {
|
|
2703
3156
|
throw new errors.AlgoliaSearchError(message);
|
2704
3157
|
}
|
2705
3158
|
|
2706
|
-
},{"
|
3159
|
+
},{"15":15,"16":16,"26":26,"27":27,"28":28,"29":29,"7":7,"8":8}],15:[function(require,module,exports){
|
3160
|
+
(function (process){
|
2707
3161
|
module.exports = AlgoliaSearchCore;
|
2708
3162
|
|
2709
|
-
var errors = require(
|
2710
|
-
var exitPromise = require(
|
2711
|
-
var IndexCore = require(
|
3163
|
+
var errors = require(29);
|
3164
|
+
var exitPromise = require(30);
|
3165
|
+
var IndexCore = require(18);
|
3166
|
+
var store = require(35);
|
2712
3167
|
|
2713
|
-
// We will always put the API KEY in the JSON body in case of too long API KEY
|
3168
|
+
// We will always put the API KEY in the JSON body in case of too long API KEY,
|
3169
|
+
// to avoid query string being too long and failing in various conditions (our server limit, browser limit,
|
3170
|
+
// proxies limit)
|
2714
3171
|
var MAX_API_KEY_LENGTH = 500;
|
3172
|
+
var RESET_APP_DATA_TIMER =
|
3173
|
+
process.env.RESET_APP_DATA_TIMER && parseInt(process.env.RESET_APP_DATA_TIMER, 10) ||
|
3174
|
+
60 * 2 * 1000; // after 2 minutes reset to first host
|
2715
3175
|
|
2716
3176
|
/*
|
2717
3177
|
* Algolia Search library initialization
|
@@ -2739,11 +3199,11 @@ var MAX_API_KEY_LENGTH = 500;
|
|
2739
3199
|
* If you provide them, you will less benefit from our HA implementation
|
2740
3200
|
*/
|
2741
3201
|
function AlgoliaSearchCore(applicationID, apiKey, opts) {
|
2742
|
-
var debug = require(
|
3202
|
+
var debug = require(1)('algoliasearch');
|
2743
3203
|
|
2744
|
-
var clone = require(
|
2745
|
-
var isArray = require(
|
2746
|
-
var map = require(
|
3204
|
+
var clone = require(26);
|
3205
|
+
var isArray = require(8);
|
3206
|
+
var map = require(31);
|
2747
3207
|
|
2748
3208
|
var usage = 'Usage: algoliasearch(applicationID, apiKey, opts)';
|
2749
3209
|
|
@@ -2758,25 +3218,24 @@ function AlgoliaSearchCore(applicationID, apiKey, opts) {
|
|
2758
3218
|
this.applicationID = applicationID;
|
2759
3219
|
this.apiKey = apiKey;
|
2760
3220
|
|
2761
|
-
var defaultHosts = shuffle([
|
2762
|
-
this.applicationID + '-1.algolianet.com',
|
2763
|
-
this.applicationID + '-2.algolianet.com',
|
2764
|
-
this.applicationID + '-3.algolianet.com'
|
2765
|
-
]);
|
2766
3221
|
this.hosts = {
|
2767
3222
|
read: [],
|
2768
3223
|
write: []
|
2769
3224
|
};
|
2770
3225
|
|
2771
|
-
this.hostIndex = {
|
2772
|
-
read: 0,
|
2773
|
-
write: 0
|
2774
|
-
};
|
2775
|
-
|
2776
3226
|
opts = opts || {};
|
2777
3227
|
|
2778
3228
|
var protocol = opts.protocol || 'https:';
|
2779
|
-
|
3229
|
+
this._timeouts = opts.timeouts || {
|
3230
|
+
connect: 1 * 1000, // 500ms connect is GPRS latency
|
3231
|
+
read: 2 * 1000,
|
3232
|
+
write: 30 * 1000
|
3233
|
+
};
|
3234
|
+
|
3235
|
+
// backward compat, if opts.timeout is passed, we use it to configure all timeouts like before
|
3236
|
+
if (opts.timeout) {
|
3237
|
+
this._timeouts.connect = this._timeouts.read = this._timeouts.write = opts.timeout;
|
3238
|
+
}
|
2780
3239
|
|
2781
3240
|
// while we advocate for colon-at-the-end values: 'http:' for `opts.protocol`
|
2782
3241
|
// we also accept `http` and `https`. It's a common error.
|
@@ -2788,11 +3247,19 @@ function AlgoliaSearchCore(applicationID, apiKey, opts) {
|
|
2788
3247
|
throw new errors.AlgoliaSearchError('protocol must be `http:` or `https:` (was `' + opts.protocol + '`)');
|
2789
3248
|
}
|
2790
3249
|
|
2791
|
-
|
3250
|
+
this._checkAppIdData();
|
3251
|
+
|
2792
3252
|
if (!opts.hosts) {
|
3253
|
+
var defaultHosts = map(this._shuffleResult, function(hostNumber) {
|
3254
|
+
return applicationID + '-' + hostNumber + '.algolianet.com';
|
3255
|
+
});
|
3256
|
+
|
3257
|
+
// no hosts given, compute defaults
|
2793
3258
|
this.hosts.read = [this.applicationID + '-dsn.algolia.net'].concat(defaultHosts);
|
2794
3259
|
this.hosts.write = [this.applicationID + '.algolia.net'].concat(defaultHosts);
|
2795
3260
|
} else if (isArray(opts.hosts)) {
|
3261
|
+
// when passing custom hosts, we need to have a different host index if the number
|
3262
|
+
// of write/read hosts are different.
|
2796
3263
|
this.hosts.read = clone(opts.hosts);
|
2797
3264
|
this.hosts.write = clone(opts.hosts);
|
2798
3265
|
} else {
|
@@ -2803,7 +3270,6 @@ function AlgoliaSearchCore(applicationID, apiKey, opts) {
|
|
2803
3270
|
// add protocol and lowercase hosts
|
2804
3271
|
this.hosts.read = map(this.hosts.read, prepareHost(protocol));
|
2805
3272
|
this.hosts.write = map(this.hosts.write, prepareHost(protocol));
|
2806
|
-
this.requestTimeout = timeout;
|
2807
3273
|
|
2808
3274
|
this.extraHeaders = [];
|
2809
3275
|
|
@@ -2848,14 +3314,18 @@ AlgoliaSearchCore.prototype.setExtraHeader = function(name, value) {
|
|
2848
3314
|
* @param algoliaAgent the agent to add
|
2849
3315
|
*/
|
2850
3316
|
AlgoliaSearchCore.prototype.addAlgoliaAgent = function(algoliaAgent) {
|
2851
|
-
this._ua
|
3317
|
+
if (this._ua.indexOf(';' + algoliaAgent) === -1) {
|
3318
|
+
this._ua += ';' + algoliaAgent;
|
3319
|
+
}
|
2852
3320
|
};
|
2853
3321
|
|
2854
3322
|
/*
|
2855
3323
|
* Wrapper that try all hosts to maximize the quality of service
|
2856
3324
|
*/
|
2857
3325
|
AlgoliaSearchCore.prototype._jsonRequest = function(initialOpts) {
|
2858
|
-
|
3326
|
+
this._checkAppIdData();
|
3327
|
+
|
3328
|
+
var requestDebug = require(1)('algoliasearch:' + initialOpts.url);
|
2859
3329
|
|
2860
3330
|
var body;
|
2861
3331
|
var cache = initialOpts.cache;
|
@@ -2865,7 +3335,12 @@ AlgoliaSearchCore.prototype._jsonRequest = function(initialOpts) {
|
|
2865
3335
|
var hasFallback = client._useFallback && client._request.fallback && initialOpts.fallback;
|
2866
3336
|
var headers;
|
2867
3337
|
|
2868
|
-
if (
|
3338
|
+
if (
|
3339
|
+
this.apiKey.length > MAX_API_KEY_LENGTH &&
|
3340
|
+
initialOpts.body !== undefined &&
|
3341
|
+
(initialOpts.body.params !== undefined || // index.search()
|
3342
|
+
initialOpts.body.requests !== undefined) // client.search()
|
3343
|
+
) {
|
2869
3344
|
initialOpts.body.apiKey = this.apiKey;
|
2870
3345
|
headers = this._computeRequestHeaders(false);
|
2871
3346
|
} else {
|
@@ -2880,6 +3355,8 @@ AlgoliaSearchCore.prototype._jsonRequest = function(initialOpts) {
|
|
2880
3355
|
var debugData = [];
|
2881
3356
|
|
2882
3357
|
function doRequest(requester, reqOpts) {
|
3358
|
+
client._checkAppIdData();
|
3359
|
+
|
2883
3360
|
var startTime = new Date();
|
2884
3361
|
var cacheID;
|
2885
3362
|
|
@@ -2926,13 +3403,13 @@ AlgoliaSearchCore.prototype._jsonRequest = function(initialOpts) {
|
|
2926
3403
|
// re-compute headers, they could be omitting the API KEY
|
2927
3404
|
headers = client._computeRequestHeaders();
|
2928
3405
|
|
2929
|
-
reqOpts.
|
2930
|
-
client.
|
3406
|
+
reqOpts.timeouts = client._getTimeoutsForRequest(initialOpts.hostType);
|
3407
|
+
client._setHostIndexByType(0, initialOpts.hostType);
|
2931
3408
|
usingFallback = true; // the current request is now using fallback
|
2932
3409
|
return doRequest(client._request.fallback, reqOpts);
|
2933
3410
|
}
|
2934
3411
|
|
2935
|
-
var currentHost = client.
|
3412
|
+
var currentHost = client._getHostByType(initialOpts.hostType);
|
2936
3413
|
|
2937
3414
|
var url = currentHost + reqOpts.url;
|
2938
3415
|
var options = {
|
@@ -2940,12 +3417,12 @@ AlgoliaSearchCore.prototype._jsonRequest = function(initialOpts) {
|
|
2940
3417
|
jsonBody: reqOpts.jsonBody,
|
2941
3418
|
method: reqOpts.method,
|
2942
3419
|
headers: headers,
|
2943
|
-
|
3420
|
+
timeouts: reqOpts.timeouts,
|
2944
3421
|
debug: requestDebug
|
2945
3422
|
};
|
2946
3423
|
|
2947
|
-
requestDebug('method: %s, url: %s, headers: %j,
|
2948
|
-
options.method, url, options.headers, options.
|
3424
|
+
requestDebug('method: %s, url: %s, headers: %j, timeouts: %d',
|
3425
|
+
options.method, url, options.headers, options.timeouts);
|
2949
3426
|
|
2950
3427
|
if (requester === client._request.fallback) {
|
2951
3428
|
requestDebug('using fallback');
|
@@ -2988,7 +3465,7 @@ AlgoliaSearchCore.prototype._jsonRequest = function(initialOpts) {
|
|
2988
3465
|
content: body || null,
|
2989
3466
|
contentLength: body !== undefined ? body.length : null,
|
2990
3467
|
method: reqOpts.method,
|
2991
|
-
|
3468
|
+
timeouts: reqOpts.timeouts,
|
2992
3469
|
url: reqOpts.url,
|
2993
3470
|
startTime: startTime,
|
2994
3471
|
endTime: endTime,
|
@@ -3041,7 +3518,7 @@ AlgoliaSearchCore.prototype._jsonRequest = function(initialOpts) {
|
|
3041
3518
|
content: body || null,
|
3042
3519
|
contentLength: body !== undefined ? body.length : null,
|
3043
3520
|
method: reqOpts.method,
|
3044
|
-
|
3521
|
+
timeouts: reqOpts.timeouts,
|
3045
3522
|
url: reqOpts.url,
|
3046
3523
|
startTime: startTime,
|
3047
3524
|
endTime: endTime,
|
@@ -3081,14 +3558,15 @@ AlgoliaSearchCore.prototype._jsonRequest = function(initialOpts) {
|
|
3081
3558
|
|
3082
3559
|
function retryRequest() {
|
3083
3560
|
requestDebug('retrying request');
|
3084
|
-
client.
|
3561
|
+
client._incrementHostIndex(initialOpts.hostType);
|
3085
3562
|
return doRequest(requester, reqOpts);
|
3086
3563
|
}
|
3087
3564
|
|
3088
3565
|
function retryRequestWithHigherTimeout() {
|
3089
3566
|
requestDebug('retrying request with higher timeout');
|
3090
|
-
client.
|
3091
|
-
|
3567
|
+
client._incrementHostIndex(initialOpts.hostType);
|
3568
|
+
client._incrementTimeoutMultipler();
|
3569
|
+
reqOpts.timeouts = client._getTimeoutsForRequest(initialOpts.hostType);
|
3092
3570
|
return doRequest(requester, reqOpts);
|
3093
3571
|
}
|
3094
3572
|
}
|
@@ -3099,7 +3577,7 @@ AlgoliaSearchCore.prototype._jsonRequest = function(initialOpts) {
|
|
3099
3577
|
method: initialOpts.method,
|
3100
3578
|
body: body,
|
3101
3579
|
jsonBody: initialOpts.body,
|
3102
|
-
|
3580
|
+
timeouts: client._getTimeoutsForRequest(initialOpts.hostType)
|
3103
3581
|
}
|
3104
3582
|
);
|
3105
3583
|
|
@@ -3137,7 +3615,7 @@ AlgoliaSearchCore.prototype._getSearchParams = function(args, params) {
|
|
3137
3615
|
};
|
3138
3616
|
|
3139
3617
|
AlgoliaSearchCore.prototype._computeRequestHeaders = function(withAPIKey) {
|
3140
|
-
var forEach = require(
|
3618
|
+
var forEach = require(5);
|
3141
3619
|
|
3142
3620
|
var requestHeaders = {
|
3143
3621
|
'x-algolia-agent': this._ua,
|
@@ -3179,8 +3657,8 @@ AlgoliaSearchCore.prototype._computeRequestHeaders = function(withAPIKey) {
|
|
3179
3657
|
* @return {Promise|undefined} Returns a promise if no callback given
|
3180
3658
|
*/
|
3181
3659
|
AlgoliaSearchCore.prototype.search = function(queries, opts, callback) {
|
3182
|
-
var isArray = require(
|
3183
|
-
var map = require(
|
3660
|
+
var isArray = require(8);
|
3661
|
+
var map = require(31);
|
3184
3662
|
|
3185
3663
|
var usage = 'Usage: client.search(arrayOfQueries[, callback])';
|
3186
3664
|
|
@@ -3288,13 +3766,113 @@ AlgoliaSearchCore.prototype.clearCache = function() {
|
|
3288
3766
|
|
3289
3767
|
/**
|
3290
3768
|
* Set the number of milliseconds a request can take before automatically being terminated.
|
3291
|
-
*
|
3769
|
+
* @deprecated
|
3292
3770
|
* @param {Number} milliseconds
|
3293
3771
|
*/
|
3294
3772
|
AlgoliaSearchCore.prototype.setRequestTimeout = function(milliseconds) {
|
3295
3773
|
if (milliseconds) {
|
3296
|
-
this.
|
3774
|
+
this._timeouts.connect = this._timeouts.read = this._timeouts.write = milliseconds;
|
3775
|
+
}
|
3776
|
+
};
|
3777
|
+
|
3778
|
+
/**
|
3779
|
+
* Set the three different (connect, read, write) timeouts to be used when requesting
|
3780
|
+
* @param {Object} timeouts
|
3781
|
+
*/
|
3782
|
+
AlgoliaSearchCore.prototype.setTimeouts = function(timeouts) {
|
3783
|
+
this._timeouts = timeouts;
|
3784
|
+
};
|
3785
|
+
|
3786
|
+
/**
|
3787
|
+
* Get the three different (connect, read, write) timeouts to be used when requesting
|
3788
|
+
* @param {Object} timeouts
|
3789
|
+
*/
|
3790
|
+
AlgoliaSearchCore.prototype.getTimeouts = function() {
|
3791
|
+
return this._timeouts;
|
3792
|
+
};
|
3793
|
+
|
3794
|
+
AlgoliaSearchCore.prototype._getAppIdData = function() {
|
3795
|
+
var data = store.get(this.applicationID);
|
3796
|
+
if (data !== null) this._cacheAppIdData(data);
|
3797
|
+
return data;
|
3798
|
+
};
|
3799
|
+
|
3800
|
+
AlgoliaSearchCore.prototype._setAppIdData = function(data) {
|
3801
|
+
data.lastChange = (new Date()).getTime();
|
3802
|
+
this._cacheAppIdData(data);
|
3803
|
+
return store.set(this.applicationID, data);
|
3804
|
+
};
|
3805
|
+
|
3806
|
+
AlgoliaSearchCore.prototype._checkAppIdData = function() {
|
3807
|
+
var data = this._getAppIdData();
|
3808
|
+
var now = (new Date()).getTime();
|
3809
|
+
if (data === null || now - data.lastChange > RESET_APP_DATA_TIMER) {
|
3810
|
+
return this._resetInitialAppIdData(data);
|
3297
3811
|
}
|
3812
|
+
|
3813
|
+
return data;
|
3814
|
+
};
|
3815
|
+
|
3816
|
+
AlgoliaSearchCore.prototype._resetInitialAppIdData = function(data) {
|
3817
|
+
var newData = data || {};
|
3818
|
+
newData.hostIndexes = {read: 0, write: 0};
|
3819
|
+
newData.timeoutMultiplier = 1;
|
3820
|
+
newData.shuffleResult = newData.shuffleResult || shuffle([1, 2, 3]);
|
3821
|
+
return this._setAppIdData(newData);
|
3822
|
+
};
|
3823
|
+
|
3824
|
+
AlgoliaSearchCore.prototype._cacheAppIdData = function(data) {
|
3825
|
+
this._hostIndexes = data.hostIndexes;
|
3826
|
+
this._timeoutMultiplier = data.timeoutMultiplier;
|
3827
|
+
this._shuffleResult = data.shuffleResult;
|
3828
|
+
};
|
3829
|
+
|
3830
|
+
AlgoliaSearchCore.prototype._partialAppIdDataUpdate = function(newData) {
|
3831
|
+
var foreach = require(5);
|
3832
|
+
var currentData = this._getAppIdData();
|
3833
|
+
foreach(newData, function(value, key) {
|
3834
|
+
currentData[key] = value;
|
3835
|
+
});
|
3836
|
+
|
3837
|
+
return this._setAppIdData(currentData);
|
3838
|
+
};
|
3839
|
+
|
3840
|
+
AlgoliaSearchCore.prototype._getHostByType = function(hostType) {
|
3841
|
+
return this.hosts[hostType][this._getHostIndexByType(hostType)];
|
3842
|
+
};
|
3843
|
+
|
3844
|
+
AlgoliaSearchCore.prototype._getTimeoutMultiplier = function() {
|
3845
|
+
return this._timeoutMultiplier;
|
3846
|
+
};
|
3847
|
+
|
3848
|
+
AlgoliaSearchCore.prototype._getHostIndexByType = function(hostType) {
|
3849
|
+
return this._hostIndexes[hostType];
|
3850
|
+
};
|
3851
|
+
|
3852
|
+
AlgoliaSearchCore.prototype._setHostIndexByType = function(hostIndex, hostType) {
|
3853
|
+
var clone = require(26);
|
3854
|
+
var newHostIndexes = clone(this._hostIndexes);
|
3855
|
+
newHostIndexes[hostType] = hostIndex;
|
3856
|
+
this._partialAppIdDataUpdate({hostIndexes: newHostIndexes});
|
3857
|
+
return hostIndex;
|
3858
|
+
};
|
3859
|
+
|
3860
|
+
AlgoliaSearchCore.prototype._incrementHostIndex = function(hostType) {
|
3861
|
+
return this._setHostIndexByType(
|
3862
|
+
(this._getHostIndexByType(hostType) + 1) % this.hosts[hostType].length, hostType
|
3863
|
+
);
|
3864
|
+
};
|
3865
|
+
|
3866
|
+
AlgoliaSearchCore.prototype._incrementTimeoutMultipler = function() {
|
3867
|
+
var timeoutMultiplier = Math.max(this._timeoutMultiplier + 1, 4);
|
3868
|
+
return this._partialAppIdDataUpdate({timeoutMultiplier: timeoutMultiplier});
|
3869
|
+
};
|
3870
|
+
|
3871
|
+
AlgoliaSearchCore.prototype._getTimeoutsForRequest = function(hostType) {
|
3872
|
+
return {
|
3873
|
+
connect: this._timeouts.connect * this._timeoutMultiplier,
|
3874
|
+
complete: this._timeouts[hostType] * this._timeoutMultiplier
|
3875
|
+
};
|
3298
3876
|
};
|
3299
3877
|
|
3300
3878
|
function prepareHost(protocol) {
|
@@ -3365,13 +3943,14 @@ function removeCredentials(headers) {
|
|
3365
3943
|
return newHeaders;
|
3366
3944
|
}
|
3367
3945
|
|
3368
|
-
},
|
3369
|
-
|
3370
|
-
var
|
3371
|
-
var
|
3372
|
-
var
|
3373
|
-
var
|
3374
|
-
var
|
3946
|
+
}).call(this,require(12))
|
3947
|
+
},{"1":1,"12":12,"18":18,"26":26,"29":29,"30":30,"31":31,"35":35,"5":5,"8":8}],16:[function(require,module,exports){
|
3948
|
+
var inherits = require(7);
|
3949
|
+
var IndexCore = require(18);
|
3950
|
+
var deprecate = require(27);
|
3951
|
+
var deprecatedMessage = require(28);
|
3952
|
+
var exitPromise = require(30);
|
3953
|
+
var errors = require(29);
|
3375
3954
|
|
3376
3955
|
module.exports = Index;
|
3377
3956
|
|
@@ -3420,7 +3999,7 @@ Index.prototype.addObject = function(content, objectID, callback) {
|
|
3420
3999
|
* content: the server answer that updateAt and taskID
|
3421
4000
|
*/
|
3422
4001
|
Index.prototype.addObjects = function(objects, callback) {
|
3423
|
-
var isArray = require(
|
4002
|
+
var isArray = require(8);
|
3424
4003
|
var usage = 'Usage: index.addObjects(arrayOfObjects[, callback])';
|
3425
4004
|
|
3426
4005
|
if (!isArray(objects)) {
|
@@ -3487,7 +4066,7 @@ Index.prototype.partialUpdateObject = function(partialObject, createIfNotExists,
|
|
3487
4066
|
* content: the server answer that updateAt and taskID
|
3488
4067
|
*/
|
3489
4068
|
Index.prototype.partialUpdateObjects = function(objects, callback) {
|
3490
|
-
var isArray = require(
|
4069
|
+
var isArray = require(8);
|
3491
4070
|
var usage = 'Usage: index.partialUpdateObjects(arrayOfObjects[, callback])';
|
3492
4071
|
|
3493
4072
|
if (!isArray(objects)) {
|
@@ -3543,7 +4122,7 @@ Index.prototype.saveObject = function(object, callback) {
|
|
3543
4122
|
* content: the server answer that updateAt and taskID
|
3544
4123
|
*/
|
3545
4124
|
Index.prototype.saveObjects = function(objects, callback) {
|
3546
|
-
var isArray = require(
|
4125
|
+
var isArray = require(8);
|
3547
4126
|
var usage = 'Usage: index.saveObjects(arrayOfObjects[, callback])';
|
3548
4127
|
|
3549
4128
|
if (!isArray(objects)) {
|
@@ -3608,8 +4187,8 @@ Index.prototype.deleteObject = function(objectID, callback) {
|
|
3608
4187
|
* content: the server answer that contains 3 elements: createAt, taskId and objectID
|
3609
4188
|
*/
|
3610
4189
|
Index.prototype.deleteObjects = function(objectIDs, callback) {
|
3611
|
-
var isArray = require(
|
3612
|
-
var map = require(
|
4190
|
+
var isArray = require(8);
|
4191
|
+
var map = require(31);
|
3613
4192
|
|
3614
4193
|
var usage = 'Usage: index.deleteObjects(arrayOfObjectIDs[, callback])';
|
3615
4194
|
|
@@ -3648,8 +4227,8 @@ Index.prototype.deleteObjects = function(objectIDs, callback) {
|
|
3648
4227
|
* error: null or Error('message')
|
3649
4228
|
*/
|
3650
4229
|
Index.prototype.deleteByQuery = function(query, params, callback) {
|
3651
|
-
var clone = require(
|
3652
|
-
var map = require(
|
4230
|
+
var clone = require(26);
|
4231
|
+
var map = require(31);
|
3653
4232
|
|
3654
4233
|
var indexObj = this;
|
3655
4234
|
var client = indexObj.as;
|
@@ -3759,9 +4338,9 @@ Index.prototype.browseAll = function(query, queryParameters) {
|
|
3759
4338
|
query = undefined;
|
3760
4339
|
}
|
3761
4340
|
|
3762
|
-
var merge = require(
|
4341
|
+
var merge = require(32);
|
3763
4342
|
|
3764
|
-
var IndexBrowser = require(
|
4343
|
+
var IndexBrowser = require(17);
|
3765
4344
|
|
3766
4345
|
var browser = new IndexBrowser();
|
3767
4346
|
var client = this.as;
|
@@ -4221,7 +4800,7 @@ Index.prototype.deleteUserKey = function(key, callback) {
|
|
4221
4800
|
* @see {@link https://www.algolia.com/doc/rest_api#AddIndexKey|Algolia REST API Documentation}
|
4222
4801
|
*/
|
4223
4802
|
Index.prototype.addUserKey = function(acls, params, callback) {
|
4224
|
-
var isArray = require(
|
4803
|
+
var isArray = require(8);
|
4225
4804
|
var usage = 'Usage: index.addUserKey(arrayOfAcls[, params, callback])';
|
4226
4805
|
|
4227
4806
|
if (!isArray(acls)) {
|
@@ -4304,7 +4883,7 @@ Index.prototype.addUserKeyWithValidity = deprecate(function deprecatedAddUserKey
|
|
4304
4883
|
* @see {@link https://www.algolia.com/doc/rest_api#UpdateIndexKey|Algolia REST API Documentation}
|
4305
4884
|
*/
|
4306
4885
|
Index.prototype.updateUserKey = function(key, acls, params, callback) {
|
4307
|
-
var isArray = require(
|
4886
|
+
var isArray = require(8);
|
4308
4887
|
var usage = 'Usage: index.updateUserKey(key, arrayOfAcls[, params, callback])';
|
4309
4888
|
|
4310
4889
|
if (!isArray(acls)) {
|
@@ -4342,15 +4921,15 @@ Index.prototype.updateUserKey = function(key, acls, params, callback) {
|
|
4342
4921
|
});
|
4343
4922
|
};
|
4344
4923
|
|
4345
|
-
},{"
|
4924
|
+
},{"17":17,"18":18,"26":26,"27":27,"28":28,"29":29,"30":30,"31":31,"32":32,"7":7,"8":8}],17:[function(require,module,exports){
|
4346
4925
|
'use strict';
|
4347
4926
|
|
4348
4927
|
// This is the object returned by the `index.browseAll()` method
|
4349
4928
|
|
4350
4929
|
module.exports = IndexBrowser;
|
4351
4930
|
|
4352
|
-
var inherits = require(
|
4353
|
-
var EventEmitter = require(
|
4931
|
+
var inherits = require(7);
|
4932
|
+
var EventEmitter = require(4).EventEmitter;
|
4354
4933
|
|
4355
4934
|
function IndexBrowser() {
|
4356
4935
|
}
|
@@ -4383,8 +4962,10 @@ IndexBrowser.prototype._clean = function() {
|
|
4383
4962
|
this.removeAllListeners('result');
|
4384
4963
|
};
|
4385
4964
|
|
4386
|
-
},{"
|
4387
|
-
var buildSearchMethod = require(
|
4965
|
+
},{"4":4,"7":7}],18:[function(require,module,exports){
|
4966
|
+
var buildSearchMethod = require(25);
|
4967
|
+
var deprecate = require(27);
|
4968
|
+
var deprecatedMessage = require(28);
|
4388
4969
|
|
4389
4970
|
module.exports = IndexCore;
|
4390
4971
|
|
@@ -4536,7 +5117,7 @@ IndexCore.prototype.similarSearch = buildSearchMethod('similarQuery');
|
|
4536
5117
|
* @see {@link https://www.algolia.com/doc/rest_api#Browse|Algolia REST API Documentation}
|
4537
5118
|
*/
|
4538
5119
|
IndexCore.prototype.browse = function(query, queryParameters, callback) {
|
4539
|
-
var merge = require(
|
5120
|
+
var merge = require(32);
|
4540
5121
|
|
4541
5122
|
var indexObj = this;
|
4542
5123
|
|
@@ -4616,6 +5197,50 @@ IndexCore.prototype.browseFrom = function(cursor, callback) {
|
|
4616
5197
|
});
|
4617
5198
|
};
|
4618
5199
|
|
5200
|
+
/*
|
5201
|
+
* Search for facet values
|
5202
|
+
* https://www.algolia.com/doc/rest-api/search#search-for-facet-values
|
5203
|
+
*
|
5204
|
+
* @param {string} params.facetName Facet name, name of the attribute to search for values in.
|
5205
|
+
* Must be declared as a facet
|
5206
|
+
* @param {string} params.facetQuery Query for the facet search
|
5207
|
+
* @param {string} [params.*] Any search parameter of Algolia,
|
5208
|
+
* see https://www.algolia.com/doc/api-client/javascript/search#search-parameters
|
5209
|
+
* Pagination is not supported. The page and hitsPerPage parameters will be ignored.
|
5210
|
+
* @param callback (optional)
|
5211
|
+
*/
|
5212
|
+
IndexCore.prototype.searchForFacetValues = function(params, callback) {
|
5213
|
+
var clone = require(26);
|
5214
|
+
var omit = require(33);
|
5215
|
+
var usage = 'Usage: index.searchForFacetValues({facetName, facetQuery, ...params}[, callback])';
|
5216
|
+
|
5217
|
+
if (params.facetName === undefined || params.facetQuery === undefined) {
|
5218
|
+
throw new Error(usage);
|
5219
|
+
}
|
5220
|
+
|
5221
|
+
var facetName = params.facetName;
|
5222
|
+
var filteredParams = omit(clone(params), function(keyName) {
|
5223
|
+
return keyName === 'facetName';
|
5224
|
+
});
|
5225
|
+
var searchParameters = this.as._getSearchParams(filteredParams, '');
|
5226
|
+
|
5227
|
+
return this.as._jsonRequest({
|
5228
|
+
method: 'POST',
|
5229
|
+
url: '/1/indexes/' +
|
5230
|
+
encodeURIComponent(this.indexName) + '/facets/' + encodeURIComponent(facetName) + '/query',
|
5231
|
+
hostType: 'read',
|
5232
|
+
body: {params: searchParameters},
|
5233
|
+
callback: callback
|
5234
|
+
});
|
5235
|
+
};
|
5236
|
+
|
5237
|
+
IndexCore.prototype.searchFacet = deprecate(function(params, callback) {
|
5238
|
+
return this.searchForFacetValues(params, callback);
|
5239
|
+
}, deprecatedMessage(
|
5240
|
+
'index.searchFacet(params[, callback])',
|
5241
|
+
'index.searchForFacetValues(params[, callback])'
|
5242
|
+
));
|
5243
|
+
|
4619
5244
|
IndexCore.prototype._search = function(params, url, callback) {
|
4620
5245
|
return this.as._jsonRequest({
|
4621
5246
|
cache: this.cache,
|
@@ -4674,8 +5299,8 @@ IndexCore.prototype.getObject = function(objectID, attrs, callback) {
|
|
4674
5299
|
* @param objectIDs the array of unique identifier of objects to retrieve
|
4675
5300
|
*/
|
4676
5301
|
IndexCore.prototype.getObjects = function(objectIDs, attributesToRetrieve, callback) {
|
4677
|
-
var isArray = require(
|
4678
|
-
var map = require(
|
5302
|
+
var isArray = require(8);
|
5303
|
+
var map = require(31);
|
4679
5304
|
|
4680
5305
|
var usage = 'Usage: index.getObjects(arrayOfObjectIDs[, callback])';
|
4681
5306
|
|
@@ -4719,7 +5344,7 @@ IndexCore.prototype.indexName = null;
|
|
4719
5344
|
IndexCore.prototype.typeAheadArgs = null;
|
4720
5345
|
IndexCore.prototype.typeAheadValueOption = null;
|
4721
5346
|
|
4722
|
-
},{"
|
5347
|
+
},{"25":25,"26":26,"27":27,"28":28,"31":31,"32":32,"33":33,"8":8}],19:[function(require,module,exports){
|
4723
5348
|
(function (process){
|
4724
5349
|
'use strict';
|
4725
5350
|
|
@@ -4727,29 +5352,29 @@ IndexCore.prototype.typeAheadValueOption = null;
|
|
4727
5352
|
// It's using $http to do requests with a JSONP fallback
|
4728
5353
|
// $q promises are returned
|
4729
5354
|
|
4730
|
-
var inherits = require(
|
5355
|
+
var inherits = require(7);
|
4731
5356
|
|
4732
|
-
var forEach = require(
|
5357
|
+
var forEach = require(5);
|
4733
5358
|
|
4734
|
-
var AlgoliaSearch = require(
|
4735
|
-
var errors = require(
|
4736
|
-
var inlineHeaders = require(
|
4737
|
-
var jsonpRequest = require(
|
4738
|
-
var places = require(
|
5359
|
+
var AlgoliaSearch = require(14);
|
5360
|
+
var errors = require(29);
|
5361
|
+
var inlineHeaders = require(23);
|
5362
|
+
var jsonpRequest = require(24);
|
5363
|
+
var places = require(34);
|
4739
5364
|
|
4740
5365
|
// expose original algoliasearch fn in window
|
4741
|
-
window.algoliasearch = require(
|
5366
|
+
window.algoliasearch = require(20);
|
4742
5367
|
|
4743
5368
|
if (process.env.NODE_ENV === 'debug') {
|
4744
|
-
require(
|
5369
|
+
require(1).enable('algoliasearch*');
|
4745
5370
|
}
|
4746
5371
|
|
4747
5372
|
window.angular.module('algoliasearch', [])
|
4748
5373
|
.service('algolia', ['$http', '$q', '$timeout', function algoliaSearchService($http, $q, $timeout) {
|
4749
5374
|
function algoliasearch(applicationID, apiKey, opts) {
|
4750
|
-
var cloneDeep = require(
|
5375
|
+
var cloneDeep = require(26);
|
4751
5376
|
|
4752
|
-
var getDocumentProtocol = require(
|
5377
|
+
var getDocumentProtocol = require(22);
|
4753
5378
|
|
4754
5379
|
opts = cloneDeep(opts || {});
|
4755
5380
|
|
@@ -4762,14 +5387,14 @@ window.angular.module('algoliasearch', [])
|
|
4762
5387
|
return new AlgoliaSearchAngular(applicationID, apiKey, opts);
|
4763
5388
|
}
|
4764
5389
|
|
4765
|
-
algoliasearch.version = require(
|
5390
|
+
algoliasearch.version = require(36);
|
4766
5391
|
algoliasearch.ua = 'Algolia for AngularJS ' + algoliasearch.version;
|
4767
5392
|
algoliasearch.initPlaces = places(algoliasearch);
|
4768
5393
|
|
4769
5394
|
// we expose into window no matter how we are used, this will allow
|
4770
5395
|
// us to easily debug any website running algolia
|
4771
5396
|
window.__algolia = {
|
4772
|
-
debug: require(
|
5397
|
+
debug: require(1),
|
4773
5398
|
algoliasearch: algoliasearch
|
4774
5399
|
};
|
4775
5400
|
|
@@ -4800,7 +5425,7 @@ window.angular.module('algoliasearch', [])
|
|
4800
5425
|
// will cancel the xhr
|
4801
5426
|
timeoutDeferred.resolve('test');
|
4802
5427
|
reject(new errors.RequestTimeout());
|
4803
|
-
}, opts.
|
5428
|
+
}, opts.timeouts.complete);
|
4804
5429
|
|
4805
5430
|
var requestHeaders = {};
|
4806
5431
|
|
@@ -4926,41 +5551,41 @@ window.angular.module('algoliasearch', [])
|
|
4926
5551
|
};
|
4927
5552
|
}]);
|
4928
5553
|
|
4929
|
-
}).call(this,require(
|
4930
|
-
},{"
|
5554
|
+
}).call(this,require(12))
|
5555
|
+
},{"1":1,"12":12,"14":14,"20":20,"22":22,"23":23,"24":24,"26":26,"29":29,"34":34,"36":36,"5":5,"7":7}],20:[function(require,module,exports){
|
4931
5556
|
'use strict';
|
4932
5557
|
|
4933
|
-
var AlgoliaSearch = require(
|
4934
|
-
var createAlgoliasearch = require(
|
5558
|
+
var AlgoliaSearch = require(14);
|
5559
|
+
var createAlgoliasearch = require(21);
|
4935
5560
|
|
4936
5561
|
module.exports = createAlgoliasearch(AlgoliaSearch);
|
4937
5562
|
|
4938
|
-
},{"
|
5563
|
+
},{"14":14,"21":21}],21:[function(require,module,exports){
|
4939
5564
|
(function (process){
|
4940
5565
|
'use strict';
|
4941
5566
|
|
4942
|
-
var global = require(
|
4943
|
-
var Promise = global.Promise || require(
|
5567
|
+
var global = require(6);
|
5568
|
+
var Promise = global.Promise || require(3).Promise;
|
4944
5569
|
|
4945
5570
|
// This is the standalone browser build entry point
|
4946
5571
|
// Browser implementation of the Algolia Search JavaScript client,
|
4947
5572
|
// using XMLHttpRequest, XDomainRequest and JSONP as fallback
|
4948
5573
|
module.exports = function createAlgoliasearch(AlgoliaSearch, uaSuffix) {
|
4949
|
-
var inherits = require(
|
4950
|
-
var errors = require(
|
4951
|
-
var inlineHeaders = require(
|
4952
|
-
var jsonpRequest = require(
|
4953
|
-
var places = require(
|
5574
|
+
var inherits = require(7);
|
5575
|
+
var errors = require(29);
|
5576
|
+
var inlineHeaders = require(23);
|
5577
|
+
var jsonpRequest = require(24);
|
5578
|
+
var places = require(34);
|
4954
5579
|
uaSuffix = uaSuffix || '';
|
4955
5580
|
|
4956
5581
|
if (process.env.NODE_ENV === 'debug') {
|
4957
|
-
require(
|
5582
|
+
require(1).enable('algoliasearch*');
|
4958
5583
|
}
|
4959
5584
|
|
4960
5585
|
function algoliasearch(applicationID, apiKey, opts) {
|
4961
|
-
var cloneDeep = require(
|
5586
|
+
var cloneDeep = require(26);
|
4962
5587
|
|
4963
|
-
var getDocumentProtocol = require(
|
5588
|
+
var getDocumentProtocol = require(22);
|
4964
5589
|
|
4965
5590
|
opts = cloneDeep(opts || {});
|
4966
5591
|
|
@@ -4973,14 +5598,14 @@ module.exports = function createAlgoliasearch(AlgoliaSearch, uaSuffix) {
|
|
4973
5598
|
return new AlgoliaSearchBrowser(applicationID, apiKey, opts);
|
4974
5599
|
}
|
4975
5600
|
|
4976
|
-
algoliasearch.version = require(
|
5601
|
+
algoliasearch.version = require(36);
|
4977
5602
|
algoliasearch.ua = 'Algolia for vanilla JavaScript ' + uaSuffix + algoliasearch.version;
|
4978
5603
|
algoliasearch.initPlaces = places(algoliasearch);
|
4979
5604
|
|
4980
5605
|
// we expose into window no matter how we are used, this will allow
|
4981
5606
|
// us to easily debug any website running algolia
|
4982
5607
|
global.__algolia = {
|
4983
|
-
debug: require(
|
5608
|
+
debug: require(1),
|
4984
5609
|
algoliasearch: algoliasearch
|
4985
5610
|
};
|
4986
5611
|
|
@@ -4991,7 +5616,6 @@ module.exports = function createAlgoliasearch(AlgoliaSearch, uaSuffix) {
|
|
4991
5616
|
|
4992
5617
|
if (support.hasXMLHttpRequest) {
|
4993
5618
|
support.cors = 'withCredentials' in new XMLHttpRequest();
|
4994
|
-
support.timeout = 'timeout' in new XMLHttpRequest();
|
4995
5619
|
}
|
4996
5620
|
|
4997
5621
|
function AlgoliaSearchBrowser() {
|
@@ -5014,8 +5638,20 @@ module.exports = function createAlgoliasearch(AlgoliaSearch, uaSuffix) {
|
|
5014
5638
|
|
5015
5639
|
var body = opts.body;
|
5016
5640
|
var req = support.cors ? new XMLHttpRequest() : new XDomainRequest();
|
5017
|
-
var
|
5641
|
+
var reqTimeout;
|
5018
5642
|
var timedOut;
|
5643
|
+
var connected = false;
|
5644
|
+
|
5645
|
+
reqTimeout = setTimeout(onTimeout, opts.timeouts.connect);
|
5646
|
+
// we set an empty onprogress listener
|
5647
|
+
// so that XDomainRequest on IE9 is not aborted
|
5648
|
+
// refs:
|
5649
|
+
// - https://github.com/algolia/algoliasearch-client-js/issues/76
|
5650
|
+
// - 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
|
5651
|
+
req.onprogress = onProgress;
|
5652
|
+
if ('onreadystatechange' in req) req.onreadystatechange = onReadyStateChange;
|
5653
|
+
req.onload = onLoad;
|
5654
|
+
req.onerror = onError;
|
5019
5655
|
|
5020
5656
|
// do not rely on default XHR async flag, as some analytics code like hotjar
|
5021
5657
|
// breaks it and set it to false by default
|
@@ -5025,6 +5661,7 @@ module.exports = function createAlgoliasearch(AlgoliaSearch, uaSuffix) {
|
|
5025
5661
|
req.open(opts.method, url);
|
5026
5662
|
}
|
5027
5663
|
|
5664
|
+
// headers are meant to be sent after open
|
5028
5665
|
if (support.cors) {
|
5029
5666
|
if (body) {
|
5030
5667
|
if (opts.method === 'POST') {
|
@@ -5037,40 +5674,18 @@ module.exports = function createAlgoliasearch(AlgoliaSearch, uaSuffix) {
|
|
5037
5674
|
req.setRequestHeader('accept', 'application/json');
|
5038
5675
|
}
|
5039
5676
|
|
5040
|
-
// we set an empty onprogress listener
|
5041
|
-
// so that XDomainRequest on IE9 is not aborted
|
5042
|
-
// refs:
|
5043
|
-
// - https://github.com/algolia/algoliasearch-client-js/issues/76
|
5044
|
-
// - 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
|
5045
|
-
req.onprogress = function noop() {};
|
5046
|
-
|
5047
|
-
req.onload = load;
|
5048
|
-
req.onerror = error;
|
5049
|
-
|
5050
|
-
if (support.timeout) {
|
5051
|
-
// .timeout supported by both XHR and XDR,
|
5052
|
-
// we do receive timeout event, tested
|
5053
|
-
req.timeout = opts.timeout;
|
5054
|
-
|
5055
|
-
req.ontimeout = timeout;
|
5056
|
-
} else {
|
5057
|
-
ontimeout = setTimeout(timeout, opts.timeout);
|
5058
|
-
}
|
5059
|
-
|
5060
5677
|
req.send(body);
|
5061
5678
|
|
5062
5679
|
// event object not received in IE8, at least
|
5063
5680
|
// but we do not use it, still important to note
|
5064
|
-
function
|
5681
|
+
function onLoad(/* event */) {
|
5065
5682
|
// When browser does not supports req.timeout, we can
|
5066
5683
|
// have both a load and timeout event, since handled by a dumb setTimeout
|
5067
5684
|
if (timedOut) {
|
5068
5685
|
return;
|
5069
5686
|
}
|
5070
5687
|
|
5071
|
-
|
5072
|
-
clearTimeout(ontimeout);
|
5073
|
-
}
|
5688
|
+
clearTimeout(reqTimeout);
|
5074
5689
|
|
5075
5690
|
var out;
|
5076
5691
|
|
@@ -5095,14 +5710,12 @@ module.exports = function createAlgoliasearch(AlgoliaSearch, uaSuffix) {
|
|
5095
5710
|
}
|
5096
5711
|
}
|
5097
5712
|
|
5098
|
-
function
|
5713
|
+
function onError(event) {
|
5099
5714
|
if (timedOut) {
|
5100
5715
|
return;
|
5101
5716
|
}
|
5102
5717
|
|
5103
|
-
|
5104
|
-
clearTimeout(ontimeout);
|
5105
|
-
}
|
5718
|
+
clearTimeout(reqTimeout);
|
5106
5719
|
|
5107
5720
|
// error event is trigerred both with XDR/XHR on:
|
5108
5721
|
// - DNS error
|
@@ -5114,14 +5727,26 @@ module.exports = function createAlgoliasearch(AlgoliaSearch, uaSuffix) {
|
|
5114
5727
|
);
|
5115
5728
|
}
|
5116
5729
|
|
5117
|
-
function
|
5118
|
-
|
5119
|
-
|
5120
|
-
req.abort();
|
5121
|
-
}
|
5730
|
+
function onTimeout() {
|
5731
|
+
timedOut = true;
|
5732
|
+
req.abort();
|
5122
5733
|
|
5123
5734
|
reject(new errors.RequestTimeout());
|
5124
5735
|
}
|
5736
|
+
|
5737
|
+
function onConnect() {
|
5738
|
+
connected = true;
|
5739
|
+
clearTimeout(reqTimeout);
|
5740
|
+
reqTimeout = setTimeout(onTimeout, opts.timeouts.complete);
|
5741
|
+
}
|
5742
|
+
|
5743
|
+
function onProgress() {
|
5744
|
+
if (!connected) onConnect();
|
5745
|
+
}
|
5746
|
+
|
5747
|
+
function onReadyStateChange() {
|
5748
|
+
if (!connected && req.readyState > 1) onConnect();
|
5749
|
+
}
|
5125
5750
|
});
|
5126
5751
|
};
|
5127
5752
|
|
@@ -5157,8 +5782,8 @@ module.exports = function createAlgoliasearch(AlgoliaSearch, uaSuffix) {
|
|
5157
5782
|
return algoliasearch;
|
5158
5783
|
};
|
5159
5784
|
|
5160
|
-
}).call(this,require(
|
5161
|
-
},{"
|
5785
|
+
}).call(this,require(12))
|
5786
|
+
},{"1":1,"12":12,"22":22,"23":23,"24":24,"26":26,"29":29,"3":3,"34":34,"36":36,"6":6,"7":7}],22:[function(require,module,exports){
|
5162
5787
|
'use strict';
|
5163
5788
|
|
5164
5789
|
module.exports = getDocumentProtocol;
|
@@ -5174,12 +5799,12 @@ function getDocumentProtocol() {
|
|
5174
5799
|
return protocol;
|
5175
5800
|
}
|
5176
5801
|
|
5177
|
-
},{}],
|
5802
|
+
},{}],23:[function(require,module,exports){
|
5178
5803
|
'use strict';
|
5179
5804
|
|
5180
5805
|
module.exports = inlineHeaders;
|
5181
5806
|
|
5182
|
-
var encode = require(
|
5807
|
+
var encode = require(13);
|
5183
5808
|
|
5184
5809
|
function inlineHeaders(url, headers) {
|
5185
5810
|
if (/\?/.test(url)) {
|
@@ -5191,12 +5816,12 @@ function inlineHeaders(url, headers) {
|
|
5191
5816
|
return url + encode(headers);
|
5192
5817
|
}
|
5193
5818
|
|
5194
|
-
},{"
|
5819
|
+
},{"13":13}],24:[function(require,module,exports){
|
5195
5820
|
'use strict';
|
5196
5821
|
|
5197
5822
|
module.exports = jsonpRequest;
|
5198
5823
|
|
5199
|
-
var errors = require(
|
5824
|
+
var errors = require(29);
|
5200
5825
|
|
5201
5826
|
var JSONPCounter = 0;
|
5202
5827
|
|
@@ -5245,7 +5870,7 @@ function jsonpRequest(url, opts, cb) {
|
|
5245
5870
|
url += '&' + opts.jsonBody.params;
|
5246
5871
|
}
|
5247
5872
|
|
5248
|
-
var ontimeout = setTimeout(timeout, opts.
|
5873
|
+
var ontimeout = setTimeout(timeout, opts.timeouts.complete);
|
5249
5874
|
|
5250
5875
|
// script onreadystatechange needed only for
|
5251
5876
|
// <= IE8
|
@@ -5318,10 +5943,10 @@ function jsonpRequest(url, opts, cb) {
|
|
5318
5943
|
}
|
5319
5944
|
}
|
5320
5945
|
|
5321
|
-
},{"
|
5946
|
+
},{"29":29}],25:[function(require,module,exports){
|
5322
5947
|
module.exports = buildSearchMethod;
|
5323
5948
|
|
5324
|
-
var errors = require(
|
5949
|
+
var errors = require(29);
|
5325
5950
|
|
5326
5951
|
function buildSearchMethod(queryParam, url) {
|
5327
5952
|
return function search(query, args, callback) {
|
@@ -5366,12 +5991,12 @@ function buildSearchMethod(queryParam, url) {
|
|
5366
5991
|
};
|
5367
5992
|
}
|
5368
5993
|
|
5369
|
-
},{"
|
5994
|
+
},{"29":29}],26:[function(require,module,exports){
|
5370
5995
|
module.exports = function clone(obj) {
|
5371
5996
|
return JSON.parse(JSON.stringify(obj));
|
5372
5997
|
};
|
5373
5998
|
|
5374
|
-
},{}],
|
5999
|
+
},{}],27:[function(require,module,exports){
|
5375
6000
|
module.exports = function deprecate(fn, message) {
|
5376
6001
|
var warned = false;
|
5377
6002
|
|
@@ -5388,7 +6013,7 @@ module.exports = function deprecate(fn, message) {
|
|
5388
6013
|
return deprecated;
|
5389
6014
|
};
|
5390
6015
|
|
5391
|
-
},{}],
|
6016
|
+
},{}],28:[function(require,module,exports){
|
5392
6017
|
module.exports = function deprecatedMessage(previousUsage, newUsage) {
|
5393
6018
|
var githubAnchorLink = previousUsage.toLowerCase()
|
5394
6019
|
.replace('.', '')
|
@@ -5398,17 +6023,17 @@ module.exports = function deprecatedMessage(previousUsage, newUsage) {
|
|
5398
6023
|
'`. Please see https://github.com/algolia/algoliasearch-client-js/wiki/Deprecated#' + githubAnchorLink;
|
5399
6024
|
};
|
5400
6025
|
|
5401
|
-
},{}],
|
6026
|
+
},{}],29:[function(require,module,exports){
|
5402
6027
|
'use strict';
|
5403
6028
|
|
5404
6029
|
// This file hosts our error definitions
|
5405
6030
|
// We use custom error "types" so that we can act on them when we need it
|
5406
6031
|
// e.g.: if error instanceof errors.UnparsableJSON then..
|
5407
6032
|
|
5408
|
-
var inherits = require(
|
6033
|
+
var inherits = require(7);
|
5409
6034
|
|
5410
6035
|
function AlgoliaSearchError(message, extraProperties) {
|
5411
|
-
var forEach = require(
|
6036
|
+
var forEach = require(5);
|
5412
6037
|
|
5413
6038
|
var error = this;
|
5414
6039
|
|
@@ -5478,7 +6103,7 @@ module.exports = {
|
|
5478
6103
|
)
|
5479
6104
|
};
|
5480
6105
|
|
5481
|
-
},{"
|
6106
|
+
},{"5":5,"7":7}],30:[function(require,module,exports){
|
5482
6107
|
// Parse cloud does not supports setTimeout
|
5483
6108
|
// We do not store a setTimeout reference in the client everytime
|
5484
6109
|
// We only fallback to a fake setTimeout when not available
|
@@ -5487,8 +6112,8 @@ module.exports = function exitPromise(fn, _setTimeout) {
|
|
5487
6112
|
_setTimeout(fn, 0);
|
5488
6113
|
};
|
5489
6114
|
|
5490
|
-
},{}],
|
5491
|
-
var foreach = require(
|
6115
|
+
},{}],31:[function(require,module,exports){
|
6116
|
+
var foreach = require(5);
|
5492
6117
|
|
5493
6118
|
module.exports = function map(arr, fn) {
|
5494
6119
|
var newArr = [];
|
@@ -5498,8 +6123,8 @@ module.exports = function map(arr, fn) {
|
|
5498
6123
|
return newArr;
|
5499
6124
|
};
|
5500
6125
|
|
5501
|
-
},{"
|
5502
|
-
var foreach = require(
|
6126
|
+
},{"5":5}],32:[function(require,module,exports){
|
6127
|
+
var foreach = require(5);
|
5503
6128
|
|
5504
6129
|
module.exports = function merge(destination/* , sources */) {
|
5505
6130
|
var sources = Array.prototype.slice.call(arguments);
|
@@ -5519,14 +6144,30 @@ module.exports = function merge(destination/* , sources */) {
|
|
5519
6144
|
return destination;
|
5520
6145
|
};
|
5521
6146
|
|
5522
|
-
},{"
|
6147
|
+
},{"5":5}],33:[function(require,module,exports){
|
6148
|
+
module.exports = function omit(obj, test) {
|
6149
|
+
var keys = require(10);
|
6150
|
+
var foreach = require(5);
|
6151
|
+
|
6152
|
+
var filtered = {};
|
6153
|
+
|
6154
|
+
foreach(keys(obj), function doFilter(keyName) {
|
6155
|
+
if (test(keyName) !== true) {
|
6156
|
+
filtered[keyName] = obj[keyName];
|
6157
|
+
}
|
6158
|
+
});
|
6159
|
+
|
6160
|
+
return filtered;
|
6161
|
+
};
|
6162
|
+
|
6163
|
+
},{"10":10,"5":5}],34:[function(require,module,exports){
|
5523
6164
|
module.exports = createPlacesClient;
|
5524
6165
|
|
5525
|
-
var buildSearchMethod = require(
|
6166
|
+
var buildSearchMethod = require(25);
|
5526
6167
|
|
5527
6168
|
function createPlacesClient(algoliasearch) {
|
5528
6169
|
return function places(appID, apiKey, opts) {
|
5529
|
-
var cloneDeep = require(
|
6170
|
+
var cloneDeep = require(26);
|
5530
6171
|
|
5531
6172
|
opts = opts && cloneDeep(opts) || {};
|
5532
6173
|
opts.hosts = opts.hosts || [
|
@@ -5550,9 +6191,87 @@ function createPlacesClient(algoliasearch) {
|
|
5550
6191
|
};
|
5551
6192
|
}
|
5552
6193
|
|
5553
|
-
},{"
|
6194
|
+
},{"25":25,"26":26}],35:[function(require,module,exports){
|
6195
|
+
(function (global){
|
6196
|
+
var debug = require(1)('algoliasearch:src/hostIndexState.js');
|
6197
|
+
var localStorageNamespace = 'algoliasearch-client-js';
|
6198
|
+
|
6199
|
+
var store;
|
6200
|
+
var moduleStore = {
|
6201
|
+
state: {},
|
6202
|
+
set: function(key, data) {
|
6203
|
+
this.state[key] = data;
|
6204
|
+
return this.state[key];
|
6205
|
+
},
|
6206
|
+
get: function(key) {
|
6207
|
+
return this.state[key] || null;
|
6208
|
+
}
|
6209
|
+
};
|
6210
|
+
|
6211
|
+
var localStorageStore = {
|
6212
|
+
set: function(key, data) {
|
6213
|
+
try {
|
6214
|
+
var namespace = JSON.parse(global.localStorage[localStorageNamespace]);
|
6215
|
+
namespace[key] = data;
|
6216
|
+
global.localStorage[localStorageNamespace] = JSON.stringify(namespace);
|
6217
|
+
return namespace[key];
|
6218
|
+
} catch (e) {
|
6219
|
+
debug('localStorage set failed with', e);
|
6220
|
+
cleanup();
|
6221
|
+
store = moduleStore;
|
6222
|
+
return store.set(key, data);
|
6223
|
+
}
|
6224
|
+
},
|
6225
|
+
get: function(key) {
|
6226
|
+
return JSON.parse(global.localStorage[localStorageNamespace])[key] || null;
|
6227
|
+
}
|
6228
|
+
};
|
6229
|
+
|
6230
|
+
store = supportsLocalStorage() ? localStorageStore : moduleStore;
|
6231
|
+
|
6232
|
+
module.exports = {
|
6233
|
+
get: getOrSet,
|
6234
|
+
set: getOrSet
|
6235
|
+
};
|
6236
|
+
|
6237
|
+
function getOrSet(key, data) {
|
6238
|
+
if (arguments.length === 1) {
|
6239
|
+
return store.get(key);
|
6240
|
+
}
|
6241
|
+
|
6242
|
+
return store.set(key, data);
|
6243
|
+
}
|
6244
|
+
|
6245
|
+
function supportsLocalStorage() {
|
6246
|
+
try {
|
6247
|
+
if ('localStorage' in global &&
|
6248
|
+
global.localStorage !== null &&
|
6249
|
+
!global.localStorage[localStorageNamespace]) {
|
6250
|
+
// actual creation of the namespace
|
6251
|
+
global.localStorage.setItem(localStorageNamespace, JSON.stringify({}));
|
6252
|
+
return true;
|
6253
|
+
}
|
6254
|
+
|
6255
|
+
return false;
|
6256
|
+
} catch (_) {
|
6257
|
+
return false;
|
6258
|
+
}
|
6259
|
+
}
|
6260
|
+
|
6261
|
+
// In case of any error on localStorage, we clean our own namespace, this should handle
|
6262
|
+
// quota errors when a lot of keys + data are used
|
6263
|
+
function cleanup() {
|
6264
|
+
try {
|
6265
|
+
global.localStorage.removeItem(localStorageNamespace);
|
6266
|
+
} catch (_) {
|
6267
|
+
// nothing to do
|
6268
|
+
}
|
6269
|
+
}
|
6270
|
+
|
6271
|
+
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
6272
|
+
},{"1":1}],36:[function(require,module,exports){
|
5554
6273
|
'use strict';
|
5555
6274
|
|
5556
|
-
module.exports = '3.
|
6275
|
+
module.exports = '3.20.3';
|
5557
6276
|
|
5558
|
-
},{}]},{},[
|
6277
|
+
},{}]},{},[19]);
|