-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
211 lines (180 loc) · 5.81 KB
/
script.js
File metadata and controls
211 lines (180 loc) · 5.81 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
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
function setActiveLink(event) {
// Menghapus class 'active' dan aria-current dari semua elemen
document.querySelectorAll(".nav-link").forEach((link) => {
link.classList.remove("active");
link.removeAttribute("aria-current");
});
// Menambahkan class 'active' dan aria-current ke elemen yang di-klik
event.target.classList.add("active");
event.target.setAttribute("aria-current", "page");
}
// Menambahkan event listener untuk setiap item menu
document.querySelectorAll(".nav-link").forEach((link) => {
link.addEventListener("click", setActiveLink);
});
var tooltipTriggerList = [].slice.call(
document.querySelectorAll('[data-bs-toggle="tooltip"]')
);
var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
return new bootstrap.Tooltip(tooltipTriggerEl);
});
document.getElementById("copy-icon").addEventListener("click", function () {
// Enable textarea temporarily to allow copying
const textarea = document.getElementById("cipher-text");
textarea.disabled = false;
// Get the content from the textarea
const textToCopy = textarea.value;
// Copy to clipboard
navigator.clipboard
.writeText(textToCopy)
.then(function () {
// Change icon to bi-clipboard-check
const icon = document.getElementById("copy-icon");
icon.classList.remove("bi-clipboard");
icon.classList.add("bi-clipboard-check");
// Update tooltip to 'Copied!'
const tooltip = bootstrap.Tooltip.getInstance(icon); // Get tooltip instance
tooltip.setContent({ ".tooltip-inner": "Copied!" }); // Update tooltip content
// Disable textarea again
textarea.disabled = true;
})
.catch(function (err) {
console.error("Error copying text: ", err);
});
});
document.getElementById("copy-icon-2").addEventListener("click", function () {
// Enable textarea temporarily to allow copying
const textarea = document.getElementById("plain-text");
textarea.disabled = false;
// Get the content from the textarea
const textToCopy = textarea.value;
// Copy to clipboard
navigator.clipboard
.writeText(textToCopy)
.then(function () {
// Change icon to bi-clipboard-check
const icon = document.getElementById("copy-icon-2");
icon.classList.remove("bi-clipboard");
icon.classList.add("bi-clipboard-check");
// Update tooltip to 'Copied!'
const tooltip = bootstrap.Tooltip.getInstance(icon); // Get tooltip instance
tooltip.setContent({ ".tooltip-inner": "Copied!" }); // Update tooltip content
// Disable textarea again
textarea.disabled = true;
})
.catch(function (err) {
console.error("Error copying text: ", err);
});
});
$(document).ready(function () {
// Fungsi untuk format hasil pencarian
function formatResult(number) {
if (!number.id) return number.text;
return $("<span>" + number.text + "</span>");
}
// Fungsi untuk format item terpilih
function formatSelection(number) {
return number.text;
}
// Custom matcher untuk pencarian
function customMatcher(params, data) {
// Jika tidak ada term pencarian, kembalikan semua data
if ($.trim(params.term) === "") {
return data;
}
// Skip jika tidak ada properti 'text'
if (typeof data.text === "undefined") {
return null;
}
// Cek apakah data.text mengandung term pencarian
if (data.text.toLowerCase().indexOf(params.term.toLowerCase()) > -1) {
return data;
}
return null;
}
// Inisialisasi Select2
$(".select2-p").select2({
placeholder: "-- Select a number --",
allowClear: true,
data: bil_prima.map((number) => ({
id: number,
text: number.toString(),
})),
minimumResultsForSearch: 1,
matcher: customMatcher,
templateResult: formatResult,
templateSelection: formatSelection,
// Tambahan konfigurasi
dropdownParent: $(".container"),
width: "100%",
// Event handlers
language: {
noResults: function () {
return "No numbers found";
},
},
});
// Event handlers
$(".select2-p").on("select2:select", function (e) {
console.log("Selected number:", e.params.data.text);
});
$(".select2-p").on("select2:unselect", function (e) {
console.log("Unselected number:", e.params.data.text);
});
});
$(document).ready(function () {
// Fungsi untuk format hasil pencarian
function formatResult(number) {
if (!number.id) return number.text;
return $("<span>" + number.text + "</span>");
}
// Fungsi untuk format item terpilih
function formatSelection(number) {
return number.text;
}
// Custom matcher untuk pencarian
function customMatcher(params, data) {
// Jika tidak ada term pencarian, kembalikan semua data
if ($.trim(params.term) === "") {
return data;
}
// Skip jika tidak ada properti 'text'
if (typeof data.text === "undefined") {
return null;
}
// Cek apakah data.text mengandung term pencarian
if (data.text.toLowerCase().indexOf(params.term.toLowerCase()) > -1) {
return data;
}
return null;
}
// Inisialisasi Select2
$(".select2-q").select2({
placeholder: "-- Select a number --",
allowClear: true,
data: bil_prima.map((number) => ({
id: number,
text: number.toString(),
})),
minimumResultsForSearch: 1,
matcher: customMatcher,
templateResult: formatResult,
templateSelection: formatSelection,
// Tambahan konfigurasi
dropdownParent: $(".container"),
width: "100%",
// Event handlers
language: {
noResults: function () {
return "No numbers found";
},
},
});
// Event handlers
$(".select2-p").on("select2:select", function (e) {
console.log("Selected number:", e.params.data.text);
});
$(".select2-p").on("select2:unselect", function (e) {
console.log("Unselected number:", e.params.data.text);
});
});