main.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /**
  2. * Builds the demo page
  3. */
  4. function init() {
  5. buildCodeExample();
  6. buildNavigation();
  7. }
  8. /**
  9. * Creates the navigation components
  10. */
  11. function buildNavigation() {
  12. $('.example_btn').click( function() {
  13. $(document).scrollTop( $("#test").offset().top );
  14. });
  15. $('.events code').click( function() {
  16. location.href = '../docs/%24.fn.swipe.html#event:' + $(this).text();
  17. });
  18. $('.properties code').click( function() {
  19. location.href = '../docs/%24.fn.swipe.defaults.html#' + $(this).text();
  20. });
  21. $('.methods code').click( function() {
  22. location.href = '../docs/%24.fn.swipe.html#' + $(this).text();
  23. });
  24. }
  25. /**
  26. * Copies the <script> tag contents, and populates the demo pretty print div to display the
  27. * code example.
  28. */
  29. function buildCodeExample() {
  30. $('.prettyprint').each(function( index ) {
  31. //$(this).text( $("#"+$(this).attr('data-src')).html() );
  32. var src = $("#"+$(this).attr('data-src')).html();
  33. if(src) {
  34. var lines = src.split("\n");
  35. var trimedLines=[];
  36. var trimIndex=null;
  37. for (var i=0; i<lines.length; i++) {
  38. var line = lines[i];
  39. if(trimIndex===null) {
  40. var trimmed = line.trimLeft();
  41. if(line.length>0) {
  42. trimIndex = line.length - trimmed.length;
  43. }
  44. }
  45. if(line.length>0) {
  46. //Tabs to spaces
  47. line = line.replace(/\t/g, ' '); //not using $nbsp; as we want to display HTML tags, so we set the text value, not html
  48. trimedLines.push( line.substr(trimIndex) );
  49. }
  50. };
  51. var html = trimedLines.join("\n");
  52. $(this).text( html );
  53. }
  54. });
  55. //prettyPrint();
  56. }
  57. $(function() {
  58. init();
  59. });