materialize_css.html 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8" />
  5. <title>CSS Integration JSON Editor Example</title>
  6. <!-- Materialize CSS, Material Icons -->
  7. <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/css/materialize.min.css">
  8. <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
  9. <style>
  10. html { font-size: 12px; line-height: 1.3; }
  11. </style>
  12. <!-- Scripts. -->
  13. <script src="https://cdn.jsdelivr.net/npm/@json-editor/json-editor/dist/jsoneditor.min.js"></script>
  14. <script>
  15. // Set the default CSS theme and icon library globally
  16. JSONEditor.defaults.theme = 'materialize';
  17. JSONEditor.defaults.iconlib = 'materialicons';
  18. </script>
  19. </head>
  20. <body>
  21. <div class="container">
  22. <div class="row">
  23. <div class="col s12">
  24. <h1>Materialize CSS &ndash; JSON Editor Example</h1>
  25. </div>
  26. </div>
  27. <div class="row">
  28. <div class="col s6">
  29. <p>JSON Editor supports these popular CSS frameworks:</p>
  30. <ul>
  31. <li>Bootstrap 2</li>
  32. <li>Bootstrap 3</li>
  33. <li>Foundation 3</li>
  34. <li>Foundation 4</li>
  35. <li>Foundation 5</li>
  36. <li>jQuery UI</li>
  37. <li>
  38. Materialize <span class="grey-text">(shown here, see <a href="http://materializecss.com/">http://materializecss.com/</a>)</span>
  39. </li>
  40. </ul>
  41. </div>
  42. <div class="col s6">
  43. <p>JSON Editor supports these popular icon libraries:</p>
  44. <ul>
  45. <li>Bootstrap 2 Glyphicons</li>
  46. <li>Bootstrap 3 Glyphicons</li>
  47. <li>Foundicons 2</li>
  48. <li>Foundicons 3</li>
  49. <li>jQueryUI</li>
  50. <li>Font Awesome 3</li>
  51. <li>Font Awesome 4</li>
  52. <li>
  53. Material Icons <span class="grey-text">(shown here, see <a href="https://material.io/icons/">https://material.io/icons/</a>)</span>
  54. </li>
  55. </ul>
  56. </div>
  57. </div>
  58. <div class="row">
  59. <div class="col s12">
  60. <button id="submit" class="btn waves-effect waves-light">
  61. Submit (console.log)
  62. <i class="material-icons right">send</i>
  63. </button>
  64. <button id="restore" class="btn waves-effect waves-light">Restore to Default</button>
  65. <span id="valid_indicator" class="badge"></span>
  66. </div>
  67. </div>
  68. <div class="row">
  69. <div id="editor_holder" class="col s12"></div>
  70. </div>
  71. </div>
  72. <script type="text/javascript" src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
  73. <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/js/materialize.min.js"></script>
  74. <script>
  75. // This is the starting value for the editor
  76. // We will use this to seed the initial editor
  77. // and to provide a "Restore to Default" button.
  78. var starting_value = {
  79. name: "John Smith",
  80. age: 35,
  81. gender: "male",
  82. location: {
  83. city: "San Francisco",
  84. state: "California"
  85. },
  86. pets: [
  87. {
  88. name: "Spot",
  89. type: "dog",
  90. fixed: true
  91. },
  92. {
  93. name: "Whiskers",
  94. type: "cat",
  95. fixed: false
  96. }
  97. ],
  98. "cars": [
  99. {
  100. manufacturer: "Ford",
  101. model: "Mustang"
  102. },
  103. {
  104. manufacturer: "Lamborghini",
  105. model: "Diablo"
  106. }
  107. ]
  108. };
  109. // Initialize the editor
  110. var editor = new JSONEditor(document.getElementById('editor_holder'),{
  111. // Enable fetching schemas via ajax
  112. ajax: true,
  113. // The schema for the editor
  114. schema: {
  115. $ref: "person.json",
  116. format: "grid"
  117. },
  118. // Seed the form with a starting value
  119. startval: starting_value
  120. });
  121. // Hook up the submit button to log to the console
  122. document.getElementById('submit').addEventListener('click',function() {
  123. // Get the value from the editor
  124. console.log(editor.getValue());
  125. });
  126. // Hook up the Restore to Default button
  127. document.getElementById('restore').addEventListener('click',function() {
  128. editor.setValue(starting_value);
  129. });
  130. // Hook up the validation indicator to update its
  131. // status whenever the editor changes
  132. editor.on('change',function() {
  133. // Get an array of errors from the validator
  134. var errors = editor.validate();
  135. var indicator = document.getElementById('valid_indicator');
  136. // Not valid
  137. if(errors.length) {
  138. indicator.className = 'badge red';
  139. indicator.textContent = 'invalid';
  140. }
  141. // Valid
  142. else {
  143. indicator.className = 'badge green white-text';
  144. indicator.textContent = 'valid';
  145. }
  146. });
  147. </script>
  148. </body>
  149. </html>