-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscripts.js
164 lines (144 loc) · 4.03 KB
/
scripts.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
// Google VR API script to swap out photos
var vrView;
var browserHeight = $(window).height();
var carouselHeight = $('.carousel').height();
var thumbnailWidth = 150 + 16;
// All the scenes for the experience
// To add a photo, you must include a title feild, a link to the 360 photo in the
// image feild, and a thumbnail of the VR Photo
var scenes = [
{
title: 'Marine Drive',
image: 'images/marine-drive.jpg',
thumbnail: 'images/marine-drive-thumb.jpg'
},
{
title: 'Mosquito Field',
image: 'images/mosquito-field.jpg',
thumbnail: 'images/mosquito-field-thumb.jpg'
},
{
title: 'Museum of Anthropology',
image: 'images/moa.jpg',
thumbnail: 'images/moa-thumb.jpg'
},
{
title: 'Wreck Beach',
image: 'images/wreck-beach.jpg',
thumbnail: 'images/wreck-beach-thumb.jpg'
},
{
title: 'AMS Nest',
image: 'images/nest.jpg',
thumbnail: 'images/nest-thumb.jpg'
},
{
title: 'Nitobe Garden',
image: 'images/nitobe.jpg',
thumbnail: 'images/nitobe-thumb.jpg'
},
{
title: 'Tower Beach Stairs',
image: 'images/tower-beach.jpg',
thumbnail: 'images/tower-beach-thumb.jpg'
},
{
title: 'Pacific Spirit Park',
image: 'images/pacific-spirit.jpg',
thumbnail: 'images/pacific-spirit-thumb.jpg'
}
];
var activeScene = 0;
function renderCarousel() {
var carousel = $('.carousel');
scenes.forEach(function(scene, i) {
var item = $('<li></li>');
var image = $('<img />');
image.attr('src', scene.thumbnail);
var tooltip = $('<span></span>');
tooltip.addClass('tooltiptext');
tooltip.text(scene.title);
item.append(image);
item.append(tooltip);
item.data('i', i);
if (activeScene == i) {
item.addClass('current');
}
carousel.append(item);
});
}
function onLoad() {
vrView = new VRView.Player('#vrview', {
width: '100%',
height: browserHeight,
image: 'images/marine-drive.jpg',
is_stereo: false,
is_autopan_off: true
});
vrView.on('ready', onVRViewReady);
vrView.on('modechange', onModeChange);
vrView.on('error', onVRViewError);
}
function loadScene(id) {
// Set the image
vrView.setContent({
image: scenes[id].image,
//preview: scenes[id].preview,
is_autopan_off: true
});
}
//Will allow the gallery to slide when the width of the window is less than 800 pixels
function mobileResize() {
var windowWidth = $(window).width();
if(windowWidth < 800){
var carouselOffset = (thumbnailWidth * activeScene) + (thumbnailWidth / 2);
$('ul.carousel').css('margin-left', -carouselOffset);
$('.Gallery').css('left', '50%');
$(document).on('click', 'ul.carousel li', function(e) {
$('.Gallery').css('left', '50%');
e.preventDefault();
var i = $(this).data('i');
activeScene = i;
loadScene(i);
var carouselOffset = (thumbnailWidth * i) + (thumbnailWidth / 2);
$('ul.carousel').css('margin-left', -carouselOffset);
$('ul.carousel li').removeClass('current');
$(this).addClass('current');
});
}
else {
$('.Gallery').css('text-align', 'center');
$('ul.carousel').css('text-align', 'center');
$('ul.carousel li').css('display', 'inline-block');
$(document).on('click', 'ul.carousel li', function(e) {
e.preventDefault();
var i = $(this).data('i');
activeScene = i;
loadScene(i);
$('ul.carousel li').removeClass('current');
$(this).addClass('current');
});
}
}
function onVRViewReady(e) {
console.log('onVRViewReady');
mobileResize();
}
function onModeChange(e) {
console.log('onModeChange', e.mode);
}
function onVRViewError(e) {
console.log('Error! %s', e.message);
}
window.addEventListener('load', onLoad);
//Will change the carousel's dimensions and the VR view's dimensions when the window is resized
$(function () {
renderCarousel();
$( window ).resize(function() {
browserHeight = $(window).height();
carouselHeight = $('.carousel').height();
$( "#vrview" ).css( {width: '100%',
height: browserHeight});
mobileResize();
});
});