1/*! jquery.findyourrep 2014-03-29 Copyright (c) 2014 Dan Drinkard, Sunlight Foundation <[email protected]> under a BSD3 License. 2 3This package contains Geocoder-JS, Copyright (c) 2013 Brandon Morrison under an MIT License: 4 5The MIT License (MIT) 6 7Permission is hereby granted, free of charge, to any person obtaining a copy 8of this software and associated documentation files (the "Software"), to deal 9in the Software without restriction, including without limitation the rights 10to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11copies of the Software, and to permit persons to whom the Software is 12furnished to do so, subject to the following conditions: 13 14The above copyright notice and this permission notice shall be included in 15all copies or substantial portions of the Software. 16 17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23THE SOFTWARE. 24*/ 25if(function(){"use strict";var a={};a.version="0.0.0",a.createGeocoder=function(b){var c=new a.ProviderFactory;return c.createProvider(b)};var b="object"==typeof window?window:"object"==typeof exports?exports:{};b.GeocoderJS=a}(),"function"==typeof define&&define.amd&&define(GeocoderJS),"undefined"==typeof GeocoderJS&&"function"==typeof require)var GeocoderJS=require("../GeocoderJS.js");if(function(a){"use strict";a.ProviderBase=function(){},a.ProviderBase.prototype={geocode:function(){},geodecode:function(){},mapToGeocoded:function(){},executeRequest:function(){}}}(GeocoderJS),"undefined"==typeof GeocoderJS&&"function"==typeof require)var GeocoderJS=require("./GeocoderJS.js");if(function(a){"use strict";a.Geocoded=function(){},a.Geocoded.prototype={getCoordinates:function(){return[this.latitude,this.longitude]},getLatitude:function(){return this.latitude},getLongitude:function(){return this.longitude},getBounds:function(){},getStreetNumber:function(){return this.streetNumber},getStreetName:function(){return this.streetName},getCity:function(){return this.city},getZipcode:function(){return this.postal_code},getCityDistrict:function(){},getCounty:function(){},getCountyCode:function(){},getRegion:function(){return this.region}}}(GeocoderJS),"undefined"==typeof GeocoderJS&&"function"==typeof require)var GeocoderJS=require("./GeocoderJS.js");if(function(a){"use strict";var b={type:"Feature",properties:{},geometry:{type:"Point",coordinates:[]}};a.GeoJSONDumper=function(){return{dump:function(a){var c=b;return c.geometry.coordinates=[a.getLongitude(),a.getLatitude()],c}}}}(GeocoderJS),"undefined"==typeof GeocoderJS&&"function"==typeof require){var GeocoderJS=require("../GeocoderJS.js");require("../ExternalURILoader.js")}if(function(a){"use strict";a.ProviderFactory=function(){},a.ProviderFactory.prototype.createProvider=function(b){"string"==typeof b&&(b={provider:b});var c,d=new a.ExternalURILoader;switch(b.provider){case"google":c=new a.GoogleAPIProvider(b);break;case"mapquest":c=new a.MapquestProvider(b);break;case"openstreetmap":c=new a.OpenStreetMapProvider(d,b)}return c}}(GeocoderJS),"undefined"==typeof GeocoderJS&&"function"==typeof require)var GeocoderJS=require("../GeocoderJS.js");if(function(a){"use strict";var b=!1;a.ExternalURILoader=function(a){this.options={},void 0===a&&(a={}),this.setOptions(a)},a.ExternalURILoader.prototype.setOptions=function(a){var b={protocol:null,host:null,pathname:null};for(var c in b)this.options[c]=void 0!==a[c]?a[c]:b[c]},a.ExternalURILoader.prototype.executeRequest=function(c,d){function e(c,d){var e,f=require("url"),h=require(b?"https":"http"),i={protocol:b?"https":"http",host:g.options.host,pathname:g.options.pathname,query:c};i.query.sensor="false",e=f.format(i),h.get(e,function(b){if(200!=b.statusCode)throw"Received HTTP status code "+b.statusCode+" when attempting geocoding request.";b.data="",b.setEncoding("utf8"),b.on("data",function(a){b.data+=a}),b.on("end",function(){if(!b.data||!b.data.length)throw"Received empty data when attempting geocoding request.";var c=!1,e=0,f=[];try{c=JSON.parse(b.data)}
25catch(g){throw"Received invalid JSON data when attempting geocoding request."}if(c&&c.status){if("OVER_QUERY_LIMIT"===c.status)throw"Exceeded daily quota when attempting geocoding request.";if("OK"===c.status&&c.results){for(;e<c.results.length;e++)f.push(a.GoogleAPIProvider.prototype.mapToGeocoded(c.results[e]));return d(f)}}throw"Received unexpected JSON data when attempting geocoding request."})}).on("error",function(a){throw a})}function f(a,b){var c=new XMLHttpRequest,d=!1,e="//"+g.options.host+"/"+g.options.pathname+"?";!window.XDomainRequest||"withCredentials"in c||(c=new XDomainRequest,d=!0);for(var f in a)a.hasOwnProperty(f)&&(e+=encodeURIComponent(f)+"="+encodeURIComponent(a[f])+"&");c.onload=function(){if(200!=this.status&&!d)return console.log("Received HTTP status code "+this.status+" when attempting geocoding request."),b(null);if(!this.responseText||!this.responseText.length)return console.log("Received empty data when attempting geocoding request."),b(null);var a=!1;try{a=JSON.parse(this.responseText)}catch(c){return console.log("Received invalid JSON data when attempting geocoding request."),b(null)}return a?b(a):(console.log("Received unexpected JSON data when attempting geocoding request."),b(null))},c.open("GET",e),c.send()}var g=this;if("undefined"!=typeof XMLHttpRequest)return f(c,d);try{return require("url"),require(b?"https":"http"),e(c,d)}catch(h){}return d(null)}}(GeocoderJS),"undefined"==typeof GeocoderJS&&"function"==typeof require){var GeocoderJS=require("../GeocoderJS.js");require("../Geocoded.js"),require("../providers/ProviderBase.js")}if(function(a){"use strict";function b(b,c){var e,f=require("url"),g=require(d?"https":"http"),h={protocol:d?"https":"http",host:"maps.googleapis.com",pathname:"maps/api/geocode/json",query:b};h.query.sensor="false",e=f.format(h),g.get(e,function(b){if(200!=b.statusCode)throw"Received HTTP status code "+b.statusCode+" when attempting geocoding request.";b.data="",b.setEncoding("utf8"),b.on("data",function(a){b.data+=a}),b.on("end",function(){if(!b.data||!b.data.length)throw"Received empty data when attempting geocoding request.";var d=!1,e=0,f=[];try{d=JSON.parse(b.data)}catch(g){throw"Received invalid JSON data when attempting geocoding request."}if(d&&d.status){if("OVER_QUERY_LIMIT"===d.status)throw"Exceeded daily quota when attempting geocoding request.";if("OK"===d.status&&d.results){for(;e<d.results.length;e++)f.push(a.GoogleAPIProvider.prototype.mapToGeocoded(d.results[e]));return c(f)}}throw"Received unexpected JSON data when attempting geocoding request."})}).on("error",function(a){throw a})}function c(b,c){var e=new XMLHttpRequest,f=!1,g=(d?"https":"http")+"://maps.googleapis.com/maps/api/geocode/json?sensor=false&";!window.XDomainRequest||"withCredentials"in e||(e=new XDomainRequest,f=!0);for(var h in b)b.hasOwnProperty(h)&&(g+=encodeURIComponent(h)+"="+encodeURIComponent(b[h]));e.onload=function(){if(200!=this.status&&!f)return console.log("Received HTTP status code "+this.status+" when attempting geocoding request."),c(null);if(!this.responseText||!this.responseText.length)return console.log("Received empty data when attempting geocoding request."),c(null);var b=!1,d=0,e=[];try{b=JSON.parse(this.responseText)}catch(g){return console.log("Received invalid JSON data when attempting geocoding request."),c(null)}if(b&&b.status){if("OVER_QUERY_LIMIT"===b.status)return console.log("Exceeded daily quota when attempting geocoding request."),c(null);if("OK"===b.status&&b.results){for(;d<b.results.length;
25d++)e.push(a.GoogleAPIProvider.prototype.mapToGeocoded(b.results[d]));return c(e)}}return console.log("Received unexpected JSON data when attempting geocoding request."),c(null)},e.open("GET",g),e.send()}var d=!1;a.GoogleAPIProvider=function(a){"object"!=typeof a&&(a={}),d=a.useSSL},a.GoogleAPIProvider.prototype=new a.ProviderBase,a.GoogleAPIProvider.prototype.constructor=a.GoogleAPIProvider,a.GoogleAPIProvider.prototype.geocode=function(a,b){this.executeRequest({address:a},b)},a.GoogleAPIProvider.prototype.geodecode=function(a,b,c){this.executeRequest({latlng:a+","+b},c)},a.GoogleAPIProvider.prototype.executeRequest=function(a,e){if("undefined"!=typeof XMLHttpRequest)return c(a,e);try{return require("url"),require(d?"https":"http"),b(a,e)}catch(f){}return e(null)},a.GoogleAPIProvider.prototype.mapToGeocoded=function(b){var c=new a.Geocoded;c.latitude=b.geometry.location.lat,c.longitude=b.geometry.location.lng;for(var d in b.address_components)for(var e in b.address_components[d].types)switch(b.address_components[d].types[e]){case"street_number":c.streetNumber=b.address_components[d].long_name;break;case"route":c.streetName=b.address_components[d].long_name;break;case"locality":c.city=b.address_components[d].long_name;break;case"administrative_area_level_1":c.region=b.address_components[d].long_name;break;case"postal_code":c.postal_code=b.address_components[d].long_name}return c}}(GeocoderJS),"undefined"==typeof GeocoderJS&&"function"==typeof require)var GeocoderJS=require("../GeocoderJS.js");if(function(a){"use strict";a.MapquestProvider=function(a){"object"!=typeof a&&(a={});var b={apiKey:""};for(var c in b)void 0===a[c]&&(a[c]=b[c]);this.apiKey=a.apiKey},a.MapquestProvider.prototype=new a.ProviderBase,a.MapquestProvider.prototype.constructor=a.MapquestProvider,a.MapquestProvider.prototype.geocode=function(a,b){this.executeRequest({location:a},b)},a.MapquestProvider.prototype.mapToGeocoded=function(b){var c=new a.Geocoded;return c.latitude=b[0].latLng.lat,c.longitude=b[0].latLng.lng,c.city=b[0].adminArea5,c.region=b[0].adminArea4,c},a.MapquestProvider.prototype.executeRequest=function(b,c){var d=new XMLHttpRequest,e=!1,f="http://open.mapquestapi.com/geocoding/v1/address?outFormat=json&location="+encodeURIComponent(b.location);!window.XDomainRequest||"withCredentials"in d||(d=new XDomainRequest,e=!0),this.apiKey&&(f+="&key="+this.apiKey),d.onload=function(){if(200!=this.status&&!e)return console.log("Received HTTP status code "+this.status+" when attempting geocoding request."),c(null);if(!this.responseText||!this.responseText.length)return console.log("Received empty data when attempting geocoding request."),c(null);var b=!1,d=0,f=[];try{b=JSON.parse(this.responseText)}catch(g){return console.log("Received invalid JSON data when attempting geocoding request."),c(null)}if(b&&b.info){if("OVER_QUERY_LIMIT"===b.status)return console.log("Exceeded daily quota when attempting geocoding request."),c(null);if(0===b.info.statuscode&&b.results){for(;d<b.results.length;d++)f.push(a.MapquestProvider.prototype.mapToGeocoded(b.results[d].locations));return c(f)}}return console.log("Received unexpected JSON data when attempting geocoding request."),c(null)},d.open("GET",f),d.send()}}(GeocoderJS),"undefined"==typeof GeocoderJS&&"function"==typeof require){var GeocoderJS=require("../GeocoderJS.js");require("../Geocoded.js"),require("../ExternalURILoader.js"),require("../providers/ProviderBase.js")}!function(a){"use strict";a.OpenStreetMapProvider=function(b){if(void 0===b)throw"No external loader defined.";this.externalLoader=b,a.OpenStreetMapProvider.prototype=new a.ProviderBase,a.OpenStreetMapProvider.prototype.constructor=a.GoogleAPIProvider},a.OpenStreetMapProvider.prototype.geocode=function(a,b){this.externalLoader.setOptions({protocol:"http",host:"nominatim.openstreetmap.org",pathname:"search"});var c={format:"json",q:a,addressdetails:1};this.executeRequest(c,b)},a.OpenStreetMapProvider.prototype.geodecode=function(a,b,c){this.externalLoader.setOptions({protocol:"http",host:"nominatim.openstreetmap.org",pathname:"reverse"});var d={format:"json",lat:a,lon:b,addressdetails:1,zoom:18},e=this;this.externalLoader.executeRequest(d,function(a){var b=[];b.push(e.mapToGeocoded(a)),c(b)})}
25,a.OpenStreetMapProvider.prototype.executeRequest=function(a,b){var c=this;this.externalLoader.executeRequest(a,function(a){var d=[];for(var e in a)d.push(c.mapToGeocoded(a[e]));b(d)})},a.OpenStreetMapProvider.prototype.mapToGeocoded=function(b){var c=new a.Geocoded;return c.latitude=1*b.lat,c.longitude=1*b.lon,c.streetNumber=void 0!==b.address.house_number?b.address.house_number:void 0,c.streetName=b.address.road,c.city=b.address.city,c.region=b.address.state,c.postal_code=b.address.postcode,c}}(GeocoderJS),function(a){a.FYR||(a.FYR={}),a.FYR.bootstrap=function(a,b){a.findYourRep={},a.findYourRep._version="0.0.3",a.findYourRep.sunlightApiKey=null,a.findYourRep.defaultGeocoder="google",a.findYourRep.geocodeWithSSL=!("http:"===location.protocol&&b.XDomainRequest&&!("withCredentials"in new XMLHttpRequest)),a.findYourRep.geocoderApiKey=null,a.findYourRep.templateContext={title:"Find Your Representatives",apis:"congress, openstates",text:"Enter your address to see who represents you.",action:"Go!"},a.findYourRep.apiCall=function(b,c){return a.getJSON(b,c)},a.findYourRep.geocodeOrResolveImmediately=function(b){var c;return c="object"==typeof b?a.Deferred().resolve(b):a.findYourRep.geocode(b)},a.findYourRep.render=function(a,b){return a.replace(/\{\{ ?([\w\d_]+) ?\}\}/gi,function(a,c){return b[c]||""})},a.findYourRep.geocode=function(b,c){var d,e=new a.Deferred,f={provider:c||a.findYourRep.defaultGeocoder,useSSL:a.findYourRep.geocodeWithSSl};return a.findYourRep.geocoderApiKey&&(f.apiKey=a.findYourRep.geocoderApiKey),d=new GeocoderJS.createGeocoder(f),d.geocode(b,function(a){try{e.resolve(a[0])}catch(b){e.resolve({})}}),e},a.findYourRep.openstates=function(c){var d=new a.Deferred,e="http://openstates.org/api/v1/legislators/geo?callback=?",f={};return f.apikey=a.findYourRep.sunlightApiKey,b.location.protocol.match(/https/)?d.reject("Aborting Open States query--it does not support HTTPS :(\n Ask for it here! https://sunlight.atlassian.net/browse/OS-26"):a.findYourRep.geocodeOrResolveImmediately(c).done(function(b){f.lat=b.latitude,f["long"]=b.longitude,a.findYourRep.apiCall(e,f).done(function(a){d.resolve(a)})}),d},a.findYourRep.congress=function(b){var c=new a.Deferred,d="https://congress.api.sunlightfoundation.com/legislators/locate?callback=?",e={};return e.apikey=a.findYourRep.sunlightApiKey,a.findYourRep.geocodeOrResolveImmediately(b).done(function(b){e.latitude=b.latitude,e.longitude=b.longitude,a.findYourRep.apiCall(d,e).done(function(a){c.resolve(a)})}),c},a.findYourRep.getTemplateContext=function(a,b){var c={};return"congress"==b?(c={senate:a.state_name,house:a.state+"-"+a.district,D:"Democrat",R:"Republican",I:"Independent"},{name:a.title+" "+a.first_name+" "+a.last_name,details:c[a.party]+", "+c[a.chamber],photoUrl:"https://d26u557eiepppx.cloudfront.net/images/congress/225x275/"+a.bioguide_id+".jpg",resultUrl:"http://opencongress.org/people/show/"+a.govtrack_id}):"openstates"==b?(c={upper:"Upper Chamber",lower:"Lower Chamber",Democratic:"Democrat",Republican:"Republican",Independent:"Independent"},{name:a.full_name,details:c[a.party]+", "+a.state.toUpperCase()+"-"+a.district+" ("+c[a.chamber]+")",photoUrl:a.photo_url,resultUrl:"http://openstates.org/"+a.state+"/legislators/"+a.id}):void 0},a.findYourRep.formTemplate="<div class='find-your-rep fyr-container' id='fyr{{ idx }}' data-apis='{{ apis }}'><h3>{{ title }}</h3><p>{{ text }}</p><div class='fyr-controls'><textarea placeholder='Enter your address'>{{ defaultValue }}</textarea><button class='fyr-submit'>{{ action }}</button></div><small>Powered by <a href='http://sunlightfoundation.com'>The Sunlight Foundation</a></small></div>",a.findYourRep.resultsTemplate="<div class='fyr-results'><h3>Your Representatives</h3><div class='fyr-congress cf' style='display:none;'><h4>In Congress</h4><ul class='fyr-reps'></ul></div><div class='fyr-openstates cf' style='display:none;'><h4>State Representatives</h4><ul class='fyr-reps'></ul></div><a href='#' class='fyr-back'>« start over</a><small>Powered by <a href='http://sunlightfoundation.com'>The Sunlight Foundation</a></small></div>",a.findYourRep.resultTemplate="<li class='fyr-rep cf'><a href='{{ resultUrl }}' target='_top'><img src='{{ photoUrl }}' alt='photo of'><h4>{{ name }}</h4><p class='fyr-details'>{{ details }}</p></a></li>",a.fn.findYourRep=function(c){var d,e=a.findYourRep.templateContext;return a.findYourRep.sunlightApiKey=c.apikey||a.findYourRep.sunlightApiKey,delete c.apikey,e=a.extend({},e,c),d=e.apis.split(/, ?/),a(this).each(function(c,f){a(f).on("click",".fyr-back",function(b){b.preventDefault(),a(f).html(a.findYourRep.render(a.findYourRep.formTemplate,e))}),a(f).on("click",".fyr-submit",function(c){c.preventDefault(),c.stopPropagation();var e=a(f).find("textarea").eq(0).val();a(f).find(".fyr-container").eq(0).html(a.findYourRep.render(a.findYourRep.resultsTemplate,{})),a.findYourRep.geocode(e).done(function(c){a.each(d,function(d,e){a.findYourRep[e](c).done(function(b){var c=b.results||b||[],d=["senate","upper"];return 0===c.length||"500"==c.status?(a(f).find(".fyr-"+e).eq(0).show().find(".fyr-reps").append('<li class="fyr-rep">No results found.</li>').show(),!1):(c=c.sort(function(b,c){return b.chamber==c.chamber?0:"-1"!=a.inArray(b.chamber,d)?-1:1}),void a.each(c,function(b,c){a(f).find(".fyr-"+e).eq(0).show().find(".fyr-reps").eq(0).append(a.findYourRep.render(a.findYourRep.resultTemplate,a.findYourRep.getTemplateContext(c,e)))}))}).fail(function(a){b.console&&console.log&&console.log(a)})})})}),a(f).html(a.findYourRep.render(a.findYourRep.formTemplate,e))})}},a.FYR.onNewJq=function(){var b;a.console&&console.log&&console.log("Saving new jQuery at FYR.$"),a.FYR.$=jQuery.noConflict(!0),b=a.FYR.$,a.FYR.bootstrap(a.FYR.$,a),"undefined"!=typeof FYR.$els&&b.each(FYR.$els,function(a,c){b(c.els).findYourRep(c.opts)})};var b=$.map(jQuery.fn.jquery.split("."),function(a){return("0"+a).slice(-2)}).slice(0,2).join(".");if("undefined"==typeof jQuery||"01.07">b){a.console&&console.log&&console.log("Downloading jQuery because it was old or missing...");var c=document.createElement("script");c.src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js",c.onload=FYR.onNewJq,document.getElementsByTagName("head")[0].appendChild(c),jQuery.fn.findYourRep=function(b){return a.FYR.$els||(a.FYR.$els=[]),a.FYR.$els.push({els:this,opts:b}),jQuery(this)}}else FYR.bootstrap(jQuery,a)}(this);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.