From ff81de9ade39c9c6b98ce184ba9cb990dcab6faa Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Thu, 30 Aug 2012 09:04:52 -0700 Subject: [PATCH 1/3] Remove unnecessary arguments to sidebar partial --- app/views/site/_sidebar.html.erb | 4 ++-- app/views/site/edit.html.erb | 2 +- app/views/site/index.html.erb | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/views/site/_sidebar.html.erb b/app/views/site/_sidebar.html.erb index 481f897957..6c763c1d38 100644 --- a/app/views/site/_sidebar.html.erb +++ b/app/views/site/_sidebar.html.erb @@ -28,7 +28,7 @@ $("#sidebar").css("display", "block"); - <%= onopen %> + resizeMap(); onclose = options.onclose; } @@ -36,7 +36,7 @@ $(".sidebar_close").click(function (e) { $("#sidebar").css("display", "none"); - <%= onclose %> + resizeMap(); if (onclose) { onclose(); diff --git a/app/views/site/edit.html.erb b/app/views/site/edit.html.erb index 5e091339c2..45cc6c7f96 100644 --- a/app/views/site/edit.html.erb +++ b/app/views/site/edit.html.erb @@ -15,7 +15,7 @@ <% end %> <% end %> -<%= render :partial => 'sidebar', :locals => { :onopen => "resizeMap();", :onclose => "resizeMap();" } %> +<%= render :partial => 'sidebar' %> <%= render :partial => 'search' %> <%= render :partial => 'resize' %> diff --git a/app/views/site/index.html.erb b/app/views/site/index.html.erb index dc0e02f6fa..877bc17719 100644 --- a/app/views/site/index.html.erb +++ b/app/views/site/index.html.erb @@ -10,7 +10,7 @@ <% end -%> <% end -%> -<%= render :partial => 'sidebar', :locals => { :onopen => "resizeMap();", :onclose => "resizeMap();" } %> +<%= render :partial => 'sidebar' %> <%= render :partial => 'key' %> <%= render :partial => 'search' %> From 4e084a5c8a82c1cb4dc778d8e3a8acae131802c9 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Thu, 30 Aug 2012 09:06:31 -0700 Subject: [PATCH 2/3] Remove unused function --- app/views/site/_sidebar.html.erb | 5 ----- 1 file changed, 5 deletions(-) diff --git a/app/views/site/_sidebar.html.erb b/app/views/site/_sidebar.html.erb index 6c763c1d38..5cb3386d68 100644 --- a/app/views/site/_sidebar.html.erb +++ b/app/views/site/_sidebar.html.erb @@ -45,10 +45,5 @@ e.preventDefault(); }); - - function updateSidebar(title, content) { - $("#sidebar_title").html(title); - $("#sidebar_content").html(content); - } // --> From bbba3db4ed74e6276027efedae137e274e50840e Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Thu, 30 Aug 2012 09:20:20 -0700 Subject: [PATCH 3/3] Move sidebar JS to application bundle It's required on the main page so will nearly always be loaded anyway. Enclosed in anonymous function to avoid leaking `onclose` global variable. --- app/assets/javascripts/application.js | 1 + app/assets/javascripts/sidebar.js | 39 +++++++++++++++++++++++++++ app/views/site/_sidebar.html.erb | 39 --------------------------- 3 files changed, 40 insertions(+), 39 deletions(-) create mode 100644 app/assets/javascripts/sidebar.js diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index dcc5d43f80..c98be65912 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -10,6 +10,7 @@ //= require export //= require map //= require menu +//= require sidebar if ( !Array.prototype.forEach ) { Array.prototype.forEach = function(fn, scope) { diff --git a/app/assets/javascripts/sidebar.js b/app/assets/javascripts/sidebar.js new file mode 100644 index 0000000000..ea499bbcce --- /dev/null +++ b/app/assets/javascripts/sidebar.js @@ -0,0 +1,39 @@ +var openSidebar; +(function () { + var onclose; + + openSidebar = function(options) { + options = options || {}; + + if (onclose) { + onclose(); + onclose = null; + } + + if (options.title) { $("#sidebar_title").html(options.title); } + + if (options.width) { $("#sidebar").width(options.width); } + else { $("#sidebar").width("30%"); } + + $("#sidebar").css("display", "block"); + + resizeMap(); + + onclose = options.onclose; + }; + + $(document).ready(function () { + $(".sidebar_close").click(function (e) { + $("#sidebar").css("display", "none"); + + resizeMap(); + + if (onclose) { + onclose(); + onclose = null; + } + + e.preventDefault(); + }); + }); +})(); diff --git a/app/views/site/_sidebar.html.erb b/app/views/site/_sidebar.html.erb index 5cb3386d68..bea37d0d99 100644 --- a/app/views/site/_sidebar.html.erb +++ b/app/views/site/_sidebar.html.erb @@ -8,42 +8,3 @@ - -