script.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. (function($) {
  2. $(document).ready(function(){
  3. // putting lines by the pre blocks
  4. $("pre").each(function(){
  5. var pre = $(this).text().split("\n");
  6. var lines = new Array(pre.length+1);
  7. for(var i = 0; i < pre.length; i++) {
  8. var wrap = Math.floor(pre[i].split("").length / 70)
  9. if (pre[i]==""&&i==pre.length-1) {
  10. lines.splice(i, 1);
  11. } else {
  12. lines[i] = i+1;
  13. for(var j = 0; j < wrap; j++) {
  14. lines[i] += "\n";
  15. }
  16. }
  17. }
  18. $(this).before("<pre class='lines'>" + lines.join("\n") + "</pre>");
  19. });
  20. var headings = [];
  21. var collectHeaders = function(){
  22. headings.push({"top":$(this).offset().top - 15,"text":$(this).text()});
  23. }
  24. if($(".markdown-body h1").length > 1) $(".markdown-body h1").each(collectHeaders)
  25. else if($(".markdown-body h2").length > 1) $(".markdown-body h2").each(collectHeaders)
  26. else if($(".markdown-body h3").length > 1) $(".markdown-body h3").each(collectHeaders)
  27. $(window).scroll(function(){
  28. if(headings.length==0) return true;
  29. var scrolltop = $(window).scrollTop() || 0;
  30. if(headings[0] && scrolltop < headings[0].top) {
  31. $(".current-section").css({"opacity":0,"visibility":"hidden"});
  32. return false;
  33. }
  34. $(".current-section").css({"opacity":1,"visibility":"visible"});
  35. for(var i in headings) {
  36. if(scrolltop >= headings[i].top) {
  37. $(".current-section .name").text(headings[i].text);
  38. }
  39. }
  40. });
  41. $(".current-section a").click(function(){
  42. $(window).scrollTop(0);
  43. return false;
  44. })
  45. });
  46. }
  47. var defaultSettings = {
  48. milestoneNumber : 10,
  49. usePHPapi : true,
  50. apiPath : '/',
  51. repo : 'rails',
  52. username : 'rails'
  53. };
  54. $.fn.releaseNotes = function(settings){
  55. settings = $.extend({}, defaultSettings, settings || {});
  56. var apiPath = apiPath."api.php";
  57. var respType = (settings.usePHPapi) ? "jsonp" : "json"
  58. return this.each(function(){
  59. releases.load(this, settings);
  60. });
  61. var releases = {
  62. load: function(){
  63. this.callApi({
  64. action:"milestones"
  65. }).success(function(resp){
  66. console.log(resp)
  67. })
  68. },
  69. callApi: function(action){
  70. return $.ajax({
  71. url:this.urls[action](),
  72. dataType:respType,
  73. data:settings
  74. })
  75. },
  76. urls : {
  77. milestones : function(){
  78. if(settings.usePHPapi){
  79. return $url = "/repos/". $configs["username"] ."/". $configs["repo"] ."/milestones";
  80. }else{
  81. return apiPath;
  82. }
  83. }
  84. }
  85. }
  86. }
  87. )(jQuery)