Sort tags as they are added to photo.

master
voussoir 2020-09-12 16:52:46 -07:00
parent be7decf330
commit c11fb12069
1 changed files with 18 additions and 0 deletions

View File

@ -327,6 +327,7 @@ function add_photo_tag_callback(response)
li.appendChild(tag_object); li.appendChild(tag_object);
li.appendChild(remove_button); li.appendChild(remove_button);
this_tags.appendChild(li); this_tags.appendChild(li);
sort_tag_objects();
} }
function remove_photo_tag_form(photo_id, tagname) function remove_photo_tag_form(photo_id, tagname)
@ -382,6 +383,23 @@ function add_remove_photo_tag_callback(response)
common.create_message_bubble(message_area, message_positivity, message_text, 8000); common.create_message_bubble(message_area, message_positivity, message_text, 8000);
} }
function sort_tag_objects()
{
const tag_list = document.getElementById("this_tags");
const lis = Array.from(tag_list.children).filter(el => el.getElementsByClassName("tag_object").length);
function compare(li1, li2)
{
const tag1 = li1.querySelector(".tag_object:last-of-type").innerText;
const tag2 = li2.querySelector(".tag_object:last-of-type").innerText;
return tag1 < tag2 ? -1 : 1;
}
lis.sort(compare);
for (const li of lis)
{
tag_list.appendChild(li);
}
}
function generate_thumbnail_callback(response) function generate_thumbnail_callback(response)
{ {
if (response.meta.status == 200) if (response.meta.status == 200)