-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathdemo.js
More file actions
47 lines (41 loc) · 1.38 KB
/
demo.js
File metadata and controls
47 lines (41 loc) · 1.38 KB
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
(function ($) {
var editorconfig = require('editorconfig');
function createFiles() {
var configFiles = [], configSuffix = "/.editorconfig";
$('.js-ec-demo-config').each(function () {
var pathLength, configPath, form = $(this);
configPath = form.find('[name="filename"]').val();
pathLength = configPath.length - configSuffix.length;
if (configPath.indexOf(configSuffix, pathLength) !== -1) {
configFiles.push({
name: configPath,
contents: form.find('[name="file"]').val()
});
}
});
return configFiles;
}
// Resize textarea automatically
$('textarea').on('input', function () {
// Set textarea height
this.style.height = 'auto';
this.style.height = this.scrollHeight + 16 + 'px';
}).trigger('input');
function renderOutput(configFiles) {
$('.js-ec-demo-output').each(function () {
var output = "", config, key, filename;
filename = $(this).find('[name="filename"]');
config = editorconfig.parseFromFiles(filename.val(), configFiles);
for (key in config) {
if (config.hasOwnProperty(key)) {
output += key + " = " + config[key] + "\n";
}
}
$(this).find('pre').text(output);
});
}
// Update output automatically
$('input, textarea').on('input', function () {
renderOutput(createFiles());
}).trigger('input');
}(jQuery));