You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 rivejä
2.4 KiB

  1. $(document).ready(function () {
  2. function initThemes(){
  3. var menu = $("#themeDropdown");
  4. menu.on("click","li > a.themeLink",function(event){
  5. switchStylesheet($(this).text());
  6. });
  7. menu.append('<li class="nav-header">Light</li>');
  8. $(".codebrush.light").each(function(index){
  9. menu.append('<li><a class="themeLink" href="#">' + $(this).attr("title") + '</a></li>');
  10. });
  11. menu.append('<li class="nav-header">Dark</li>');
  12. $(".codebrush.dark").each(function(index){
  13. menu.append('<li><a class="themeLink" href="#">' + $(this).attr("title") + '</a></li>');
  14. });
  15. }
  16. function switchStylesheet(styleName)
  17. {
  18. $('link.codebrush').each(function(i)
  19. {
  20. this.disabled = true;
  21. if($(this).attr('title') == styleName)
  22. {
  23. this.disabled = false;
  24. }
  25. });
  26. $('#themeDropdown > li').each(function(i)
  27. {
  28. $(this).removeClass('active');
  29. if($('a.themeLink',this).text() == styleName)
  30. {
  31. $(this).addClass('active');
  32. }
  33. });
  34. $.cookie("doccoCodeTheme",styleName,{path:'/',expires:365});
  35. }
  36. function initHiddenCode()
  37. {
  38. $.each($('.docco-section'), function() {
  39. var $this = $(this);
  40. var code = $('pre', $this);
  41. var lines = code.text().split('\n');
  42. $('.linecount', $this).text(lines.length);
  43. $('.hidden-code, .hidden-doc', $this).hide();
  44. });
  45. $('.hidden-code-toggle').click(function (e) {
  46. var $target = $(e.target);
  47. var $section = $("#section-" + $target.attr("index"));
  48. $(".hidden-code, .hidden-doc", $section).slideToggle("slow", function() {
  49. var $this = $(this);
  50. if ($this.is(":visible")) {
  51. var newText = $target.html().replace("Show","Hide");
  52. $target.html(newText);
  53. }
  54. else {
  55. var newText = $target.html().replace("Hide","Show");
  56. $target.html(newText);
  57. }
  58. });
  59. });
  60. }
  61. var myTheme = $.cookie("doccoCodeTheme");
  62. if(null == myTheme)
  63. {
  64. myTheme = "IDEA";
  65. }
  66. initThemes();
  67. switchStylesheet(myTheme);
  68. hljs.initHighlightingOnLoad();
  69. initHiddenCode();
  70. });