bootswatch.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. (function(){
  2. $(window).scroll(function () {
  3. var top = $(document).scrollTop();
  4. $('.splash').css({
  5. 'background-position': '0px -'+(top/3).toFixed(2)+'px'
  6. });
  7. if(top > 50)
  8. $('#home > .navbar').removeClass('navbar-transparent');
  9. else
  10. $('#home > .navbar').addClass('navbar-transparent');
  11. });
  12. $("a[href='#']").click(function(e) {
  13. e.preventDefault();
  14. });
  15. var $button = $("<div id='source-button' class='btn btn-primary btn-xs'>&lt; &gt;</div>").click(function(){
  16. var html = $(this).parent().html();
  17. html = cleanSource(html);
  18. $("#source-modal pre").text(html);
  19. $("#source-modal").modal();
  20. });
  21. $('.bs-component [data-toggle="popover"]').popover();
  22. $('.bs-component [data-toggle="tooltip"]').tooltip();
  23. $(".bs-component").hover(function(){
  24. $(this).append($button);
  25. $button.show();
  26. }, function(){
  27. $button.hide();
  28. });
  29. function cleanSource(html) {
  30. var lines = html.split(/\n/);
  31. lines.shift();
  32. lines.splice(-1, 1);
  33. var indentSize = lines[0].length - lines[0].trim().length,
  34. re = new RegExp(" {" + indentSize + "}");
  35. lines = lines.map(function(line){
  36. if (line.match(re)) {
  37. line = line.substring(indentSize);
  38. }
  39. return line;
  40. });
  41. lines = lines.join("\n");
  42. return lines;
  43. }
  44. })();