-
Notifications
You must be signed in to change notification settings - Fork 9
/
main.js
50 lines (42 loc) · 1.37 KB
/
main.js
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
(function($) {
var editorconfig = require('./node_modules/editorconfig/editorconfig.js');
function createFiles() {
return [{
name: $.get('.editorconfig input').value,
contents: $.get('.editorconfig textarea').value
}];
}
var setTextAreaHeight = function (el) {
// Set textarea height
el.style.height = 'auto';
el.style.height = el.scrollHeight + 16 + 'px';
// Get maximum section height
var maxHeight = 0;
$.byTag('section').forEach(function(el) {
el.style.height = 'auto';
if (el.clientHeight > maxHeight) maxHeight = el.clientHeight;
});
// Set section height
$.byTag('section').forEach(function(el) { el.style.height = maxHeight; });
};
$.byTag('textarea').forEach(function(el) {
var textareaInput = function () { setTextAreaHeight(el); };
el.on('input', textareaInput);
textareaInput();
});
$('input, textarea').forEach(function (el) {
var updateDemo = function () {
var configFiles = createFiles();
$('.output [name=filename]').forEach(function (el) {
var output = "";
var config = editorconfig.parseFromFiles(el.value, configFiles);
for (var key in config) {
output += key + " = " + config[key] + "\n";
}
$.get('.output pre').innerText = output;
});
};
el.on('input', updateDemo);
updateDemo();
});
}(vQuery));