-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
245 lines (196 loc) · 6.73 KB
/
index.html
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
<html>
<head>
<script type='text/javascript' src='./lib/jquery.js' ></script>
<script type='text/javascript' src='./lib/jquery-ui.js' ></script>
<script type='text/javascript' src='./lib/jquery-ui-timepicker.js' ></script>
<link type='text/css' rel='stylesheet' href='./lib/jquery-theme/smoothness/jquery-ui-1.8.7.custom.css' />
<link type='text/css' rel='stylesheet' href='./lib/jquery-theme/jquery-timepicker.css' />
<script type='text/javascript' src='./js/date.js' ></script>
<script type='text/javascript' src='./js/reittiopas.js' ></script>
<script type='text/javascript' src='./js/reittiopas-hsl.js' ></script>
<link type='text/css' rel='stylesheet' href='./style.css' />
</head>
<body>
<span class='logo'>Perille</span> – next generation Reittiopas
<div id='entrypane' class='wrapper'>
<div id='results'>
</div>
<div class='entry'>
<input id='from' class='address-entry' />
<span class='button geolocation right'>My location</span>
</div>
<div class='entry'>
<input id='to' class='address-entry' />
<span class='button geolocation right'>My location</span>
</div>
<div class='entry'>
<input id='date' size='10' />
<input id='time' size='5' />
<span id='mode-selection' class='right'>
<input type="radio" id="mode-selection-arrive" name="mode-selection-radio" value='arrival' /><label for="mode-selection-arrive">Arrive</label>
<input type="radio" id="mode-selection-leave" name="mode-selection-radio" value='departure' checked="checked" /><label for="mode-selection-leave">Leave</label>
</span>
</div>
<div class='entry'>
<span id='search' class='button'>Make it so</span>
</div>
<script type='text/javascript'>
// human error
function error(msg){
var div = $('<div>');
div.html( msg );
div.dialog({
modal: true,
buttons: {
Ok: function() {
$( this ).dialog( "close" );
}
}
});
}
// rotate certain text in given field
function rotateText( field, text ) {
var ii = 0;
var timer = setInterval( function() {
var i = ii % text.length;
var temp = text.slice(0, i) + '|' + text.slice(i + 1, text.length);
field.val(temp);
ii++;
} , 250 );
return timer;
}
// buttonize all buttons
$('.button').button();
$('#mode-selection').buttonset();
$('document').ready( function() {
// initialize hsl (set up correct values for mapping)
hsl.init();
var now = new Date();
$('#date').datepicker( {
dateFormat : 'dd.mm.yy'
} );
$('#date').val( now.date() + '.' + now.month() + '.' + now.year() );
$('#time').timepicker();
$('#time').val( now.hours() + ':' + now.minutes() );
$('#back').click( function(){
$('#entrypane').show('drop', 'slow');
$('#resultpane').hide();
});
// end ready
} );
$('.address-entry').keyup( function() {
var t = $(this);
var address = t.val();
// only search when there are 3 or more characters
if( address.length < 3 ) { return; }
reittiopas.address_to_location( address , function(data) {
// case when only one response comes from server => put directly to display
if( data.length == 1 ) {
t.val( data[0].name );
t.data('location', data[0].coords );
} else {
// hack
var temp = data.map( function(data) {
return { label: data.name, coords: data.coords };
} );
t.autocomplete( 'option', 'source', temp );
}
} );
} );
$('.address-entry').autocomplete( {
minLenght : 3,
select: function(event, ui) {
$(this).data('location', ui.item.coords );
}
} );
// geolocation when pressed
$('.geolocation').click( function() {
var button = $(this);
var field = button.parent().find('.address-entry');
var timer = rotateText( field, 'Searching' );
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(
function(position){
reittiopas.location_to_address( position.coords.latitude, position.coords.longitude, function(json) {
clearInterval( timer );
field.val( json[0].name );
field.data('location', json[0].coords );
}); },
function(){
clearInterval( timer );
error( 'Geeez! I can\'t figure out where you are. You\'re on your own now! Sorry :(');
$('.geolocation').button('disable');
}
);
} else {
clearInterval( timer );
error( 'Your browser doesn\'t support geolocation. Try to update your browser!' );
$('.geolocation').button('disable');
}
} );
$('#search').click( function() {
// get the selected time variables
var date = $('#date').val().split('.');
var time = $('#time').val().split(':');
date = date.map( function(a,b) { return parseInt( a , 10 ); } );
time = time.map( function(a,b) { return parseInt( a , 10 ); } );
var searchDate = new Date( date[2] , date[1], date[0], time[0], time[1], 0, 0 );
var mode = $('input:radio[name=mode-selection-radio]:checked').val();
reittiopas.route( $('#from').data('location'), $('#to').data('location'), searchDate, mode, function(response) {
$('#wait-icon').hide('explode');
$('#resultpane').show('drop', 'slow');
$.each( response, function( i, route ) {
var item = $('<li>');
var end = hsl.decode( route[0].legs[ route[0].legs.length - 1 ] )
var start = hsl.decode( route[0].legs[0] );
item.html( start.first.time.toString() + '-' + end.last.time.toString() );
var parts = $('<ol>');
var coords = [];
$.each( route[0].legs , function(i, leg) {
leg = hsl.decode( leg );
var detailView = '<span class="detail">' + leg.first.name + ' @ ' + leg.first.time.toString() + ' - ' + leg.last.name + ' @ ' + leg.last.time.toString() + '</span>';
parts.append( '<li>' + leg.type + ' ' + leg.code + ' ' + detailView + '</li>' );
coords.push( leg.first.location );
} );
item.append( parts );
item.hover( function() {
$(this).find('.detail').fadeIn();
// clear content
$('#route-images').html('');
$.each( coords , function() {
var data = $(this);
data = data[0];
var img = $('<img>');
img.height('100px');
img.attr( 'src' , 'http://perille.mante.li/streetimage/image.php?latitude=' + data.x + '&longitude=' + data.y );
$('#route-images').append( img );
console.log( img );
} );
}, function() {
$(this).find('.detail').fadeOut();
} );
$('#routes').append( item );
} );
} );
$('#entrypane').hide('drop');
$('#wait-icon').show();
$('#wait-icon').effect('pulsate');
} );
</script>
</div>
<div id='wait-icon' style='background: blue; position: absolute; top: 25%; left: 25%; width: 50px; height: 50px; display: none;'></div>
<div id='resultpane' style='display:none' class='wrapper'>
<span id='back' class='button' style='float: right;'>Go back!</span>
<div id='route-images' style='float: right; width: 25%;'>
</div>
<ul id='routes'>
</ul>
</div>
<div id='footer'>
Perille is a product by <a href="http://mante.li">Manteli Technologies</a>.
</div>
<script type='text/javascript'>
$('#footer').position( { my : 'bottom', at : 'bottom', of : $('body') } );
</script>
</body>
</html>