-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrenderer.js
83 lines (73 loc) · 2.11 KB
/
renderer.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
window.$ = window.jQuery = require('jquery');
var pantry;
const PkgxPantry = require('pkgx-pantry');
// Document ready
$(function () {
generate();
getPantry();
$(".hide-switch").on("click", function () {
if (this.checked) {
$(this).parent().next(".hide").slideDown();
} else {
$(this).parent().next(".hide").slideUp();
}
});
$("input").on("change", function () {
generate();
});
$("select").on("change", function () {
generate();
});
$("textarea").on("change", function () {
generate();
});
$('.copy').on('click', function() {
let content = $(this).text();
navigator.clipboard.writeText(content);
createToast('<i class="bi bi-clipboard-check"></i> Content copied to clipboard');
});
// Save package
$('#btnSave').on('click', function () {
package.set(packageData.package.name, packageData);
createToast(`<i class="bi bi-clipboard-check"></i> Package <b>${packageData.package.name}</b> saved!`);
});
// Load package
$('#btnLoad').on('click', function () {
package.modal();
});
// Remove dropdown when clicked outside
$(document).on('click', function(event) {
$('.autocomplete-result').remove();
});
});
const getPantry = async () => {
try {
await PkgxPantry.getPackages().then((data) => {
pantry = data;
});
} catch (error) {
console.error("Error:", error);
}
};
const autocomplete = (text) => {
let search = [];
const filteredArray = pantry.filter(item => item.project.includes(text));
filteredArray.slice(0, 10).forEach((item) => {
search.push(item.project);
});
return search;
};
var toastCounter = 0;
const createToast = (text) => {
html = `
<div class="toast align-items-center text-bg-primary border-0" role="alert" aria-live="assertive" aria-atomic="true" id="toast-${toastCounter}">
<div class="d-flex">
<div class="toast-body">${text}</div>
<button type="button" class="btn-close btn-close-white me-2 m-auto" data-bs-dismiss="toast" aria-label="Close"></button>
</div>
</div>
`;
$('#toasts').append(html);
$(`#toast-${toastCounter}`).toast('show');
toastCounter++;
};