customscripts.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. $('#mysidebar').height($(".nav").height());
  2. $( document ).ready(function() {
  3. //this script says, if the height of the viewport is greater than 800px, then insert affix class, which makes the nav bar float in a fixed
  4. // position as your scroll. if you have a lot of nav items, this height may not work for you.
  5. var h = $(window).height();
  6. //console.log (h);
  7. if (h > 800) {
  8. $( "#mysidebar" ).attr("class", "nav affix");
  9. }
  10. // activate tooltips. although this is a bootstrap js function, it must be activated this way in your theme.
  11. $('[data-toggle="tooltip"]').tooltip({
  12. placement : 'top'
  13. });
  14. /**
  15. * AnchorJS
  16. */
  17. anchors.add('h2,h3,h4,h5');
  18. });
  19. // needed for nav tabs on pages. See Formatting > Nav tabs for more details.
  20. // script from http://stackoverflow.com/questions/10523433/how-do-i-keep-the-current-tab-active-with-twitter-bootstrap-after-a-page-reload
  21. $(function() {
  22. var json, tabsState;
  23. $('a[data-toggle="pill"], a[data-toggle="tab"]').on('shown.bs.tab', function(e) {
  24. var href, json, parentId, tabsState;
  25. tabsState = localStorage.getItem("tabs-state");
  26. json = JSON.parse(tabsState || "{}");
  27. parentId = $(e.target).parents("ul.nav.nav-pills, ul.nav.nav-tabs").attr("id");
  28. href = $(e.target).attr('href');
  29. json[parentId] = href;
  30. return localStorage.setItem("tabs-state", JSON.stringify(json));
  31. });
  32. tabsState = localStorage.getItem("tabs-state");
  33. json = JSON.parse(tabsState || "{}");
  34. $.each(json, function(containerId, href) {
  35. return $("#" + containerId + " a[href=" + href + "]").tab('show');
  36. });
  37. $("ul.nav.nav-pills, ul.nav.nav-tabs").each(function() {
  38. var $this = $(this);
  39. if (!json[$this.attr("id")]) {
  40. return $this.find("a[data-toggle=tab]:first, a[data-toggle=pill]:first").tab("show");
  41. }
  42. });
  43. });