Remove inline javascript from potlatch view
This commit is contained in:
parent
56e96d856c
commit
8c3d16ecc4
4 changed files with 71 additions and 59 deletions
61
app/assets/javascripts/edit/potlatch.js.erb
Normal file
61
app/assets/javascripts/edit/potlatch.js.erb
Normal file
|
@ -0,0 +1,61 @@
|
|||
//= require swfobject
|
||||
|
||||
$(document).ready(function () {
|
||||
window.changesaved = true;
|
||||
|
||||
window.markChanged = function (saved) {
|
||||
window.changesaved = saved;
|
||||
}
|
||||
|
||||
$(window).on("beforeunload", function() {
|
||||
if (!window.changesaved) {
|
||||
return I18n.t("site.edit.potlatch_unsaved_changes");
|
||||
}
|
||||
});
|
||||
|
||||
window.updatelinks = function (lon, lat, zoom, layers, minlon, minlat, maxlon, maxlat, object) {
|
||||
var hash = OSM.formatHash({ lon: lon, lat: lat, zoom: zoom });
|
||||
|
||||
if (hash !== location.hash) {
|
||||
location.replace(hash);
|
||||
}
|
||||
|
||||
updateLinks({ lon: lon, lat: lat }, zoom);
|
||||
}
|
||||
|
||||
var potlatch = $("#potlatch"),
|
||||
urlparams = OSM.params(),
|
||||
potlatch_swf = <%= asset_path("potlatch/potlatch.swf").to_json %>,
|
||||
install_swf = <%= asset_path("expressInstall.swf").to_json %>,
|
||||
flashvars = {},
|
||||
params = {},
|
||||
attributes = {};
|
||||
|
||||
flashvars.winie = document.all && window.print ? true : false;
|
||||
flashvars.token = potlatch.data("token");
|
||||
|
||||
if (potlatch.data("lat") && potlatch.data("lon")) {
|
||||
flashvars.lat = potlatch.data("lat");
|
||||
flashvars.long = potlatch.data("lon");
|
||||
flashvars.scale = potlatch.data("zoom");
|
||||
} else {
|
||||
var mapParams = OSM.mapParams();
|
||||
|
||||
flashvars.lat = mapParams.lat;
|
||||
flashvars.long = mapParams.lon;
|
||||
flashvars.scale = mapParams.zoom || 17;
|
||||
}
|
||||
|
||||
if (flashvars.scale < 11) flashvars.scale = 11;
|
||||
|
||||
if (urlparams.gpx) flashvars.gpx = urlparams.gpx;
|
||||
if (urlparams.way) flashvars.way = urlparams.way;
|
||||
if (urlparams.node) flashvars.node = urlparams.node;
|
||||
if (urlparams.custombg) flashvars.custombg = urlparams.custombg;
|
||||
|
||||
attributes.id = "potlatch";
|
||||
attributes.bgcolor = "#FFFFFF";
|
||||
|
||||
swfobject.embedSWF(potlatch_swf, "potlatch", "100%", "100%", "6",
|
||||
install_swf, flashvars, params, attributes);
|
||||
});
|
|
@ -1,60 +1,10 @@
|
|||
<%= javascript_include_tag "edit/potlatch" %>
|
||||
|
||||
<div id="map">
|
||||
<div id="potlatch"><%= raw t 'site.edit.flash_player_required' %></div>
|
||||
<% session[:token] = @user.tokens.create.token unless session[:token] and UserToken.find_by_token(session[:token]) -%>
|
||||
<% data = { :token => session[:token] } -%>
|
||||
<% data[:lat] = @lat if @lat -%>
|
||||
<% data[:lon] = @lon if @lon -%>
|
||||
<% data[:zoom] = @zoom if @zoom -%>
|
||||
<%= content_tag :div, raw(t("site.edit.flash_player_required")), :id => "potlatch", :data => data %>
|
||||
</div>
|
||||
|
||||
<%= javascript_include_tag 'swfobject.js' %>
|
||||
|
||||
<% session[:token] = @user.tokens.create.token unless session[:token] and UserToken.find_by_token(session[:token]) %>
|
||||
|
||||
<script type="text/javascript" defer="defer">
|
||||
var changesaved=true;
|
||||
var winie=false; if (document.all && window.print) { winie=true; }
|
||||
|
||||
window.onbeforeunload=function() {
|
||||
if (!changesaved) {
|
||||
return '<%= escape_javascript(t('site.edit.potlatch_unsaved_changes')) %>';
|
||||
}
|
||||
}
|
||||
|
||||
function markChanged(a) { changesaved=a; }
|
||||
|
||||
function updatelinks(lon,lat,zoom,layers,minlon,minlat,maxlon,maxlat,object) {
|
||||
updateLinks({ lon: lon, lat: lat }, zoom);
|
||||
|
||||
var hash = OSM.formatHash({ lon: lon, lat: lat, zoom: zoom });
|
||||
if (hash !== location.hash) {
|
||||
location.replace(hash);
|
||||
}
|
||||
}
|
||||
|
||||
function doSWF(lat,lon,sc) {
|
||||
if (sc < 11) sc = 11;
|
||||
|
||||
var flashvars = {};
|
||||
flashvars.winie = winie;
|
||||
flashvars.scale = sc;
|
||||
flashvars.token = '<%= session[:token] %>';
|
||||
if (lat) { flashvars.lat = lat; }
|
||||
if (lon) { flashvars.long = lon; }
|
||||
<% if params['gpx'] %>flashvars.gpx = '<%= h(params['gpx'] ) %>';<% end %>
|
||||
<% if params['way'] %>flashvars.way = '<%= h(params['way'] ) %>';<% end %>
|
||||
<% if params['node'] %>flashvars.node = '<%= h(params['node'] ) %>';<% end %>
|
||||
<% if params['tileurl'] %>flashvars.custombg = '<%= h(params['tileurl']) %>';<% end %>
|
||||
|
||||
var params = {};
|
||||
|
||||
var attributes = {};
|
||||
attributes.id = "potlatch";
|
||||
attributes.bgcolor = "#FFFFFF";
|
||||
|
||||
swfobject.embedSWF("<%= asset_path("/potlatch/potlatch.swf") %>", "potlatch", "100%", "100%", "6","<%= asset_path("expressInstall.swf") %>", flashvars, params, attributes);
|
||||
// 700,600 for fixed size, 100%,100% for resizable
|
||||
}
|
||||
|
||||
<% if @lat && @lon -%>
|
||||
doSWF(<%= @lat %>, <%= @lon %>, <%= @zoom %>);
|
||||
<% else -%>
|
||||
var mapParams = OSM.mapParams();
|
||||
doSWF(mapParams.lat, mapParams.lon, mapParams.zoom || 17);
|
||||
<% end -%>
|
||||
</script>
|
||||
|
|
|
@ -27,6 +27,7 @@ translations:
|
|||
- "*.time"
|
||||
- "*.browse.start_rjs.*"
|
||||
- "*.javascripts.*"
|
||||
- "*.site.edit.*"
|
||||
- "*.site.index.remote_failed"
|
||||
- "*.site.sidebar.search_results"
|
||||
- "*.diary_entry.edit.marker_text"
|
||||
|
|
|
@ -12,7 +12,7 @@ Rails.application.config.assets.paths << Rails.root.join("config")
|
|||
# Precompile additional assets.
|
||||
# application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
|
||||
Rails.application.config.assets.precompile += %w(index.js browse.js welcome.js fixthemap.js)
|
||||
Rails.application.config.assets.precompile += %w(user.js login.js diary_entry.js)
|
||||
Rails.application.config.assets.precompile += %w(user.js login.js diary_entry.js edit/*.js)
|
||||
Rails.application.config.assets.precompile += %w(screen-ltr.css print-ltr.css)
|
||||
Rails.application.config.assets.precompile += %w(screen-rtl.css print-rtl.css)
|
||||
Rails.application.config.assets.precompile += %w(leaflet-all.css leaflet.ie.css)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue