From: John Firebaugh Date: Thu, 30 Aug 2012 16:20:20 +0000 (-0700) Subject: Move sidebar JS to application bundle X-Git-Tag: live~5941 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/d6a8aaa3690a86820ecc6198f1d5455d8f6cbbe5?ds=sidebyside Move sidebar JS to application bundle It's required on the main page so will nearly always be loaded anyway. Enclosed in an anonymous function to avoid leaking the onclose global. --- diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 78cbb57ea..4a653f956 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 /* * Called as the user scrolls/zooms around to aniplate hrefs of the diff --git a/app/assets/javascripts/sidebar.js b/app/assets/javascripts/sidebar.js new file mode 100644 index 000000000..4ef379bf5 --- /dev/null +++ b/app/assets/javascripts/sidebar.js @@ -0,0 +1,40 @@ +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"); + + $("#sidebar").trigger("opened"); + + onclose = options.onclose; + }; + + $(document).ready(function () { + $(".sidebar_close").click(function (e) { + $("#sidebar").css("display", "none"); + + $("#sidebar").trigger("closed"); + + if (onclose) { + onclose(); + onclose = null; + } + + e.preventDefault(); + }); + }); +})(); diff --git a/app/views/site/_sidebar.html.erb b/app/views/site/_sidebar.html.erb index 5e91bec1c..bea37d0d9 100644 --- a/app/views/site/_sidebar.html.erb +++ b/app/views/site/_sidebar.html.erb @@ -8,47 +8,3 @@ - -