From d6a8aaa3690a86820ecc6198f1d5455d8f6cbbe5 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Thu, 30 Aug 2012 09:20:20 -0700 Subject: [PATCH] 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. --- app/assets/javascripts/application.js | 1 + app/assets/javascripts/sidebar.js | 40 ++++++++++++++++++++++++ app/views/site/_sidebar.html.erb | 44 --------------------------- 3 files changed, 41 insertions(+), 44 deletions(-) create mode 100644 app/assets/javascripts/sidebar.js 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 @@ - - -- 2.39.5