Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 106 lines (83 sloc) 2.678 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
#Routing information
showing = null
route = null
#F coffescript scope
selectedCountries = null
worldCountries = null

HashBangs = Backbone.Router.extend
  routes:
    "home": "showHome"

    "about" : 'showAbout'

    "compare" : "showCompare"
    "compare/:log/*countries": "showCompare"

    "watch" : 'showWatch'
    "watch/:abs/:hour" : 'showWatch'

    "bubble" : 'showBubble'
    "bubble/:country" : 'showBubble'

    "rank" : 'showRank'
    "rank/:main" : 'showRank'
    "rank/:main/*sub" : 'showRank' #Splat to take care of sub categories like ERM / CRM


    "*path":"showHome"
  initialize: (options)->
    worldCountries = _.map(data.countries.features,(d)-> d.properties.name)

  showHome: ()->
    $("#main").html($("#home").html())
    showing="home"
    updateTopLinks()
    route.navigate("/home")

  showAbout: ()->
    $("#main").html($("#about").html())
    showing="about"
    updateTopLinks()

  showCompare: (log_q,countries)->
    if log_q
      compare.log_q = (log_q == "true") #logic hack
    if countries
      selectedCountries = _.map(countries.split("/"), (c)-> if c.length is 0 then null else decodeURI(c))
    else
      selectedCountries = ["Philippines","India","Bangladesh","Pakistan","Russia","Ukraine","United States"]
    while selectedCountries.length isnt 60 #compare.rainbow.length
      selectedCountries.push(null)

    if showing isnt "compare"
      $("#main").html($("#compare").html())
      showing="compare"
      updateTopLinks()
      createCompareChart()
    updateCompareChart()

  showWatch: (abs,hour)->
    if showing isnt "watch"
      $("#main").html($("#watch").html())
      showing="watch"
      updateTopLinks()
      createWatchChart()
    updateWatchChart(abs,hour)

  showBubble: (givenCountry)->
    if showing isnt "bubble"
      $("#main").html($("#bubble").html())
      showing="bubble"
      updateTopLinks()
      createBubbleChart()
    updateBubbleChart(givenCountry)

  showRank: (main,sub)->
    if showing isnt "rank"
      $("#main").html($("#rank").html())
      showing="rank"
      updateTopLinks()
      createRankChart()
    m = if main then decodeURI(main) else null
    s = if sub then decodeURI(sub) else null
    updateRankChart(m,s)

updateTopLinks = ()->
   $("ul.nav > li").removeClass("active")
   $("#link-#{showing}").addClass("active")

$(".hidden").toggleClass("hidden").hide()



#Start everything up
start = ()->
  route = new HashBangs()
  Backbone.history.start()
  if Backbone.history.fragment is "" then route.navigate("home",{trigger: true})

  reset = ()->
    showing = ""
    route.navigate("#{Backbone.history.fragment}",
      {trigger: true})

  $(window).resize(reset)
Something went wrong with that request. Please try again.