From 5414a36b2db42f08a492aac8a2d30b54d37c5a92 Mon Sep 17 00:00:00 2001 From: SansGuidon Date: Wed, 4 Jun 2025 23:59:49 +0000 Subject: [PATCH] fix(shaarli/edit) restore native tag auto complete --- morgan/editlink.html | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) 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 @@ -{/if} +{/if} \ No newline at end of file