crep.js
1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
function removeAfter(string, pattern) {
var n = string.indexOf(pattern);
return string.substring(0, n != -1 ? n : string.length);
}
function pageName(href) {
if (href.indexOf(window.location.host) >= 0) {
href = removeAfter(removeAfter(href, '?'), '#')
hrefE = href.split('/')
return hrefE[hrefE.length - 1]
}
return false
}
function pageSpecific(location) {
if (pageName(location) == 'contact') {
initializeMap()
}
}
function actLink(ev) {
var location = ev.currentTarget.href
var page = pageName(location)
if (page && page != pageName(window.location.href)) {
loadDoc(location, function () {
history.pushState({
loc: location
}, document.title, location)
})
return false
}
}
function dynamiseLinks(el) {
$("a", el).click(actLink)
}
function loadDoc(location, callback) {
if (!callback) {
callaback = function () {
return undefined
}
}
$.get(location + '?c', function (data) {
mainContainer = $("#mainContainer")
mainContainer.html(data)
dynamiseLinks(mainContainer)
pageSpecific(location)
callback()
})
}
function historyChange(ev) {
loadDoc(ev.state.loc)
}
$(document).ready(function () {
dynamiseLinks(document)
pageSpecific(window.location.href)
window.onpopstate = historyChange
})
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"
});
}