Move user JS to page-specific script file
In this case it was difficult to eliminate interpolation in a separate step, so I didn't bother.
This commit is contained in:
parent
4f552430b4
commit
dd1ec4eb9b
6 changed files with 97 additions and 104 deletions
45
app/assets/javascripts/user.js
Normal file
45
app/assets/javascripts/user.js
Normal file
|
@ -0,0 +1,45 @@
|
|||
function init(){
|
||||
var params = $("#map").data();
|
||||
var map = createMap("map");
|
||||
|
||||
setMapCenter(new OpenLayers.LonLat(params.lon, params.lat), params.zoom);
|
||||
|
||||
if ($("#map").hasClass("set_location")) {
|
||||
var marker;
|
||||
|
||||
if (params.marker) {
|
||||
marker = addMarkerToMap(new OpenLayers.LonLat(params.lon, params.lat));
|
||||
}
|
||||
|
||||
map.events.register("click", map, function (e) {
|
||||
closeMapPopup();
|
||||
|
||||
if (document.getElementById('updatehome').checked) {
|
||||
var lonlat = getEventPosition(e);
|
||||
|
||||
document.getElementById('homerow').className = '';
|
||||
document.getElementById('home_lat').value = lonlat.lat;
|
||||
document.getElementById('home_lon').value = lonlat.lon;
|
||||
|
||||
if (marker) {
|
||||
removeMarkerFromMap(marker);
|
||||
}
|
||||
|
||||
marker = addMarkerToMap(lonlat);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
addMarkerToMap(new OpenLayers.LonLat(params.lon, params.lat), null, params.marker.description);
|
||||
|
||||
$("[data-user]").each(function () {
|
||||
var user = $(this).data('user');
|
||||
if (user.lon && user.lat) {
|
||||
var icon = OpenLayers.Marker.defaultIcon();
|
||||
icon.url = OpenLayers.Util.getImageLocation(user.icon);
|
||||
addMarkerToMap(new OpenLayers.LonLat(user.lon, user.lat), icon, user.description);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
window.onload = init;
|
|
@ -1,7 +1,15 @@
|
|||
<tr>
|
||||
<td rowspan="3">
|
||||
<%
|
||||
user_data = {
|
||||
:lon => contact.home_lon,
|
||||
:lat => contact.home_lat,
|
||||
:icon => type == "friend" ? "marker-blue.png" : "marker-green.png",
|
||||
:description => render(:partial => "popup", :object => contact, :locals => {:type => type})
|
||||
}
|
||||
%>
|
||||
<%= content_tag "td", :rowspan => 3, :data => {:user => user_data} do %>
|
||||
<%= user_thumbnail contact %>
|
||||
</td>
|
||||
<% end %>
|
||||
<td>
|
||||
<%= link_to h(contact.display_name), :controller => 'user', :action => 'view', :display_name => contact.display_name %>
|
||||
<% if @this_user.home_lon and @this_user.home_lat and contact.home_lon and contact.home_lat %>
|
||||
|
|
|
@ -1,91 +0,0 @@
|
|||
<%
|
||||
if @user.home_lat.nil? or @user.home_lon.nil?
|
||||
lon = h(params['lon'] || '0')
|
||||
lat = h(params['lat'] || '20')
|
||||
zoom = h(params['zoom'] || '1')
|
||||
else
|
||||
marker = true
|
||||
mlon = @user.home_lon
|
||||
mlat = @user.home_lat
|
||||
lon = @user.home_lon
|
||||
lat = @user.home_lat
|
||||
zoom = '12'
|
||||
end
|
||||
%>
|
||||
|
||||
<script type="text/javascript">
|
||||
<!--
|
||||
var marker;
|
||||
|
||||
function init(){
|
||||
var centre = new OpenLayers.LonLat(<%= lon %>, <%= lat %>);
|
||||
<% if params[:scale].to_f > 0 then -%>
|
||||
var zoom = <%= scale_to_zoom params[:scale] %>;
|
||||
<% else -%>
|
||||
var zoom = <%= zoom %>;
|
||||
<% end -%>
|
||||
|
||||
var map = createMap("map");
|
||||
|
||||
setMapCenter(centre, zoom);
|
||||
|
||||
<% if marker %>
|
||||
marker = addMarkerToMap(
|
||||
new OpenLayers.LonLat(<%= mlon %>, <%= mlat %>)
|
||||
<% if not setting_location %>
|
||||
, null, '<%=escape_javascript(render(:partial => "popup", :object => @user, :locals => { :type => "your location" })) %>'
|
||||
<% end %>
|
||||
);
|
||||
<% end %>
|
||||
|
||||
<% if setting_location %>
|
||||
map.events.register("click", map, setHome);
|
||||
<% end %>
|
||||
|
||||
<% if show_other_users %>
|
||||
<% friends = @user.friends.collect { |f| f.befriendee }.select { |f| !f.home_lat.nil? and !f.home_lon.nil? } %>
|
||||
<% nearest = @user.nearby - friends %>
|
||||
|
||||
var near_icon = OpenLayers.Marker.defaultIcon();
|
||||
near_icon.url = OpenLayers.Util.getImageLocation("marker-green.png");
|
||||
<% nearest.each do |u| %>
|
||||
addMarkerToMap(new OpenLayers.LonLat(
|
||||
<%= u.home_lon %>, <%= u.home_lat %>), near_icon.clone(),
|
||||
'<%= escape_javascript(render(:partial => "popup", :object => u, :locals => { :type => "nearby mapper" })) %>'
|
||||
);
|
||||
<% end %>
|
||||
|
||||
var friend_icon = OpenLayers.Marker.defaultIcon();
|
||||
friend_icon.url = OpenLayers.Util.getImageLocation("marker-blue.png");
|
||||
<% friends.each do |u| %>
|
||||
addMarkerToMap(new OpenLayers.LonLat(
|
||||
<%= u.home_lon %>, <%= u.home_lat %>), friend_icon.clone(),
|
||||
'<%= escape_javascript(render(:partial => "popup", :object => u, :locals => { :type => "friend" })) %>'
|
||||
);
|
||||
<% end %>
|
||||
<% end %>
|
||||
}
|
||||
|
||||
<% if setting_location %>
|
||||
function setHome( e ) {
|
||||
closeMapPopup();
|
||||
|
||||
if (document.getElementById('updatehome').checked) {
|
||||
var lonlat = getEventPosition(e);
|
||||
|
||||
document.getElementById('homerow').className = '';
|
||||
document.getElementById('home_lat').value = lonlat.lat;
|
||||
document.getElementById('home_lon').value = lonlat.lon;
|
||||
|
||||
if (marker) {
|
||||
removeMarkerFromMap(marker);
|
||||
}
|
||||
|
||||
marker = addMarkerToMap(lonlat);
|
||||
}
|
||||
}
|
||||
<% end %>
|
||||
|
||||
window.onload = init;
|
||||
// -->
|
||||
</script>
|
|
@ -117,7 +117,23 @@
|
|||
<td></td>
|
||||
<td>
|
||||
<p><%= t 'user.account.update home location on click' %> <input type="checkbox" value="1" <% unless @user.home_lat and @user.home_lon %> checked="checked" <% end %> id="updatehome" /> </p>
|
||||
<div id="map" class="user_map"></div>
|
||||
<% content_for :head do %>
|
||||
<%= javascript_include_tag "user" %>
|
||||
<% end %>
|
||||
<%
|
||||
home = @user.home_lat && @user.home_lon
|
||||
data = {
|
||||
:lon => @user.home_lon || params['lon'] || 0,
|
||||
:lat => @user.home_lat || params['lat'] || 20,
|
||||
:zoom => home ? 12 : params['zoom'] || 1,
|
||||
:marker => !!home
|
||||
}
|
||||
|
||||
if params[:scale].to_f > 0 then
|
||||
data[:zoom] = scale_to_zoom params[:scale]
|
||||
end
|
||||
%>
|
||||
<%= content_tag "div", "", :id => "map", :class => "user_map set_location", :data => data %>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
|
@ -128,8 +144,6 @@
|
|||
</table>
|
||||
<% end %>
|
||||
|
||||
<%= render :partial => 'map', :locals => { :setting_location => true, :show_other_users => false } %>
|
||||
|
||||
<% unless @user.data_public? %>
|
||||
<a name="public"></a>
|
||||
<h2><%= t 'user.account.public editing note.heading' %></h2>
|
||||
|
|
|
@ -104,13 +104,30 @@
|
|||
<% end -%>
|
||||
|
||||
<% if @user and @this_user.id == @user.id %>
|
||||
<div id="map" class="user_map">
|
||||
<% if @this_user.home_lat.nil? or @this_user.home_lon.nil? %>
|
||||
<% if @this_user.home_lat.nil? or @this_user.home_lon.nil? %>
|
||||
<div id="map" class="user_map">
|
||||
<p id="no_home_location"><%= raw(t 'user.view.if set location', :settings_link => (link_to t('user.view.settings_link_text'), :controller => 'user', :action => 'account', :display_name => @user.display_name)) %></p>
|
||||
<% else %>
|
||||
<%= render :partial => 'map', :locals => { :setting_location => false, :show_other_users => true } %>
|
||||
</div>
|
||||
<% else %>
|
||||
<% content_for :head do %>
|
||||
<%= javascript_include_tag "user" %>
|
||||
<% end %>
|
||||
</div>
|
||||
<%
|
||||
data = {
|
||||
:lon => @user.home_lon,
|
||||
:lat => @user.home_lat,
|
||||
:zoom => 12,
|
||||
:marker => {
|
||||
:description => render(:partial => "popup", :object => @user, :locals => {:type => "your location"})
|
||||
}
|
||||
}
|
||||
|
||||
if params[:scale].to_f > 0 then
|
||||
data[:zoom] = scale_to_zoom params[:scale]
|
||||
end
|
||||
%>
|
||||
<%= content_tag "div", "", :id => "map", :class => "user_map", :data => data %>
|
||||
<% end %>
|
||||
|
||||
<% friends = @this_user.friends.collect { |f| f.befriendee } %>
|
||||
<% nearby = @this_user.nearby - friends %>
|
||||
|
@ -123,7 +140,7 @@
|
|||
<%= link_to t('user.view.friends_changesets'), friend_changesets_path %><br/>
|
||||
<%= link_to t('user.view.friends_diaries'), friend_diaries_path %><br/><br/>
|
||||
<table id="friends">
|
||||
<%= render :partial => "contact", :collection => friends %>
|
||||
<%= render :partial => "contact", :collection => friends, :locals => {:type => "friend"} %>
|
||||
</table>
|
||||
<% end %>
|
||||
|
||||
|
@ -135,7 +152,7 @@
|
|||
<%= link_to t('user.view.nearby_changesets'), nearby_changesets_path %><br/>
|
||||
<%= link_to t('user.view.nearby_diaries'), nearby_diaries_path %><br/><br/>
|
||||
<table id="nearbyusers">
|
||||
<%= render :partial => "contact", :collection => nearby %>
|
||||
<%= render :partial => "contact", :collection => nearby, :locals => {:type => "nearby mapper"} %>
|
||||
</table>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
|
|
@ -56,7 +56,7 @@ OpenStreetMap::Application.configure do
|
|||
# config.action_controller.asset_host = "http://assets.example.com"
|
||||
|
||||
# Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added)
|
||||
config.assets.precompile += %w( index.js edit.js browse.js changeset.js pngfix.js swfobject.js )
|
||||
config.assets.precompile += %w( index.js edit.js browse.js changeset.js user.js pngfix.js swfobject.js )
|
||||
config.assets.precompile += %w( large-ltr.css small-ltr.css print-ltr.css )
|
||||
config.assets.precompile += %w( large-rtl.css small-rtl.css print-rtl.css )
|
||||
config.assets.precompile += %w( browse.css theme/openstreetmap/style.css )
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue