UNPKG

pelias-leaflet-plugin

Version:

Add Pelias geocoding to your Leaflet map.

1 lines 23.9 kB
(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(_dereq_,module,exports){function corslite(url,callback,cors){var sent=false;if(typeof window.XMLHttpRequest==="undefined"){return callback(Error("Browser not supported"))}if(typeof cors==="undefined"){var m=url.match(/^\s*https?:\/\/[^\/]*/);cors=m&&m[0]!==location.protocol+"//"+location.hostname+(location.port?":"+location.port:"")}var x=new window.XMLHttpRequest;function isSuccessful(status){return status>=200&&status<300||status===304}if(cors&&!("withCredentials"in x)){x=new window.XDomainRequest;var original=callback;callback=function(){if(sent){original.apply(this,arguments)}else{var that=this,args=arguments;setTimeout(function(){original.apply(that,args)},0)}}}function loaded(){if(x.status===undefined||isSuccessful(x.status))callback.call(x,null,x);else callback.call(x,x,null)}if("onload"in x){x.onload=loaded}else{x.onreadystatechange=function readystate(){if(x.readyState===4){loaded()}}}x.onerror=function error(evt){callback.call(this,evt||true,null);callback=function(){}};x.onprogress=function(){};x.ontimeout=function(evt){callback.call(this,evt,null);callback=function(){}};x.onabort=function(evt){callback.call(this,evt,null);callback=function(){}};x.open("GET",url,true);x.send(null);sent=true;return x}if(typeof module!=="undefined")module.exports=corslite},{}],2:[function(_dereq_,module,exports){(function(global){"use strict";if(!global.console){global.console={}}var con=global.console;var prop,method;var dummy=function(){};var properties=["memory"];var methods=("assert,clear,count,debug,dir,dirxml,error,exception,group,"+"groupCollapsed,groupEnd,info,log,markTimeline,profile,profiles,profileEnd,"+"show,table,time,timeEnd,timeline,timelineEnd,timeStamp,trace,warn").split(",");while(prop=properties.pop())if(!con[prop])con[prop]={};while(method=methods.pop())if(typeof con[method]!=="function")con[method]=dummy})(typeof window==="undefined"?this:window)},{}],3:[function(_dereq_,module,exports){(function(global){"use strict";_dereq_("console-polyfill");var L=typeof window!=="undefined"?window["L"]:typeof global!=="undefined"?global["L"]:null;var corslite=_dereq_("@mapbox/corslite");var throttle=_dereq_("./utils/throttle");var escapeRegExp=_dereq_("./utils/escapeRegExp");var VERSION="1.9.4";var MINIMUM_INPUT_LENGTH_FOR_AUTOCOMPLETE=1;var FULL_WIDTH_MARGIN=20;var FULL_WIDTH_TOUCH_ADJUSTED_MARGIN=4;var RESULTS_HEIGHT_MARGIN=20;var API_RATE_LIMIT=250;var TEXT_STRINGS={INPUT_PLACEHOLDER:"Search",INPUT_TITLE_ATTRIBUTE:"Search",RESET_TITLE_ATTRIBUTE:"Reset",NO_RESULTS:"No results were found.",ERROR_403:"A valid API key is needed for this search feature.",ERROR_404:"The search service cannot be found. :-(",ERROR_408:"The search service took too long to respond. Try again in a second.",ERROR_429:"There were too many requests. Try again in a second.",ERROR_500:"The search service is not working right now. Please try again later.",ERROR_502:"Connection lost. Please try again later.",ERROR_DEFAULT:"The search service is having problems :-("};var Geocoder=L.Control.extend({version:VERSION,includes:L.Evented?L.Evented.prototype:L.Mixin.Events,options:{position:"topleft",attribution:'Geocoding by <a href="https://geocode.earth">Geocode.earth</a>',url:"https://api.geocode.earth/v1",placeholder:null,bounds:false,focus:true,layers:null,panToPoint:true,pointIcon:true,polygonIcon:true,fullWidth:650,markers:true,overrideBbox:false,expanded:false,autocomplete:true,place:false,textStrings:TEXT_STRINGS},initialize:function(apiKey,options){if(window.XDomainRequest){this.options.url="//api.geocode.earth/v1"}if(typeof apiKey==="object"&&!!apiKey){options=apiKey}else{this.apiKey=apiKey}if(options&&typeof options.latlng!=="undefined"){if(typeof options.focus==="undefined"){options.focus=options.latlng}console.warn("[leaflet-geocoder-mapzen] DEPRECATION WARNING:","As of v1.6.0, the `latlng` option is deprecated. It has been renamed to `focus`. `latlng` will be removed in a future version.")}if(options&&typeof options.title!=="undefined"){options.textStrings=options.textStrings||{};options.textStrings.INPUT_TITLE_ATTRIBUTE=options.title;console.warn("[leaflet-geocoder-mapzen] DEPRECATION WARNING:","As of v1.8.0, the `title` option is deprecated. Please set the property `INPUT_TITLE_ATTRIBUTE` on the `textStrings` option instead. `title` will be removed in a future version.")}if(options&&typeof options.placeholder!=="undefined"){if(!(options.textStrings&&typeof options.textStrings.INPUT_PLACEHOLDER!=="undefined")){options.textStrings=options.textStrings||{};options.textStrings.INPUT_PLACEHOLDER=options.placeholder}}if(options&&typeof options.textStrings==="object"){for(var prop in this.options.textStrings){if(typeof options.textStrings[prop]==="undefined"){options.textStrings[prop]=this.options.textStrings[prop]}}}L.Util.setOptions(this,options);this.markers=[];var mapzenHostedServiceUrl="//search.mapzen.com";if(this.options.url.indexOf(mapzenHostedServiceUrl)>-1){console.warn("Mapzen is shutting down its services including Search. Read more at https://mapzen.com/blog/shutdown. To learn more about Pelias, the open-source geocoder that powers Mapzen Search, and the Pelias team’s plan for the future, please visit http://pelias.io.")}},reset:function(){this._input.value="";L.DomUtil.addClass(this._reset,"leaflet-pelias-hidden");this.removeMarkers();this.clearResults();this.fire("reset")},getLayers:function(params){var layers=this.options.layers;if(!layers){return params}params.layers=layers;return params},getBoundingBoxParam:function(params){var bounds=this.options.bounds;if(!bounds){return params}if(bounds===true&&this._map){bounds=this._map.getBounds();params=makeParamsFromLeaflet(params,bounds)}else if(typeof bounds==="object"&&bounds.isValid&&bounds.isValid()){params=makeParamsFromLeaflet(params,bounds)}else if(L.Util.isArray(bounds)){var latLngBounds=L.latLngBounds(bounds);if(latLngBounds.isValid&&latLngBounds.isValid()){params=makeParamsFromLeaflet(params,latLngBounds)}}function makeParamsFromLeaflet(params,latLngBounds){params["boundary.rect.min_lon"]=latLngBounds.getWest();params["boundary.rect.min_lat"]=latLngBounds.getSouth();params["boundary.rect.max_lon"]=latLngBounds.getEast();params["boundary.rect.max_lat"]=latLngBounds.getNorth();return params}return params},getFocusParam:function(params){var focus=this.options.focus;if(!focus){return params}if(focus===true&&this._map){var mapCenter=this._map.getCenter();params["focus.point.lat"]=mapCenter.lat;params["focus.point.lon"]=mapCenter.lng}else if(typeof focus==="object"){var latlng=L.latLng(focus);params["focus.point.lat"]=latlng.lat;params["focus.point.lon"]=latlng.lng}return params},getParams:function(params){params=params||{};params=this.getBoundingBoxParam(params);params=this.getFocusParam(params);params=this.getLayers(params);if(this.apiKey){params.api_key=this.apiKey}var newParams=this.options.params;if(!newParams){return params}if(typeof newParams==="object"){for(var prop in newParams){params[prop]=newParams[prop]}}return params},serialize:function(params){var data="";for(var key in params){if(params.hasOwnProperty(key)){var param=params[key];var type=param.toString();var value;if(data.length){data+="&"}switch(type){case"[object Array]":value=param[0].toString()==="[object Object]"?JSON.stringify(param):param.join(",");break;case"[object Object]":value=JSON.stringify(param);break;case"[object Date]":value=param.valueOf();break;default:value=param;break}data+=encodeURIComponent(key)+"="+encodeURIComponent(value)}}return data},search:function(input){if(!input)return;var url=this.options.url+"/search";var params={text:input};this.callPelias(url,params,"search")},autocomplete:throttle(function(input){if(!input)return;var url=this.options.url+"/autocomplete";var params={text:input};this.callPelias(url,params,"autocomplete")},API_RATE_LIMIT),place:function(id){if(!id)return;var url=this.options.url+"/place";var params={ids:id};this.callPelias(url,params,"place")},handlePlaceResponse:function(response){},maxReqTimestampRendered:(new Date).getTime(),callPelias:function(endpoint,params,type){params=this.getParams(params);L.DomUtil.addClass(this._search,"leaflet-pelias-loading");var reqStartedAt=(new Date).getTime();var paramString=this.serialize(params);var url=endpoint+"?"+paramString;var self=this;function handleResponse(err,response){L.DomUtil.removeClass(self._search,"leaflet-pelias-loading");var results;try{results=JSON.parse(response.responseText)}catch(e){err={code:500,message:"Parse Error"}}if(err){var errorMessage;switch(err.code){case 403:errorMessage=self.options.textStrings["ERROR_403"];break;case 404:errorMessage=self.options.textStrings["ERROR_404"];break;case 408:errorMessage=self.options.textStrings["ERROR_408"];break;case 429:errorMessage=self.options.textStrings["ERROR_429"];break;case 500:errorMessage=self.options.textStrings["ERROR_500"];break;case 502:errorMessage=self.options.textStrings["ERROR_502"];break;default:errorMessage=self.options.textStrings["ERROR_DEFAULT"];break}self.showMessage(errorMessage);self.fire("error",{results:results,endpoint:endpoint,requestType:type,params:params,errorCode:err.code,errorMessage:errorMessage})}if(results&&results.geocoding&&results.geocoding.errors){errorMessage=results.geocoding.errors[0];self.showMessage(errorMessage);self.fire("error",{results:results,endpoint:endpoint,requestType:type,params:params,errorCode:err.code,errorMessage:errorMessage});return}if(results&&results.features){if(type==="autocomplete"||type==="search"){if(self._input.value===""||self.maxReqTimestampRendered>=reqStartedAt){return}else{self.maxReqTimestampRendered=reqStartedAt}}if(type==="place"){self.handlePlaceResponse(results)}if(type==="autocomplete"||type==="search"){self.showResults(results.features,params.text)}self.fire("results",{results:results,endpoint:endpoint,requestType:type,params:params})}}corslite(url,handleResponse,true)},highlight:function(text,focus){var r=RegExp("("+escapeRegExp(focus)+")","gi");return text.replace(r,"<strong>$1</strong>")},getIconType:function(layer){var pointIcon=this.options.pointIcon;var polygonIcon=this.options.polygonIcon;var classPrefix="leaflet-pelias-layer-icon-";if(layer.match("venue")||layer.match("address")){if(pointIcon===true){return{type:"class",value:classPrefix+"point"}}else if(pointIcon===false){return false}else{return{type:"image",value:pointIcon}}}else{if(polygonIcon===true){return{type:"class",value:classPrefix+"polygon"}}else if(polygonIcon===false){return false}else{return{type:"image",value:polygonIcon}}}},showResults:function(features,input){if(features.length===0){this.showMessage(this.options.textStrings["NO_RESULTS"]);return}var resultsContainer=this._results;resultsContainer.innerHTML="";resultsContainer.style.display="block";resultsContainer.style.maxHeight=this._map.getSize().y-resultsContainer.offsetTop-this._container.offsetTop-RESULTS_HEIGHT_MARGIN+"px";var list=L.DomUtil.create("ul","leaflet-pelias-list",resultsContainer);for(var i=0,j=features.length;i<j;i++){var feature=features[i];var resultItem=L.DomUtil.create("li","leaflet-pelias-result",list);resultItem.feature=feature;resultItem.layer=feature.properties.layer;resultItem.coords=feature.geometry.coordinates;var icon=this.getIconType(feature.properties.layer);if(icon){var layerIconContainer=L.DomUtil.create("span","leaflet-pelias-layer-icon-container",resultItem);var layerIcon;if(icon.type==="class"){layerIcon=L.DomUtil.create("div","leaflet-pelias-layer-icon "+icon.value,layerIconContainer)}else{layerIcon=L.DomUtil.create("img","leaflet-pelias-layer-icon",layerIconContainer);layerIcon.src=icon.value}layerIcon.title="layer: "+feature.properties.layer}resultItem.innerHTML+=this.highlight(feature.properties.label,input)}},showMessage:function(text){var resultsContainer=this._results;resultsContainer.innerHTML="";resultsContainer.style.display="block";var messageEl=L.DomUtil.create("div","leaflet-pelias-message",resultsContainer);messageEl.appendChild(document.createTextNode(text))},removeMarkers:function(){if(this.options.markers){for(var i=0;i<this.markers.length;i++){this._map.removeLayer(this.markers[i])}this.markers=[]}},showMarker:function(text,latlng){this._map.setView(latlng,this._map.getZoom()||8);var markerOptions=typeof this.options.markers==="object"?this.options.markers:{};if(this.options.markers){var marker=new L.marker(latlng,markerOptions).bindPopup(text);this._map.addLayer(marker);this.markers.push(marker);marker.openPopup()}},fitBoundingBox:function(bbox){this._map.fitBounds([[bbox[1],bbox[0]],[bbox[3],bbox[2]]],{animate:true,maxZoom:16})},setSelectedResult:function(selected,originalEvent){var latlng=L.GeoJSON.coordsToLatLng(selected.feature.geometry.coordinates);this._input.value=selected.textContent||selected.innerText;var layer=selected.feature.properties.layer;if(layer!=="venue"&&layer!=="address"&&selected.feature.bbox&&!this.options.overrideBbox){this.removeMarkers();this.fitBoundingBox(selected.feature.bbox)}else{this.removeMarkers();this.showMarker(selected.innerHTML,latlng)}this.fire("select",{originalEvent:originalEvent,latlng:latlng,feature:selected.feature});this.blur();if(this.options.place&&selected.feature.properties.gid){this.place(selected.feature.properties.gid)}},focus:function(){if(!L.DomUtil.hasClass(this._container,"leaflet-pelias-expanded")){this.expand()}this._input.focus()},blur:function(){this._input.blur();this.clearResults();if(this._input.value===""&&this._results.style.display!=="none"){L.DomUtil.addClass(this._reset,"leaflet-pelias-hidden");if(!this.options.expanded){this.collapse()}}},clearResults:function(force){this._results.style.display="none";if(this._input.value===""||force===true){this._results.innerHTML=""}this._enableMapScrollWheelZoom()},expand:function(){L.DomUtil.addClass(this._container,"leaflet-pelias-expanded");this.setFullWidth();this.fire("expand")},collapse:function(){L.DomUtil.removeClass(this._container,"leaflet-pelias-expanded");this._input.blur();this.clearFullWidth();this.clearResults();this.fire("collapse")},setFullWidth:function(){if(this.options.fullWidth){this._map.invalidateSize();var mapWidth=this._map.getSize().x;var touchAdjustment=L.Browser.touch?FULL_WIDTH_TOUCH_ADJUSTED_MARGIN:0;var width=mapWidth-FULL_WIDTH_MARGIN-touchAdjustment;if(typeof this.options.fullWidth==="number"&&mapWidth>=window.parseInt(this.options.fullWidth,10)){this.clearFullWidth();return}this._container.style.width=width.toString()+"px"}},clearFullWidth:function(){if(this.options.fullWidth){this._container.style.width=""}},onAdd:function(map){var container=L.DomUtil.create("div","leaflet-pelias-control leaflet-bar leaflet-control");this._body=document.body||document.getElementsByTagName("body")[0];this._container=container;this._input=L.DomUtil.create("input","leaflet-pelias-input",this._container);this._input.spellcheck=false;L.DomEvent.addListener(this._input,"focus",function(e){this.fire("focus",{originalEvent:e})},this);L.DomEvent.addListener(this._input,"blur",function(e){this.fire("blur",{originalEvent:e})},this);if(this.options.textStrings["INPUT_TITLE_ATTRIBUTE"]){this._input.title=this.options.textStrings["INPUT_TITLE_ATTRIBUTE"]}if(this.options.textStrings["INPUT_PLACEHOLDER"]){this._input.placeholder=this.options.textStrings["INPUT_PLACEHOLDER"]}this._search=L.DomUtil.create("a","leaflet-pelias-search-icon",this._container);this._reset=L.DomUtil.create("div","leaflet-pelias-close leaflet-pelias-hidden",this._container);this._reset.innerHTML="×";this._reset.title=this.options.textStrings["RESET_TITLE_ATTRIBUTE"];this._results=L.DomUtil.create("div","leaflet-pelias-results leaflet-bar",this._container);if(this.options.expanded){this.expand()}L.DomEvent.on(this._container,"click",function(e){this._input.focus()},this).on(this._input,"focus",function(e){if(this._input.value&&this._results.children.length){this._results.style.display="block"}},this).on(this._map,"click",function(e){this.blur()},this).on(this._search,"click",function(e){L.DomEvent.stopPropagation(e);if(L.DomUtil.hasClass(this._container,"leaflet-pelias-expanded")){if(this.options.expanded===true){this._input.focus()}else{L.DomUtil.addClass(this._reset,"leaflet-pelias-hidden");this.collapse()}}else{if(this._input.value.length>0){L.DomUtil.removeClass(this._reset,"leaflet-pelias-hidden")}this.expand();this._input.focus()}},this).on(this._reset,"click",function(e){this.reset();this._input.focus();L.DomEvent.stopPropagation(e)},this).on(this._input,"keydown",function(e){var list=this._results.querySelectorAll(".leaflet-pelias-result");var selected=this._results.querySelectorAll(".leaflet-pelias-selected")[0];var selectedPosition;var self=this;var panToPoint=function(selected,options){if(selected&&options.panToPoint){var layer=selected.feature.properties.layer;if(layer!=="venue"&&layer!=="address"&&selected.feature.bbox&&!options.overrideBbox){self.removeMarkers();self.fitBoundingBox(selected.feature.bbox)}else{self.removeMarkers();self.showMarker(selected.innerHTML,L.GeoJSON.coordsToLatLng(selected.feature.geometry.coordinates))}}};var scrollSelectedResultIntoView=function(selected){var selectedRect=selected.getBoundingClientRect();var resultsRect=self._results.getBoundingClientRect();if(selectedRect.bottom>resultsRect.bottom){self._results.scrollTop=selected.offsetTop+selected.offsetHeight-self._results.offsetHeight}else if(selectedRect.top<resultsRect.top){self._results.scrollTop=selected.offsetTop}};for(var i=0;i<list.length;i++){if(list[i]===selected){selectedPosition=i;break}}switch(e.keyCode){case 13:if(selected){this.setSelectedResult(selected,e)}else{var text=(e.target||e.srcElement).value;this.search(text)}L.DomEvent.preventDefault(e);break;case 38:if(list.length===0||this._results.style.display==="none"){return}if(selected){L.DomUtil.removeClass(selected,"leaflet-pelias-selected")}var previousItem=list[selectedPosition-1];var highlighted=selected&&previousItem?previousItem:list[list.length-1];L.DomUtil.addClass(highlighted,"leaflet-pelias-selected");scrollSelectedResultIntoView(highlighted);panToPoint(highlighted,this.options);this._input.value=highlighted.textContent||highlighted.innerText;this.fire("highlight",{originalEvent:e,latlng:L.GeoJSON.coordsToLatLng(highlighted.feature.geometry.coordinates),feature:highlighted.feature});L.DomEvent.preventDefault(e);break;case 40:if(list.length===0||this._results.style.display==="none"){return}if(selected){L.DomUtil.removeClass(selected,"leaflet-pelias-selected")}var nextItem=list[selectedPosition+1];var highlighted=selected&&nextItem?nextItem:list[0];L.DomUtil.addClass(highlighted,"leaflet-pelias-selected");scrollSelectedResultIntoView(highlighted);panToPoint(highlighted,this.options);this._input.value=highlighted.textContent||highlighted.innerText;this.fire("highlight",{originalEvent:e,latlng:L.GeoJSON.coordsToLatLng(highlighted.feature.geometry.coordinates),feature:highlighted.feature});L.DomEvent.preventDefault(e);break;default:break}},this).on(this._input,"keyup",function(e){var key=e.which||e.keyCode;var text=(e.target||e.srcElement).value;if(text.length>0){L.DomUtil.removeClass(this._reset,"leaflet-pelias-hidden")}else{L.DomUtil.addClass(this._reset,"leaflet-pelias-hidden")}if(key===13||key===38||key===40){return}if(key===27){if(text.length===0||this._results.style.display==="none"){this._input.blur();if(!this.options.expanded&&L.DomUtil.hasClass(this._container,"leaflet-pelias-expanded")){this.collapse()}}this.clearResults(true);L.DomUtil.removeClass(this._search,"leaflet-pelias-loading");return}if(text!==this._lastValue){this._lastValue=text;if(text.length>=MINIMUM_INPUT_LENGTH_FOR_AUTOCOMPLETE&&this.options.autocomplete===true){this.autocomplete(text)}else{this.clearResults(true)}}},this).on(this._results,"click",function(e){L.DomEvent.preventDefault(e);L.DomEvent.stopPropagation(e);var _selected=this._results.querySelectorAll(".leaflet-pelias-selected")[0];if(_selected){L.DomUtil.removeClass(_selected,"leaflet-pelias-selected")}var selected=e.target||e.srcElement;var findParent=function(){if(!L.DomUtil.hasClass(selected,"leaflet-pelias-result")){selected=selected.parentElement;if(selected){findParent()}}return selected};findParent();if(selected){L.DomUtil.addClass(selected,"leaflet-pelias-selected");this.setSelectedResult(selected,e)}},this);if(this.options.fullWidth){L.DomEvent.on(window,"resize",function(e){if(L.DomUtil.hasClass(this._container,"leaflet-pelias-expanded")){this.setFullWidth()}},this)}L.DomEvent.on(this._results,"mouseover",this._disableMapScrollWheelZoom,this);L.DomEvent.on(this._results,"mouseout",this._enableMapScrollWheelZoom,this);L.DomEvent.on(this._map,"mousedown",this._onMapInteraction,this);L.DomEvent.on(this._map,"touchstart",this._onMapInteraction,this);L.DomEvent.disableClickPropagation(this._container);if(map.attributionControl){map.attributionControl.addAttribution(this.options.attribution)}return container},_onMapInteraction:function(event){this.blur();if(!this.options.expanded){if(!this._input.value&&L.DomUtil.hasClass(this._container,"leaflet-pelias-expanded")){this.collapse()}}},_disableMapScrollWheelZoom:function(event){if(!this._map.scrollWheelZoom.enabled()){return}this._scrollWheelZoomEnabled=this._map.scrollWheelZoom.enabled();if(this._scrollWheelZoomEnabled){this._map.scrollWheelZoom.disable()}},_enableMapScrollWheelZoom:function(event){if(this._scrollWheelZoomEnabled){this._map.scrollWheelZoom.enable()}},onRemove:function(map){if(map.attributionControl){map.attributionControl.removeAttribution(this.options.attribution)}}});module.exports=Geocoder}).call(this,typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{"./utils/escapeRegExp":5,"./utils/throttle":6,"@mapbox/corslite":1,"console-polyfill":2}],4:[function(_dereq_,module,exports){(function(global){(function(root,factory){var L;if(typeof define==="function"&&define.amd){define(["leaflet"],factory)}else if(typeof module==="object"&&module.exports){L=typeof window!=="undefined"?window["L"]:typeof global!=="undefined"?global["L"]:null;module.exports=factory(L)}else{if(typeof root.L==="undefined"){throw new Error("Leaflet must be loaded first")}root.Geocoder=factory(root.L)}})(this,function(L){"use strict";var Geocoder=_dereq_("./core");L.Control.Geocoder=Geocoder;L.control.geocoder=function(apiKey,options){return new L.Control.Geocoder(apiKey,options)};return Geocoder})}).call(this,typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{"./core":3}],5:[function(_dereq_,module,exports){function escapeRegExp(str){return str.replace(/[-[\]\/{}()*+?.\\^$|]/g,"\\$&")}module.exports=escapeRegExp},{}],6:[function(_dereq_,module,exports){function throttle(func,wait,options){var context,args,result;var timeout=null;var previous=0;if(!options)options={};var later=function(){previous=options.leading===false?0:(new Date).getTime();timeout=null;result=func.apply(context,args);if(!timeout)context=args=null};return function(){var now=(new Date).getTime();if(!previous&&options.leading===false)previous=now;var remaining=wait-(now-previous);context=this;args=arguments;if(remaining<=0||remaining>wait){if(timeout){clearTimeout(timeout);timeout=null}previous=now;result=func.apply(context,args);if(!timeout)context=args=null}else if(!timeout&&options.trailing!==false){timeout=setTimeout(later,remaining)}return result}}module.exports=throttle},{}]},{},[4]);