Blame view

js/crep.js 2.32 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
54
55
56
57
58
59
60
61
62
63
64
65
      var eventsLeft = 2
      var html = ''
  
      function events() {
          eventsLeft += -1
          if (eventsLeft <= 0) {
              mainContainer.html(html)
              dynamiseLinks(mainContainer)
              pageSpecific(location)
              mainContainer.animate({
                  height: "toggle",
                  opacity: 1
              })
              console.debug(callback)
              callback()
          }
      }
      var mainContainer = $("#mainContainer")
      mainContainer.animate({
          height: "toggle",
          opacity: 0
      }, 'fast', events)
dcc55bea   Geoffrey PREUD'HOMME   Minor cleanup nav...
66
      $.get(location + '?c', function (data) {
ae5ad01d   Geoffrey PREUD'HOMME   Animations !
67
68
          html = data
          events()
dcc55bea   Geoffrey PREUD'HOMME   Minor cleanup nav...
69
70
      })
  
b8d34eaa   Geoffrey PREUD'HOMME   Moved map initial...
71
72
  }
  
d71b5167   Geoffrey PREUD'HOMME   Almost functionni...
73
74
75
76
  function historyChange(ev) {
      loadDoc(ev.state.loc)
  }
  
8485d451   Geoffrey PREUD'HOMME   New dynamic JS nav
77
78
  $(document).ready(function () {
      dynamiseLinks(document)
b8d34eaa   Geoffrey PREUD'HOMME   Moved map initial...
79
      pageSpecific(window.location.href)
d71b5167   Geoffrey PREUD'HOMME   Almost functionni...
80
      window.onpopstate = historyChange
b8d34eaa   Geoffrey PREUD'HOMME   Moved map initial...
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
  })
  
  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"
      });
  }