tutorial.tmpl 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?js
  2. var hasCodeTab = false;
  3. var self = this;
  4. ?>
  5. <section>
  6. <header>
  7. <?js if (children.length > 0) { ?>
  8. <ul><?js
  9. children.forEach(function(t) { ?>
  10. <li><?js= self.tutoriallink(t.name) ?></li>
  11. <?js }); ?></ul>
  12. <?js } ?>
  13. <h2><?js= header ?></h2>
  14. </header>
  15. <?js if (isHtmlTutorial) { ?>
  16. <?js hasCodeTab = !!(codeJs || codeHtml) ? 'nav nav-tabs' : 'nav nav-tabs hidden'; ?>
  17. <ul id="example-nav" class="<?js= hasCodeTab ?>">
  18. <li role="presentation" id="example-result-btn" class="active" onclick="showResult()">
  19. <a href="#">Result</a>
  20. </li>
  21. <li role="presentation" id="example-js-btn" class="<?js= codeJs ? '' : 'hidden' ?>" onclick="showJs()">
  22. <a href="#">JS</a>
  23. </li>
  24. <li role="presentation" id="example-html-btn" class="<?js= codeHtml ? '' : 'hidden' ?>" onclick="showHtml()">
  25. <a href="#">HTML</a>
  26. </li>
  27. </ul>
  28. <article>
  29. <?js
  30. var src = 'tutorials/' + originalFileName + '.html';
  31. ?>
  32. <iframe id="example-result" width="100%" height="800" frameborder="0" src=<?js= src ?>></iframe>
  33. <div id="example-js" class="hidden"><pre class="prettyprint source"><?js= codeJs ?></pre></div>
  34. <div id="example-html" class="hidden"><pre class="prettyprint source"><?js= codeHtml ?></pre></div>
  35. </article>
  36. <?js } else { ?>
  37. <article class="readme">
  38. <?js= content ?>
  39. </article>
  40. <?js } ?>
  41. </section>
  42. <?js if (isHtmlTutorial) {?>
  43. <script>
  44. var exampleResult = document.getElementById('example-result');
  45. var exampleJs = document.getElementById('example-js');
  46. var exampleHtml = document.getElementById('example-html');
  47. var exampleResultBtn = document.getElementById('example-result-btn');
  48. var exampleJsBtn = document.getElementById('example-js-btn');
  49. var exampleHtmlBtn = document.getElementById('example-html-btn');
  50. function setActive(el) {
  51. el.className += ' active';
  52. }
  53. function setInactive(el) {
  54. el.className = el.className.replace(/\s*active\s*/g, '');
  55. }
  56. function show(el) {
  57. el.className = el.className.replace(/\s*hidden\s*/g, '');
  58. }
  59. function hide(el) {
  60. el.className += ' hidden';
  61. }
  62. function showJs() {
  63. hide(exampleHtml);
  64. hide(exampleResult);
  65. setInactive(exampleHtmlBtn);
  66. setInactive(exampleResultBtn);
  67. show(exampleJs);
  68. setActive(exampleJsBtn);
  69. }
  70. function showHtml() {
  71. hide(exampleJs);
  72. hide(exampleResult);
  73. setInactive(exampleJsBtn);
  74. setInactive(exampleResultBtn);
  75. show(exampleHtml);
  76. setActive(exampleHtmlBtn);
  77. }
  78. function showResult() {
  79. hide(exampleJs);
  80. hide(exampleHtml);
  81. setInactive(exampleJsBtn);
  82. setInactive(exampleHtmlBtn);
  83. show(exampleResult);
  84. setActive(exampleResultBtn);
  85. }
  86. </script>
  87. <?js } ?>