Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

139 rader
4.0 KiB

  1. $(document).ready(function () {
  2. var grabber = $('#grabber');
  3. var startX;
  4. function positionGrabber(){
  5. grabber.draggable("option","containment",[200,0,$(window).width() - 200,0]);
  6. grabber.css({
  7. height: function(){
  8. return ($(document).height() - $(".code:visible").first().position().top);
  9. }
  10. ,left: function(){
  11. return $(".code pre:visible").first().position().left;
  12. }
  13. ,top: function(){
  14. return $(".code:visible").first().position().top;
  15. }
  16. });
  17. }
  18. function initGrabber(){
  19. grabber.draggable({
  20. axis:'x'
  21. ,start:function(event,ui){
  22. startX = ui.position.left;
  23. }
  24. ,drag: function(event,ui){
  25. var xOffset = ui.position.left - startX;
  26. var newDocW = $(".doc:visible").first().width() + xOffset;
  27. var newDocPercent = ( 100 * newDocW / parseFloat($(".doc").first().parent().css("width")) )+ "%" ;
  28. var newCodeW = $(".code:visible").first().width() - xOffset;
  29. var newCodePercent = ( 100 * newCodeW / parseFloat($(".code").first().parent().css("width")) )+ "%" ;
  30. $(".doc").width(newDocPercent);
  31. $(".code").width(newCodePercent);
  32. startX = $(".code pre:visible").first().position().left;
  33. }
  34. ,stop: function(){
  35. positionGrabber();
  36. }
  37. });
  38. positionGrabber();
  39. }
  40. function initThemes(){
  41. var menu = $("#themeDropdown");
  42. menu.on("click","li > a.themeLink",function(event){
  43. switchStylesheet($(this).text());
  44. });
  45. menu.append('<li class="nav-header">Light</li>');
  46. $(".codebrush.light").each(function(index){
  47. menu.append('<li><a class="themeLink" href="#">' + $(this).attr("title") + '</a></li>');
  48. });
  49. menu.append('<li class="nav-header">Dark</li>');
  50. $(".codebrush.dark").each(function(index){
  51. menu.append('<li><a class="themeLink" href="#">' + $(this).attr("title") + '</a></li>');
  52. });
  53. }
  54. function switchStylesheet(styleName)
  55. {
  56. $('link.codebrush').each(function(i)
  57. {
  58. this.disabled = true;
  59. if($(this).attr('title') == styleName)
  60. {
  61. this.disabled = false;
  62. }
  63. });
  64. $('#themeDropdown > li').each(function(i)
  65. {
  66. $(this).removeClass('active');
  67. if($('a.themeLink',this).text() == styleName)
  68. {
  69. $(this).addClass('active');
  70. }
  71. });
  72. $.cookie("doccoCodeTheme",styleName,{path:'/',expires:365});
  73. }
  74. function initHiddenCode()
  75. {
  76. $.each($('.docco-section'), function() {
  77. var $this = $(this);
  78. var code = $('pre', $this);
  79. var lines = code.text().split('\n');
  80. $('.linecount', $this).text(lines.length);
  81. $('.hidden-code, .hidden-doc', $this).hide();
  82. });
  83. $('.hidden-code-toggle').click(function (e) {
  84. var $target = $(e.target);
  85. var $section = $("#section-" + $target.attr("index"));
  86. $(".hidden-code, .hidden-doc", $section).slideToggle("slow", function() {
  87. var $this = $(this);
  88. if ($this.is(":visible")) {
  89. var newText = $target.html().replace("Show","Hide");
  90. $target.html(newText);
  91. }
  92. else {
  93. var newText = $target.html().replace("Hide","Show");
  94. $target.html(newText);
  95. }
  96. positionGrabber();
  97. });
  98. });
  99. }
  100. var myTheme = $.cookie("doccoCodeTheme");
  101. if(null == myTheme)
  102. {
  103. myTheme = "IDEA";
  104. }
  105. initThemes();
  106. switchStylesheet(myTheme);
  107. initGrabber();
  108. $(window).on('resize',positionGrabber);
  109. hljs.initHighlightingOnLoad();
  110. initHiddenCode();
  111. });