ContributionMap=function(n,t,i){var r=new t.Application;r.on("start",function(n){var e,t,l,a;console.log("2021");var s=r.module("Entities"),v=new s.GeographicDataManager({baseUrl:n.baseUrl,geographicDataFiles:n.geographicDataFiles}),h=r.module("Map"),f=r.module("QueryBuilder");n.parentUrl&&(f.parentUrl=n.parentUrl,f.parentHost=n.parentUrl.replace("https://","").replace("http://","").split("/").join("/").split("?")[0],e=n.parentUrl.replace("https://","").replace("http://","").split("/"),f.parentSearch=f.parentUrl.indexOf("?")===-1?"":e[e.length-1]);var u=(new h.Link.QueryStringParser).queryString,o=new s.Query({office:i("#selOffice").val(),candidate:i("#selCandidate").val(),geography:i("#selGeography").val(),filingPeriod:i("#selFilingPeriod").val(),amountType:i("input:radio[name=radAmountType]").filter(":checked").val()}),c={};for(t in u){c[t]=u[t];o.set(c);switch(t.toLowerCase()){case"office":u[t].toLowerCase()==="mayorall"&&(u[t]="mayorall");i("#selOffice").val(u[t]);break;case"candidate":u[t].toLowerCase()!=="allall"?(l=0,a=setInterval(function(){(l>20||i("#selCandidate option[value='"+u[t]+"']").length>0)&&(i("#selCandidate").val(u[t]),clearInterval(a))},200)):i("#selCandidate").val(u[t]);break;case"geography":i("#selGeography").val(u[t]);break;case"filingperiod":i("#selFilingPeriod").val(u[t]);break;case"amounttype":i("input:radio[value="+u[t]+"]").attr("checked",!0)}}h.start({config:n,query:o,queryString:u});f.start({config:n,query:o})});return r}(Backbone,Marionette,$,_);ContributionMapConfig=function(n){var t=n.baseUrl,i=n.parentUrl;return{baseUrl:t,parentUrl:i||null,mapConfig:{initialExtent:{lowerLeft:[40.5159961,-74.2090879],upperRight:[40.8952556,-73.5902721]},baseMapStyles:[{featureType:"poi",elementType:"labels",stylers:[{visibility:"off"}]},{featureType:"all",elementType:"all",stylers:[{lightness:40},{gamma:.8},{saturation:-95}]},{featureType:"road.local",elementType:"geometry",stylers:[{saturation:-73},{lightness:33},{gamma:.8},{visibility:"simplified"}]},{featureType:"road.arterial",elementType:"geometry",stylers:[{saturation:-91},{gamma:.8},{visibility:"simplified"},{lightness:100}]},{featureType:"road.arterial",elementType:"labels.text",stylers:[{visibility:"on"},{weight:.1}]},{featureType:"road.arterial",elementType:"labels.icon",stylers:[{visibility:"simplified"}]},{featureType:"road.highway",elementType:"geometry",stylers:[{visibility:"simplified"},{saturation:-91},{gamma:.8},{lightness:94}]},{featureType:"road.highway",elementType:"labels",stylers:[{visibility:"on"},{weight:.1}]}]},geographicDataFiles:{citycouncildistricts:{label:"City Council District",url:"geography/NYCC2013lbl.topojson.js",idPropertyName:"CounDist",hoverTitleTemplate:"City Council District <%= id %>",legendTemplate:"City Council District <%= id %>"},electiondistricts:{label:"Election District",url:"geography/nyed20c_clipped.topojson.js",idPropertyName:"ElectDist",hoverTitleTemplate:"Election District <%= parseInt(id.toString().substring(2,5)) %> in Assembly District <%= id.toString().substring(0,2) %> ",legendTemplate:"Election District <%= id %>"},neighborhoods:{label:"Neighborhood",url:"geography/NTAnycAll.topojson.js",idPropertyName:"NTACode",namePropertyName:"NTAName",hoverTitleTemplate:"the <%= name %> neighborhood area (<%= id %>)",legendTemplate:"Neighborhood Area <%= id %>"},nysassemblydistricts:{label:"New York State Assembly District",url:"geography/NysAssembly_clipped_65pct.topojson.js",idPropertyName:"AssmDist",hoverTitleTemplate:"New York State Assembly District <%= id %>",legendTemplate:"New York State AD <%= id %>"},zipcodes:{label:"ZIP Code",url:"geography/NYCZIPCODESESRI2019.topojson.js",idPropertyName:"ZIPCODE",hoverTitleTemplate:"ZIP Code <%= id %>",legendTemplate:"ZIP Code <%= id %>"}},colorSchemes:{redAlphaBlack:["rgba(255, 255, 255, 0.8)","rgba(255, 255, 179, 0.8)","rgba(255, 218, 117, 0.8)","rgba(252, 141, 61, 0.8)","rgba(252, 78, 43, 0.8)","rgba(189, 0, 38, 0.8)","rgba(128, 0, 38, 0.8)","rgba(60, 0, 38, 0.8)","rgba(26, 0, 16, 0.8)"],redAlpha8:["rgba(255, 255, 255, 0.8)","rgba(255, 255, 179, 0.8)","rgba(255, 218, 117, 0.8)","rgba(252, 141, 61, 0.8)","rgba(252, 78, 43, 0.8)","rgba(189, 0, 38, 0.8)","rgba(128, 0, 38, 0.8)","rgba(60, 0, 38, 0.8)"],greenAlphaBlack:["rgba(255, 255, 255, 0.8)","rgba(229,245,224, 0.8)","rgba(199,233,192, 0.8)","rgba(116,196,118, 0.8)","rgba(65,171,93, 0.8)","rgba(35,139,69, 0.8)","rgba(0,109,44, 0.8)","rgba(0, 69, 28, 0.8)","rgba(0,40,0, 0.8)"],greenAlphaYellowBlack:["rgba(255, 255, 255, 0.8)","rgba(217,240,163, 0.8)","rgba(173,221,142, 0.8)","rgba(120,198,121, 0.8)","rgba(65,171,93, 0.8)","rgba(35,132,67, 0.8)","rgba(0,104,55, 0.8)","rgba(0,69,41, 0.8)","rgba(0,30,0, 0.8)"],blueAlpha:["rgba(247,251,255, 0.8)","rgba(222,235,247, 0.8)","rgba(198,219,239, 0.8)","rgba(158,202,225, 0.8)","rgba(107,174,214, 0.8)","rgba(66,146,198, 0.8)","rgba(33,113,181, 0.8)","rgba(8,81,156, 0.8)","rgba(8,48,107, 0.8)"]},dataBreaks:{totalDefault:{type:"total",colorScheme:"greenAlphaYellowBlack",breaks:[{min:-1e7,max:100},{min:100,max:500},{min:500,max:1e3},{min:1e3,max:5e3},{min:5e3,max:1e4},{min:1e4,max:25e3},{min:25e3,max:1e5},{min:1e5,max:1e6},{min:1e6,max:Infinity}]},countDefault:{type:"number",colorScheme:"blueAlpha",breaks:[{min:1,max:2},{min:2,max:5},{min:5,max:10},{min:10,max:25},{min:25,max:50},{min:50,max:100},{min:100,max:200},{min:200,max:500},{min:500,max:Infinity}]},averageDefault:{type:"average",colorScheme:"redAlpha8",breaks:[{min:-1e7,max:25},{min:25,max:50},{min:50,max:100},{min:100,max:250},{min:250,max:500},{min:500,max:1e3},{min:1e3,max:2500},{min:2500,max:Infinity}]}}}};ContributionMap.module("Common",function(n,t,i,r,u){n.LoadingView=r.ItemView.extend({template:"#loading-view",className:"loading-spinner",initialize:function(n){var n=n||{};this.title=n.title||"Loading Data";this.message=n.message||"Please wait, data is loading."},serializeData:function(){return{title:this.title,message:this.message}},onShow:function(){this.startSpinning()},startSpinning:function(){u(".spinner").spin({lines:13,length:20,width:10,radius:30,corners:1,rotate:0,direction:1,color:"#0044ff",speed:1,trail:90,shadow:!1,hwaccel:!1})}})});ContributionMap.module("Common",function(n){n.templateHelpers={addCommas:function(n){n+="";x=n.split(".");x1=x[0];x2=x.length>1?"."+x[1]:"";for(var t=/(\d+)(\d{3})/;t.test(x1);)x1=x1.replace(t,"$1,$2");return x1+x2}}});ContributionMap.module("Entities",function(n,t,i,r,u){var e="api/candidates",f;n.on("start",function(n){e=n.baseUrl+e});n.Candidate=i.Model.extend({defaults:{totalContributionAmount:0,totalNumberOfContributions:0,totalFromInsideNyc:0,totalFromOutsideNyc:0,lessThanOrEqualTo250:0,greaterThan250:0}});n.CandidateList=i.Collection.extend({url:function(){return e},model:n.Candidate});f={};n.CandidateList.getByOffice=function(t){var i=null;return t&&(i={race:t}),f[t]||(f[t]=(new n.CandidateList).fetch({data:i}).then(function(t){return new n.CandidateList(t)})),f[t]};n.CandidateList.getAll=function(){var t="allthecandidates";return f[t]||(f[t]=(new n.CandidateList).fetch({}).then(function(t){return new n.CandidateList(t)})),f[t]};n.CandidateList.getContributionsByCandidate=function(t,i){var r=e+"/"+t+"/filingperiods/"+i;return u.ajax({url:r,dataType:"json"}).then(function(t){return new n.Candidate(t)})}});ContributionMap.module("Entities",function(n,t,i,r,u,f){var o,e;n.DataBreak=i.Model.extend({});n.DataBreakList=i.Collection.extend({model:n.DataBreak});n.DataBreakList.getByType=function(n){return e.find(function(t){return t.get("type")===n})};n.on("start",function(t){var i,r;o=t.colorSchemes;e=new n.DataBreakList;i=t.dataBreaks;for(r in i)e.add(f.extend(i[r],{name:r}));e.each(function(n){for(var i=n.get("breaks"),u=o[n.get("colorScheme")],t=0,r=i.length;t<r;t++)i[t].color=u[t]})})});ContributionMap.module("Entities",function(n,t,i,r,u,f){n.ContributionDataManager=function(n){this.baseUrl=n.baseUrl+"api/candidates/"};f.extend(n.ContributionDataManager.prototype,i.Events,{buildUrl:function(n,t,i){return this.baseUrl+n+"/"+t+"/filingPeriods/"+i},getData:function(n,t,i){return this.fetchData(this.buildUrl(n,t,i)).then(function(n){return n})},fetchData:function(n){return u.ajax({dataType:"json",url:n,context:this})}})});ContributionMap.module("Entities",function(n,t,i,r,u,f){n.GeographicDataManager=function(n){this.baseUrl=n.baseUrl;this.geographicDataFiles=n.geographicDataFiles;this.geoJsonData={}};f.extend(n.GeographicDataManager.prototype,i.Events,{getData:function(n){return this.geoJsonData[n]||(this.geoJsonData[n]=this.fetchGeoJson(this.geographicDataFiles[n].url).then(function(t){var r,i;if(t.objects[n]&&t.objects[n].geometries)for(r=t.objects[n].geometries,i=0;i<r.length;i++)r[i].id=r[i].id||r[i].properties.id;return t})),this.geoJsonData[n]},fetchGeoJson:function(n){var n=this.baseUrl+n;return u.ajax({dataType:"json",url:n,context:this})}});var e;n.on("start",function(t){e=_geographicDataManager=new n.GeographicDataManager({baseUrl:t.baseUrl,geographicDataFiles:t.geographicDataFiles})});n.GeographicDataManager.getInstance=function(){return e}});ContributionMap.module("Entities",function(n,t,i,r,u){var f;n.on("start",function(){f=u("#selFilingPeriod")});n.Query=i.Model.extend({defaults:{office:"All Races",candidate:"AllAll",geography:"zipcodes",amountType:"total",filingPeriod:0},currentOfficeIsACityCouncilDistrict:function(){var n=this.get("office");return n.toLowerCase().indexOf("city council ")>-1?!0:!1},getFilingPeriodLabel:function(){var n=this.get("filingPeriod"),t=f.find('option[value="'+n+'"]').text();return n!==0&&(t+=" filing period"),t}})});ContributionMap.module("About",function(n,t,i,r,u){n.AboutWindow=i.View.extend({el:u("#aboutModal"),initialize:function(n,t){var i=t.baseUrl,r=this;this.$el.on("show.bs.modal",function(){var n=r.tabs.find("#aboutTab");n.tab("show")});this.tabs=u("#aboutTabs");this.tabs.bind("show.bs.tab",function(n){var t=u(n.target),r=u(t.attr("href")),f=i+r.attr("data-html");u.ajax({url:f,type:"GET",dataType:"html",cache:!1,success:function(n){var i=n.replace(/^[\S\s]*<body[^>]*?>/i,"").replace(/<\/body[\S\s]*$/i,"");r.html(i);t.tab()}})});this.render()},render:function(){return this},showWin:function(n){this.$el.modal("show");var t=this.tabs.find(n);t.tab("show")}});t.on("start",function(t){var i=new n.AboutWindow(null,{baseUrl:t.baseUrl})})});ContributionMap.module("About",function(n,t,i,r,u){n.ShareWindow=i.View.extend({el:u("#shareModal"),initialize:function(n,t){var i=t.baseUrl,r=this;this.$el.on("show.bs.modal",function(){var n=r.tabs.find("#shareTab");n.tab("show")});this.tabs=u("#shareTabs");this.tabs.bind("show.bs.tab",function(n){var t=u(n.target),r=u(t.attr("href")),f=i+r.attr("data-html");u.ajax({url:f,type:"GET",dataType:"html",cache:!1,success:function(n){var i=n.replace(/^[\S\s]*<body[^>]*?>/i,"").replace(/<\/body[\S\s]*$/i,"");r.html(i);t.tab()}})});this.render()},render:function(){return this},showWin:function(n){this.$el.modal("show");var t=this.tabs.find(n);t.tab("show")}});t.on("start",function(t){var i=new n.ShareWindow(null,{baseUrl:t.baseUrl})})});ContributionMap.module("Map",{startWithParent:!1,define:function(n){var t,i;n.on("start",function(r){i=r.query;t=n.Controller;t.initialize(r.config,r.query,r.queryString)})}});ContributionMap.module("Map",function(n,t,i,r,u){var f,e,c,s,o,h,l;n.Controller={initialize:function(t,i,r){c=new n.LoadingMask;c.showBusy(!0);this.initMap(t.mapConfig,r);this.initQueryVisualizer(t,i,r);this.initializeMapControls(t,i);l=new n.Layer.HighlightedCouncilDistrictLayer({map:f,geographyType:"citycouncildistricts"});i.on("change:office",function(n,t){n.currentOfficeIsACityCouncilDistrict()?l.highlightFeature(t):l.highlightFeature(null)});i.currentOfficeIsACityCouncilDistrict()&&l.highlightFeature(i.get("office"));return},initMap:function(n,t){var i,r;f=new google.maps.Map(document.getElementById("map"),{streetViewControl:!1,mapTypeControlOptions:{position:google.maps.ControlPosition.BOTTOM_LEFT},panControl:!1,zoomControlOptions:{position:google.maps.ControlPosition.RIGHT_BOTTOM},styles:n.baseMapStyles});t.z&&t.latlng?(i=t.latlng.split(","),f.setOptions({zoom:parseInt(t.z,10),center:new google.maps.LatLng(i[0],i[1])})):(r=new google.maps.LatLngBounds(new google.maps.LatLng(n.initialExtent.lowerLeft[0],n.initialExtent.lowerLeft[1]),new google.maps.LatLng(n.initialExtent.upperRight[0],n.initialExtent.upperRight[1])),f.fitBounds(r))},initializeMapControls:function(i,r){var l=new n.AmountTypeSelector.AmountTypeControl,a,c,v;l.setMap(f,google.maps.ControlPosition.RIGHT_TOP);l.show(r);s=new n.Legend.LegendControl({geographicDataFiles:i.geographicDataFiles});s.setMap(f,google.maps.ControlPosition.RIGHT_TOP);s.showLegend(r);r.on("change:amountType",function(){s.showLegend(r)});r.on("change:office",function(){s.showOffice(r)});h=new n.CandidateSummary.CandidateSummaryControl;h.setMap(f,google.maps.ControlPosition.LEFT_TOP);a=new n.LogoControl;a.setMap(f,google.maps.ControlPosition.LEFT_BOTTOM);t.Entities.CandidateList.getContributionsByCandidate(r.get("candidate"),r.get("filingPeriod")).then(function(n){h.showCandidate(n,r);o.setCandidate(n)});r.on("change:candidate",function(n){t.Entities.CandidateList.getContributionsByCandidate(n.get("candidate"),n.get("filingPeriod")).then(function(t){h.showCandidate(t,n);o.setCandidate(t)})});r.on("change:filingPeriod",function(n){t.Entities.CandidateList.getContributionsByCandidate(n.get("candidate"),n.get("filingPeriod")).then(function(t){h.showCandidate(t,n);o.setCandidate(t)})});c=new n.Search.SearchControl({config:i});c.setMap(f,google.maps.ControlPosition.LEFT_TOP);c.setQuery(r);c.on("selected",function(n){e.findFeature(n.item,n.geography)});o=new n.Identify.IdentifyControl({geographicDataFiles:i.geographicDataFiles});o.setMap(f,google.maps.ControlPosition.LEFT_TOP);v=new n.Link.LinkView({query:r,map:f,queryVisualizer:e});u("#link-region").append(v.render().el).hide();r.attributes.embed?u("#full-map-link").show():(u("#link-region").show(),u("#share-modal-link").show(),u("#2017-link").show(),u("#queryBuilderForm").show())},initQueryVisualizer:function(t,i,r){e=new n.QueryVisualizer({map:f,config:t,query:i});e.once("ready",function(){r.selected&&e.findFeature(r.selected.toUpperCase(),i.get("geography"))});e.on("query:changed",function(){c.showBusy(!0)});e.on("style:updated",function(){c.showBusy(!1)});e.on("selected",function(n){o.setFeatureData(n);s.showSelected(n)});e.on("unselected",function(){o.setFeatureData(null);s.showSelected(null)});e.on("highlighted",function(n){o.setFeatureData(n)});e.on("unhighlighted",function(){o.setFeatureData(null)})},addMapClickHandler:function(){},identify:function(){},zoomToBounds:function(n){f.fitBounds(n,{paddingTopLeft:[300,0]})},buildVal:function(n){return n.getProperty("totalPre")+n.getProperty("totalPost")},setContributionLayer:function(n){_dataVisualizer.show(n);s.showLegend(n)},showCandidate:function(n){h.showCandidate(n)},showDistrict:function(n){_cityCouncilDistrict.forEach(function(n){_cityCouncilDistrict.remove(n)});n.indexOf("City Council ")>-1?u.when(t.request("citycouncildistrict:byname",n)).done(function(n){_cityCouncilDistrict.addGeoJson(n,{idPropertyName:"CounDist"});_cityCouncilDistrict.setMap(f)}):_cityCouncilDistrict.setMap(null)}}});ContributionMap.module("Map",function(n,t,i,r,u,f){n.LoadingMask=function(){this.maskDiv=u(".loading-mask");this.loadingView=new t.Common.LoadingView({title:" ",message:" "});this.maskDiv.append(this.loadingView.render().el);this.loadingView.startSpinning();this.showBusy(!1)};f.extend(n.LoadingMask.prototype,{showBusy:function(n){n?this.maskDiv.css({display:"block"}):this.maskDiv.css({display:"none"})}})});ContributionMap.module("Map",function(n,t,i,r,u,f){var e=navigator.userAgent.search(/webkit/i)>0;n.QueryVisualizer=function(n){this.map=n.map;this.query=n.query;this.dataManager=new t.Entities.ContributionDataManager({baseUrl:n.config.baseUrl});this.geoManager=t.Entities.GeographicDataManager.getInstance();this.listenTo(this.query,"change:candidate",this.onQueryChanged);this.listenTo(this.query,"change:geography",this.onQueryChanged);this.listenTo(this.query,"change:amountType",this.onQueryChanged);this.listenTo(this.query,"change:filingPeriod",this.onQueryChanged);this.dataBreak=t.Entities.DataBreakList.getByType(this.query.get("amountType"));this.contributionData=null;this.geoLayers={};this.geoLayersFeatureCount={};u.when(this.updateData(),this.updateGeography()).done(u.proxy(function(){this.updateStyle();this.trigger("ready")},this))};f.extend(n.QueryVisualizer.prototype,i.Events,{valueFunctions:{pre:function(n,t){var i=n.prePrimTot,r=n.prePrimNum;return t==="average"?i<0&&r===0?i:i/r:t==="number"?r:i},post:function(n,t){var i=n.postPrimTot,r=n.postPrimNum;return t==="average"?i/r:t==="number"?r:i},combined:function(n,t){var i=n.prePrimTot+n.postPrimTot,r=n.prePrimNum+n.postPrimNum;return t==="average"?i/r:t==="number"?r:i}},onQueryChanged:function(n){if(this.trigger("query:changed"),n.hasChanged("candidate")&&u.when(this.updateData(),this.updateGeography()).done(u.proxy(function(){this.updateStyle();this.selectedFeature&&this.selectFeature(this.selectedFeature,this.geoLayers[this.query.get("geography")])},this)),n.hasChanged("geography")){var i=this.geoLayers[this.query.previous("geography")];this.unhighlightFeature(this.highlightedFeature,i);this.unselectFeature(this.selectedFeature,i);u.when(this.updateData(),this.updateGeography()).done(u.proxy(function(){this.updateStyle()},this))}n.hasChanged("filingPeriod")&&u.when(this.updateData(),this.updateGeography()).done(u.proxy(function(){this.updateStyle();this.selectedFeature&&this.selectFeature(this.selectedFeature,this.geoLayers[this.query.get("geography")])},this));n.hasChanged("amountType")&&(this.dataBreak=t.Entities.DataBreakList.getByType(n.get("amountType")),this.updateStyle())},updateGeography:function(){var n=this.query.get("geography");return this.geoLayers[n]?u.Deferred().resolve(this.geoLayers[n]):this.geoManager.getData(n).then(u.proxy(function(t){var u=f.keys(t.objects)[0],r=topojson.feature(t,t.objects[u]),i;return this.geoLayersFeatureCount[n]=r.features.length,this.geoLayers[n]=new google.maps.Data({style:{fillOpacity:0,strokeOpacity:0}}),this.geoLayers[n].addGeoJson(r),i=this,this.geoLayers[n].addListener("mouseover",function(n){i.highlightFeature(n.feature,this)}),this.geoLayers[n].addListener("mouseout",function(n){i.unhighlightFeature(n.feature,this)}),this.geoLayers[n].addListener("click",function(n){i.selectedFeature&&i.selectedFeature===n.feature?(i.unselectFeature(n.feature,this),i.highlightFeature(n.feature,this)):i.selectFeature(n.feature,this)}),this.geoLayers[n]},this))},updateData:function(){var n=this.query.get("candidate"),t=this.query.get("geography"),i=this.query.get("filingPeriod");return this.dataManager.getData(n,t,i).then(u.proxy(function(n){this.contributionData=n},this))},updateStyle:function(){this.trigger("style:updating");var l=this.query,t=this.dataBreak.get("breaks"),o=this.valueFunctions.pre,s=this.query.get("amountType"),n=this.query.get("geography"),h=this.contributionData,r=0,u=this.geoLayersFeatureCount[n],i=this,c=function(n){var e,y,f;r+=1;r===u&&i.trigger("style:updated");var c,l=1,a=.7,p=n.getId(),v=h[p];if(!v)return{fillColor:"rgb(211,211,211)",fillOpacity:.3,strokeOpacity:0,strokeColor:"#ffffff",strokeWeight:.5};if(e=o(v,s),y=t.length,e===0)c="rgb(211,211,211)",l=.3,a=0;else for(f=0;f<y;f++)if(e>=t[f].min&&e<=t[f].max){c=t[f].color;break}return{fillColor:c,fillOpacity:l,strokeColor:"#ffffff",strokeWeight:.5,strokeOpacity:a}};e&&u>2e3&&i.geoLayers[n].setMap(null);i.geoLayers[n].setStyle(c);f.each(this.geoLayers,function(t,i){i!==n&&t.getMap()&&t.setMap(null)},this);this.geoLayers[n].getMap()||this.geoLayers[n].setMap(this.map)},show:function(n){console.log(n);var e=n.get("candidate"),i=n.get("geography"),r=this;u.when(this.dataManager.getData(e,i),this.geoManager.getData(i)).done(function(u,e){var s,h;f.each(r.dataLayers,function(n){n.setMap(null)});r.dataLayers[i]||(s=f.keys(e.objects)[0],h=topojson.feature(e,e.objects[s]),r.dataLayers[i]=new google.maps.Data,r.dataLayers[i].addGeoJson(h));var c=t.Entities.DataBreakList.getByType(n.get("amountType")),o=c.get("breaks"),l=function(n){var c=n.getId(),i=u[n.getId()],r=i?i.totalPre+i.totalPost:0,f,e=1,s=.7,h=o.length,t;if(r===0)f="rgb(211,211,211)",e=.3,s=0;else for(t=0;t<h;t++)if(r>=o[t].min&&r<=o[t].max){f=o[t].color;break}return{fillColor:f,fillOpacity:e,strokeColor:"#ffffff",strokeWeight:.5,strokeOpacity:s}};r.dataLayers[i].setStyle(l);r.dataLayers[i].setMap(r.map)})},processPoints:function(n,t,i){n instanceof google.maps.LatLng?t.call(i,n):n instanceof google.maps.Data.Point?t.call(i,n.get()):n.getArray().forEach(function(n){this.processPoints(n,t,i)},this)},getPolygonBounds:function(n){var t=new google.maps.LatLngBounds;return this.processPoints(n.getGeometry(),t.extend,t),t},findFeature:function(n,t){var u=this.geoLayers[t],i=u.getFeatureById(n),r;i&&(this.selectFeature(i,u),r=this.getPolygonBounds(i),this.map.panToBounds(r),this.map.fitBounds(r),this.map.setZoom(this.map.getZoom()-1))},selectFeature:function(n,t){this.selectedFeature=n;t.revertStyle();t.overrideStyle(n,{strokeColor:"#dd00dd",strokeOpacity:.7,strokeWeight:4,zIndex:2});var i=this.eventData(n);this.trigger("selected",i)},unselectFeature:function(n,t){n&&(t.revertStyle(),this.selectedFeature=null,this.trigger("unselected",n))},highlightFeature:function(n,t){if(this.highlightedFeature=n,this.selectedFeature)n.getId()!==this.selectedFeature.getId()&&t.overrideStyle(n,{strokeColor:"#707070",strokeOpacity:.7,strokeWeight:3,zIndex:2});else{t.overrideStyle(n,{strokeColor:"#000000",strokeOpacity:.7,strokeWeight:3,zIndex:2});var i=this.eventData(n);this.trigger("highlighted",i)}},unhighlightFeature:function(n,t){n&&(this.selectedFeature&&n.getId()===this.selectedFeature.getId()||t.revertStyle(this.highlightedFeature),this.selectedFeature||this.trigger("unhighlighted",n),this.highlightedFeature=null)},eventData:function(n){var t=n.getId(),i=n.getProperty("NTAName"),r=this.contributionData[t]||{id:t,prePrimTot:0,postPrimTot:0,prePrimNum:0,postPrimNum:0},u=f.extend({name:i},r);return{query:this.query,data:u}}})});ContributionMap.module("Map",function(n,t,i,r,u,f){n.LogoControl=function(){this.baseDiv=document.createElement("div");this.$baseDiv=u(this.baseDiv);var n=f.template(u("#logo-control").html());this.$baseDiv.html(n())};f.extend(n.LogoControl.prototype,{setMap:function(n,t){n.controls[t].push(this.baseDiv)}})});ContributionMap.module("Map",function(n,t,i,r,u){n.getNyccfbSearchPageLink=function(n){var e=n.contributorType||"individuals",f=n.query,i=n.candidate,r=n.zipCode,t={};t.ec="2021";t.rt="can";t.trans="ABC,M";switch(e){case"individuals":t.ct="IND,CAN,SPO,FAM";break;case"committees_unions":t.ct="PCOMC,PCOMZ,PCOMP,empo,CORP,PART,LLC,othr_unkn"}return i&&(i.get("cfbOfficeId")&&(t.ofc=i.get("cfbOfficeId")),i.get("cfbRecipId")?t.cand=i.get("cfbRecipId"):console.log("no cand")),f.get("filingPeriod")>0&&(t.stmt=f.get("filingPeriod")),r&&(t.geo=r.id,t.zip=r.id),"https://www.nyccfb.info/FTMSearch/Candidates/Contributions?"+u.param(t)}});ContributionMap.module("Map.AmountTypeSelector",function(n,t,i,r,u,f){n.AmountTypeControl=function(){this.baseDiv=document.createElement("div");this.$baseDiv=u(this.baseDiv)};f.extend(n.AmountTypeControl.prototype,{setMap:function(n,t){this.map=n;n.controls[t].push(this.baseDiv)},show:function(t){var i=new n.AmountTypeView({model:t});i.render();this.$baseDiv.html(i.el)}})});ContributionMap.module("Map.AmountTypeSelector",function(n,t,i){n.AmountTypeView=i.Marionette.ItemView.extend({el:".amount-type-selector",render:function(){this.bindUIElements();this.$el.css({display:"block"})},ui:{radDataType:"input:radio[name=radAmountType]"},events:{"change @ui.radDataType":"onRadDataTypeChanged"},onRadDataTypeChanged:function(){this.model.set("amountType",this.ui.radDataType.filter(":checked").val())}})});ContributionMap.module("Map.Legend",function(n,t,i,r,u,f){n.LegendControl=function(n){this.baseDiv=document.createElement("div");this.$baseDiv=u(this.baseDiv);this.legendView=null;this.geographicDataLegendTemplates={};f.each(f.keys(n.geographicDataFiles),function(t){this.geographicDataLegendTemplates[t]=f.template(n.geographicDataFiles[t].legendTemplate)},this)};f.extend(n.LegendControl.prototype,{setMap:function(n,t){n.controls[t].push(this.baseDiv)},showLegend:function(r){var u=t.Entities.DataBreakList.getByType(r.get("amountType"));this.legendView=new n.LegendView({model:u,collection:new i.Collection(u.get("breaks"))});this.$baseDiv.html(this.legendView.render().el);this.showOffice(r)},showOffice:function(n){var t=n.get("office"),i,r;t.indexOf("City Council")>-1?(i=t.split(" ")[2],r=this.geographicDataLegendTemplates.citycouncildistricts({id:i}),this.legendView.showCityCouncilLegendItem(r)):this.legendView.showCityCouncilLegendItem(null)},showSelected:function(n){if(n){var t=n.data,i=n.query,r=this.geographicDataLegendTemplates[i.get("geography")]({id:t.id,name:t.name});this.legendView.showSelectedDistrictLegendItem(r)}else this.legendView.showSelectedDistrictLegendItem(null)}})});ContributionMap.module("Map.Legend",function(n,t,i,r,u,f){n.LegendItemView=i.Marionette.ItemView.extend({template:"#legend-item",templateHelpers:f.extend(t.Common.templateHelpers,{fixMaxValueText:function(n){return n===Infinity?"or greater":n===-1e7?"<$0":n},asMoney:function(n){return newVal=this.fixMaxValueText(n),isNaN(newVal)?newVal:"$"+this.addCommas(newVal)}}),tagName:"li",className:"legend-item"});n.LegendItemViewNumber=n.LegendItemView.extend({template:"#legend-item-number"});n.LegendView=i.Marionette.CompositeView.extend({template:"#legend-composite",className:"legend",getChildView:function(){return this.model.get("type")==="number"?n.LegendItemViewNumber:n.LegendItemView},childViewContainer:".legend-items",templateHelpers:{getAmountTypeTitle:function(n){return n==="number"?n+" of":n}},ui:{cityCouncilLegendItem:".city-council-legend-item",selectedDistrictLegendItem:".selected-district-legend-item"},showCityCouncilLegendItem:function(n){n?(this.ui.cityCouncilLegendItem.find("span").text(n),this.ui.cityCouncilLegendItem.show()):this.ui.cityCouncilLegendItem.hide()},showSelectedDistrictLegendItem:function(n){n?(this.ui.selectedDistrictLegendItem.find("span").text(n),this.ui.selectedDistrictLegendItem.show()):this.ui.selectedDistrictLegendItem.hide()}})});ContributionMap.module("Map.CandidateSummary",function(n,t,i,r,u,f){n.CandidateSummaryControl=function(){this.$baseDiv=u("#candidateSummary");this.inOutNycChartColors=["#008000","#800080"];this.contributionAmountChartColors=["#2244ee","#ee2222"];this.contributorTypeChartColors=["#2166ac","#d1e5f0"]};f.extend(n.CandidateSummaryControl.prototype,{setMap:function(n,t){this.map=n;n.controls[t].push(this.baseDiv)},showCandidate:function(t,i){var u,r;t&&(u=new n.CandidateSummaryView({model:t,query:i}),this.$baseDiv.html(u.render().el),this.showChartPrimaryInOutNyc(t),this.showChartPrimaryAmount(t),this.showChartPrimaryContributorType(t),r=this,google.maps.event.addListenerOnce(this.map,"idle",function(){r.showChartPrimaryInOutNyc(t);r.showChartPrimaryAmount(t)}))},showChart:function(n,t,i,r){t=f.map(t,function(n){return Math.round(n)});n.sparkline(t,{offset:-90,type:"pie",width:"32",height:"32",sliceColors:i,borderWidth:0,tooltipPrefix:r,tooltipFormat:'<span style="color: {{color}}">&#9679;<\/span> {{prefix}}{{value}} ({{percent.1}}%)'})},showChartPrimaryInOutNyc:function(n){var t=[n.get("totalFromInsideNyc"),n.get("totalFromOutsideNyc")];this.showChart(this.$baseDiv.find("#piePrimaryInNyc"),t,this.inOutNycChartColors,"$")},showChartGeneralInOutNyc:function(n){var t=[n.get("generalDetails").totalFromInsideNyc,n.get("generalDetails").totalFromOutsideNyc];this.showChart(this.$baseDiv.find("#pieGeneralInNyc"),t,this.inOutNycChartColors,"$")},showChartOverallInOutNyc:function(n){var t=[n.get("primaryDetails").totalFromInsideNyc+n.get("generalDetails").totalFromInsideNyc,n.get("primaryDetails").totalFromOutsideNyc+n.get("generalDetails").totalFromOutsideNyc];this.showChart(this.$baseDiv.find("#pieOverallInNyc"),t,this.inOutNycChartColors,"$")},showChartPrimaryAmount:function(n){var t=[n.get("lessThanOrEqualTo250"),n.get("greaterThan250")];this.showChart(this.$baseDiv.find("#piePrimaryAmount"),t,this.contributionAmountChartColors,"")},showChartGeneralAmount:function(n){var t=[n.get("generalDetails").lessThanOrEqualTo250,n.get("generalDetails").greaterThan250];this.showChart(this.$baseDiv.find("#pieGeneralAmount"),t,this.contributionAmountChartColors,"")},showChartOverallAmount:function(n){var t=[n.get("primaryDetails").lessThanOrEqualTo250+n.get("generalDetails").lessThanOrEqualTo250,n.get("primaryDetails").greaterThan250+n.get("generalDetails").greaterThan250];this.showChart(this.$baseDiv.find("#pieOverallAmount"),t,this.contributionAmountChartColors,"")},showChartPrimaryContributorType:function(n){var t=[n.get("totalFromIndividuals"),n.get("totalFromNotIndividuals")];this.showChart(this.$baseDiv.find("#piePrimaryContributorType"),t,this.contributorTypeChartColors,"$")}})});ContributionMap.module("Map.CandidateSummary",function(n,t,i,r,u,f){n.CandidateSummaryView=i.Marionette.ItemView.extend({template:"#candidate-info",className:"candidate-info",tooltipTemplates:{tooltiptotal:f.template(u("#tooltip-total").html())},onRender:function(){this.$el.find(".tooltip-total").tooltip({html:"true",title:this.tooltipTemplates.tooltiptotal()})},templateHelpers:f.extend(t.Common.templateHelpers,{formatNumber:function(n){return n?this.addCommas(Math.round(n)):0},getSum:function(n,t){return n?n+t:0},getAverage:function(n,t){return t?n/t:0},getPercent:function(n,t){if(!t)return 0;var i=n/t*100;return Math.round(i*10)/10}}),serializeData:function(){var n=this.options.query.getFilingPeriodLabel(),i=t.Map.getNyccfbSearchPageLink({query:this.options.query,candidate:this.model}),r=t.Map.getNyccfbSearchPageLink({contributorType:"committees_unions",query:this.options.query,candidate:this.model});return f.extend(this.model.toJSON(),{filingPeriodLabel:n,nyccfbSearchPageLink:i,nyccfbSearchPageLinkCommittees:r})}})});ContributionMap.module("Map.Identify",function(n,t,i,r,u,f){n.IdentifyControl=function(n){this.baseDiv=document.createElement("div");this.$baseDiv=u(this.baseDiv);this.geographicDataTitleTemplates={};f.each(f.keys(n.geographicDataFiles),function(t){this.geographicDataTitleTemplates[t]=f.template(n.geographicDataFiles[t].hoverTitleTemplate)},this)};f.extend(n.IdentifyControl.prototype,{setMap:function(n,t){this.map=n;n.controls[t].push(this.baseDiv)},setCandidate:function(n){this.candidate=n;this.show(this.item,this.candidate)},setFeatureData:function(n){this.item=n;this.show(this.item,this.candidate)},show:function(i,r){var s;if(i){var f=i.query.get("geography"),u=i.data,e,o=!1;f=="zipcodes"&&r&&(o=!0,e=t.Map.getNyccfbSearchPageLink({query:i.query,candidate:r,zipCode:i.data}));s=new n.IdentifyView({data:{featureLabel:this.geographicDataTitleTemplates[f]({id:u.id,name:u.name}),totalPre:u.prePrimTot,totalPost:u.postPrimTot,numberPre:u.prePrimNum,numberPost:u.postPrimNum,showCfbLink:o,nyccfbSearchPageLink:e}});this.$baseDiv.html(s.render().el)}else this.$baseDiv.html("")}})});ContributionMap.module("Map.Identify",function(n,t,i,r,u,f){n.IdentifyView=i.Marionette.ItemView.extend({className:"panel panel-default hover-info",template:"#hover-info",templateHelpers:f.extend(t.Common.templateHelpers,{formatNumber:function(n){return n?this.addCommas(Math.round(n)):0},getSum:function(n,t){return n?n+t:0},getAverage:function(n,t){return t?n/t:0}}),serializeData:function(){return this.options.data}})});ContributionMap.module("Map.Search",function(n,t,i,r,u,f){n.SearchControl=function(n){this.baseDiv=document.createElement("div");this.baseDiv.className="search-control";this.baseDiv.style.zIndex=1;this.title=document.createElement("label");u(this.title).text("Search By...");this.baseDiv.appendChild(this.title);this.input=document.createElement("input");this.input.type="text";this.input.className="form-control";this.baseDiv.appendChild(this.input);this.geoLabelsForTitle={};f.each(f.keys(n.config.geographicDataFiles),function(t){this.geoLabelsForTitle[t]=n.config.geographicDataFiles[t].label},this);this.geoManager=t.Entities.GeographicDataManager.getInstance();this.bh=new Bloodhound({datumTokenizer:function(n){for(var t=n.name,f=[t].concat(Bloodhound.tokenizers.nonword(t)),r,i=1,e=t.length;i<e;i++)r=t.charAt(i),u.trim(r)!==""&&r===r.toUpperCase()&&f.push(t.slice(i));return f},queryTokenizer:Bloodhound.tokenizers.whitespace,local:[],sorter:function(n,t){var i=n.name.toLowerCase(),r=t.name.toLowerCase();return i<r?-1:i>r?1:0}});u(this.input).typeahead({hint:!1,highlight:!0,minLength:1},{source:this.bh,limit:10,display:"name"});var i=this;u(this.input).on("typeahead:selected",function(n,t){i.trigger("selected",{item:t.id,geography:i.query.get("geography")})})};f.extend(n.SearchControl.prototype,i.Events,{setMap:function(n,t){n.controls[t].push(this.baseDiv)},setQuery:function(n){this.query=n;this.query.on("change:geography",this.onQueryGeographyChanged,this);this.onQueryGeographyChanged(n,n.get("geography"))},setTitle:function(n){u(this.title).text("Search By "+this.geoLabelsForTitle[n])},onQueryGeographyChanged:function(n,t){this.setTitle(t);u(this.input).val("");u(this.input).typeahead("val","");this.geoManager.getData(t).then(u.proxy(function(n){var t=f.keys(n.objects)[0],i=n.objects[t].geometries,r=f.map(i,function(n){var t,i;return t=n.id+"",i=n.properties?n.properties.NTAName||t:t,{id:t,name:i}});this.bh.clear();this.bh.local=r;this.bh.initialize(!0)},this))}})});ContributionMap.module("Map.Link",function(n,t,i,r,u){n.LinkView=r.ItemView.extend({template:"#link-view",className:"link-view",initialize:function(n){this.query=n.query;this.map=n.map;this.queryVisualizer=n.queryVisualizer;this.listenTo(this.query,"change:candidate",this.updatetxtLink);this.listenTo(this.query,"change:geography",this.updatetxtLink);this.listenTo(this.query,"change:filingPeriod",this.updatetxtLink);this.listenTo(this.query,"change:amountType",this.updatetxtLink);google.maps.event.addListener(this.map,"idle",u.proxy(this.updatetxtLink,this));this.listenTo(this.queryVisualizer,"selected",this.updatetxtLink);this.listenTo(this.queryVisualizer,"unselected",this.updatetxtLink)},onRender:function(){},ui:{txtLink:"#txtLink"},events:{"click .btn-select":"onBtnSelectClick"},onBtnSelectClick:function(){this.ui.txtLink.focus();this.ui.txtLink[0].setSelectionRange?this.ui.txtLink[0].setSelectionRange(0,this.ui.txtLink[0].value.length):this.ui.txtLink.select()},getBaseUrl:function(){var n=location.protocol+"//"+(t.QueryBuilder.parentHost||location.host);return t.QueryBuilder.parentHost&&typeof t.QueryBuilder.parentHost!="undefined"||(n+=window.parent.location.pathname),n},generateLink:function(){var n={},i=this.map.getCenter(),t;return i&&(n.latlng=i.toUrlValue(),n.z=this.map.getZoom()),t=this.query,n.office=t.get("office"),n.candidate=t.get("candidate"),n.geography=t.get("geography"),n.amountType=t.get("amountType"),n.filingPeriod=t.get("filingPeriod"),this.queryVisualizer.selectedFeature&&(n.selected=this.queryVisualizer.selectedFeature.getId()),this.getBaseUrl()+"?"+u.param(n)},updatetxtLink:function(){var n=this.generateLink();this.ui.txtLink.val(n);console.log(n);u("#full-map-link").attr("href",n)}})});ContributionMap.module("Map.Link",function(n,t,i,r,u,f){n.QueryStringParser=function(){return this.queryString=this.parseQueryString(t.module("QueryBuilder").parentSearch||window.location.search),this};f.extend(n.QueryStringParser.prototype,{parseQueryString:function(n){var t,u,i,r;if(n=="")return{};if(t=n.split("?")[1].split("&"),t=="")return{};for(u={},i=0;i<t.length;++i)(r=t[i].split("="),r.length==2)&&(u[r[0]]=decodeURIComponent(r[1].replace(/\+/g," ")));return u}})});ContributionMap.module("Map.Layer",function(n,t,i,r,u,f){n.HighlightedCouncilDistrictLayer=function(n){this.geographyType=n.geographyType;this.geoManager=t.Entities.GeographicDataManager.getInstance();this.geoJson=null;this.data=new google.maps.Data({map:n.map,style:{clickable:!1,fillOpacity:0,strokeColor:"#0000ff",zIndex:100,strokeWeight:2}})};f.extend(n.HighlightedCouncilDistrictLayer.prototype,i.Events,{getGeoJson:function(){return this.geoJson?u.Deferred().resolve(this.geoJson):this.geoManager.getData(this.geographyType).then(u.proxy(function(n){var t=f.keys(n.objects)[0];return this.geoJson=topojson.feature(n,n.objects[t]),this.geoJson},this))},getFeatureByName:function(n){var t=parseInt(n.split(" ")[2],10);return this.getFeature(t)},getFeature:function(n){return this.getGeoJson().then(u.proxy(function(t){var i=t.features;return f.find(i,function(t){return t.id===n})},this))},highlightFeature:function(n){this.unhighlightAll();n&&this.getFeatureByName(n).then(u.proxy(function(n){this.data.addGeoJson(n)},this))},unhighlightAll:function(){var n=this.data;n.forEach(function(t){n.remove(t)})}})});ContributionMap.module("QueryBuilder",{startWithParent:!1,define:function(n){n.on("start",function(t){var i=t.query,r=new n.QueryBuilderView({model:i}),u;r.render();u=new n.CandidateSearchBox({query:i})})}});ContributionMap.module("QueryBuilder",function(n,t,i,r,u){n.QueryBuilderView=i.Marionette.ItemView.extend({el:"#queryBuilderForm",render:function(){this.bindUIElements()},modelEvents:{"change:office":"onOfficeChanged","change:candidate":"onCandidateChanged"},ui:{selOffice:"#selOffice",selCandidate:"#selCandidate",selGeography:"#selGeography",selFilingPeriod:"#selFilingPeriod"},events:{"change @ui.selOffice":"onSelOfficeChanged","change @ui.selCandidate":"onSelCandidateChanged","change @ui.selGeography":"onSelGeographyChanged","change @ui.selFilingPeriod":"onSelFilingPeriodChanged"},onSelOfficeChanged:function(){this.model.set("office",this.ui.selOffice.val())},onSelCandidateChanged:function(){this.model.set("candidate",this.ui.selCandidate.val())},onSelGeographyChanged:function(){this.model.set("geography",this.ui.selGeography.val())},onSelFilingPeriodChanged:function(){this.model.set("filingPeriod",this.ui.selFilingPeriod.val())},onOfficeChanged:function(){t.Entities.CandidateList.getByOffice(this.model.get("office")).then(u.proxy(function(n){this.updateCandidateList(n);this.model.changed.candidate?(this.ui.selOffice.val(this.model.get("office")),this.ui.selCandidate.val(this.model.get("candidate"))):this.model.set("candidate",n.at(0).get("id"))},this))},onCandidateChanged:function(n,t){this.ui.selCandidate.val(t)},updateCandidateList:function(n){var t=this.ui.selCandidate;t.empty();n.each(function(n){t.append(u("<option><\/option>").attr("value",n.get("id")).text(n.get("name")))})}})});ContributionMap.module("QueryBuilder",function(n,t,i,r,u,f){n.CandidateSearchBox=function(n){this.txtBox=u("#txtCandidateSearch");this.query=n.query;this.datum=null;this.bh=new Bloodhound({datumTokenizer:function(n){for(var t=n.name,f=[t].concat(Bloodhound.tokenizers.nonword(t)),r,i=1,e=t.length;i<e;i++)r=t.charAt(i),u.trim(r)!==""&&r===r.toUpperCase()&&f.push(t.slice(i));return f},queryTokenizer:Bloodhound.tokenizers.whitespace,local:[],sorter:function(n,t){var i=n.name.toLowerCase(),r=t.name.toLowerCase();return i<r?-1:i>r?1:0}});this.txtBox.typeahead({hint:!1,highlight:!0,minLength:1},{source:this.bh,limit:10,display:"name"});var i=this;this.txtBox.on("typeahead:selected",function(n,t){i.query.set({office:t.office,candidate:t.id})});this.txtBox.on("focus",function(){i.datum===null&&t.Entities.CandidateList.getAll().then(function(n){i.datum=n.map(function(n){var t,i;return t=n.id+"",office=n.get("officeName"),i=n.get("name")+" - "+n.get("officeName"),{id:t,name:i,office:office}});i.bh.clear();i.bh.local=i.datum;i.bh.initialize(!0)})})};f.extend(n.CandidateSearchBox.prototype,i.Events,{})})