File: materialize_css.html

package info (click to toggle)
json-editor.js 1.3.2%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster
  • size: 1,692 kB
  • sloc: perl: 39; makefile: 5
file content (164 lines) | stat: -rw-r--r-- 5,419 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>CSS Integration JSON Editor Example</title>

    <!-- Materialize CSS, Material Icons -->
    <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
    <link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
    <style>
        html { font-size: 12px; line-height: 1.3; }
    </style>

    <!-- Scripts. -->
    <script src="../../../javascript/json-editor/jsoneditor.min.js"></script>
    <script>
        // Set the default CSS theme and icon library globally
        JSONEditor.defaults.theme = 'materialize';
        JSONEditor.defaults.iconlib = 'materialicons';
    </script>

  </head>
  <body>
    <div class="container">

        <div class="row">
            <div class="col s12">
                <h1>Materialize CSS &ndash; JSON Editor Example</h1>
            </div>
        </div>

        <div class="row">
            <div class="col s6">
                <p>JSON Editor supports these popular CSS frameworks:</p>
                <ul>
                    <li>Bootstrap 2</li>
                    <li>Bootstrap 3</li>
                    <li>Foundation 3</li>
                    <li>Foundation 4</li>
                    <li>Foundation 5</li>
                    <li>jQuery UI</li>
                    <li>
                      Materialize <span class="grey-text">(shown here, see <a href="http://materializecss.com/">http://materializecss.com/</a>)</span>
                    </li>
                </ul>
            </div>
            <div class="col s6">
                <p>JSON Editor supports these popular icon libraries:</p>
                <ul>
                    <li>Bootstrap 2 Glyphicons</li>
                    <li>Bootstrap 3 Glyphicons</li>
                    <li>Foundicons 2</li>
                    <li>Foundicons 3</li>
                    <li>jQueryUI</li>
                    <li>Font Awesome 3</li>
                    <li>Font Awesome 4</li>
                    <li>
                      Material Icons <span class="grey-text">(shown here, see <a href="https://material.io/icons/">https://material.io/icons/</a>)</span>
                    </li>
                </ul>
            </div>
        </div>
        <div class="row">
            <div class="col s12">
                <button id="submit" class="btn waves-effect waves-light">
                    Submit (console.log)
                    <i class="material-icons right">send</i>
                </button>
                <button id="restore"  class="btn waves-effect waves-light">Restore to Default</button>
                <span id="valid_indicator" class="badge"></span>
            </div>
        </div>
        <div class="row">
            <div id="editor_holder" class="col s12"></div>
        </div>
    </div>

    <script type="text/javascript" src="../../../javascript/jquery/jquery.min.js"></script>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>

    <script>
      // This is the starting value for the editor
      // We will use this to seed the initial editor 
      // and to provide a "Restore to Default" button.
      var starting_value = {
        name: "John Smith",
        age: 35,
        gender: "male",
        location: {
          city: "San Francisco",
          state: "California"
        },
        pets: [
          {
            name: "Spot",
            type: "dog",
            fixed: true
          },
          {
            name: "Whiskers",
            type: "cat",
            fixed: false
          }
        ],
        "cars": [
            {
                manufacturer: "Ford",
                model: "Mustang"
            },
            {
                manufacturer: "Lamborghini",
                model: "Diablo"
            }
        ]
      };
      
      // Initialize the editor
      var editor = new JSONEditor(document.getElementById('editor_holder'),{
        // Enable fetching schemas via ajax
        ajax: true,
        
        // The schema for the editor
        schema: {
          $ref: "person.json",
          format: "grid"
        },
        
        // Seed the form with a starting value
        startval: starting_value
      });
      
      // Hook up the submit button to log to the console
      document.getElementById('submit').addEventListener('click',function() {
        // Get the value from the editor
        console.log(editor.getValue());
      });
      
      // Hook up the Restore to Default button
      document.getElementById('restore').addEventListener('click',function() {
        editor.setValue(starting_value);
      });
      
      // Hook up the validation indicator to update its 
      // status whenever the editor changes
      editor.on('change',function() {
        // Get an array of errors from the validator
        var errors = editor.validate();
        
        var indicator = document.getElementById('valid_indicator');
        
        // Not valid
        if(errors.length) {
          indicator.className = 'badge red';
          indicator.textContent = 'invalid';
        }
        // Valid
        else {
          indicator.className = 'badge green white-text';
          indicator.textContent = 'valid';
        }
      });
    </script>
  </body>
</html>