$("nav.primary li a").on("click", function() {
$("header").toggleClass("closed");
});
+
+ var application_data = $("head").data();
+
+ I18n.default_locale = OSM.DEFAULT_LOCALE;
+ I18n.locale = application_data.locale;
+ I18n.fallbacks = true;
+
+ OSM.preferred_editor = application_data.preferredEditor;
+
+ if (application_data.user) {
+ OSM.user = application_data.user;
+
+ if (application_data.userHome) {
+ OSM.home = application_data.userHome;
+ }
+ }
+
+ if (application_data.location) {
+ OSM.location = application_data.location;
+ }
});
//= require ohauth
$(document).ready(function () {
+ var application_data = $("head").data();
+
function makeAbsolute(url) {
var a = document.createElement('a');
a.href = url;
return a.href;
}
- if (OSM.oauth_token) {
+ if (application_data.token) {
var headerGenerator = window.ohauth.headerGenerator({
- consumer_key: OSM.oauth_consumer_key,
- consumer_secret: OSM.oauth_consumer_secret,
- token: OSM.oauth_token,
- token_secret: OSM.oauth_token_secret
+ consumer_key: application_data.consumerKey,
+ consumer_secret: application_data.consumerSecret,
+ token: application_data.token,
+ token_secret: application_data.tokenSecret
});
$.ajaxPrefilter(function(options, jqxhr) {
MAPQUEST_DIRECTIONS_URL: <%= MAPQUEST_DIRECTIONS_URL.to_json %>,
MAPZEN_VALHALLA_URL: <%= MAPZEN_VALHALLA_URL.to_json %>,
OSRM_URL: <%= OSRM_URL.to_json %>,
+ DEFAULT_LOCALE: <%= I18n.default_locale.to_json %>,
<% if defined?(MAPQUEST_KEY) %>
MAPQUEST_KEY: <%= MAPQUEST_KEY.to_json %>,
def current_page_class(path)
:current if current_page?(path)
end
+
+ def application_data
+ data = {
+ :locale => I18n.locale,
+ :preferred_editor => preferred_editor
+ }
+
+ if @user
+ data[:user] = @user.id.to_json
+
+ unless @user.home_lon.nil? || @user.home_lat.nil?
+ data[:user_home] = { :lat => @user.home_lat, :lon => @user.home_lon }
+ end
+ end
+
+ data[:location] = session[:location] if session[:location]
+
+ if @oauth
+ data[:token] = @oauth.token
+ data[:token_secret] = @oauth.secret
+ data[:consumer_key] = @oauth.client_application.key
+ data[:consumer_secret] = @oauth.client_application.secret
+ end
+
+ data
+ end
end
-<head>
+<%= content_tag :head, :data => application_data do %>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0"/>
<!--[if lt IE 9]><%= javascript_include_tag "html5shiv" %><![endif]-->
<%= yield :head %>
<%= yield :auto_discovery_link_tag %>
<%= csrf_meta_tag %>
- <script type="text/javascript">
- I18n.defaultLocale = "<%= I18n.default_locale %>";
- I18n.locale = "<%= I18n.locale %>";
- I18n.fallbacks = true;
- <% if @user -%>
- OSM.user = <%= @user.id.to_json.html_safe %>;
- <% unless @user.home_lon.nil? or @user.home_lat.nil? -%>
- OSM.home = <%= { :lat => @user.home_lat, :lon => @user.home_lon }.to_json.html_safe %>;
- <% end -%>
- <% end -%>
- <% if session[:location] -%>
- OSM.location = <%= session[:location].to_json.html_safe %>;
- <% end -%>
- OSM.preferred_editor = <%= preferred_editor.to_json.html_safe %>;
- <% if @oauth -%>
- OSM.oauth_token = "<%= @oauth.token %>";
- OSM.oauth_token_secret = "<%= @oauth.secret %>";
- OSM.oauth_consumer_key = "<%= @oauth.client_application.key %>";
- OSM.oauth_consumer_secret = "<%= @oauth.client_application.secret %>";
- <% end -%>
- </script>
<title><%= t 'layouts.project_name.title' %><%= ' | ' + @title if @title %></title>
-</head>
+<% end %>