diff --git a/morgan/editlink.html b/morgan/editlink.html
index cc73b2c..4313e99 100644
--- a/morgan/editlink.html
+++ b/morgan/editlink.html
@@ -148,6 +148,9 @@
document.addEventListener('DOMContentLoaded', function() {
var input = document.getElementById("lf_tags{$batchId}");
var suggestionsContainer = document.getElementById("tag-suggestions{$batchId}");
+ // liste complète des tags depuis data-list
+ var allTags = input.getAttribute('data-list').split(/,\s*/);
+
var mapping = [
{ keys: ['accessibility','accessibilité','web development','web design','html','css','websites'], tags: ['web'] },
{ keys: ['accounting','comptabilité'], tags: ['accounting'] },
@@ -290,14 +293,21 @@
{ keys: ['youtube.com','invidious','peertube','watch?v'], tags: ['video'] },
{ keys: ['zoemp','zoemp.be'], tags: ['zoemp'] }
];
+
var matchCounts = {};
var tagify = new Tagify(input, {
delimiters: ",| ",
pattern: /^.{1,50}$/,
trim: true,
keepInvalidTags: false,
- whitelist: [],
- dropdown: { enabled: 0 },
+ whitelist: [], // sera mis à jour dynamiquement
+ dropdown: {
+ enabled: 1, // activation du dropdown à la frappe
+ fuzzySearch: true,
+ position: 'all',
+ maxItems: 50,
+ closeOnSelect: false
+ },
maxTags: 50,
duplicates: false,
originalInputValueFormat: function(valuesArr) {
@@ -312,6 +322,8 @@
var existing = tagify.value.map(function(item){ return item.value; });
matchCounts = {};
var suggested = {};
+
+ // Calcule le nombre d’occurrences de chaque tag via les règles
mapping.forEach(function(entry) {
var matchesKey = entry.keys.filter(function(k){ return desc.includes(k.toLowerCase()); }).length;
entry.tags.forEach(function(t) {
@@ -319,6 +331,7 @@
suggested[t] = (suggested[t] || 0) + (matchesKey > 0 ? 1 : 0);
});
});
+
var highPriority = [], medPriority = [], lowPriority = [];
Object.keys(suggested).forEach(function(t) {
if (existing.indexOf(t) !== -1) return;
@@ -326,9 +339,21 @@
else if (suggested[t] === 1) medPriority.push(t);
else lowPriority.push(t);
});
- // tronque lowPriority à 5 éléments (ou autre nombre souhaité)
+
+ // Tronquer à 5 lowPriority
lowPriority = lowPriority.slice(0, 5);
var ordered = highPriority.concat(medPriority).concat(lowPriority);
+
+ // On complète la whitelist avec le reste des tags non déjà listés
+ var fallback = allTags.filter(function(t) {
+ return ordered.indexOf(t) === -1 && existing.indexOf(t) === -1;
+ });
+
+ var finalList = ordered.concat(fallback);
+ tagify.settings.whitelist = finalList;
+ tagify.dropdown.show.call(tagify, finalList);
+
+ // Met à jour les suggestions affichées sous l’input
suggestionsContainer.innerHTML = '';
ordered.forEach(function(tag) {
var el = document.createElement('span');
@@ -364,4 +389,4 @@