This repository has been archived by the owner on Sep 9, 2019. It is now read-only.
forked from JJediny/json2yaml-editor
-
Notifications
You must be signed in to change notification settings - Fork 8
/
index.html
139 lines (128 loc) · 5.33 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>.about.yml Editor</title>
<!-- Foundation CSS framework (Bootstrap and jQueryUI also supported) -->
<link rel='stylesheet' href='//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css'>
<!-- Font Awesome icons (Bootstrap, Foundation, and jQueryUI also supported) -->
<link rel='stylesheet' href='//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.0.3/css/font-awesome.css'>
<link rel='stylesheet' href='assets/css/style.css'>
<script src="//code.jquery.com/jquery-1.12.2.min.js" integrity="sha256-lZFHibXzMHo3GGeehn1hudTAP3Sc0uKXBXAzHX1sjtk=" crossorigin="anonymous"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0-alpha1/jquery.min.js"></script>
<script src="assets/js/jsoneditor.js"></script>
<script src="assets/js/json2yaml.js"></script>
<!-- SimpleMDE Simple Markdown Editor -->
<link rel="stylesheet" href="//cdn.jsdelivr.net/simplemde/latest/simplemde.min.css">
<script src="//cdn.jsdelivr.net/simplemde/latest/simplemde.min.js"></script>
<!-- Hypothesis annotator -->
<!-- <script async defer src="//hypothes.is/embed.js"></script> -->
<script>
// Set the default CSS theme and icon library globally
JSONEditor.defaults.options.theme = 'bootstrap3';
JSONEditor.defaults.options.iconlib = 'bootstrap3';
JSONEditor.defaults.options.disable_edit_json = 'true';
</script>
</head>
<body>
<div class='row'>
<div class='col-sm-12 col-md-6'>
<h1>Jekyll Page Builder for data.json</h1>
</div>
</div>
<div class='row'>
<div class='col-sm-12 col-md-6'>
<button type='button' class='btn btn-default pull-left' data-toggle="modal" data-target="#markdown-modal">Markdown Editor</button>
<button id='generate' type='button' class='btn btn-danger pull-right' data-toggle="modal" data-target="#yaml-modal">Generate</button>
<span id='valid_indicator' class='label'></span>
</div>
</div>
<div id='editor_holder' class='col-sm-12 col-md-6'></div>
<!-- YAML Modal -->
<div id="yaml-modal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">YAML Output</h4>
</div>
<div class="modal-body">
<div id='editor_holder' class='well'>
<textarea id='yamloutput' class='yamlwindow' style="width: 100%"></textarea>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<!-- Markdown Modal -->
<div id="markdown-modal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Markdown Editor</h4>
</div>
<div class="modal-body">
<textarea id="markdown-editor" style="display: none;"></textarea>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<script>
$.getJSON('ref/data.json', function(data) {
// Initialize the editor
var editor = new JSONEditor(document.getElementById('editor_holder'),{
// Enable fetching schemas via ajax
ajax: true,
// The schema for the editor
schema: data
});
// Hook up the generate button to output to the text field
document.getElementById('generate').addEventListener('click',function() {
// Get the value from the editor
var yaml = json2yaml(editor.getValue());
console.log(editor.getValue());
$("#yamloutput").val(yaml);
console.log(yaml);
});
// 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 = 'label alert';
indicator.textContent = 'not valid';
}
// Valid
else {
indicator.className = 'label success';
indicator.textContent = 'valid';
var yaml = json2yaml(editor.getValue());
$("#yamloutput").val(yaml);
}
});
});
new SimpleMDE({
element: document.getElementById("markdown-editor"),
spellChecker: true,
autosave: {
enabled: true,
unique_id: "markdown-editor",
},
});
</script>
</script>
</body>
</html>