Blame view

js/crep.js 1.97 KB
e6ec151e   Geoffrey PREUD'HOMME   Ensure only corre...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
  function removeAfter(string, pattern) {
      var n = string.indexOf(pattern);
      return string.substring(0, n != -1 ? n : string.length);
  }
  
  function pageName(href) {
      console.debug(href)
      if (href.indexOf(window.location.host) >= 0) {
          href = removeAfter(removeAfter(href, '?'), '#')
          console.debug(href)
          hrefE = href.split('/')
          console.debug(hrefE)
          return hrefE[hrefE.length - 1]
      }
      return false
  }
  
dcc55bea   Geoffrey PREUD'HOMME   Minor cleanup nav...
18
  function pageSpecific(location) {
e6ec151e   Geoffrey PREUD'HOMME   Ensure only corre...
19
      if (pageName(location) == 'contact') {
dcc55bea   Geoffrey PREUD'HOMME   Minor cleanup nav...
20
21
22
23
24
          initializeMap()
      }
  }
  
  function actLink(ev) {
8485d451   Geoffrey PREUD'HOMME   New dynamic JS nav
25
      var location = ev.currentTarget.href
e6ec151e   Geoffrey PREUD'HOMME   Ensure only corre...
26
27
      var page = pageName(location)
      if (page && page != pageName(window.location.href)) {
d6489a75   Geoffrey PREUD'HOMME   History working w...
28
29
30
31
32
          loadDoc(location, function () {
              history.pushState({
                  loc: location
              }, document.title, location)
          })
8485d451   Geoffrey PREUD'HOMME   New dynamic JS nav
33
34
          return false
      }
7ab7e900   Jean Wasilewski   file function added
35
36
  }
  
8485d451   Geoffrey PREUD'HOMME   New dynamic JS nav
37
  function dynamiseLinks(el) {
dcc55bea   Geoffrey PREUD'HOMME   Minor cleanup nav...
38
      $("a", el).click(actLink)
8485d451   Geoffrey PREUD'HOMME   New dynamic JS nav
39
40
  }
  
be816fc8   Geoffrey PREUD'HOMME   Removed extra par...
41
  function loadDoc(location, callback) {
d6489a75   Geoffrey PREUD'HOMME   History working w...
42
43
44
45
46
      if (!callback) {
          callaback = function () {
              return undefined
          }
      }
dcc55bea   Geoffrey PREUD'HOMME   Minor cleanup nav...
47
48
49
      $.get(location + '?c', function (data) {
          mainContainer = $("#mainContainer")
          mainContainer.html(data)
dcc55bea   Geoffrey PREUD'HOMME   Minor cleanup nav...
50
51
          dynamiseLinks(mainContainer)
          pageSpecific(location)
d6489a75   Geoffrey PREUD'HOMME   History working w...
52
          callback()
dcc55bea   Geoffrey PREUD'HOMME   Minor cleanup nav...
53
54
      })
  
b8d34eaa   Geoffrey PREUD'HOMME   Moved map initial...
55
56
  }
  
d71b5167   Geoffrey PREUD'HOMME   Almost functionni...
57
58
59
60
  function historyChange(ev) {
      loadDoc(ev.state.loc)
  }
  
8485d451   Geoffrey PREUD'HOMME   New dynamic JS nav
61
62
  $(document).ready(function () {
      dynamiseLinks(document)
b8d34eaa   Geoffrey PREUD'HOMME   Moved map initial...
63
      pageSpecific(window.location.href)
d71b5167   Geoffrey PREUD'HOMME   Almost functionni...
64
      window.onpopstate = historyChange
b8d34eaa   Geoffrey PREUD'HOMME   Moved map initial...
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
  })
  
  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({
          position: polytechPos,
          map: map,
          title: "Polytech Lille"
      });
  }