app/assets/javascripts/trestle/_sidebar.js in trestle-0.8.4 vs app/assets/javascripts/trestle/_sidebar.js in trestle-0.8.5
- old
+ new
@@ -38,15 +38,36 @@
sidebar.find('.toggle-sidebar').on('click', function(e) {
e.preventDefault();
if (sidebar.hasClass('expanded') || sidebar.hasClass('collapsed')) {
sidebar.removeClass('expanded').removeClass('collapsed');
- document.cookie = "trestle:sidebar=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT";
+ Trestle.cookie.delete("trestle:sidebar");
} else if ($(document).width() >= 1200) {
sidebar.addClass('collapsed');
- document.cookie = "trestle:sidebar=collapsed; path=/";
+ Trestle.cookie.set("trestle:sidebar", "collapsed");
} else if ($(document).width() >= 768) {
sidebar.addClass('expanded');
- document.cookie = "trestle:sidebar=expanded; path=/";
+ Trestle.cookie.set("trestle:sidebar", "expanded");
}
});
+
+
+ // Toggle navigation groups
+
+ sidebar.find('.nav-header a').on('click', function(e) {
+ e.preventDefault();
+
+ $(this).closest('ul').toggleClass('collapsed');
+
+ var collapsed = sidebar.find('.collapsed .nav-header a').map(function() {
+ return $(this).attr('href').replace(/^#/, '');
+ }).toArray();
+
+ Trestle.cookie.set("trestle:navigation:collapsed", collapsed.join(","))
+ });
+
+
+ // Scroll sidebar to active item
+
+ var active = sidebar.find('.active');
+ sidebar.find('.app-sidebar-inner').scrollTop(active.offset().top - 100);
});