This repository has been archived by the owner on Dec 8, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathindex.html
85 lines (75 loc) · 2.92 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
<!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='//cdn.jsdelivr.net/foundation/5.0.2/css/foundation.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="//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>
<script>
// Set the default CSS theme and icon library globally
JSONEditor.defaults.theme = 'foundation5';
JSONEditor.defaults.iconlib = 'fontawesome4';
</script>
</head>
<body>
<div class='row'>
<div class='medium-12 columns'>
<h1>.about.yml editor</h1>
</div>
</div>
<div class='row'>
<div class='medium-12-columns'>
<button id='generate' class='tiny'>Generate</button>
<span id='valid_indicator' class='label'></span>
</div>
</div>
<div class='row'>
<div id='editor_holder' class='medium-7 columns'></div>
<div class='medium-5 columns'><textarea id='yamloutput' class='yamlwindow'></textarea></div>
</div>
<script>
$.getJSON('https://raw.githubusercontent.com/18F/about_yml/master/lib/about_yml/schema.json', function(data) {
// Initialize the editor
var editor = new JSONEditor(document.getElementById('editor_holder'),{
// Enable fetching schemas via ajax
ajax: false,
// 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);
}
});
});
</script>
</body>
</html>