From 6b7854065340b62bc6aa69d7cde86cf1d5e26dad Mon Sep 17 00:00:00 2001 From: Erik Michaels-Ober Date: Mon, 28 Feb 2011 21:11:07 -0800 Subject: [PATCH] Optimize --- app/views/layouts/application.html.erb | 36 ++++++++++++++------------ 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 80ac60e..b1ccb20 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -16,19 +16,10 @@ mapTypeId: google.maps.MapTypeId.ROADMAP }; map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); - var redMarker = '/images/markers/red.png'; var greenMarker = '/images/markers/green.png'; -<% @hydrants.each do |hydrant| %> - <% if user = hydrant.user %> - <% require 'digest/md5' %> - <% hash = Digest::MD5.hexdigest(user.email) %> - var contentString = '\ -

Adopted by <%= hydrant.user.name %>

\ -Email a reminder to shovel\ -' - <% else %> - var contentString = '\ + var openInfoWindow; + var formString = '\
\

Adopt this Hydrant

\ <%= form_tag do %>\ @@ -66,21 +57,32 @@ <% end %>\
\ '; +<% @hydrants.each do |hydrant| %> + <% if user = hydrant.user %> + <% require 'digest/md5' %> + <% hash = Digest::MD5.hexdigest(user.email) %> + var contentString = '\ +

Adopted by <%= hydrant.user.name %>

\ +Email a reminder to shovel\ +' + <% else %> + var contentString = formString; <% end %> - var h<%= hydrant.id %>InfoWindow = new google.maps.InfoWindow({ - content: contentString - }); var h<%= hydrant.id %>LatLng = new google.maps.LatLng(<%= hydrant.lat %>, <%= hydrant.lng %>); var h<%= hydrant.id %>Marker = new google.maps.Marker({ position: h<%= hydrant.id %>LatLng, map: map, icon: <%= hydrant.user_id ? "greenMarker" : "redMarker" %> }); + var h<%= hydrant.id %>InfoWindow = new google.maps.InfoWindow({ + content: contentString + }); google.maps.event.addListener(h<%= hydrant.id %>Marker, 'click', function() { - <% @hydrants.each do |hydrant| %> - h<%= hydrant.id %>InfoWindow.close(); - <% end %> + if(openInfoWindow) { + openInfoWindow.close(); + } h<%= hydrant.id %>InfoWindow.open(map, h<%= hydrant.id %>Marker); + openInfoWindow = h<%= hydrant.id %>InfoWindow; }); <% end %> $('.box input[type="radio"]').live('click', function() {