Blame view

js/crep.js 3.86 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
  }
  
71b34f50   Geoffrey PREUD'HOMME   Navigation preser...
15
16
17
18
19
  function updateScrollData() {
      history.state.scrollTop = $(document.body).scrollTop()
      history.replaceState(history.state)
  }
  
dcc55bea   Geoffrey PREUD'HOMME   Minor cleanup nav...
20
  function pageSpecific(location) {
e6ec151e   Geoffrey PREUD'HOMME   Ensure only corre...
21
      if (pageName(location) == 'contact') {
dcc55bea   Geoffrey PREUD'HOMME   Minor cleanup nav...
22
23
          initializeMap()
      }
71b34f50   Geoffrey PREUD'HOMME   Navigation preser...
24
      $(document).scroll(updateScrollData)
dcc55bea   Geoffrey PREUD'HOMME   Minor cleanup nav...
25
26
  }
  
71b34f50   Geoffrey PREUD'HOMME   Navigation preser...
27
28
  
  
dcc55bea   Geoffrey PREUD'HOMME   Minor cleanup nav...
29
  function actLink(ev) {
8485d451   Geoffrey PREUD'HOMME   New dynamic JS nav
30
      var location = ev.currentTarget.href
e6ec151e   Geoffrey PREUD'HOMME   Ensure only corre...
31
32
      var page = pageName(location)
      if (page && page != pageName(window.location.href)) {
d6489a75   Geoffrey PREUD'HOMME   History working w...
33
34
35
36
37
          loadDoc(location, function () {
              history.pushState({
                  loc: location
              }, document.title, location)
          })
8485d451   Geoffrey PREUD'HOMME   New dynamic JS nav
38
39
          return false
      }
7ab7e900   Jean Wasilewski   file function added
40
41
  }
  
8485d451   Geoffrey PREUD'HOMME   New dynamic JS nav
42
  function dynamiseLinks(el) {
dcc55bea   Geoffrey PREUD'HOMME   Minor cleanup nav...
43
      $("a", el).click(actLink)
8485d451   Geoffrey PREUD'HOMME   New dynamic JS nav
44
45
  }
  
be816fc8   Geoffrey PREUD'HOMME   Removed extra par...
46
  function loadDoc(location, callback) {
d6489a75   Geoffrey PREUD'HOMME   History working w...
47
      if (!callback) {
ae5ad01d   Geoffrey PREUD'HOMME   Animations !
48
          callback = function () {
d6489a75   Geoffrey PREUD'HOMME   History working w...
49
50
51
              return undefined
          }
      }
ae5ad01d   Geoffrey PREUD'HOMME   Animations !
52
53
      var eventsLeft = 2
      var html = ''
0b2adb5b   Geoffrey PREUD'HOMME   Better animation
54
55
56
      var mainContainer = $("#mainContainer")
      var oldHeight = mainContainer.height()
  
ae5ad01d   Geoffrey PREUD'HOMME   Animations !
57
58
59
      function events() {
          eventsLeft += -1
          if (eventsLeft <= 0) {
0b2adb5b   Geoffrey PREUD'HOMME   Better animation
60
61
              // In
              //  Calculations
ae5ad01d   Geoffrey PREUD'HOMME   Animations !
62
              mainContainer.html(html)
0b2adb5b   Geoffrey PREUD'HOMME   Better animation
63
64
65
66
              mainContainer.height('auto')
              newHeight = mainContainer.height()
              mainContainer.height(oldHeight)
              //  Transition
ae5ad01d   Geoffrey PREUD'HOMME   Animations !
67
              mainContainer.animate({
0b2adb5b   Geoffrey PREUD'HOMME   Better animation
68
                  height: newHeight,
9186f728   Geoffrey PREUD'HOMME   Auto scroll top
69
                  opacity: 1,
0b2adb5b   Geoffrey PREUD'HOMME   Better animation
70
71
72
73
74
              }, 'fast', function () {
                  mainContainer.height('auto')
                  dynamiseLinks(mainContainer)
                  pageSpecific(location)
                  callback()
ae5ad01d   Geoffrey PREUD'HOMME   Animations !
75
              })
ae5ad01d   Geoffrey PREUD'HOMME   Animations !
76
77
          }
      }
0b2adb5b   Geoffrey PREUD'HOMME   Better animation
78
      // Out
71b34f50   Geoffrey PREUD'HOMME   Navigation preser...
79
80
81
82
      $(document).off('scroll', updateScrollData)
      $(document.body).animate({
          scrollTop: $('.navbar-lower').height()
      }, 'fast')
815cd881   Geoffrey PREUD'HOMME   Changed animation...
83
84
85
86
      $.get(location + '?c', function (data) {
          html = data
          events()
      })
0b2adb5b   Geoffrey PREUD'HOMME   Better animation
87
      mainContainer.height(oldHeight)
ae5ad01d   Geoffrey PREUD'HOMME   Animations !
88
      mainContainer.animate({
15d0e53c   Geoffrey PREUD'HOMME   Always remove you...
89
          opacity: 0
ae5ad01d   Geoffrey PREUD'HOMME   Animations !
90
      }, 'fast', events)
b8d34eaa   Geoffrey PREUD'HOMME   Moved map initial...
91
92
  }
  
d71b5167   Geoffrey PREUD'HOMME   Almost functionni...
93
  function historyChange(ev) {
71b34f50   Geoffrey PREUD'HOMME   Navigation preser...
94
95
96
97
98
99
100
      loadDoc(ev.state.loc, function () {
          if (ev.state.scrollTop > $('.navbar-lower').height()) {
              $(document.body).animate({
                  scrollTop: ev.state.scrollTop
              }, 'fast')
          }
      })
d71b5167   Geoffrey PREUD'HOMME   Almost functionni...
101
102
  }
  
8485d451   Geoffrey PREUD'HOMME   New dynamic JS nav
103
  $(document).ready(function () {
71b34f50   Geoffrey PREUD'HOMME   Navigation preser...
104
105
106
107
108
109
      dynamiseLinks(document.body)
      var current = window.location.href
      pageSpecific(current)
      history.replaceState({
          loc: current
      }, document.title, current)
d71b5167   Geoffrey PREUD'HOMME   Almost functionni...
110
      window.onpopstate = historyChange
32bad9bd   Geoffrey PREUD'HOMME   Added navbar togg...
111
112
113
114
115
      $('.navbar-fixed-top .navbar-toggle').click(function () {
          $(document.body).animate({
              scrollTop: 0
          })
      })
b8d34eaa   Geoffrey PREUD'HOMME   Moved map initial...
116
117
118
119
120
121
122
123
124
125
126
127
128
  })
  
  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
129
130
131
132
133
134
135
136
          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...
137
138
          map: map,
          title: "Polytech Lille"
16450111   Geoffrey PREUD'HOMME   Popup Window on map
139
140
141
142
143
144
145
      })
      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...
146
  }