You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

126 lines
3.5KB

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>FIGlet Example</title>
  5. </head>
  6. <body>
  7. <div>
  8. <label for="font">Font:</label>
  9. <select id="font">
  10. <option value="3D Diagonal">3D Diagonal</option>
  11. <option value="Dancing Font">Dancing Font</option>
  12. <option value="Ghost">Ghost</option>
  13. <option value="Graffiti">Graffiti</option>
  14. <option value="Patorjk's Cheese">Patorjk's Cheese</option>
  15. <option value="Standard" selected>Standard</option>
  16. </select>
  17. </div>
  18. <div>
  19. <label for="hLayout">Horizontal Layout:</label>
  20. <select id="hLayout">
  21. <option value="default" selected>Default</option>
  22. <option value="full">Full</option>
  23. <option value="fitted">Fitted</option>
  24. <option value="controlled smushing">Controlled Smushing</option>
  25. <option value="universal smushing">Universal Smushing</option>
  26. </select>
  27. </div>
  28. <div>
  29. <label for="vLayout">Vertical Layout:</label>
  30. <select id="vLayout">
  31. <option value="default" selected>Default</option>
  32. <option value="full">Full</option>
  33. <option value="fitted">Fitted</option>
  34. <option value="controlled smushing">Controlled Smushing</option>
  35. <option value="universal smushing">Universal Smushing</option>
  36. </select>
  37. </div>
  38. <div>
  39. <label for="inputText">Input:</label>
  40. </div>
  41. <textarea id="inputText" style="height:100px;width:200px;">test
  42. 123</textarea>
  43. <p></p>
  44. <div>
  45. <label for="outputFigDisplay">Output</label>
  46. </div>
  47. <div id="outputFigDisplay"></div>
  48. <script type="text/javascript" src="../../lib/figlet.js"></script>
  49. <script>
  50. if (window.location.protocol === 'file:') {
  51. alert('fetch APi does not support file: protocol.');
  52. }
  53. figlet.defaults({
  54. fontPath: '../../fonts'
  55. });
  56. figlet.preloadFonts(["Standard", "Ghost"], function() {
  57. console.log('prefetching done (only did it for 2 fonts)!');
  58. });
  59. /*
  60. Generates the put
  61. */
  62. var update = function() {
  63. var fontName = document.querySelector('#font option:checked').value,
  64. inputText = document.querySelector('#inputText').value,
  65. vLayout = document.querySelector('#vLayout option:checked').value,
  66. hLayout = document.querySelector('#hLayout option:checked').value;
  67. /*
  68. How to use the text output.
  69. The below call could also have been: figlet.text(...
  70. */
  71. figlet(inputText, {
  72. font: fontName,
  73. horizontalLayout: hLayout,
  74. verticalLayout: vLayout
  75. }, function(err, text) {
  76. if (err) {
  77. console.log('something went wrong...');
  78. console.dir(err);
  79. return;
  80. }
  81. document.querySelector('#outputFigDisplay').innerHTML = ("<pre>" + text + "</pre>");
  82. });
  83. /*
  84. How to read the metadata for a font
  85. */
  86. /*
  87. figlet.metadata(fontName, function(err, options, headerComment) {
  88. if (err) {
  89. console.log('something went wrong...');
  90. console.dir(err);
  91. return;
  92. }
  93. console.dir(options);
  94. console.log(headerComment);
  95. });
  96. */
  97. };
  98. /*
  99. GUI Controls
  100. */
  101. document.querySelector('#hLayout').addEventListener("change", update);
  102. document.querySelector('#vLayout').addEventListener("change", update);
  103. document.querySelector('#font').addEventListener("change", update);
  104. document.querySelector('#inputText').addEventListener("keyup", update);
  105. update(); // init
  106. </script>
  107. </body>
  108. </html>