-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathmain.js
96 lines (73 loc) · 2.49 KB
/
main.js
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
(function () {
'use strict';
var conf = {};
// Init functions, called on DOMContentLoaded event
conf.init = function () {
conf.map.init($('#map-canvas'));
conf.menu.init();
};
/***
Google Maps implementation
***/
conf.map = {
marker: '/static/img/marker-default.png'
};
// Google Maps configs
conf.map.init = function ($element) {
conf.map.element = $element;
conf.map.geocoder = new google.maps.Geocoder();
conf.map.latlng = new google.maps.LatLng(0, 0);
conf.map.options = {
zoom: 16,
center: conf.map.latlng,
scrollwheel: false,
streetViewControl: true,
labels: true,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
conf.map.canvas = new google.maps.Map(conf.map.element.get(0), conf.map.options);
conf.map.canvas.setCenter(conf.map.latlng);
conf.map.createMarker();
};
conf.map.createMarker = function () {
conf.map.address = conf.map.element.attr('data-address');
conf.map.geocoder.geocode({ 'address': conf.map.address}, function (results, status) {
if (status === google.maps.GeocoderStatus.OK) {
conf.map.canvas.setCenter(results[0].geometry.location);
new google.maps.Marker({
map: conf.map.canvas,
position: results[0].geometry.location,
icon: conf.map.marker
});
} else {
if (window.console) {
console.log('Google Maps was not loaded: ', status);
}
}
});
};
/***
Create animated scroll for menu links
***/
conf.menu = {
itemsSelector: '.nav-link[href^="#"]',
animationSpeed: 400
};
conf.menu.init = function () {
conf.menu.menuItems = $(conf.menu.itemsSelector);
conf.menu.document = $('html, body');
conf.menu.menuItems.on('click.animateScroll', function (event) {
event.preventDefault();
conf.menu.animateTo(event.target);
});
};
conf.menu.animateTo = function (link) {
var $link = $(link),
href = $link.attr('href'),
offSetTop = $(href).offset().top;
conf.menu.document.finish().animate({scrollTop : offSetTop}, conf.menu.animationSpeed, function () {
location.hash = href;
});
};
conf.init();
}());