]> git.openstreetmap.org Git - rails.git/commitdiff
Port map key to new UI
authorJohn Firebaugh <john.firebaugh@gmail.com>
Wed, 12 Jun 2013 19:09:16 +0000 (12:09 -0700)
committerJohn Firebaugh <john.firebaugh@gmail.com>
Thu, 18 Jul 2013 17:45:14 +0000 (10:45 -0700)
app/assets/javascripts/index.js
app/assets/javascripts/index/key.js [deleted file]
app/assets/javascripts/leaflet.key.js
app/views/site/index.html.erb
config/locales/en.yml

index 710095e2d501db51713cbba52eac50aefbf628b7..c96d18afd31e57dfd364ac6ec8f2a238b29b9a3b 100644 (file)
@@ -7,7 +7,6 @@
 //= require leaflet.share
 //= require index/browse
 //= require index/export
 //= require leaflet.share
 //= require index/browse
 //= require index/export
-//= require index/key
 //= require index/notes
 
 $(document).ready(function () {
 //= require index/notes
 
 $(document).ready(function () {
diff --git a/app/assets/javascripts/index/key.js b/app/assets/javascripts/index/key.js
deleted file mode 100644 (file)
index 5592a29..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-$(document).ready(function () {
-  $("#open_map_key").click(function (e) {
-    e.preventDefault();
-
-    var url = $(this).attr('href'),
-        title = $(this).text();
-
-    function updateMapKey() {
-      var mapLayer = getMapBaseLayerId(),
-          mapZoom = map.getZoom();
-
-      $(".mapkey-table-entry").each(function () {
-        var data = $(this).data();
-
-        if (mapLayer == data.layer &&
-            mapZoom >= data.zoomMin && mapZoom <= data.zoomMax) {
-          $(this).show();
-        } else {
-          $(this).hide();
-        }
-      });
-    }
-
-    $("#sidebar_content").load(url, updateMapKey);
-
-    openSidebar({ title: title });
-
-    $("#sidebar").one("closed", function () {
-      map.off("zoomend baselayerchange", updateMapKey);
-    });
-
-    map.on("zoomend baselayerchange", updateMapKey);
-  });
-});
index 5756f0c4179b6572a0f1c2bf18e08d228b26bb79..4906cfcff67d8ae874c1e2fc5f92d027289ebfeb 100644 (file)
@@ -1,4 +1,4 @@
-L.OSM.key = function(options) {
+L.OSM.key = function (options) {
   var control = L.control(options);
 
   control.onAdd = function (map) {
   var control = L.control(options);
 
   control.onAdd = function (map) {
@@ -8,10 +8,55 @@ L.OSM.key = function(options) {
     $('<a>')
       .attr('class', 'control-button')
       .attr('href', '#')
     $('<a>')
       .attr('class', 'control-button')
       .attr('href', '#')
-      .attr('title', 'Map Key')
+      .attr('title', I18n.t("javascripts.key.tooltip"))
       .html('<span class="icon key"></span>')
       .html('<span class="icon key"></span>')
+      .on('click', toggle)
       .appendTo($container);
 
       .appendTo($container);
 
+    var $ui = $('<div>')
+      .attr('class', 'layers-ui')
+      .appendTo(options.uiPane);
+
+    $('<h2>')
+      .text(I18n.t('javascripts.key.title'))
+      .appendTo($ui);
+
+    var $section = $('<section>')
+      .appendTo($ui);
+
+    function toggle(e) {
+      e.stopPropagation();
+      e.preventDefault();
+
+      var controlContainer = $('.leaflet-control-container .leaflet-top.leaflet-right');
+
+      if ($ui.is(':visible')) {
+        $(options.uiPane).hide();
+        controlContainer.css({paddingRight: '0'});
+        map.off("zoomend baselayerchange", update);
+      } else {
+        $(options.uiPane).show();
+        controlContainer.css({paddingRight: '200px'});
+        map.on("zoomend baselayerchange", update);
+        $section.load('/key', update);
+      }
+    }
+
+    function update() {
+      var mapLayer = getMapBaseLayerId(map),
+        mapZoom = map.getZoom();
+
+      $(".mapkey-table-entry").each(function () {
+        var data = $(this).data();
+
+        if (mapLayer == data.layer && mapZoom >= data.zoomMin && mapZoom <= data.zoomMax) {
+          $(this).show();
+        } else {
+          $(this).hide();
+        }
+      });
+    }
+
     return $container[0];
   };
 
     return $container[0];
   };
 
index 478669529f802a1a28e5b46bdabff7f82e22b9c7..525811ce461587277a54b4be6263533a0eacd615 100644 (file)
@@ -2,10 +2,6 @@
   <%= javascript_include_tag "index" %>
 <% end %>
 
   <%= javascript_include_tag "index" %>
 <% end %>
 
-<% content_for :left_menu do %>
-  <li><h4><%= link_to t("site.key.map_key"), {:action => :key}, :id => "open_map_key", :title => t("site.key.map_key_tooltip") %></h4></li>
-<% end %>
-
 <%= render :partial => 'home_link' %>
 <%= render :partial => 'sidebar' %>
 <%= render :partial => 'search' %>
 <%= render :partial => 'home_link' %>
 <%= render :partial => 'sidebar' %>
 <%= render :partial => 'search' %>
index c621b40feede296fa3c8ce4dde64d055b5b047c4..15fadd9dd3dd86baf939250f39739d85b5087bef 100644 (file)
@@ -1338,8 +1338,6 @@ en:
       submit_text: "Go"
       search_help: "examples: 'Alkmaar', 'Regent Street, Cambridge', 'CB2 5AQ', or 'post offices near Lünen' <a href='http://wiki.openstreetmap.org/wiki/Search'>more examples...</a>"
     key:
       submit_text: "Go"
       search_help: "examples: 'Alkmaar', 'Regent Street, Cambridge', 'CB2 5AQ', or 'post offices near Lünen' <a href='http://wiki.openstreetmap.org/wiki/Search'>more examples...</a>"
     key:
-      map_key: "Map Key"
-      map_key_tooltip: "Key for the map"
       table:
         entry:
           motorway: "Motorway"
       table:
         entry:
           motorway: "Motorway"
@@ -2042,6 +2040,9 @@ en:
     share:
       title: "Share"
       cancel: "Cancel"
     share:
       title: "Share"
       cancel: "Cancel"
+    key:
+      title: "Map Key"
+      tooltip: "Key for the map"
     map:
       base:
         standard: Standard
     map:
       base:
         standard: Standard