rancher.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. jQuery(document).ready(function () {
  2. checkActiveState();
  3. // Set height
  4. var content_height = $(".col-sm-9").height();
  5. $(".col-sm-3").css("min-height", content_height + "px");
  6. $("ul.nav li a").click(function (event) {
  7. var link = $(this);
  8. var local_destination = link.attr("href");
  9. if ( link.data('toggle') )
  10. {
  11. return;
  12. }
  13. event.preventDefault();
  14. if ( window.location.protocol === 'file:' )
  15. {
  16. if ( local_destination.substr(-1) === '/' )
  17. {
  18. local_destination += 'index.html';
  19. }
  20. window.location.href = local_destination;
  21. return false;
  22. }
  23. $.get(local_destination, function (data) {
  24. var title = $(data).find("title").text();
  25. var local_content = $(data).find(".col-sm-9").html();
  26. changeUrl(title, local_destination);
  27. checkActiveState();
  28. $(".col-sm-9").html(local_content);
  29. //If has a class hash (jump on the page)
  30. if(link.hasClass('hash')){
  31. var local_destination_array = local_destination.split('#');
  32. var paragraph_id = local_destination_array[1];
  33. var paragraph_destination = $('.col-sm-9 #' + paragraph_id).offset().top;
  34. $('body,html').animate({scrollTop: paragraph_destination + "px"});
  35. }
  36. // Set height
  37. var content_height = $(".col-sm-9").height();
  38. $(".col-sm-3").css("min-height", content_height + "px");
  39. });
  40. setTimeout(function() {
  41. linkAnchors();
  42. },250);
  43. });
  44. linkAnchors();
  45. });
  46. function linkAnchors() {
  47. $('.content-container H3[id], .content-container H4[id], .content-container H5[id], .content-container H6[id]').each(function(idx, el) {
  48. $(el).append($('<a />').addClass('header-anchor').attr('href', '#' + el.id).html('<i class="fa fa-link" aria-hidden="true"></i>'));
  49. });
  50. }
  51. function changeUrl(title, url) {
  52. if (typeof (history.pushState) != "undefined") {
  53. var obj = {Title: title, Url: url};
  54. history.pushState(obj, obj.Title, obj.Url);
  55. }
  56. }
  57. function checkActiveState() {
  58. $('UL.nav UL').removeClass('in');
  59. $('UL A').each(function(idx, a) {
  60. var $a = $(a);
  61. if ( a.href === window.location.href )
  62. {
  63. $a.addClass('active');
  64. $a.closest('.list-group-submenu-submenu').parent().children('a').addClass("active");
  65. $a.closest('.list-group-submenu').parent().children('a').addClass("active");
  66. $a.parents('UL').addClass('in');
  67. }
  68. else
  69. {
  70. $a.removeClass('active');
  71. }
  72. });
  73. }