]> git.openstreetmap.org Git - rails.git/blob - app/assets/javascripts/edit/potlatch2.js.erb
Remove link_to_if since it's in a clause with the same condition
[rails.git] / app / assets / javascripts / edit / potlatch2.js.erb
1 //= require swfobject
2
3 $(document).ready(function () {
4   window.changesaved = true;
5
6   window.markChanged = function (saved) {
7     window.changesaved = saved;
8   }
9
10   $(window).on("beforeunload", function() {
11     if (!window.changesaved) {
12       return I18n.t("site.edit.potlatch2_unsaved_changes");
13     }
14   });
15
16   window.mapMoved = $.throttle(250, function(lon, lat, zoom) {
17     var hash = OSM.formatHash({ lon: lon, lat: lat, zoom: zoom });
18
19     if (hash !== location.hash) {
20       location.replace(hash);
21     }
22
23     updateLinks({ lon: lon, lat: lat }, zoom);
24   });
25
26   var potlatch = $("#potlatch"),
27       urlparams = OSM.params(),
28       potlatch_swf = <%= asset_path("potlatch2.swf").to_json %>,
29       install_swf = <%= asset_path("expressInstall.swf").to_json %>,
30       flashvars = {},
31       params = {};
32       attributes = {};
33
34   if (potlatch.data("lat") && potlatch.data("lon")) {
35     flashvars.lat = potlatch.data("lat");
36     flashvars.lon = potlatch.data("lon");
37     flashvars.zoom = potlatch.data("zoom");
38   } else {
39     var mapParams = OSM.mapParams();
40
41     flashvars.lat = mapParams.lat;
42     flashvars.lon = mapParams.lon;
43     flashvars.zoom = mapParams.zoom || 17;
44   }
45   
46   if (potlatch.data("token")) {
47     flashvars.oauth_token = potlatch.data("token");
48     flashvars.oauth_token_secret = potlatch.data("token-secret");
49     flashvars.oauth_consumer_key = potlatch.data("consumer-key");
50     flashvars.oauth_consumer_secret = potlatch.data("consumer-secret");
51   } else {
52     alert(I18n.t("site.edit.potlatch2_not_configured"));
53   }
54
55   flashvars.assets = <%= asset_path("potlatch2/assets.zip").to_json %>;
56   flashvars.font_library = <%= asset_path("potlatch2/FontLibrary.swf").to_json %>;
57   flashvars.locale = potlatch.data("locale");
58   flashvars.locale_paths = potlatch.data("locale") + "=" + potlatch.data("locale-path");
59   flashvars.intro_image = <%= asset_path("help/introduction.jpg").to_json %>;
60   flashvars.intro_video = <%= asset_path("help/introduction.mp4").to_json %>;
61   if (urlparams.gpx) flashvars.gpx = urlparams.gpx;
62   if (urlparams.tileurl) flashvars.tileurl = urlparams.tileurl;
63   flashvars.api = location.protocol + "//" + location.host + "/api/" + OSM.API_VERSION + "/";
64   flashvars.policy = location.protocol + "//" + location.host + "/api/crossdomain.xml";
65   flashvars.connection = "XML";
66   flashvars.show_help = "once";
67   flashvars.user_check = "warn";
68   flashvars.maximise_function = "maximiseMap";
69   flashvars.minimise_function = "minimiseMap";
70   flashvars.move_function = "mapMoved";
71
72   params.base = "/potlatch2";
73
74   attributes.id = "potlatch";
75   attributes.bgcolor = "#FFFFFF";
76
77   swfobject.embedSWF(potlatch_swf, "potlatch", "100%", "100%", "10.1.102",
78                      install_swf, flashvars, params, attributes);
79
80   if (flashvars.lat && flashvars.lon) {
81     updateLinks({ lon: flashvars.lon, lat: flashvars.lat }, flashvars.scale);
82   }
83 });