Skip to content
This repository has been archived by the owner on Mar 2, 2022. It is now read-only.

Commit

Permalink
seperated javascript from index into new file index.js
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Shapiro committed Jun 17, 2010
1 parent 9f0628c commit 4fa6f95
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 102 deletions.
108 changes: 6 additions & 102 deletions war/index.jsp
Expand Up @@ -25,58 +25,11 @@
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" src="/js/index.js"></script>
<script type="text/javascript">
var map;
var eventArray = new Array();
var eventDescription = $('#mn_eventDescription');
eventDescription.empty();
function changeDiscription(desc){
var eventDescription = $('#mn_eventDescription');
eventDescription.empty();
eventDescription.append(desc);
}
function topic_show(event_id){
changeDiscription("");
for (var i = 0; i < eventArray.length; i++){
if (event_id == -1) {
eventArray[i].marker.setVisible(true);
}
else{
if (eventArray[i].id == event_id){
eventArray[i].marker.setVisible(true);
changeDiscription(eventArray[i].description + '<br><br><a href="/Event?' + eventArray[i].id + '"> Group Page </a>');
} else {
eventArray[i].marker.setVisible(false);
}
}
}
}
function create_map(){
map = new google.maps.Map(document.getElementById("map_canvas"), {
zoom: 15,
center: new google.maps.LatLng(0,0),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
}
function use_everywhere(){
var event_object;
var bounds = new google.maps.LatLngBounds();
var events = $('#mn_geoListContext');
//create map
create_map();
function loadEvents(){
<%
String key = "empty";
Expand Down Expand Up @@ -131,61 +84,12 @@
}
%>
events.empty();
$.each(data.results, function(i, ev) {
if (ev.lon != ''){
random_offset = (2*Math.random() - 1)/500;
random_offset2 = (2*Math.random() - 1)/500;
//create new point for each event and extend map bounds to include it
point = new google.maps.LatLng(parseFloat(ev.lat) + random_offset, parseFloat(ev.lon) + random_offset2);
bounds.extend(point);
var marker = new google.maps.Marker({
position: point,
map: map,
title: ev.container.name,
});
var date = new Date(ev.time);
var date_string = date.getMonth() + "/" + date.getDate() + "/" + date.getFullYear() + " " + date.getHours() + ":";
if (date.getMinutes() < 10) {
date_string = date_string + "0" + date.getMinutes();
} else{
date_string = date_string + date.getMinutes();
}
events.append('<a href="javascript:topic_show(' + ev.id + ')" class="mn_geoListItem_link"><span class="mn_geoListItem"><span class="mn_geoListItem_date"> ' + date_string + ' </span><span class="mn_geoListItem_where"> ' + ev.city + ' </span><span class="mn_geoListItem_title"> ' + ev.container.name + ' </span></span></a>');
//provide link for each point with event info
google.maps.event.addListener(marker, 'click', function() {
var link = '<b><a href="' + ev.meetup_url + '" style="color:Blue">' + ev.container.name + '</a></b><br>WHERE: ' + ev.venue_name + '<br>WHEN: ' + date_string + '<br>';
var win = new google.maps.InfoWindow({
content: link,
});
win.open(map, marker);
});
event_object = new Object;
event_object.id = ev.id;
event_object.description = ev.description;
event_object.marker = marker;
eventArray.push(event_object);
}
});
events.append('<a href="javascript:topic_show(-1)" class="mn_geoListItem_link"><span class="mn_geoListItem"><span class="mn_geoListItem_date"> Show All </span><span class="mn_geoListItem_where"> </span><span class="mn_geoListItem_title"> </span></span></a>');
//fit map and set loc to adress
map.fitBounds(bounds);
}
use_everywhere(data);
}
</script>
</head>
<body id="meetupNowBody" onload="use_everywhere()">
<body id="meetupNowBody" onload="loadEvents()">

<div id="mew_header">
<div id="mew_headerBody">
Expand Down
117 changes: 117 additions & 0 deletions war/js/index.js
@@ -0,0 +1,117 @@

var map;
var eventArray = new Array();
var eventDescription = $('#mn_eventDescription');


//set description to any string
function changeDiscription(desc){
var eventDescription = $('#mn_eventDescription');
eventDescription.empty();
eventDescription.append(desc);
}

//shows only one topic on map and gives its descriptions and links on the side
//if event_id = -1 then shows all and no description or links
function topic_show(event_id){
changeDiscription("");
for (var i = 0; i < eventArray.length; i++){
if (event_id == -1) {
eventArray[i].marker.setVisible(true);
}
else{
if (eventArray[i].id == event_id){
eventArray[i].marker.setVisible(true);
changeDiscription(eventArray[i].description + '<br><br><a href="/Event?' + eventArray[i].id + '"> Event Page </a><br><a href="/Group?' + eventArray[i].cont_id + '"> Group Page </a>');


} else {
eventArray[i].marker.setVisible(false);
}
}

}

}

//creates new google map
function create_map(){
map = new google.maps.Map(document.getElementById("map_canvas"), {
zoom: 15,
center: new google.maps.LatLng(0,0),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
}

//populates map and list with events
function use_everywhere(data){
var event_object;
var bounds = new google.maps.LatLngBounds();

var events = $('#mn_geoListContext');

//create map
create_map();

//clear events
events.empty();
$.each(data.results, function(i, ev) {
if (ev.lon != ''){

random_offset = (2*Math.random() - 1)/1000;
random_offset2 = (2*Math.random() - 1)/1000;

//create new point for each event and extend map bounds to include it
point = new google.maps.LatLng(parseFloat(ev.lat) + random_offset, parseFloat(ev.lon) + random_offset2);
bounds.extend(point);

//creat marker for point
var marker = new google.maps.Marker({
position: point,
map: map,
title: ev.container.name,
});

//epoc time to date string
var date = new Date(ev.time);
var date_string = date.getMonth() + "/" + date.getDate() + "/" + date.getFullYear() + " " + date.getHours() + ":";
if (date.getMinutes() < 10) {
date_string = date_string + "0" + date.getMinutes();
} else{
date_string = date_string + date.getMinutes();
}

//add event to list
events.append('<a href="javascript:topic_show(' + ev.id + ')" class="mn_geoListItem_link"><span class="mn_geoListItem"><span class="mn_geoListItem_date"> ' + date_string + ' </span><span class="mn_geoListItem_where"> ' + ev.city + ' </span><span class="mn_geoListItem_title"> ' + ev.container.name + ' </span></span></a>');

//provide link for each point with event info
google.maps.event.addListener(marker, 'click', function() {

var link = '<b><a href="' + ev.meetup_url + '" style="color:Blue">' + ev.container.name + '</a></b><br>WHERE: ' + ev.venue_name + '<br>WHEN: ' + date_string + '<br>';

var win = new google.maps.InfoWindow({
content: link,
});
win.open(map, marker);
});

//create event object
event_object = new Object;
event_object.id = ev.id;
event_object.description = ev.description;
event_object.marker = marker;
event_object.cont_id = ev.container.id;

//push object onto array
eventArray.push(event_object);
}
});

//add a show all option to list of events
events.append('<a href="javascript:topic_show(-1)" class="mn_geoListItem_link"><span class="mn_geoListItem"><span class="mn_geoListItem_date"> Show All </span><span class="mn_geoListItem_where"> </span><span class="mn_geoListItem_title"> </span></span></a>');

//fit map and set loc to adress
map.fitBounds(bounds);

}

0 comments on commit 4fa6f95

Please sign in to comment.