]> git.openstreetmap.org Git - rails.git/commitdiff
Update title on pushState, closes #33
authorAaron Lidman <aaronlidman@gmail.com>
Sat, 9 Nov 2013 00:10:08 +0000 (16:10 -0800)
committerAaron Lidman <aaronlidman@gmail.com>
Sat, 9 Nov 2013 00:10:08 +0000 (16:10 -0800)
19 files changed:
app/assets/javascripts/index.js
app/assets/javascripts/index/export.js
app/assets/javascripts/index/history.js
app/assets/javascripts/index/search.js
app/controllers/browse_controller.rb
app/helpers/title_helper.rb [new file with mode: 0644]
app/views/browse/changeset.html.erb
app/views/browse/node.html.erb
app/views/browse/node_history.html.erb
app/views/browse/note.html.erb
app/views/browse/relation.html.erb
app/views/browse/relation_history.html.erb
app/views/browse/way.html.erb
app/views/browse/way_history.html.erb
app/views/changeset/history.html.erb
app/views/layouts/_head.html.erb
app/views/site/export.html.erb
app/views/site/index.html.erb
config/locales/en.yml

index 816bb4e8fccad6a7d6272a2d2274ea5aab3b957f..f982ff1e1c34cd81f1c3b611a09231ca0451d657 100644 (file)
@@ -235,7 +235,11 @@ $(document).ready(function () {
     page.pushstate = page.popstate = function(path) {
       $("#content").addClass("overlay-sidebar");
       map.invalidateSize();
-      $('#sidebar_content').load(path);
+      $('#sidebar_content').load(path, function(a, b, xhr) {
+        if (xhr.getResponseHeader('X-Page-Title')) {
+          document.title = xhr.getResponseHeader('X-Page-Title');
+        }
+      });
     };
 
     page.unload = function() {
@@ -250,7 +254,10 @@ $(document).ready(function () {
     var page = {};
 
     page.pushstate = page.popstate = function(path, type, id) {
-      $('#sidebar_content').load(path, function() {
+      $('#sidebar_content').load(path, function(a, b, xhr) {
+        if (xhr.getResponseHeader('X-Page-Title')) {
+          document.title = xhr.getResponseHeader('X-Page-Title');
+        }
         page.load(path, type, id);
       });
     };
index 413caea3f737aa666c37687d2583c36f78205598..4842fff0ca4c081b154e4e79845db2ba0113c3cf 100644 (file)
@@ -51,7 +51,12 @@ OSM.Export = function(map) {
 
   page.pushstate = page.popstate = function(path) {
     $("#export_tab").addClass("current");
-    $("#sidebar_content").load(path, page.load);
+    $("#sidebar_content").load(path, function(a, b, xhr) {
+      if (xhr.getResponseHeader('X-Page-Title')) {
+        document.title = xhr.getResponseHeader('X-Page-Title');
+      }
+      page.load();
+    });
   };
 
   page.load = function() {
index be62d37344d692b9797c749c6e55062e4fc69b36..6cbc86307b97b4446214b9d977fdce95207c5a85 100644 (file)
@@ -47,7 +47,7 @@ OSM.History = function(map) {
       url: window.location.pathname,
       method: "GET",
       data: {bbox: map.getBounds().toBBoxString()},
-      success: function(html) {
+      success: function(html, status, xhr) {
         $('#sidebar_content .changesets').html(html);
         updateMap();
       }
@@ -99,7 +99,12 @@ OSM.History = function(map) {
 
   page.pushstate = page.popstate = function(path) {
     $("#history_tab").addClass("current");
-    $("#sidebar_content").load(path, page.load);
+    $("#sidebar_content").load(path, function(a, b, xhr) {
+      if (xhr.getResponseHeader('X-Page-Title')) {
+        document.title = xhr.getResponseHeader('X-Page-Title');
+      }
+      page.load();
+    });
   };
 
   page.load = function() {
index c97b6991dfa0dc2cdcd7989aaff4124ccfedbcb4..e92f3747f0b39e1c472d339a0db5fe725780cec7 100644 (file)
@@ -49,7 +49,12 @@ OSM.Search = function(map) {
   page.pushstate = page.popstate = function(path) {
     var params = querystring.parse(path.substring(path.indexOf('?') + 1));
     $("#query").val(params.query);
-    $("#sidebar_content").load(path, page.load);
+    $("#sidebar_content").load(path, function() {
+      if (xhr.getResponseHeader('X-Page-Title')) {
+        document.title = xhr.getResponseHeader('X-Page-Title');
+      }
+      page.load();
+    });
   };
 
   page.load = function() {
index cbb0f202395e92e1eabbd453a7e7f14f675247ca..61982a940fc1fe39586e04090734efab92d612f2 100644 (file)
@@ -62,7 +62,6 @@ class BrowseController < ApplicationController
     @way_pages, @ways = paginate(:old_ways, :conditions => {:changeset_id => @changeset.id}, :per_page => 10, :parameter => 'way_page')
     @relation_pages, @relations = paginate(:old_relations, :conditions => {:changeset_id => @changeset.id}, :per_page => 10, :parameter => 'relation_page')
       
-    @title = "#{I18n.t('browse.changeset.title')} | #{@changeset.id}"
     @next = Changeset.where("id > ?", @changeset.id).order(:id => :asc).first
     @prev = Changeset.where("id < ?", @changeset.id).order(:id => :desc).first
 
@@ -77,7 +76,6 @@ class BrowseController < ApplicationController
   def note
     @type = "note"
     @note = Note.find(params[:id])
-    @title = "#{I18n.t('browse.note.title')} | #{@note.id}"
     @next = Note.visible.where("id > ?", @note.id).order(:id => :asc).first
     @prev = Note.visible.where("id < ?", @note.id).order(:id => :desc).first
   rescue ActiveRecord::RecordNotFound
diff --git a/app/helpers/title_helper.rb b/app/helpers/title_helper.rb
new file mode 100644 (file)
index 0000000..181c12a
--- /dev/null
@@ -0,0 +1,11 @@
+module TitleHelper
+  def set_title(title = false)
+    if title
+        title = t('layouts.project_name.title') + ' | ' + title
+    else
+        title = t('layouts.project_name.title')
+    end
+    response.headers["X-Page-Title"] = title 
+    @title = title
+  end
+end
index 5063d6e079a6927a410fde9b7e3ebd30e76e59bf..696a8ca8964540055a585d782cb304ef82ee83ca 100644 (file)
@@ -1,3 +1,5 @@
+<% set_title("#{t('browse.changeset.title')} | #{@changeset.id}") %>
+
 <h2>
   <a class="geolink" href="<%= root_path %>"><span class="icon close"></span></a>
   <%= t 'browse.changeset.changeset', :id => @changeset.id %>
index 0c81b411c7a2f6e03adf300af9e89351348b036a..8847adb19bf0ec133e71431c2d974549ed62a5fa 100644 (file)
@@ -1,6 +1,6 @@
 <%
 @name = printable_name @node
-@title = t('browse.node.node') + ' | ' + @name
+set_title(t('browse.node.node') + ' | ' + @name)
 %>
 
 <h2>
index 8bc4ed8ab5c0d2e6ac4592d27736d5d23935e2bc..c476b23babdab06aecd69e220012c7cbc377fd45 100644 (file)
@@ -1,6 +1,6 @@
 <%
 @name = printable_name @node
-@title = t('browse.node_history.node_history') + ' | ' + @name
+set_title(t('browse.node_history.node_history') + ' | ' + @name)
 %>
 
 <h2>
index 948cd3a06315ba2cbb0335c1f42621b2ec12e241..a20de88a0e307b604c867930ed3e93d76cc56107 100644 (file)
@@ -1,3 +1,5 @@
+<% set_title("#{t('browse.note.title')} | #{@note.id}") %>
+
 <h2>
   <a class="geolink" href="<%= root_path %>"><span class="icon close"></span></a>
   <%= t "browse.note.#{@note.status}_title", :note_name => @note.id %>
index 125efb0d60dca95603f47f5b00e9538bf03507f2..44baa48deb21b22886878ea9b671034432c7e582 100644 (file)
@@ -1,6 +1,6 @@
 <%
 @name = printable_name @relation
-@title = t('browse.relation.relation') + ' | ' + @name
+set_title(t('browse.relation.relation') + ' | ' + @name)
 %>
 
 <h2>
index d059b11b449208195d0d1aa87f37767373664722..144c7d47652292a8108517b89546ff364a24bdea 100644 (file)
@@ -1,6 +1,6 @@
 <%
 @name = printable_name @relation
-@title = t('browse.relation_history.relation_history') + ' | ' + @name
+set_title(t('browse.relation_history.relation_history') + ' | ' + @name)
 %>
 
 <h2>
index ce67fb8a91e9cac761c917401d1db47e2b72e8d9..619b9314b5e13f55236eb7912fa5223d27abdd57 100644 (file)
@@ -1,6 +1,6 @@
 <%
 @name = printable_name @way
-@title = t('browse.way.way') + ' | ' + @name
+set_title(t('browse.way.way') + ' | ' + @name)
 %>
 <h2>
     <a class="geolink" href="<%= root_path %>"><span class="icon close"></span></a>
index a747572c1c87e772622b71dd14da12e8d2a0cd15..6e234454d8638a6d09338c375ab4bb2d17f8f41e 100644 (file)
@@ -1,6 +1,6 @@
 <%
 @name = printable_name @way
-@title = t('browse.way_history.way_history') + ' | ' + @name
+set_title(t('browse.way_history.way_history') + ' | ' + @name)
 %>
 
 <h2>
index 022523efadee0a715a568c0282494d1340864c45..23fee589c8260915049837c9eb0c96158b1e7e6e 100644 (file)
@@ -6,16 +6,16 @@
 
 <%
    if params[:friends] and @user
-     @title = t 'changeset.list.title_friend'
+     set_title(t 'changeset.list.title_friend')
      @heading = t 'changeset.list.title_friend'
    elsif params[:nearby] and @user
-     @title = t 'changeset.list.title_nearby'
+     set_title(t 'changeset.list.title_nearby')
      @heading = t 'changeset.list.title_nearby'
    elsif params[:display_name]
-     @title = t 'changeset.list.title_user', :user => params[:display_name]
+     set_title(t 'changeset.list.title_user', :user => params[:display_name])
      @heading = t('changeset.list.title_user', :user => link_to(params[:display_name], :controller => "user", :action => "view", :display_name => params[:display_name])).html_safe
    else
-     @title = t 'changeset.list.title'
+     set_title(t 'changeset.list.title')
      @heading = t 'changeset.list.title'
    end
 %>
index 5b2a0aa6f7eaed8322d39f9a23f0c3dfbce27753..a1f11f7005f21cf9c089d441d8dbf161f2edee1b 100644 (file)
@@ -45,5 +45,5 @@
     OSM.oauth_consumer_secret = "<%= @oauth.client_application.secret %>";
     <% end -%>
   </script>
-  <title><%= t 'layouts.project_name.title' %><%= ' | '+ @title if @title %></title>
+  <title><%= @title %></title>
 </head>
index 6a2131e9038b593056d11dce9f0af27c516bf040..168f7d4396a8799d24994dbadc04bf74eef5d872 100644 (file)
@@ -1,3 +1,4 @@
+<% set_title(t('export.title')) %>
 <h2>
   <a class="geolink" href="<%= root_path %>"><span class="icon close"></span></a>
   <%= t 'export.start_rjs.export' %>
index 8a6a5d85a9bb99e5cc6e38a8ffa9bed3bef841fe..6f215235cfe686b409bb64e36fa3bf870dca74e6 100644 (file)
@@ -1,4 +1,7 @@
-<% content_for(:content_class) { "overlay-sidebar" } %>
+<%
+    set_title()
+    content_for(:content_class) { "overlay-sidebar" }
+%>
 
 <% unless @user %>
   <div class="welcome">
index cbd1c60c1a7b6b92fdd7cd5ab6f2fd0d113f97c6..1de138f2d115886feadebe2d968ac45b6daebedd 100644 (file)
@@ -396,6 +396,7 @@ en:
       newer_comments: "Newer Comments"
       older_comments: "Older Comments"
   export:
+    title: "Export"
     start:
       area_to_export: "Area to Export"
       manually_select: "Manually select a different area"