fix(shaarli/edit) restore native tag auto complete
This commit is contained in:
@ -148,6 +148,9 @@
|
|||||||
document.addEventListener('DOMContentLoaded', function() {
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
var input = document.getElementById("lf_tags{$batchId}");
|
var input = document.getElementById("lf_tags{$batchId}");
|
||||||
var suggestionsContainer = document.getElementById("tag-suggestions{$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 = [
|
var mapping = [
|
||||||
{ keys: ['accessibility','accessibilité','web development','web design','html','css','websites'], tags: ['web'] },
|
{ keys: ['accessibility','accessibilité','web development','web design','html','css','websites'], tags: ['web'] },
|
||||||
{ keys: ['accounting','comptabilité'], tags: ['accounting'] },
|
{ keys: ['accounting','comptabilité'], tags: ['accounting'] },
|
||||||
@ -290,14 +293,21 @@
|
|||||||
{ keys: ['youtube.com','invidious','peertube','watch?v'], tags: ['video'] },
|
{ keys: ['youtube.com','invidious','peertube','watch?v'], tags: ['video'] },
|
||||||
{ keys: ['zoemp','zoemp.be'], tags: ['zoemp'] }
|
{ keys: ['zoemp','zoemp.be'], tags: ['zoemp'] }
|
||||||
];
|
];
|
||||||
|
|
||||||
var matchCounts = {};
|
var matchCounts = {};
|
||||||
var tagify = new Tagify(input, {
|
var tagify = new Tagify(input, {
|
||||||
delimiters: ",| ",
|
delimiters: ",| ",
|
||||||
pattern: /^.{1,50}$/,
|
pattern: /^.{1,50}$/,
|
||||||
trim: true,
|
trim: true,
|
||||||
keepInvalidTags: false,
|
keepInvalidTags: false,
|
||||||
whitelist: [],
|
whitelist: [], // sera mis à jour dynamiquement
|
||||||
dropdown: { enabled: 0 },
|
dropdown: {
|
||||||
|
enabled: 1, // activation du dropdown à la frappe
|
||||||
|
fuzzySearch: true,
|
||||||
|
position: 'all',
|
||||||
|
maxItems: 50,
|
||||||
|
closeOnSelect: false
|
||||||
|
},
|
||||||
maxTags: 50,
|
maxTags: 50,
|
||||||
duplicates: false,
|
duplicates: false,
|
||||||
originalInputValueFormat: function(valuesArr) {
|
originalInputValueFormat: function(valuesArr) {
|
||||||
@ -312,6 +322,8 @@
|
|||||||
var existing = tagify.value.map(function(item){ return item.value; });
|
var existing = tagify.value.map(function(item){ return item.value; });
|
||||||
matchCounts = {};
|
matchCounts = {};
|
||||||
var suggested = {};
|
var suggested = {};
|
||||||
|
|
||||||
|
// Calcule le nombre d’occurrences de chaque tag via les règles
|
||||||
mapping.forEach(function(entry) {
|
mapping.forEach(function(entry) {
|
||||||
var matchesKey = entry.keys.filter(function(k){ return desc.includes(k.toLowerCase()); }).length;
|
var matchesKey = entry.keys.filter(function(k){ return desc.includes(k.toLowerCase()); }).length;
|
||||||
entry.tags.forEach(function(t) {
|
entry.tags.forEach(function(t) {
|
||||||
@ -319,6 +331,7 @@
|
|||||||
suggested[t] = (suggested[t] || 0) + (matchesKey > 0 ? 1 : 0);
|
suggested[t] = (suggested[t] || 0) + (matchesKey > 0 ? 1 : 0);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
var highPriority = [], medPriority = [], lowPriority = [];
|
var highPriority = [], medPriority = [], lowPriority = [];
|
||||||
Object.keys(suggested).forEach(function(t) {
|
Object.keys(suggested).forEach(function(t) {
|
||||||
if (existing.indexOf(t) !== -1) return;
|
if (existing.indexOf(t) !== -1) return;
|
||||||
@ -326,9 +339,21 @@
|
|||||||
else if (suggested[t] === 1) medPriority.push(t);
|
else if (suggested[t] === 1) medPriority.push(t);
|
||||||
else lowPriority.push(t);
|
else lowPriority.push(t);
|
||||||
});
|
});
|
||||||
// tronque lowPriority à 5 éléments (ou autre nombre souhaité)
|
|
||||||
|
// Tronquer à 5 lowPriority
|
||||||
lowPriority = lowPriority.slice(0, 5);
|
lowPriority = lowPriority.slice(0, 5);
|
||||||
var ordered = highPriority.concat(medPriority).concat(lowPriority);
|
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 = '';
|
suggestionsContainer.innerHTML = '';
|
||||||
ordered.forEach(function(tag) {
|
ordered.forEach(function(tag) {
|
||||||
var el = document.createElement('span');
|
var el = document.createElement('span');
|
||||||
@ -364,4 +389,4 @@
|
|||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
{/if}
|
{/if}
|
Reference in New Issue
Block a user