css_integration.html 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8" />
  5. <title>CSS Integration JSON Editor Example</title>
  6. <!-- Foundation CSS framework (Bootstrap and jQueryUI also supported) -->
  7. <link rel='stylesheet' href='//cdn.jsdelivr.net/foundation/5.0.2/css/foundation.min.css'>
  8. <!-- Font Awesome icons (Bootstrap, Foundation, and jQueryUI also supported) -->
  9. <link rel='stylesheet' href='//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.0.3/css/font-awesome.css'>
  10. <script src="//unpkg.com/json-editor"></script>
  11. <script>
  12. // Set the default CSS theme and icon library globally
  13. JSONEditor.defaults.theme = 'foundation5';
  14. JSONEditor.defaults.iconlib = 'fontawesome4';
  15. </script>
  16. </head>
  17. <body>
  18. <div class='row'>
  19. <div class='medium-12 columns'>
  20. <h1>CSS Integration JSON Editor Example</h1>
  21. </div>
  22. </div>
  23. <div class='row'>
  24. <div class='medium-6 columns'>
  25. <p>JSON Editor supports these popular CSS frameworks:</p>
  26. <ul>
  27. <li>Bootstrap 2</li>
  28. <li>Bootstrap 3</li>
  29. <li>Foundation 3</li>
  30. <li>Foundation 4</li>
  31. <li>Foundation 5 (shown here)</li>
  32. <li>jQuery UI</li>
  33. </ul>
  34. </div>
  35. <div class='medium-6 columns'>
  36. <p>JSON Editor supports these popular icon libraries:</p>
  37. <ul>
  38. <li>Bootstrap 2 Glyphicons</li>
  39. <li>Bootstrap 3 Glyphicons</li>
  40. <li>Foundicons 2</li>
  41. <li>Foundicons 3</li>
  42. <li>jQueryUI</li>
  43. <li>Font Awesome 3</li>
  44. <li>Font Awesome 4 (shown here)</li>
  45. </ul>
  46. </div>
  47. </div>
  48. <div class='row'>
  49. <div class='medium-12-columns'>
  50. <button id='submit' class='tiny'>Submit (console.log)</button>
  51. <button id='restore' class='secondary tiny'>Restore to Default</button>
  52. <span id='valid_indicator' class='label'></span>
  53. </div>
  54. </div>
  55. <div class='row'>
  56. <div id='editor_holder' class='medium-12 columns'></div>
  57. </div>
  58. <script>
  59. // This is the starting value for the editor
  60. // We will use this to seed the initial editor
  61. // and to provide a "Restore to Default" button.
  62. var starting_value = {
  63. name: "John Smith",
  64. age: 35,
  65. gender: "male",
  66. location: {
  67. city: "San Francisco",
  68. state: "California"
  69. },
  70. pets: [
  71. {
  72. name: "Spot",
  73. type: "dog",
  74. fixed: true
  75. },
  76. {
  77. name: "Whiskers",
  78. type: "cat",
  79. fixed: false
  80. }
  81. ]
  82. };
  83. // Initialize the editor
  84. var editor = new JSONEditor(document.getElementById('editor_holder'),{
  85. // Enable fetching schemas via ajax
  86. ajax: true,
  87. // The schema for the editor
  88. schema: {
  89. $ref: "person.json",
  90. format: "grid"
  91. },
  92. // Seed the form with a starting value
  93. startval: starting_value
  94. });
  95. // Hook up the submit button to log to the console
  96. document.getElementById('submit').addEventListener('click',function() {
  97. // Get the value from the editor
  98. console.log(editor.getValue());
  99. });
  100. // Hook up the Restore to Default button
  101. document.getElementById('restore').addEventListener('click',function() {
  102. editor.setValue(starting_value);
  103. });
  104. // Hook up the validation indicator to update its
  105. // status whenever the editor changes
  106. editor.on('change',function() {
  107. // Get an array of errors from the validator
  108. var errors = editor.validate();
  109. var indicator = document.getElementById('valid_indicator');
  110. // Not valid
  111. if(errors.length) {
  112. indicator.className = 'label alert';
  113. indicator.textContent = 'not valid';
  114. }
  115. // Valid
  116. else {
  117. indicator.className = 'label success';
  118. indicator.textContent = 'valid';
  119. }
  120. });
  121. </script>
  122. </body>
  123. </html>