Blame view

js/crep.js 1.89 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
40
41
42
43
      if (!callback) {
          callaback = function () {
              return undefined
          }
      }
dcc55bea   Geoffrey PREUD'HOMME   Minor cleanup nav...
44
45
46
      $.get(location + '?c', function (data) {
          mainContainer = $("#mainContainer")
          mainContainer.html(data)
dcc55bea   Geoffrey PREUD'HOMME   Minor cleanup nav...
47
48
          dynamiseLinks(mainContainer)
          pageSpecific(location)
d6489a75   Geoffrey PREUD'HOMME   History working w...
49
          callback()
dcc55bea   Geoffrey PREUD'HOMME   Minor cleanup nav...
50
51
      })
  
b8d34eaa   Geoffrey PREUD'HOMME   Moved map initial...
52
53
  }
  
d71b5167   Geoffrey PREUD'HOMME   Almost functionni...
54
55
56
57
  function historyChange(ev) {
      loadDoc(ev.state.loc)
  }
  
8485d451   Geoffrey PREUD'HOMME   New dynamic JS nav
58
59
  $(document).ready(function () {
      dynamiseLinks(document)
b8d34eaa   Geoffrey PREUD'HOMME   Moved map initial...
60
      pageSpecific(window.location.href)
d71b5167   Geoffrey PREUD'HOMME   Almost functionni...
61
      window.onpopstate = historyChange
b8d34eaa   Geoffrey PREUD'HOMME   Moved map initial...
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
  })
  
  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"
      });
  }