From 8ff5a91d3240dd9b2bc9ece9a2432c6f205d6211 Mon Sep 17 00:00:00 2001 From: Nate Smith Date: Mon, 18 Aug 2014 16:16:06 -0400 Subject: [PATCH] fixing choro styles --- app/scripts/views/map.js | 26 ++++++++++++++----- bower.json | 3 ++- dist/index.html | 4 +-- dist/scripts/347e9a6f.main.js | 1 - dist/scripts/428f2505.main.js | 1 + ...{c3fe213f.vendor.js => 828851d3.vendor.js} | 2 +- 6 files changed, 26 insertions(+), 11 deletions(-) delete mode 100644 dist/scripts/347e9a6f.main.js create mode 100644 dist/scripts/428f2505.main.js rename dist/scripts/{c3fe213f.vendor.js => 828851d3.vendor.js} (99%) diff --git a/app/scripts/views/map.js b/app/scripts/views/map.js index b046917..282895a 100644 --- a/app/scripts/views/map.js +++ b/app/scripts/views/map.js @@ -96,12 +96,26 @@ WHO.Views = WHO.Views || {}; }; // get color depending on response level function getColor(d) { - return d == 2 ? 'rgb(255,252,224)' : - d == 3 ? 'rgb(250,175,78)' : - d == 4 ? 'rgb(249,145,77)' : - d == 5 ? 'rgb(247,117,77)' : - d == 6 ? 'rgb(246, 104, 61)' : - '#fff'; + console.log(feature.id); + console.log(d); + if (feature.id.substr(7,1) == 0) { + // for admin0 geoids with different scale + return d == 1 ? '#fff' : + d == 2 ? 'rgb(255,252,224)' : + d == 3 ? 'rgb(252,202,78)' : + d == 4 ? 'rgb(250,175,78)' : + d == 5 ? 'rgb(249,145,77)' : + d == 6 ? 'rgb(246,104,61)' : + '#fff'; + } + else { + return d == 1 ? '#fff' : + d == 2 ? 'rgb(252,202,78)' : + d == 3 ? 'rgb(250,175,78)' : + d == 4 ? 'rgb(249,145,77)' : + d == 5 ? 'rgb(246,104,61)' : + '#fff'; + } }; }, diff --git a/bower.json b/bower.json index 6ebdd00..37e9e33 100644 --- a/bower.json +++ b/bower.json @@ -9,7 +9,8 @@ "topojson": "~1.6.15", "queue-async": "~1.0.7", "d3-tip": "~0.6.4", - "d3": "~3.4.11" + "d3": "~3.4.11", + "firebase": "~1.0.19" }, "devDependencies": {} } diff --git a/dist/index.html b/dist/index.html index 7b480e7..d5b7fff 100644 --- a/dist/index.html +++ b/dist/index.html @@ -135,11 +135,11 @@
Response level and cases
- + - + \ No newline at end of file diff --git a/dist/scripts/347e9a6f.main.js b/dist/scripts/347e9a6f.main.js deleted file mode 100644 index b4df9b9..0000000 --- a/dist/scripts/347e9a6f.main.js +++ /dev/null @@ -1 +0,0 @@ -window.WHO={Models:{},Collections:{},Views:{},Routers:{},init:function(){"use strict";WHO.router=new WHO.Routers.App,Backbone.history.start()}},$(document).ready(function(){"use strict";WHO.init()}),WHO.Views=WHO.Views||{},function(){"use strict";WHO.Views.Map=Backbone.View.extend({events:{},initialize:function(a){this.listenTo(a.zoom,"zoom:end",this.getmap),this.spinner=new Spinner({color:"#888",length:2,speed:.8}).spin(document.getElementById("map-loader")),this.layers=[]},load:function(){this.collection.length?this.getmap():(this.listenToOnce(this.collection,"loaded",this.getmap),this.collection.query())},getmap:function(a){var b=a.level||WHO.defaultZoom;this.level!==b&&(5>b?this.getBounds(WHO.Models.Country,"country"):7>b?this.getBounds(WHO.Models.Province,"province"):this.getBounds(WHO.Models.District,"district"),this.level=b)},getBounds:function(a,b){var a=WHO.models[b]||new a;this.model=a,this.maptype=b,"FeatureCollection"!==a.get("type")?(WHO.models[b]=a,this.listenToOnce(a,"change",this.render),a.fetch()):this.render()},removeLayers:function(){_.each(this.layers,function(a){WHO.map.removeLayer(a)})},drawBounds:function(a){var b=_.values(a),c=["#fff","rgb(255,252,224)","rgb(252,202,78)","rgb(250,175,78)","rgb(249,145,77)","rgb(247,117,77)"],d=(chroma.scale(c).domain([Math.min.apply(Math,b),Math.max.apply(Math,b)]),{type:"FeatureCollection",features:_.filter(this.model.attributes.features,function(b){return a[b.id]>1})}),e=L.geoJson(d,{style:function(b){function c(a){return 2==a?"rgb(255,252,224)":3==a?"rgb(250,175,78)":4==a?"rgb(249,145,77)":5==a?"rgb(247,117,77)":6==a?"rgb(246, 104, 61)":"#fff"}return{color:"rgb(254,243,183)",fillColor:c(a[b.id]),opacity:.7,fillOpacity:.7,weight:1}},onEachFeature:function(a,b){b.on({dblclick:function(a){WHO.map.setView(a.latlng,WHO.map.getZoom()+1)}})}}).addTo(WHO.map);this.spinner.stop(),e.bringToBack(),this.layers.push(e)},render:function(){this.layers.length&&this.removeLayers();for(var a,b,c={},d=0,e=this.collection.models.length;e>d;++d)a=this.collection.models[d],b=a.get("geoID"),c[b]=a.get("level");this.drawBounds(c)},drawClusters:function(){}})}(),WHO.Views=WHO.Views||{},function(){"use strict";WHO.Views.Table=Backbone.View.extend({tagName:"div",id:"",className:"",events:{},initialize:function(){this.listenTo(this.model,"change",this.render)},render:function(){this.$el.html(this.template(this.model.toJSON()))}})}(),WHO.Views=WHO.Views||{},function(){"use strict";function a(a){return a.setDate(a.getDate()-a.getDay()),new Date(a.getFullYear(),a.getMonth(),a.getDate())}WHO.Views.epiGraph=Backbone.View.extend({events:{},initialize:function(){this.spinner=new Spinner({color:"#888",length:2,speed:.8}).spin(document.getElementById("epi-graph-loader"))},load:function(){this.collection.length?this.render():(this.listenToOnce(this.collection,"loaded",this.render),this.collection.query())},drawChart:function(a){this.spinner.stop();var b={top:10,right:60,bottom:30,left:60},c=this.$el.width()-b.left-b.right,d=180-b.top-b.bottom,e=d3.max(a,function(a){return a.total}),f=d3.scale.linear().rangeRound([0,c]).domain([0,a.length]),g=d3.scale.linear().range([d,0]).domain([0,e]),h=Math.floor(c/a.length)-1,i=h/2,j=this.order,k=[];_.each(a,function(a,b){var c=0;a.bars=_.map(a.vals,function(a,b){return{name:j[b],y0:c,y1:c+=a,val:a}}),b%5===0&&k.push({position:b,display:a.time})});var l=d3.svg.axis().scale(g).orient("right"),m=d3.time.format("%d-%m-%Y"),n=_.template("

<%= date %>

Confirmed: <%= confirmed %>
Probable: <%= probable %>
Suspected: <%= suspected %>"),o=d3.tip().attr("class","d3-tip").html(function(a){return n({date:m(a.time),confirmed:a.vals[0],probable:a.vals[1],suspected:a.vals[2]})}),p=d3.select("#epi-graph").append("svg").attr("width",c+b.left+b.right).attr("height",d+b.top+b.bottom).append("g").attr("transform","translate("+b.left+","+b.top+")");p.call(o);var q=p.selectAll(".week").data(a).enter().append("g").attr("class","week").attr("transform",function(a,b){return"translate("+(f(b)-i)+",0)"}).on("mouseover",o.show).on("mouseout",o.hide),r=(q.selectAll("rect").data(function(a){return a.bars}).enter().append("rect").attr("width",h).attr("y",function(a){return g(a.y1)}).attr("height",function(a){return d-g(a.val)||1}).attr("class",function(a){return a.name}),p.append("g").attr("class","x axis").attr("transform","translate(0,"+(d+3)+")").selectAll(".tick").data(k).enter().append("g").attr("class","tick").attr("transform",function(a){return"translate("+f(a.position)+",0)"}));r.append("line").attr("x1",0).attr("x2",0).attr("y1",0).attr("y2",5).style("stroke-width","2"),r.append("text").text(function(a){return m(a.display)}).style("text-anchor","middle").attr("dy","15px"),p.append("g").attr("transform","translate("+c+",0)").attr("class","y axis").call(l).append("text").attr("transform","rotate(-90)").attr("y",6).attr("dy","-.8em").style("text-anchor","end").text("Cases");var s=a.length;q.transition().duration(0).delay(function(a,b){return 20*(s-b)}).attr("class","week active")},render:function(){var b,c,d,e=new Date(this.collection.at(0).get("datetime")),f=(new Date(this.collection.at(this.collection.length-1).get("datetime")),6048e5),g=Date.parse(a(e)),h=g+f,i={Suspected:0,Probable:0,Confirmed:0,Total:0},j=[_.clone(i)],k=0;j[0].week=new Date(g);for(var l=0,m=this.collection.length;m>l;++l){for(b=this.collection.at(l),c=b.get("datetime");c>h;)k+=1,j.push(_.clone(i)),j[k].week=new Date(h),h+=f;d=b.get("case category"),d in j[k]&&(j[k][d]+=1,j[k].Total+=1)}this.order=["confirmed","probable","suspected"];var j=_.map(j.slice(0,-1),function(a){return{vals:[a.Confirmed,a.Probable,a.Suspected],total:a.Total,time:new Date(a.week)}});this.drawChart(j)}})}(),WHO.Collections=WHO.Collections||{},function(){"use strict";WHO.Collections.Response=Backbone.Collection.extend({model:WHO.Models.Response})}(),WHO.Collections=WHO.Collections||{},function(){"use strict";WHO.Collections.Cases=Backbone.Collection.extend({initialize:function(){this.ref=new Firebase("https://luminous-heat-4380.firebaseio.com/cases_admin_aug17")},query:function(){var a=$.proxy(this.onload,this);this.ref.once("value",a)},onload:function(a){for(var b,c=a.val(),d=Date.parse(new Date),e=Date.parse(new Date("2013","11","20")),f=0,g=c.length;g>f;++f)b=c[f].date,c[f].datetime=Date.parse(b);c=_.filter(c,function(a){return!isNaN(a.datetime)&&a.datetimee}),c=_.sortBy(c,function(a){return a.datetime}),this.reset(c),this.trigger("loaded",c)}})}(),WHO.Collections=WHO.Collections||{},function(){"use strict";WHO.Collections.GlobalRisk=Backbone.Collection.extend({initialize:function(){this.ref=new Firebase("https://luminous-heat-4380.firebaseio.com/allResponse")},query:function(){var a=$.proxy(this.onload,this);this.ref.once("value",a)},onload:function(a){var b=a.val();this.reset(b),this.trigger("loaded",b)}})}(),WHO.Models=WHO.Models||{},function(){"use strict";WHO.Models.Deployment=Backbone.Model.extend({url:"",initialize:function(){},defaults:{},validate:function(){},parse:function(a){return a}})}(),WHO.Models=WHO.Models||{},function(){"use strict";WHO.Models.Case=Backbone.Model.extend({initialize:function(){},defaults:{}})}(),WHO.Models=WHO.Models||{},function(){"use strict";WHO.Models.Country=Backbone.Model.extend({url:"geo/ADM0.topojson",parse:function(a){return topojson.feature(a,a.objects.ADM0)}})}(),WHO.Models=WHO.Models||{},function(){"use strict";WHO.Models.Province=Backbone.Model.extend({url:"geo/ADM1.topojson",parse:function(a){return topojson.feature(a,a.objects.ADM1)}})}(),WHO.Models=WHO.Models||{},function(){"use strict";WHO.Models.District=Backbone.Model.extend({url:"geo/ADM2.topojson",parse:function(a){return topojson.feature(a,a.objects.ADM2)}})}(),WHO.Views=WHO.Views||{},function(){"use strict";WHO.Views.Dropdown=Backbone.View.extend({template:_.template($("#dropdown-template").html()),events:{"click a":"select"},initialize:function(a){this.options=a.options,this.selected=this.options[0].display,this.render()},render:function(){this.$el.html(this.template({options:this.options,selected:this.selected})),this.$selected=this.$(".selected"),this.$dropdown=this.$(".dropdown")},select:function(a){return a.preventDefault(),a=a.toElement,this.$selected.text(a.innerHTML),this.$dropdown.toggleClass("open"),WHO.router.set(this.className,a.className),!1}})}(),WHO.Routers=WHO.Routers||{},function(){"use strict";function a(){var a=new WHO.Models.Zoom;WHO.collections={cases:new WHO.Collections.Cases,response:new WHO.Collections.Response,globalrisk:new WHO.Collections.GlobalRisk,clinics:new WHO.Models.Clinics},WHO.mapview=new WHO.Views.Map({el:"#map",id:"map",map:WHO.map,collection:WHO.collections.globalrisk,zoom:a}),WHO.markerview=new WHO.Views.Marker({el:"#map",id:"map",map:WHO.map,collection:WHO.collections.cases,zoom:a,model:new WHO.Models.Centroids}),WHO.epiGraph=new WHO.Views.epiGraph({el:"#epi-graph",id:"epi-graph",collection:WHO.collections.cases}),new WHO.Views.Clinic({el:"#map",id:"map",map:WHO.map,model:WHO.collections.clinics,zoom:a}),new WHO.Views.Legend({el:"#legend",id:"legend",model:a}),WHO.models={},WHO.models={},WHO.map.whenReady(function(){$('

').appendTo(WHO.$map)}),WHO.mapview.load(),WHO.epiGraph.load(),c=!0}var b="total",c=!1,d=[{display:"Most recent",val:"recent"},{display:"All",val:"all"}],e=[{display:"All cases",val:"total"},{display:"Confirmed cases",val:"confirmed"},{display:"Suspected cases",val:"suspected"},{display:"Probable cases",val:"probable"}],f={time:"",type:""};WHO.defaultZoom=3,WHO.map=L.mapbox.map("map","nate.j8n0m4ld").setView([22.23,8],WHO.defaultZoom),WHO.map.scrollWheelZoom.disable(),WHO.$map=$("#map"),WHO.Routers.App=Backbone.Router.extend({routes:{"":"newload",":time/:type":"newload"},newload:function(){a(),WHO.markerview.setFilter({type:b,time:"recent"}),WHO.markerview.load(),f.time="recent",f.type=b},newfilter:function(g,h){c||a(),-1!==_.map(d,function(a){return a.val}).indexOf(g)&&-1!==_.map(e,function(a){return a.val}).indexOf(h)?(WHO.markerview.setFilter({type:h,time:g}),this.navigate(g+"/"+h,{trigger:!1}),f.time=g,f.type=h):(WHO.markerview.setFilter({type:b,time:"recent"}),this.navigate("recent/"+b,{trigger:!1}),f.time="recent",f.type=b),WHO.markerview.load()},set:function(a,b){f[a]=b,this.navigate(f.time+"/"+f.type,{trigger:!0})}})}(),WHO.Views=WHO.Views||{},function(){"use strict";WHO.Views.Marker=Backbone.View.extend({initialize:function(a){this.listenTo(a.zoom,"zoom:end",this.getmap),this.layers=[]},setFilter:function(a){this.filters=a},load:function(){this.collection.length?this.getmap():(this.listenToOnce(this.collection,"loaded",this.getmap),this.collection.query())},getmap:function(a){var b,c;b=a&&a.level?a.level:this.level?this.level:WHO.defaultZoom,c=5>b?"country":7>b?"province":"district",this.level=b,this.maptype=c,this.popup=new L.Popup({autoPan:!1}),this.getCentroids()},getCentroids:function(){"FeatureCollection"!==this.model.get("type")?(this.listenToOnce(this.model,"change",this.render),this.model.fetch()):this.render()},removeLayers:function(){_.each(this.layers,function(a){WHO.map.removeLayer(a)})},render:function(){var a,b,c,d,e,f,g,h={},i=this.collection.at(this.collection.models.length-1).get("datetime"),j=0;switch(this.maptype){case"country":c="ADM0_NAME",d="ADM2_CODE";break;case"province":c="ADM1_NAME",d="ADM2_CODE";break;case"district":c="ADM2_NAME",d="ADM2_CODE"}for(var k=0,l=this.collection.models.length;l>k;++k)e=this.collection.models[k],a=e.get("case category").toLowerCase(),f=e.get(c),"ADM0_NAME"==c?(b=e.get(d).substring(0,5),g=b.concat("000000000000000")):"ADM1_NAME"==c?(b=e.get(d).substring(0,8),g=b.concat("000000000000")):g=e.get(d),"For Aggregates"===a||i-e.get("datetime")<=j||(g in h||(h[g]={name:f,confirmed:0,probable:0,suspected:0,hcw:0,deaths:0}),h[g][a]+=1,"TRUE"==e.get("HCW")&&(h[g].hcw+=1),"Dead"==e.get("outcome")&&(h[g].deaths+=1));_.each(h,function(a){a.total=a.confirmed+a.probable+a.suspected}),this.cases=h,this.drawMarkers(h)},drawMarkers:function(a){this.layers.length&&this.removeLayers();var b,c=("country"===this.maptype?3:5,this.maptype),d=0,e=this.popup,f=this.filters.type,g=_.max(_.map(a,function(a){return a.total})),h=d3.scale.quantize().domain([0,g]).range([50,400,800,1200,1600,2e3,2400,2800,3200,3600]),i={type:"Topology",features:_.chain(this.model.get("features")).filter(function(b){return a[b.id]}).sortBy(function(b){return-a[b.id][f]}).value()};WHO.map.on("popupclose",function(){d=0});var j=WHO.map.getZoom()<5?3.2:2.8,k=L.geoJson(i,{pointToLayer:function(b,c){return L.circleMarker(c,{radius:Math.sqrt(h(a[b.id][f])/Math.PI)/(j/1.88),weight:1.5,color:"#fff",opacity:.7,fillColor:"#99000d",fillOpacity:.7})},onEachFeature:function(f,g){g.on({dblclick:function(a){WHO.map.setView(a.latlng,WHO.map.getZoom()+1)},mousemove:function(f){if(0==d){var g=f.target;e.setLatLng(f.latlng),e.setContent('
'+c.charAt(0).toUpperCase()+c.slice(1)+": "+a[g.feature.id].name+"
Click for more information"),e._map||e.openOn(WHO.map),window.clearTimeout(b)}},mouseout:function(){0==d&&(b=window.setTimeout(function(){WHO.map.closePopup()},100))},click:function(f){d=1;var g=f.target,h=a[g.feature.id];e.setLatLng(f.latlng),e.setContent('
'+c.charAt(0).toUpperCase()+c.slice(1)+": "+a[g.feature.id].name+'
"),e._map||e.openOn(WHO.map),window.clearTimeout(b)}})}}).addTo(WHO.map);k.bringToFront(),this.layers.push(k)}})}(),WHO.Models=WHO.Models||{},function(){"use strict";WHO.Models.Zoom=Backbone.Model.extend({initialize:function(){var a,b=!1,c=this;WHO.map.on("zoomstart",function(){b=!0,window.clearTimeout(a)}),WHO.map.on("zoomend",function(){b=!1,a=window.setTimeout(function(){b||c.trigger("zoom:end",{level:WHO.map.getZoom()})},400)})}})}(),WHO.Models=WHO.Models||{},function(){"use strict";WHO.Models.Centroids=Backbone.Model.extend({url:"geo/centroids.topojson",parse:function(a){return topojson.feature(a,a.objects.centroids)}})}(),WHO.Views=WHO.Views||{},function(){"use strict";WHO.Views.Legend=Backbone.View.extend({initialize:function(){this.listenTo(this.model,"zoom:end",this.render),this.$country=this.$(".country"),this.$district=this.$(".district"),this.onCountry=!0},render:function(a){var b=a.level||WHO.defaultZoom;this.onCountry&&b>=5?(this.$country.hide(),this.$district.show(),this.onCountry=!1):!this.onCountry&&5>b&&(this.$country.show(),this.$district.hide(),this.onCountry=!0)}})}(),WHO.Views=WHO.Views||{},function(){"use strict";WHO.Views.Clinic=Backbone.View.extend({initialize:function(a){this.layers=[],this.listenTo(a.zoom,"zoom:end",this.getmap),this.listenToOnce(this.model,"loaded",this.onLoad),this.model.query(),this.on=!1,this.popup=new L.Popup({autoPan:!1})},onLoad:function(){this.getmap({level:WHO.defaultZoom})},getmap:function(a){var b=a.level||WHO.defaultZoom;b>=7&&!this.on&&(this.render(),this.on=!0),7>b&&this.on&&(this.remove(),this.on=!1)},remove:function(){_.each(this.layers,function(a){WHO.map.removeLayer(a)})},render:function(){this.layers.length&&this.remove();var a=this.popup,b=L.geoJson(this.model.attributes,{pointToLayer:function(a,b){return L.marker(b,{icon:L.icon({iconSize:[32,32],iconUrl:"img/medical-64x64.png"}),opacity:.95})},onEachFeature:function(b,c){c.on({dblclick:function(a){WHO.map.setView(a.latlng,WHO.map.getZoom()+1)},click:function(b){var c=b.target.feature.properties;a.setLatLng(b.latlng),a.setContent('
'+c.CITY+", "+c.COUNTRY+'
"),a._map||a.openOn(WHO.map)}})}}).addTo(WHO.map);this.layers.push(b)}})}(),WHO.Models=WHO.Models||{},function(){"use strict";WHO.Models.Clinics=Backbone.Model.extend({initialize:function(){this.ref=new Firebase("https://luminous-heat-4380.firebaseio.com/ebolaClinics_aug17")},query:function(){var a=$.proxy(this.onload,this);this.ref.once("value",a)},onload:function(a){var b=a.val();this.set(topojson.feature(b,b.objects.ebolaClinics)),this.trigger("loaded")}})}(); \ No newline at end of file diff --git a/dist/scripts/428f2505.main.js b/dist/scripts/428f2505.main.js new file mode 100644 index 0000000..360c7c3 --- /dev/null +++ b/dist/scripts/428f2505.main.js @@ -0,0 +1 @@ +window.WHO={Models:{},Collections:{},Views:{},Routers:{},init:function(){"use strict";WHO.router=new WHO.Routers.App,Backbone.history.start()}},$(document).ready(function(){"use strict";WHO.init()}),WHO.Views=WHO.Views||{},function(){"use strict";WHO.Views.Map=Backbone.View.extend({events:{},initialize:function(a){this.listenTo(a.zoom,"zoom:end",this.getmap),this.spinner=new Spinner({color:"#888",length:2,speed:.8}).spin(document.getElementById("map-loader")),this.layers=[]},load:function(){this.collection.length?this.getmap():(this.listenToOnce(this.collection,"loaded",this.getmap),this.collection.query())},getmap:function(a){var b=a.level||WHO.defaultZoom;this.level!==b&&(5>b?this.getBounds(WHO.Models.Country,"country"):7>b?this.getBounds(WHO.Models.Province,"province"):this.getBounds(WHO.Models.District,"district"),this.level=b)},getBounds:function(a,b){var a=WHO.models[b]||new a;this.model=a,this.maptype=b,"FeatureCollection"!==a.get("type")?(WHO.models[b]=a,this.listenToOnce(a,"change",this.render),a.fetch()):this.render()},removeLayers:function(){_.each(this.layers,function(a){WHO.map.removeLayer(a)})},drawBounds:function(a){var b=_.values(a),c=["#fff","rgb(255,252,224)","rgb(252,202,78)","rgb(250,175,78)","rgb(249,145,77)","rgb(247,117,77)"],d=(chroma.scale(c).domain([Math.min.apply(Math,b),Math.max.apply(Math,b)]),{type:"FeatureCollection",features:_.filter(this.model.attributes.features,function(b){return a[b.id]>1})}),e=L.geoJson(d,{style:function(b){function c(a){return console.log(b.id),console.log(a),0==b.id.substr(7,1)?1==a?"#fff":2==a?"rgb(255,252,224)":3==a?"rgb(252,202,78)":4==a?"rgb(250,175,78)":5==a?"rgb(249,145,77)":6==a?"rgb(246,104,61)":"#fff":1==a?"#fff":2==a?"rgb(252,202,78)":3==a?"rgb(250,175,78)":4==a?"rgb(249,145,77)":5==a?"rgb(246,104,61)":"#fff"}return{color:"rgb(254,243,183)",fillColor:c(a[b.id]),opacity:.7,fillOpacity:.7,weight:1}},onEachFeature:function(a,b){b.on({dblclick:function(a){WHO.map.setView(a.latlng,WHO.map.getZoom()+1)}})}}).addTo(WHO.map);this.spinner.stop(),e.bringToBack(),this.layers.push(e)},render:function(){this.layers.length&&this.removeLayers();for(var a,b,c={},d=0,e=this.collection.models.length;e>d;++d)a=this.collection.models[d],b=a.get("geoID"),c[b]=a.get("level");this.drawBounds(c)},drawClusters:function(){}})}(),WHO.Views=WHO.Views||{},function(){"use strict";WHO.Views.Table=Backbone.View.extend({tagName:"div",id:"",className:"",events:{},initialize:function(){this.listenTo(this.model,"change",this.render)},render:function(){this.$el.html(this.template(this.model.toJSON()))}})}(),WHO.Views=WHO.Views||{},function(){"use strict";function a(a){return a.setDate(a.getDate()-a.getDay()),new Date(a.getFullYear(),a.getMonth(),a.getDate())}WHO.Views.epiGraph=Backbone.View.extend({events:{},initialize:function(){this.spinner=new Spinner({color:"#888",length:2,speed:.8}).spin(document.getElementById("epi-graph-loader"))},load:function(){this.collection.length?this.render():(this.listenToOnce(this.collection,"loaded",this.render),this.collection.query())},drawChart:function(a){this.spinner.stop();var b={top:10,right:60,bottom:30,left:60},c=this.$el.width()-b.left-b.right,d=180-b.top-b.bottom,e=d3.max(a,function(a){return a.total}),f=d3.scale.linear().rangeRound([0,c]).domain([0,a.length]),g=d3.scale.linear().range([d,0]).domain([0,e]),h=Math.floor(c/a.length)-1,i=h/2,j=this.order,k=[];_.each(a,function(a,b){var c=0;a.bars=_.map(a.vals,function(a,b){return{name:j[b],y0:c,y1:c+=a,val:a}}),b%5===0&&k.push({position:b,display:a.time})});var l=d3.svg.axis().scale(g).orient("right"),m=d3.time.format("%d-%m-%Y"),n=_.template("

<%= date %>

Confirmed: <%= confirmed %>
Probable: <%= probable %>
Suspected: <%= suspected %>"),o=d3.tip().attr("class","d3-tip").html(function(a){return n({date:m(a.time),confirmed:a.vals[0],probable:a.vals[1],suspected:a.vals[2]})}),p=d3.select("#epi-graph").append("svg").attr("width",c+b.left+b.right).attr("height",d+b.top+b.bottom).append("g").attr("transform","translate("+b.left+","+b.top+")");p.call(o);var q=p.selectAll(".week").data(a).enter().append("g").attr("class","week").attr("transform",function(a,b){return"translate("+(f(b)-i)+",0)"}).on("mouseover",o.show).on("mouseout",o.hide),r=(q.selectAll("rect").data(function(a){return a.bars}).enter().append("rect").attr("width",h).attr("y",function(a){return g(a.y1)}).attr("height",function(a){return d-g(a.val)||1}).attr("class",function(a){return a.name}),p.append("g").attr("class","x axis").attr("transform","translate(0,"+(d+3)+")").selectAll(".tick").data(k).enter().append("g").attr("class","tick").attr("transform",function(a){return"translate("+f(a.position)+",0)"}));r.append("line").attr("x1",0).attr("x2",0).attr("y1",0).attr("y2",5).style("stroke-width","2"),r.append("text").text(function(a){return m(a.display)}).style("text-anchor","middle").attr("dy","15px"),p.append("g").attr("transform","translate("+c+",0)").attr("class","y axis").call(l).append("text").attr("transform","rotate(-90)").attr("y",6).attr("dy","-.8em").style("text-anchor","end").text("Cases");var s=a.length;q.transition().duration(0).delay(function(a,b){return 20*(s-b)}).attr("class","week active")},render:function(){var b,c,d,e=new Date(this.collection.at(0).get("datetime")),f=(new Date(this.collection.at(this.collection.length-1).get("datetime")),6048e5),g=Date.parse(a(e)),h=g+f,i={Suspected:0,Probable:0,Confirmed:0,Total:0},j=[_.clone(i)],k=0;j[0].week=new Date(g);for(var l=0,m=this.collection.length;m>l;++l){for(b=this.collection.at(l),c=b.get("datetime");c>h;)k+=1,j.push(_.clone(i)),j[k].week=new Date(h),h+=f;d=b.get("case category"),d in j[k]&&(j[k][d]+=1,j[k].Total+=1)}this.order=["confirmed","probable","suspected"];var j=_.map(j.slice(0,-1),function(a){return{vals:[a.Confirmed,a.Probable,a.Suspected],total:a.Total,time:new Date(a.week)}});this.drawChart(j)}})}(),WHO.Collections=WHO.Collections||{},function(){"use strict";WHO.Collections.Response=Backbone.Collection.extend({model:WHO.Models.Response})}(),WHO.Collections=WHO.Collections||{},function(){"use strict";WHO.Collections.Cases=Backbone.Collection.extend({initialize:function(){this.ref=new Firebase("https://luminous-heat-4380.firebaseio.com/cases_admin_aug17")},query:function(){var a=$.proxy(this.onload,this);this.ref.once("value",a)},onload:function(a){for(var b,c=a.val(),d=Date.parse(new Date),e=Date.parse(new Date("2013","11","20")),f=0,g=c.length;g>f;++f)b=c[f].date,c[f].datetime=Date.parse(b);c=_.filter(c,function(a){return!isNaN(a.datetime)&&a.datetimee}),c=_.sortBy(c,function(a){return a.datetime}),this.reset(c),this.trigger("loaded",c)}})}(),WHO.Collections=WHO.Collections||{},function(){"use strict";WHO.Collections.GlobalRisk=Backbone.Collection.extend({initialize:function(){this.ref=new Firebase("https://luminous-heat-4380.firebaseio.com/allResponse")},query:function(){var a=$.proxy(this.onload,this);this.ref.once("value",a)},onload:function(a){var b=a.val();this.reset(b),this.trigger("loaded",b)}})}(),WHO.Models=WHO.Models||{},function(){"use strict";WHO.Models.Deployment=Backbone.Model.extend({url:"",initialize:function(){},defaults:{},validate:function(){},parse:function(a){return a}})}(),WHO.Models=WHO.Models||{},function(){"use strict";WHO.Models.Case=Backbone.Model.extend({initialize:function(){},defaults:{}})}(),WHO.Models=WHO.Models||{},function(){"use strict";WHO.Models.Country=Backbone.Model.extend({url:"geo/ADM0.topojson",parse:function(a){return topojson.feature(a,a.objects.ADM0)}})}(),WHO.Models=WHO.Models||{},function(){"use strict";WHO.Models.Province=Backbone.Model.extend({url:"geo/ADM1.topojson",parse:function(a){return topojson.feature(a,a.objects.ADM1)}})}(),WHO.Models=WHO.Models||{},function(){"use strict";WHO.Models.District=Backbone.Model.extend({url:"geo/ADM2.topojson",parse:function(a){return topojson.feature(a,a.objects.ADM2)}})}(),WHO.Views=WHO.Views||{},function(){"use strict";WHO.Views.Dropdown=Backbone.View.extend({template:_.template($("#dropdown-template").html()),events:{"click a":"select"},initialize:function(a){this.options=a.options,this.selected=this.options[0].display,this.render()},render:function(){this.$el.html(this.template({options:this.options,selected:this.selected})),this.$selected=this.$(".selected"),this.$dropdown=this.$(".dropdown")},select:function(a){return a.preventDefault(),a=a.toElement,this.$selected.text(a.innerHTML),this.$dropdown.toggleClass("open"),WHO.router.set(this.className,a.className),!1}})}(),WHO.Routers=WHO.Routers||{},function(){"use strict";function a(){var a=new WHO.Models.Zoom;WHO.collections={cases:new WHO.Collections.Cases,response:new WHO.Collections.Response,globalrisk:new WHO.Collections.GlobalRisk,clinics:new WHO.Models.Clinics},WHO.mapview=new WHO.Views.Map({el:"#map",id:"map",map:WHO.map,collection:WHO.collections.globalrisk,zoom:a}),WHO.markerview=new WHO.Views.Marker({el:"#map",id:"map",map:WHO.map,collection:WHO.collections.cases,zoom:a,model:new WHO.Models.Centroids}),WHO.epiGraph=new WHO.Views.epiGraph({el:"#epi-graph",id:"epi-graph",collection:WHO.collections.cases}),new WHO.Views.Clinic({el:"#map",id:"map",map:WHO.map,model:WHO.collections.clinics,zoom:a}),new WHO.Views.Legend({el:"#legend",id:"legend",model:a}),WHO.models={},WHO.models={},WHO.map.whenReady(function(){$('

').appendTo(WHO.$map)}),WHO.mapview.load(),WHO.epiGraph.load(),c=!0}var b="total",c=!1,d=[{display:"Most recent",val:"recent"},{display:"All",val:"all"}],e=[{display:"All cases",val:"total"},{display:"Confirmed cases",val:"confirmed"},{display:"Suspected cases",val:"suspected"},{display:"Probable cases",val:"probable"}],f={time:"",type:""};WHO.defaultZoom=3,WHO.map=L.mapbox.map("map","nate.j8n0m4ld").setView([22.23,8],WHO.defaultZoom),WHO.map.scrollWheelZoom.disable(),WHO.$map=$("#map"),WHO.Routers.App=Backbone.Router.extend({routes:{"":"newload",":time/:type":"newload"},newload:function(){a(),WHO.markerview.setFilter({type:b,time:"recent"}),WHO.markerview.load(),f.time="recent",f.type=b},newfilter:function(g,h){c||a(),-1!==_.map(d,function(a){return a.val}).indexOf(g)&&-1!==_.map(e,function(a){return a.val}).indexOf(h)?(WHO.markerview.setFilter({type:h,time:g}),this.navigate(g+"/"+h,{trigger:!1}),f.time=g,f.type=h):(WHO.markerview.setFilter({type:b,time:"recent"}),this.navigate("recent/"+b,{trigger:!1}),f.time="recent",f.type=b),WHO.markerview.load()},set:function(a,b){f[a]=b,this.navigate(f.time+"/"+f.type,{trigger:!0})}})}(),WHO.Views=WHO.Views||{},function(){"use strict";WHO.Views.Marker=Backbone.View.extend({initialize:function(a){this.listenTo(a.zoom,"zoom:end",this.getmap),this.layers=[]},setFilter:function(a){this.filters=a},load:function(){this.collection.length?this.getmap():(this.listenToOnce(this.collection,"loaded",this.getmap),this.collection.query())},getmap:function(a){var b,c;b=a&&a.level?a.level:this.level?this.level:WHO.defaultZoom,c=5>b?"country":7>b?"province":"district",this.level=b,this.maptype=c,this.popup=new L.Popup({autoPan:!1}),this.getCentroids()},getCentroids:function(){"FeatureCollection"!==this.model.get("type")?(this.listenToOnce(this.model,"change",this.render),this.model.fetch()):this.render()},removeLayers:function(){_.each(this.layers,function(a){WHO.map.removeLayer(a)})},render:function(){var a,b,c,d,e,f,g,h={},i=this.collection.at(this.collection.models.length-1).get("datetime"),j=0;switch(this.maptype){case"country":c="ADM0_NAME",d="ADM2_CODE";break;case"province":c="ADM1_NAME",d="ADM2_CODE";break;case"district":c="ADM2_NAME",d="ADM2_CODE"}for(var k=0,l=this.collection.models.length;l>k;++k)e=this.collection.models[k],a=e.get("case category").toLowerCase(),f=e.get(c),"ADM0_NAME"==c?(b=e.get(d).substring(0,5),g=b.concat("000000000000000")):"ADM1_NAME"==c?(b=e.get(d).substring(0,8),g=b.concat("000000000000")):g=e.get(d),"For Aggregates"===a||i-e.get("datetime")<=j||(g in h||(h[g]={name:f,confirmed:0,probable:0,suspected:0,hcw:0,deaths:0}),h[g][a]+=1,"TRUE"==e.get("HCW")&&(h[g].hcw+=1),"Dead"==e.get("outcome")&&(h[g].deaths+=1));_.each(h,function(a){a.total=a.confirmed+a.probable+a.suspected}),this.cases=h,this.drawMarkers(h)},drawMarkers:function(a){this.layers.length&&this.removeLayers();var b,c=("country"===this.maptype?3:5,this.maptype),d=0,e=this.popup,f=this.filters.type,g=_.max(_.map(a,function(a){return a.total})),h=d3.scale.quantize().domain([0,g]).range([50,400,800,1200,1600,2e3,2400,2800,3200,3600]),i={type:"Topology",features:_.chain(this.model.get("features")).filter(function(b){return a[b.id]}).sortBy(function(b){return-a[b.id][f]}).value()};WHO.map.on("popupclose",function(){d=0});var j=WHO.map.getZoom()<5?3.2:2.8,k=L.geoJson(i,{pointToLayer:function(b,c){return L.circleMarker(c,{radius:Math.sqrt(h(a[b.id][f])/Math.PI)/(j/1.88),weight:1.5,color:"#fff",opacity:.7,fillColor:"#99000d",fillOpacity:.7})},onEachFeature:function(f,g){g.on({dblclick:function(a){WHO.map.setView(a.latlng,WHO.map.getZoom()+1)},mousemove:function(f){if(0==d){var g=f.target;e.setLatLng(f.latlng),e.setContent('
'+c.charAt(0).toUpperCase()+c.slice(1)+": "+a[g.feature.id].name+"
Click for more information"),e._map||e.openOn(WHO.map),window.clearTimeout(b)}},mouseout:function(){0==d&&(b=window.setTimeout(function(){WHO.map.closePopup()},100))},click:function(f){d=1;var g=f.target,h=a[g.feature.id];e.setLatLng(f.latlng),e.setContent('
'+c.charAt(0).toUpperCase()+c.slice(1)+": "+a[g.feature.id].name+'
"),e._map||e.openOn(WHO.map),window.clearTimeout(b)}})}}).addTo(WHO.map);k.bringToFront(),this.layers.push(k)}})}(),WHO.Models=WHO.Models||{},function(){"use strict";WHO.Models.Zoom=Backbone.Model.extend({initialize:function(){var a,b=!1,c=this;WHO.map.on("zoomstart",function(){b=!0,window.clearTimeout(a)}),WHO.map.on("zoomend",function(){b=!1,a=window.setTimeout(function(){b||c.trigger("zoom:end",{level:WHO.map.getZoom()})},400)})}})}(),WHO.Models=WHO.Models||{},function(){"use strict";WHO.Models.Centroids=Backbone.Model.extend({url:"geo/centroids.topojson",parse:function(a){return topojson.feature(a,a.objects.centroids)}})}(),WHO.Views=WHO.Views||{},function(){"use strict";WHO.Views.Legend=Backbone.View.extend({initialize:function(){this.listenTo(this.model,"zoom:end",this.render),this.$country=this.$(".country"),this.$district=this.$(".district"),this.onCountry=!0},render:function(a){var b=a.level||WHO.defaultZoom;this.onCountry&&b>=5?(this.$country.hide(),this.$district.show(),this.onCountry=!1):!this.onCountry&&5>b&&(this.$country.show(),this.$district.hide(),this.onCountry=!0)}})}(),WHO.Views=WHO.Views||{},function(){"use strict";WHO.Views.Clinic=Backbone.View.extend({initialize:function(a){this.layers=[],this.listenTo(a.zoom,"zoom:end",this.getmap),this.listenToOnce(this.model,"loaded",this.onLoad),this.model.query(),this.on=!1,this.popup=new L.Popup({autoPan:!1})},onLoad:function(){this.getmap({level:WHO.defaultZoom})},getmap:function(a){var b=a.level||WHO.defaultZoom;b>=7&&!this.on&&(this.render(),this.on=!0),7>b&&this.on&&(this.remove(),this.on=!1)},remove:function(){_.each(this.layers,function(a){WHO.map.removeLayer(a)})},render:function(){this.layers.length&&this.remove();var a=this.popup,b=L.geoJson(this.model.attributes,{pointToLayer:function(a,b){return L.marker(b,{icon:L.icon({iconSize:[32,32],iconUrl:"img/medical-64x64.png"}),opacity:.95})},onEachFeature:function(b,c){c.on({dblclick:function(a){WHO.map.setView(a.latlng,WHO.map.getZoom()+1)},click:function(b){var c=b.target.feature.properties;a.setLatLng(b.latlng),a.setContent('
'+c.CITY+", "+c.COUNTRY+'
"),a._map||a.openOn(WHO.map)}})}}).addTo(WHO.map);this.layers.push(b)}})}(),WHO.Models=WHO.Models||{},function(){"use strict";WHO.Models.Clinics=Backbone.Model.extend({initialize:function(){this.ref=new Firebase("https://luminous-heat-4380.firebaseio.com/ebolaClinics_aug17")},query:function(){var a=$.proxy(this.onload,this);this.ref.once("value",a)},onload:function(a){var b=a.val();this.set(topojson.feature(b,b.objects.ebolaClinics)),this.trigger("loaded")}})}(); \ No newline at end of file diff --git a/dist/scripts/c3fe213f.vendor.js b/dist/scripts/828851d3.vendor.js similarity index 99% rename from dist/scripts/c3fe213f.vendor.js rename to dist/scripts/828851d3.vendor.js index 57e18f6..df8932b 100644 --- a/dist/scripts/c3fe213f.vendor.js +++ b/dist/scripts/828851d3.vendor.js @@ -4,7 +4,7 @@ _.fn[b]=function(a,d,e){return null==a||"boolean"==typeof a?c.apply(this,argumen };var G={escape:{"&":"&","<":"<",">":">",'"':""","'":"'"}};G.unescape=x.invert(G.escape);var H={escape:new RegExp("["+x.keys(G.escape).join("")+"]","g"),unescape:new RegExp("("+x.keys(G.unescape).join("|")+")","g")};x.each(["escape","unescape"],function(a){x[a]=function(b){return null==b?"":(""+b).replace(H[a],function(b){return G[a][b]})}}),x.result=function(a,b){if(null==a)return void 0;var c=a[b];return x.isFunction(c)?c.call(a):c},x.mixin=function(a){y(x.functions(a),function(b){var c=x[b]=a[b];x.prototype[b]=function(){var a=[this._wrapped];return g.apply(a,arguments),M.call(this,c.apply(x,a))}})};var I=0;x.uniqueId=function(a){var b=++I+"";return a?a+b:b},x.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var J=/(.)^/,K={"'":"'","\\":"\\","\r":"r","\n":"n"," ":"t","\u2028":"u2028","\u2029":"u2029"},L=/\\|'|\r|\n|\t|\u2028|\u2029/g;x.template=function(a,b,c){var d;c=x.defaults({},c,x.templateSettings);var e=new RegExp([(c.escape||J).source,(c.interpolate||J).source,(c.evaluate||J).source].join("|")+"|$","g"),f=0,g="__p+='";a.replace(e,function(b,c,d,e,h){return g+=a.slice(f,h).replace(L,function(a){return"\\"+K[a]}),c&&(g+="'+\n((__t=("+c+"))==null?'':_.escape(__t))+\n'"),d&&(g+="'+\n((__t=("+d+"))==null?'':__t)+\n'"),e&&(g+="';\n"+e+"\n__p+='"),f=h+b.length,b}),g+="';\n",c.variable||(g="with(obj||{}){\n"+g+"}\n"),g="var __t,__p='',__j=Array.prototype.join,print=function(){__p+=__j.call(arguments,'');};\n"+g+"return __p;\n";try{d=new Function(c.variable||"obj","_",g)}catch(h){throw h.source=g,h}if(b)return d(b,x);var i=function(a){return d.call(this,a,x)};return i.source="function("+(c.variable||"obj")+"){\n"+g+"}",i},x.chain=function(a){return x(a).chain()};var M=function(a){return this._chain?x(a).chain():a};x.mixin(x),y(["pop","push","reverse","shift","sort","splice","unshift"],function(a){var b=d[a];x.prototype[a]=function(){var c=this._wrapped;return b.apply(c,arguments),"shift"!=a&&"splice"!=a||0!==c.length||delete c[0],M.call(this,c)}}),y(["concat","join","slice"],function(a){var b=d[a];x.prototype[a]=function(){return M.call(this,b.apply(this._wrapped,arguments))}}),x.extend(x.prototype,{chain:function(){return this._chain=!0,this},value:function(){return this._wrapped}}),"function"==typeof define&&define.amd&&define("underscore",[],function(){return x})}.call(this),function(a,b){if("function"==typeof define&&define.amd)define(["underscore","jquery","exports"],function(c,d,e){a.Backbone=b(a,e,c,d)});else if("undefined"!=typeof exports){var c=require("underscore");b(a,exports,c)}else a.Backbone=b(a,{},a._,a.jQuery||a.Zepto||a.ender||a.$)}(this,function(a,b,c,d){{var e=a.Backbone,f=[],g=(f.push,f.slice);f.splice}b.VERSION="1.1.2",b.$=d,b.noConflict=function(){return a.Backbone=e,this},b.emulateHTTP=!1,b.emulateJSON=!1;var h=b.Events={on:function(a,b,c){if(!j(this,"on",a,[b,c])||!b)return this;this._events||(this._events={});var d=this._events[a]||(this._events[a]=[]);return d.push({callback:b,context:c,ctx:c||this}),this},once:function(a,b,d){if(!j(this,"once",a,[b,d])||!b)return this;var e=this,f=c.once(function(){e.off(a,f),b.apply(this,arguments)});return f._callback=b,this.on(a,f,d)},off:function(a,b,d){var e,f,g,h,i,k,l,m;if(!this._events||!j(this,"off",a,[b,d]))return this;if(!a&&!b&&!d)return this._events=void 0,this;for(h=a?[a]:c.keys(this._events),i=0,k=h.length;k>i;i++)if(a=h[i],g=this._events[a]){if(this._events[a]=e=[],b||d)for(l=0,m=g.length;m>l;l++)f=g[l],(b&&b!==f.callback&&b!==f.callback._callback||d&&d!==f.context)&&e.push(f);e.length||delete this._events[a]}return this},trigger:function(a){if(!this._events)return this;var b=g.call(arguments,1);if(!j(this,"trigger",a,b))return this;var c=this._events[a],d=this._events.all;return c&&k(c,b),d&&k(d,arguments),this},stopListening:function(a,b,d){var e=this._listeningTo;if(!e)return this;var f=!b&&!d;d||"object"!=typeof b||(d=this),a&&((e={})[a._listenId]=a);for(var g in e)a=e[g],a.off(b,d,this),(f||c.isEmpty(a._events))&&delete this._listeningTo[g];return this}},i=/\s+/,j=function(a,b,c,d){if(!c)return!0;if("object"==typeof c){for(var e in c)a[b].apply(a,[e,c[e]].concat(d));return!1}if(i.test(c)){for(var f=c.split(i),g=0,h=f.length;h>g;g++)a[b].apply(a,[f[g]].concat(d));return!1}return!0},k=function(a,b){var c,d=-1,e=a.length,f=b[0],g=b[1],h=b[2];switch(b.length){case 0:for(;++dm;m++)this.trigger("change:"+h[m],this,l[h[m]],d)}if(j)return this;if(!i)for(;this._pending;)d=this._pending,this._pending=!1,this.trigger("change",this,d);return this._pending=!1,this._changing=!1,this},unset:function(a,b){return this.set(a,void 0,c.extend({},b,{unset:!0}))},clear:function(a){var b={};for(var d in this.attributes)b[d]=void 0;return this.set(b,c.extend({},a,{unset:!0}))},hasChanged:function(a){return null==a?!c.isEmpty(this.changed):c.has(this.changed,a)},changedAttributes:function(a){if(!a)return this.hasChanged()?c.clone(this.changed):!1;var b,d=!1,e=this._changing?this._previousAttributes:this.attributes;for(var f in a)c.isEqual(e[f],b=a[f])||((d||(d={}))[f]=b);return d},previous:function(a){return null!=a&&this._previousAttributes?this._previousAttributes[a]:null},previousAttributes:function(){return c.clone(this._previousAttributes)},fetch:function(a){a=a?c.clone(a):{},void 0===a.parse&&(a.parse=!0);var b=this,d=a.success;return a.success=function(c){return b.set(b.parse(c,a),a)?(d&&d(b,c,a),void b.trigger("sync",b,c,a)):!1},L(this,a),this.sync("read",this,a)},save:function(a,b,d){var e,f,g,h=this.attributes;if(null==a||"object"==typeof a?(e=a,d=b):(e={})[a]=b,d=c.extend({validate:!0},d),e&&!d.wait){if(!this.set(e,d))return!1}else if(!this._validate(e,d))return!1;e&&d.wait&&(this.attributes=c.extend({},h,e)),void 0===d.parse&&(d.parse=!0);var i=this,j=d.success;return d.success=function(a){i.attributes=h;var b=i.parse(a,d);return d.wait&&(b=c.extend(e||{},b)),c.isObject(b)&&!i.set(b,d)?!1:(j&&j(i,a,d),void i.trigger("sync",i,a,d))},L(this,d),f=this.isNew()?"create":d.patch?"patch":"update","patch"===f&&(d.attrs=e),g=this.sync(f,this,d),e&&d.wait&&(this.attributes=h),g},destroy:function(a){a=a?c.clone(a):{};var b=this,d=a.success,e=function(){b.trigger("destroy",b,b.collection,a)};if(a.success=function(c){(a.wait||b.isNew())&&e(),d&&d(b,c,a),b.isNew()||b.trigger("sync",b,c,a)},this.isNew())return a.success(),!1;L(this,a);var f=this.sync("delete",this,a);return a.wait||e(),f},url:function(){var a=c.result(this,"urlRoot")||c.result(this.collection,"url")||K();return this.isNew()?a:a.replace(/([^\/])$/,"$1/")+encodeURIComponent(this.id)},parse:function(a){return a},clone:function(){return new this.constructor(this.attributes)},isNew:function(){return!this.has(this.idAttribute)},isValid:function(a){return this._validate({},c.extend(a||{},{validate:!0}))},_validate:function(a,b){if(!b.validate||!this.validate)return!0;a=c.extend({},this.attributes,a);var d=this.validationError=this.validate(a,b)||null;return d?(this.trigger("invalid",this,d,c.extend(b,{validationError:d})),!1):!0}});var n=["keys","values","pairs","invert","pick","omit"];c.each(n,function(a){m.prototype[a]=function(){var b=g.call(arguments);return b.unshift(this.attributes),c[a].apply(c,b)}});var o=b.Collection=function(a,b){b||(b={}),b.model&&(this.model=b.model),void 0!==b.comparator&&(this.comparator=b.comparator),this._reset(),this.initialize.apply(this,arguments),a&&this.reset(a,c.extend({silent:!0},b))},p={add:!0,remove:!0,merge:!0},q={add:!0,remove:!1};c.extend(o.prototype,h,{model:m,initialize:function(){},toJSON:function(a){return this.map(function(b){return b.toJSON(a)})},sync:function(){return b.sync.apply(this,arguments)},add:function(a,b){return this.set(a,c.extend({merge:!1},b,q))},remove:function(a,b){var d=!c.isArray(a);a=d?[a]:c.clone(a),b||(b={});var e,f,g,h;for(e=0,f=a.length;f>e;e++)h=a[e]=this.get(a[e]),h&&(delete this._byId[h.id],delete this._byId[h.cid],g=this.indexOf(h),this.models.splice(g,1),this.length--,b.silent||(b.index=g,h.trigger("remove",h,this,b)),this._removeReference(h,b));return d?a[0]:a},set:function(a,b){b=c.defaults({},b,p),b.parse&&(a=this.parse(a,b));var d=!c.isArray(a);a=d?a?[a]:[]:c.clone(a);var e,f,g,h,i,j,k,l=b.at,n=this.model,o=this.comparator&&null==l&&b.sort!==!1,q=c.isString(this.comparator)?this.comparator:null,r=[],s=[],t={},u=b.add,v=b.merge,w=b.remove,x=!o&&u&&w?[]:!1;for(e=0,f=a.length;f>e;e++){if(i=a[e]||{},g=i instanceof m?h=i:i[n.prototype.idAttribute||"id"],j=this.get(g))w&&(t[j.cid]=!0),v&&(i=i===h?h.attributes:i,b.parse&&(i=j.parse(i,b)),j.set(i,b),o&&!k&&j.hasChanged(q)&&(k=!0)),a[e]=j;else if(u){if(h=a[e]=this._prepareModel(i,b),!h)continue;r.push(h),this._addReference(h,b)}h=j||h,!x||!h.isNew()&&t[h.id]||x.push(h),t[h.id]=!0}if(w){for(e=0,f=this.length;f>e;++e)t[(h=this.models[e]).cid]||s.push(h);s.length&&this.remove(s,b)}if(r.length||x&&x.length)if(o&&(k=!0),this.length+=r.length,null!=l)for(e=0,f=r.length;f>e;e++)this.models.splice(l+e,0,r[e]);else{x&&(this.models.length=0);var y=x||r;for(e=0,f=y.length;f>e;e++)this.models.push(y[e])}if(k&&this.sort({silent:!0}),!b.silent){for(e=0,f=r.length;f>e;e++)(h=r[e]).trigger("add",h,this,b);(k||x&&x.length)&&this.trigger("sort",this,b)}return d?a[0]:a},reset:function(a,b){b||(b={});for(var d=0,e=this.models.length;e>d;d++)this._removeReference(this.models[d],b);return b.previousModels=this.models,this._reset(),a=this.add(a,c.extend({silent:!0},b)),b.silent||this.trigger("reset",this,b),a},push:function(a,b){return this.add(a,c.extend({at:this.length},b))},pop:function(a){var b=this.at(this.length-1);return this.remove(b,a),b},unshift:function(a,b){return this.add(a,c.extend({at:0},b))},shift:function(a){var b=this.at(0);return this.remove(b,a),b},slice:function(){return g.apply(this.models,arguments)},get:function(a){return null==a?void 0:this._byId[a]||this._byId[a.id]||this._byId[a.cid]},at:function(a){return this.models[a]},where:function(a,b){return c.isEmpty(a)?b?void 0:[]:this[b?"find":"filter"](function(b){for(var c in a)if(a[c]!==b.get(c))return!1;return!0})},findWhere:function(a){return this.where(a,!0)},sort:function(a){if(!this.comparator)throw new Error("Cannot sort a set without a comparator");return a||(a={}),c.isString(this.comparator)||1===this.comparator.length?this.models=this.sortBy(this.comparator,this):this.models.sort(c.bind(this.comparator,this)),a.silent||this.trigger("sort",this,a),this},pluck:function(a){return c.invoke(this.models,"get",a)},fetch:function(a){a=a?c.clone(a):{},void 0===a.parse&&(a.parse=!0);var b=a.success,d=this;return a.success=function(c){var e=a.reset?"reset":"set";d[e](c,a),b&&b(d,c,a),d.trigger("sync",d,c,a)},L(this,a),this.sync("read",this,a)},create:function(a,b){if(b=b?c.clone(b):{},!(a=this._prepareModel(a,b)))return!1;b.wait||this.add(a,b);var d=this,e=b.success;return b.success=function(a,c){b.wait&&d.add(a,b),e&&e(a,c,b)},a.save(null,b),a},parse:function(a){return a},clone:function(){return new this.constructor(this.models)},_reset:function(){this.length=0,this.models=[],this._byId={}},_prepareModel:function(a,b){if(a instanceof m)return a;b=b?c.clone(b):{},b.collection=this;var d=new this.model(a,b);return d.validationError?(this.trigger("invalid",this,d.validationError,b),!1):d},_addReference:function(a){this._byId[a.cid]=a,null!=a.id&&(this._byId[a.id]=a),a.collection||(a.collection=this),a.on("all",this._onModelEvent,this)},_removeReference:function(a){this===a.collection&&delete a.collection,a.off("all",this._onModelEvent,this)},_onModelEvent:function(a,b,c,d){("add"!==a&&"remove"!==a||c===this)&&("destroy"===a&&this.remove(b,d),b&&a==="change:"+b.idAttribute&&(delete this._byId[b.previous(b.idAttribute)],null!=b.id&&(this._byId[b.id]=b)),this.trigger.apply(this,arguments))}});var r=["forEach","each","map","collect","reduce","foldl","inject","reduceRight","foldr","find","detect","filter","select","reject","every","all","some","any","include","contains","invoke","max","min","toArray","size","first","head","take","initial","rest","tail","drop","last","without","difference","indexOf","shuffle","lastIndexOf","isEmpty","chain","sample"];c.each(r,function(a){o.prototype[a]=function(){var b=g.call(arguments);return b.unshift(this.models),c[a].apply(c,b)}});var s=["groupBy","countBy","sortBy","indexBy"];c.each(s,function(a){o.prototype[a]=function(b,d){var e=c.isFunction(b)?b:function(a){return a.get(b)};return c[a](this.models,e,d)}});var t=b.View=function(a){this.cid=c.uniqueId("view"),a||(a={}),c.extend(this,c.pick(a,v)),this._ensureElement(),this.initialize.apply(this,arguments),this.delegateEvents()},u=/^(\S+)\s*(.*)$/,v=["model","collection","el","id","attributes","className","tagName","events"];c.extend(t.prototype,h,{tagName:"div",$:function(a){return this.$el.find(a)},initialize:function(){},render:function(){return this},remove:function(){return this.$el.remove(),this.stopListening(),this},setElement:function(a,c){return this.$el&&this.undelegateEvents(),this.$el=a instanceof b.$?a:b.$(a),this.el=this.$el[0],c!==!1&&this.delegateEvents(),this},delegateEvents:function(a){if(!a&&!(a=c.result(this,"events")))return this;this.undelegateEvents();for(var b in a){var d=a[b];if(c.isFunction(d)||(d=this[a[b]]),d){var e=b.match(u),f=e[1],g=e[2];d=c.bind(d,this),f+=".delegateEvents"+this.cid,""===g?this.$el.on(f,d):this.$el.on(f,g,d)}}return this},undelegateEvents:function(){return this.$el.off(".delegateEvents"+this.cid),this},_ensureElement:function(){if(this.el)this.setElement(c.result(this,"el"),!1);else{var a=c.extend({},c.result(this,"attributes"));this.id&&(a.id=c.result(this,"id")),this.className&&(a["class"]=c.result(this,"className"));var d=b.$("<"+c.result(this,"tagName")+">").attr(a);this.setElement(d,!1)}}}),b.sync=function(a,d,e){var f=x[a];c.defaults(e||(e={}),{emulateHTTP:b.emulateHTTP,emulateJSON:b.emulateJSON});var g={type:f,dataType:"json"};if(e.url||(g.url=c.result(d,"url")||K()),null!=e.data||!d||"create"!==a&&"update"!==a&&"patch"!==a||(g.contentType="application/json",g.data=JSON.stringify(e.attrs||d.toJSON(e))),e.emulateJSON&&(g.contentType="application/x-www-form-urlencoded",g.data=g.data?{model:g.data}:{}),e.emulateHTTP&&("PUT"===f||"DELETE"===f||"PATCH"===f)){g.type="POST",e.emulateJSON&&(g.data._method=f);var h=e.beforeSend;e.beforeSend=function(a){return a.setRequestHeader("X-HTTP-Method-Override",f),h?h.apply(this,arguments):void 0}}"GET"===g.type||e.emulateJSON||(g.processData=!1),"PATCH"===g.type&&w&&(g.xhr=function(){return new ActiveXObject("Microsoft.XMLHTTP")});var i=e.xhr=b.ajax(c.extend(g,e));return d.trigger("request",d,i,e),i};var w=!("undefined"==typeof window||!window.ActiveXObject||window.XMLHttpRequest&&(new XMLHttpRequest).dispatchEvent),x={create:"POST",update:"PUT",patch:"PATCH","delete":"DELETE",read:"GET"};b.ajax=function(){return b.$.ajax.apply(b.$,arguments)};var y=b.Router=function(a){a||(a={}),a.routes&&(this.routes=a.routes),this._bindRoutes(),this.initialize.apply(this,arguments)},z=/\((.*?)\)/g,A=/(\(\?)?:\w+/g,B=/\*\w+/g,C=/[\-{}\[\]+?.,\\\^$|#\s]/g;c.extend(y.prototype,h,{initialize:function(){},route:function(a,d,e){c.isRegExp(a)||(a=this._routeToRegExp(a)),c.isFunction(d)&&(e=d,d=""),e||(e=this[d]);var f=this;return b.history.route(a,function(c){var g=f._extractParameters(a,c);f.execute(e,g),f.trigger.apply(f,["route:"+d].concat(g)),f.trigger("route",d,g),b.history.trigger("route",f,d,g)}),this},execute:function(a,b){a&&a.apply(this,b)},navigate:function(a,c){return b.history.navigate(a,c),this},_bindRoutes:function(){if(this.routes){this.routes=c.result(this,"routes");for(var a,b=c.keys(this.routes);null!=(a=b.pop());)this.route(a,this.routes[a])}},_routeToRegExp:function(a){return a=a.replace(C,"\\$&").replace(z,"(?:$1)?").replace(A,function(a,b){return b?a:"([^/?]+)"}).replace(B,"([^?]*?)"),new RegExp("^"+a+"(?:\\?([\\s\\S]*))?$")},_extractParameters:function(a,b){var d=a.exec(b).slice(1);return c.map(d,function(a,b){return b===d.length-1?a||null:a?decodeURIComponent(a):null})}});var D=b.History=function(){this.handlers=[],c.bindAll(this,"checkUrl"),"undefined"!=typeof window&&(this.location=window.location,this.history=window.history)},E=/^[#\/]|\s+$/g,F=/^\/+|\/+$/g,G=/msie [\w.]+/,H=/\/$/,I=/#.*$/;D.started=!1,c.extend(D.prototype,h,{interval:50,atRoot:function(){return this.location.pathname.replace(/[^\/]$/,"$&/")===this.root},getHash:function(a){var b=(a||this).location.href.match(/#(.*)$/);return b?b[1]:""},getFragment:function(a,b){if(null==a)if(this._hasPushState||!this._wantsHashChange||b){a=decodeURI(this.location.pathname+this.location.search);var c=this.root.replace(H,"");a.indexOf(c)||(a=a.slice(c.length))}else a=this.getHash();return a.replace(E,"")},start:function(a){if(D.started)throw new Error("Backbone.history has already been started");D.started=!0,this.options=c.extend({root:"/"},this.options,a),this.root=this.options.root,this._wantsHashChange=this.options.hashChange!==!1,this._wantsPushState=!!this.options.pushState,this._hasPushState=!!(this.options.pushState&&this.history&&this.history.pushState);var d=this.getFragment(),e=document.documentMode,f=G.exec(navigator.userAgent.toLowerCase())&&(!e||7>=e);if(this.root=("/"+this.root+"/").replace(F,"/"),f&&this._wantsHashChange){var g=b.$('