-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtagList.html
More file actions
351 lines (300 loc) · 14.2 KB
/
tagList.html
File metadata and controls
351 lines (300 loc) · 14.2 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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Tag Management</title>
<style>
body {
font-family: 'Source Sans Pro', 'ui-sans-serif', 'system-ui', sans-serif;
}
.container {
display: flex;
flex-wrap: wrap;
gap: 10px;
border: 1px solid #ccc;
padding: 10px;
align-items: flex-start;
}
.top-container {
display: block;
flex-wrap: wrap;
gap: 10px;
border: 1px solid #ccc;
padding: 0px;
align-items: flex-start;
position: absolute;
background: white;
}
.pre-tag {
display: flex;
align-items: center;
gap: 8px;
background-color: #f0f0f0;
border: 1px solid #ddd;
padding: 4px 4px;
order: 0;
border-radius: 3px;
font-size: 13px;
}
.real-tag {
display: flex;
align-items: center;
gap: 8px;
padding: 4px 4px;
font-size: 13px;
/*color: #ea580c; */
/*background-image: linear-gradient(to bottom right, #ffedd5, #fdba74);*/
background-color: #f5a439;
border: 1px solid #fed7aa;;
border-radius: 3px;
/*cursor: pointer;*/
outline: none;
border-color:#fed7aa;
border-style: solid;
order: 0;
font-weight: 600;
}
.pre-tag span,
.real-tag span span {
cursor: pointer;
}
.pre-tag input[type="checkbox"] {
margin-right: 5px;
}
#add-new-tag-btn-container {
display: flex;
align-items: center;
}
#add-tag-btn-top-container {
padding: 5px;
border: 0;
}
#pre-tag-container {
padding: 5px;
border: 0;
}
#real-tag-definer {
width: 80px;
order: 1;
border: 0;
outline: none;
background: #f9f6f6;
height: 30px;
padding-top: 0px;
margin-top: 0px;
min-width: 80px;
resize: none;
}
.selected-tag {
border: 1px solid rgb(65, 107, 65);
background: #f5a439;
}
.delete-btn {
/*clip-path: polygon(10% 0, 0 10%, 40% 50%, 0 90%, 10% 100%, 50% 60%, 90% 100%, 100% 90%, 60% 50%, 100% 10%, 90% 0, 50% 40%);*/
content: "";
display: inline-block;
background-color: transparent;
width: 10px;
height: 18px;
cursor: pointer;
}
.delete-btn-inner {
clip-path: polygon(10% 0, 0 10%, 40% 50%, 0 90%, 10% 100%, 50% 60%, 90% 100%, 100% 90%, 60% 50%, 100% 10%, 90% 0, 50% 40%);
content: "";
display: inline-block;
background-color: #d40a0a67;
width: 10px;
height: 10px;
}
</style>
</head>
<body>
<!--<input type="text" id="textTagsFromDb" placeholder="Metin girin (virgülle ayırın)">-->
<div class="container" id="real-tag-container">
<input type="text" id="real-tag-definer" placeholder="Define a tag" oninput="autoExpandInput(this)">
</div>
<div class="top-container" id="pre-tag-top-container">
<div class="container" id="add-tag-btn-top-container">
<div id="add-new-tag-btn-container"></div>
</div>
<div class="container" id="pre-tag-container">
</div>
</div>
<!--<input type="text" id="textUsableTags" placeholder="Silinmemiş Metinler" readonly>
<input type="text" id="textSelectedTags" placeholder="Seçilmiş Metinler" readonly>-->
<script>
document.addEventListener('DOMContentLoaded', function () {
let tagsFromDb = [
"Surreal art", "Abstract painting", "Neon lights", "Glowing sunset", "Digital artwork", "Cosmic horror", "Retro futurism",
"Gothic architecture", "Shadowy figure", "Celestial bodies", "Magical realism", "Robot portrait", "Lost city",
"Dystopian society", "Peaceful village", "Haunted house", "Wildlife photo", "Snowy landscape", "Warrior pose", "Flower closeup",
"Oil painting", "Watercolor", "Line art", "Minimalist", "Abstract expressionism", "Cubism", "Surrealism", "Pop art", "Impressionism",
"Digital illustration", "Charcoal sketch", "Art nouveau", "Art deco", "Gothic", "Baroque", "Renaissance", "Photorealism",
"Concept art", "Pixel art", "Graffiti art", "color saturation", "contrast", "shadow", "light", "silhouette", "bokeh",
"digital drawing", "style transfer", "mood", "texture", "composition", "perspective", "depth", "focus", "color theory",
]
let usableTags = [...new Set(tagsFromDb)];
let selectedTags = [];
const textTagsFromDb = document.getElementById('textTagsFromDb');
const textUsableTags = document.getElementById('textUsableTags');
const textSelectedTags = document.getElementById('textSelectedTags');
const preTagTopContainer = document.getElementById('pre-tag-top-container');
const preTagContainer = document.getElementById('pre-tag-container');
const realTagContainer = document.getElementById('real-tag-container');
const realTagDefiner = document.getElementById('real-tag-definer');
const addNewTagBtnContainer = document.getElementById('add-tag-btn-top-container');
preTagTopContainer.style.display = 'none';
textTagsFromDb.value = tagsFromDb.join(', ');
updateUsableTagsDisplay();
realTagDefiner.addEventListener('input', function () {
// Yeni etiket ekleme butonunu güncelleme fonksiyonunu buraya taşıdık
updateAddButton(this.value);
// Etiketlerin görüntülenmesini güncelle
updateUsableTagsDisplay();
});
// Etiket ekleme butonunu güncelleyen fonksiyonu tanımlayın
function updateAddButton(value) {
addNewTagBtnContainer.innerHTML = '';
if (value.trim() !== '') {
const addButton = document.createElement('button');
addButton.textContent = `Click to add "${value}" (or press Tab)`;
addButton.onclick = function () {
addOrSelectTag(value.trim());
};
addNewTagBtnContainer.appendChild(addButton);
}
}
function resetFilter() {
realTagDefiner.value = ''; // Filtreleme input'unu temizle
updateUsableTagsDisplay(); // Tüm tag'ları tekrar listele
}
function addOrSelectTag(newTag) {
const isNewTag = !usableTags.includes(newTag);
const isNotSelected = !selectedTags.includes(newTag);
if (isNewTag && newTag !== '') {
usableTags.push(newTag);
}
if (isNewTag || isNotSelected) {
selectedTags.push(newTag);
}
resetFilter(); // Filtrelemeyi resetle ve tüm tag'ları listele
updateSelectedTagsDisplay();
addNewTagBtnContainer.innerHTML = '';
}
function updateUsableTagsDisplay() {
const filterText = realTagDefiner.value.toLowerCase().trim();
// Mevcut etiketleri kaldır
const existingTags = preTagContainer.querySelectorAll('.pre-tag');
existingTags.forEach(tag => tag.remove());
// Filtrelenmiş etiketleri göster
textUsableTags.value = usableTags.join(', ');
usableTags.forEach(function (tag) {
if (tag.toLowerCase().includes(filterText) || filterText === '') {
const tagEl = document.createElement('div');
tagEl.className = 'pre-tag';
if (selectedTags.includes(tag)) {
tagEl.classList.add('selected-tag'); // Seçili etiketler için sınıfı ekle
} else {
tagEl.classList.remove('selected-tag'); // Sınıfı kaldır
}
const tagName = document.createElement('span');
tagName.textContent = tag;
const deleteBtn = document.createElement('span');
deleteBtn.classList.add('delete-btn');
//deleteBtn.textContent = 'X';
deleteBtn.onclick = function (event) {
event.stopPropagation(); // Bu, tıklama olayının üst elementlere yayılmasını önler
usableTags = usableTags.filter(t => t !== tag);
selectedTags = selectedTags.filter(t => t !== tag); // Eğer etiket seçilmişse, seçimden kaldır
updateUsableTagsDisplay();
updateSelectedTagsDisplay();
};
const deleteBtnInner = document.createElement('span');
deleteBtnInner.classList.add('delete-btn-inner');
deleteBtn.appendChild(deleteBtnInner);
tagEl.appendChild(tagName);
tagEl.appendChild(deleteBtn);
preTagContainer.appendChild(tagEl);
// Tıklama olayı için event listener ekleme
tagEl.addEventListener('click', function() {
const tagIndex = selectedTags.indexOf(tag);
if (tagIndex === -1) {
selectedTags.push(tag); // Etiketi selectedTags listesine ekle
} else {
selectedTags.splice(tagIndex, 1); // Etiketi selectedTags listesinden çıkar
}
updateSelectedTagsDisplay();
updateUsableTagsDisplay();
});
tagEl.addEventListener('click', function(event) {
event.stopPropagation(); // Bu, tıklama olayının daha üst elementlere yayılmasını önler
// Burada, tagEl'e tıklanınca gerçekleşecek işlemler yer alır
});
deleteBtn.addEventListener('click', function(event) {
event.stopPropagation(); // Bu, tıklama olayının daha üst elementlere yayılmasını önler
// Silme işleminin gerçekleştirilmesi
});
}
});
}
function updateSelectedTagsDisplay() {
const existingTags = realTagContainer.querySelectorAll('.real-tag');
existingTags.forEach(tag => tag.remove());
textSelectedTags.value = selectedTags.join(', ');
selectedTags.forEach(function (tag) {
const tagEl = document.createElement('div');
tagEl.className = 'real-tag';
const tagName = document.createElement('span');
tagName.textContent = tag;
const deleteBtn = document.createElement('span');
deleteBtn.classList.add('delete-btn');
deleteBtn.onclick = function () {
event.stopPropagation(); // Bu, tıklama olayının üst elementlere yayılmasını önler
usableTags = usableTags.filter(t => t !== tag);
selectedTags = selectedTags.filter(t => t !== tag);
updateSelectedTagsDisplay();
updateUsableTagsDisplay();
};
const deleteBtnInner = document.createElement('span');
deleteBtnInner.classList.add('delete-btn-inner');
deleteBtn.appendChild(deleteBtnInner);
tagEl.appendChild(tagName);
tagEl.appendChild(deleteBtn);
realTagContainer.insertBefore(tagEl, realTagDefiner);
});
}
realTagContainer.addEventListener('click', function (event) {
if (event.target === realTagContainer) {
realTagDefiner.focus();
}
});
realTagContainer.addEventListener('click', function () {
preTagContainer.style.display = 'flex';
preTagTopContainer.style.display = 'block';
});
document.addEventListener('click', function (event) {
if (!preTagTopContainer.contains(event.target) && !realTagContainer.contains(event.target)) {
preTagTopContainer.style.display = 'none';
}
});
realTagDefiner.addEventListener('keydown', function (event) {
// Eğer basılan tuş Tab ise ve input alanı boş değilse
if (event.key === 'Tab' && this.value.trim() !== '') {
event.preventDefault(); // Tab tuşunun varsayılan davranışını engelle
addOrSelectTag(this.value.trim()); // addOrSelectTag fonksiyonunu çağır
}
});
});
function autoExpandInput(input) {
input.style.width = '0px';
let newWidth = input.scrollWidth + 10;
const maxWidth = 300;
if (newWidth > maxWidth) {
newWidth = maxWidth;
}
input.style.width = `${newWidth}px`;
}
</script>
</body>
</html>