]> git.openstreetmap.org Git - rails.git/commitdiff
Move sidebar JS to application bundle
authorJohn Firebaugh <john.firebaugh@gmail.com>
Thu, 30 Aug 2012 16:20:20 +0000 (09:20 -0700)
committerTom Hughes <tom@compton.nu>
Thu, 30 Aug 2012 19:30:11 +0000 (20:30 +0100)
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
app/assets/javascripts/sidebar.js [new file with mode: 0644]
app/views/site/_sidebar.html.erb

index 78cbb57ea94148a3ed9ea14e4eda4a30edb96afc..4a653f956236712a9238340d63b3b309b852644b 100644 (file)
@@ -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 (file)
index 0000000..4ef379b
--- /dev/null
@@ -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();
+    });
+  });
+})();
index 5e91bec1c0290c24fcafa750cee50fd0aeb187c2..bea37d0d99bf4992253f4c1d0467cc4bff07d5c7 100644 (file)
@@ -8,47 +8,3 @@
   <div id="sidebar_content">
   </div>
 </div>
-
-<script type="text/javascript">
-<!--
-  var onclose;
-
-  function openSidebar(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;
-  }
-
-  $(".sidebar_close").click(function (e) {
-    $("#sidebar").css("display", "none");
-
-    $("#sidebar").trigger("closed");
-
-    if (onclose) {
-       onclose();
-       onclose = null;
-    }
-
-    e.preventDefault();
-  });
-
-  function updateSidebar(title, content) {
-    $("#sidebar_title").html(title);
-    $("#sidebar_content").html(content);
-  }
-// -->
-</script>