Blame view

js/crep.js 2.75 KB
e6ec151e   Geoffrey PREUD'HOMME   Ensure only corre...
1
2
3
4
5
6
  function removeAfter(string, pattern) {
      var n = string.indexOf(pattern);
      return string.substring(0, n != -1 ? n : string.length);
  }
  
  function pageName(href) {
e6ec151e   Geoffrey PREUD'HOMME   Ensure only corre...
7
8
      if (href.indexOf(window.location.host) >= 0) {
          href = removeAfter(removeAfter(href, '?'), '#')
e6ec151e   Geoffrey PREUD'HOMME   Ensure only corre...
9
          hrefE = href.split('/')
e6ec151e   Geoffrey PREUD'HOMME   Ensure only corre...
10
11
12
13
14
          return hrefE[hrefE.length - 1]
      }
      return false
  }
  
dcc55bea   Geoffrey PREUD'HOMME   Minor cleanup nav...
15
  function pageSpecific(location) {
e6ec151e   Geoffrey PREUD'HOMME   Ensure only corre...
16
      if (pageName(location) == 'contact') {
dcc55bea   Geoffrey PREUD'HOMME   Minor cleanup nav...
17
18
19
20
21
          initializeMap()
      }
  }
  
  function actLink(ev) {
8485d451   Geoffrey PREUD'HOMME   New dynamic JS nav
22
      var location = ev.currentTarget.href
e6ec151e   Geoffrey PREUD'HOMME   Ensure only corre...
23
24
      var page = pageName(location)
      if (page && page != pageName(window.location.href)) {
d6489a75   Geoffrey PREUD'HOMME   History working w...
25
26
27
28
29
          loadDoc(location, function () {
              history.pushState({
                  loc: location
              }, document.title, location)
          })
8485d451   Geoffrey PREUD'HOMME   New dynamic JS nav
30
31
          return false
      }
7ab7e900   Jean Wasilewski   file function added
32
33
  }
  
8485d451   Geoffrey PREUD'HOMME   New dynamic JS nav
34
  function dynamiseLinks(el) {
dcc55bea   Geoffrey PREUD'HOMME   Minor cleanup nav...
35
      $("a", el).click(actLink)
8485d451   Geoffrey PREUD'HOMME   New dynamic JS nav
36
37
  }
  
be816fc8   Geoffrey PREUD'HOMME   Removed extra par...
38
  function loadDoc(location, callback) {
d6489a75   Geoffrey PREUD'HOMME   History working w...
39
      if (!callback) {
ae5ad01d   Geoffrey PREUD'HOMME   Animations !
40
          callback = function () {
d6489a75   Geoffrey PREUD'HOMME   History working w...
41
42
43
              return undefined
          }
      }
ae5ad01d   Geoffrey PREUD'HOMME   Animations !
44
45
46
47
48
49
50
51
52
53
      var eventsLeft = 2
      var html = ''
  
      function events() {
          eventsLeft += -1
          if (eventsLeft <= 0) {
              mainContainer.html(html)
              dynamiseLinks(mainContainer)
              pageSpecific(location)
              mainContainer.animate({
30f612bf   Geoffrey PREUD'HOMME   Remove your tests...
54
                  height: "toggle",
ae5ad01d   Geoffrey PREUD'HOMME   Animations !
55
56
                  opacity: 1
              })
ae5ad01d   Geoffrey PREUD'HOMME   Animations !
57
58
59
60
61
              callback()
          }
      }
      var mainContainer = $("#mainContainer")
      mainContainer.animate({
30f612bf   Geoffrey PREUD'HOMME   Remove your tests...
62
          height: "toggle",
ae5ad01d   Geoffrey PREUD'HOMME   Animations !
63
64
          opacity: 0
      }, 'fast', events)
dcc55bea   Geoffrey PREUD'HOMME   Minor cleanup nav...
65
      $.get(location + '?c', function (data) {
ae5ad01d   Geoffrey PREUD'HOMME   Animations !
66
67
          html = data
          events()
dcc55bea   Geoffrey PREUD'HOMME   Minor cleanup nav...
68
69
      })
  
b8d34eaa   Geoffrey PREUD'HOMME   Moved map initial...
70
71
  }
  
d71b5167   Geoffrey PREUD'HOMME   Almost functionni...
72
73
74
75
  function historyChange(ev) {
      loadDoc(ev.state.loc)
  }
  
8485d451   Geoffrey PREUD'HOMME   New dynamic JS nav
76
77
  $(document).ready(function () {
      dynamiseLinks(document)
b8d34eaa   Geoffrey PREUD'HOMME   Moved map initial...
78
      pageSpecific(window.location.href)
d71b5167   Geoffrey PREUD'HOMME   Almost functionni...
79
      window.onpopstate = historyChange
b8d34eaa   Geoffrey PREUD'HOMME   Moved map initial...
80
81
82
83
84
85
86
87
88
89
90
91
92
  })
  
  function initializeMap() {
      var mapCanvas = document.getElementById('map-canvas');
      mapCanvas.innerHTML = ''
      var polytechPos = new google.maps.LatLng(50.6074998, 3.1373338);
      var mapOptions = {
          center: polytechPos,
          zoom: 16,
          mapTypeId: google.maps.MapTypeId.ROADMAP
      }
      var map = new google.maps.Map(mapCanvas, mapOptions)
      var marker = new google.maps.Marker({
16450111   Geoffrey PREUD'HOMME   Popup Window on map
93
94
95
96
97
98
99
100
          place: {
              location: polytechPos,
              query: "Polytech Lille"
          },
          attribution: {
              source: "Coupe de Robotique des Écoles Primaires",
              webUrl: window.location.host
          },
b8d34eaa   Geoffrey PREUD'HOMME   Moved map initial...
101
102
          map: map,
          title: "Polytech Lille"
16450111   Geoffrey PREUD'HOMME   Popup Window on map
103
104
105
106
107
108
109
      })
      var infowindow = new google.maps.InfoWindow({
          content: "<strong>Polytech Lille</strong><br/>Lieux des évènements de la Coupe de Robotique des Écoles Primaires"
      })
      marker.addListener('click', function () {
          infowindow.open(map, this)
      })
b8d34eaa   Geoffrey PREUD'HOMME   Moved map initial...
110
  }