-
Notifications
You must be signed in to change notification settings - Fork 634
/
Copy pathapp.js
executable file
·65 lines (58 loc) · 2.11 KB
/
app.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
$.ajax('/dropdown/templates.json').success(data => {
$(".ignore-search").select2({
sorter(results) {
const query = $('.select2-search__field').val().toLowerCase();
return results.sort((a, b) => a.text.toLowerCase().indexOf(query) -
b.text.toLowerCase().indexOf(query));
},
minimumInputLength: 1,
theme: "bootstrap",
multiple: true,
data
});
});
// Delete selecitons by tag instead of individual letter
$.fn.select2.amd.require(['select2/selection/search'], function (Search) {
Search.prototype.searchRemoveChoice = function (decorated, item) {
this.trigger('unselect', {
data: item
});
this.$search.val('');
this.handleSearch();
};
});
// Highlight input on site load
setTimeout(() => {
$(".select2-search__field").focus();
}, 100);
// All users to press ctrl+enter to create template
$(".ignore-search").on("select2:selecting", e => {
setTimeout(() => {
$(".select2-search__field").keydown(e => {
if (e.keyCode == 13 && (e.metaKey || e.ctrlKey)) {
generateGitIgnore();
}
});
}, 100);
});
// Generate gitignore template
function generateGitIgnore() {
const searchString = $(".ignore-search").map(function() {return $(this).val();}).get().join(',');
const searchLength = searchString.length;
if (searchLength > 0) {
const files = searchString.replace(/^,/, '');
const uriEncodedFiles = encodeURIComponent(files);
window.location = `/api/${uriEncodedFiles}`;
$(".ignore-search").val("");
}
}
// Generate gitignore file template
function generateGitIgnoreFile() {
const searchString = $(".ignore-search").map(function() {return $(this).val();}).get().join(',');
const searchLength = searchString.length;
if (searchLength > 0) {
const files = searchString.replace(/^,/, '');
const uriEncodedFiles = encodeURIComponent(files);
window.location = `/api/f/${uriEncodedFiles}`;
}
}