From 0698de34eeba8bea68be15a92ae3e8af5786c2a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Ku=C5=BE=C3=ADlek?= Date: Wed, 22 Apr 2020 10:59:14 +0200 Subject: [PATCH] NoJS tag coloring --- yadc/assets/js/taginput.js | 24 ++++++++++++++------ yadc/bp/post.py | 8 +++++-- yadc/static/all.js | 24 ++++++++++++++------ yadc/templates/layout/base_sidebar_tags.html | 18 +++++++++++++-- 4 files changed, 56 insertions(+), 18 deletions(-) diff --git a/yadc/assets/js/taginput.js b/yadc/assets/js/taginput.js index 601ffdd..36f0579 100644 --- a/yadc/assets/js/taginput.js +++ b/yadc/assets/js/taginput.js @@ -88,7 +88,7 @@ taginputs.forEach(function (tinput) { let newtag = create_selection_tag(tagname) newtag.addEventListener('click', (event) => { remove_selected(event.target.dataset.tagname) - // console.log(`Deselected: ${event.target.dataset.tagname}`) + event.preventDefault() setTimeout(() => suggest_input.focus(), 2) }) @@ -131,12 +131,22 @@ taginputs.forEach(function (tinput) { // add_selected(tag) // }) // } - let vals = suggest_input.value.split(' ') - // console.log(vals) - vals.forEach(tag => { - if (tag == '') return - add_selected(tag) - }); + // let vals = suggest_input.value.split(' ') + // // console.log(vals) + // vals.forEach(tag => { + // if (tag == '') return + // add_selected(tag) + // }); + // Not as clean, but well whatever + selected.querySelectorAll("a").forEach(element => { + element.addEventListener('click', (event) => { + remove_selected(event.target.dataset.tagname) + event.preventDefault() + + setTimeout(() => suggest_input.focus(), 2) + }) + hidden_addtag(element.dataset.tagname) + }) suggest_input.removeAttribute('value') // Disable prefill by browser function select_suggestion(tagelement) { diff --git a/yadc/bp/post.py b/yadc/bp/post.py index e6da54a..9607c50 100644 --- a/yadc/bp/post.py +++ b/yadc/bp/post.py @@ -53,8 +53,12 @@ def posts(page): posts = posts_query.paginate(page, current_app.config.get('POSTS_PER_PAGE')) tags = tags_prepare(posts.items) - - return render_template('post/index.html', posts=posts, tags=tags) + return render_template( + 'post/index.html', + posts=posts, + tags=tags, + sel_tags=[tag for tag in tags if tag.content in f_tags] + ) @bp.route('/show/') def post_show(id): diff --git a/yadc/static/all.js b/yadc/static/all.js index 960e118..4589a32 100644 --- a/yadc/static/all.js +++ b/yadc/static/all.js @@ -176,7 +176,7 @@ taginputs.forEach(function (tinput) { let newtag = create_selection_tag(tagname) newtag.addEventListener('click', (event) => { remove_selected(event.target.dataset.tagname) - // console.log(`Deselected: ${event.target.dataset.tagname}`) + event.preventDefault() setTimeout(() => suggest_input.focus(), 2) }) @@ -219,12 +219,22 @@ taginputs.forEach(function (tinput) { // add_selected(tag) // }) // } - let vals = suggest_input.value.split(' ') - // console.log(vals) - vals.forEach(tag => { - if (tag == '') return - add_selected(tag) - }); + // let vals = suggest_input.value.split(' ') + // // console.log(vals) + // vals.forEach(tag => { + // if (tag == '') return + // add_selected(tag) + // }); + // Not as clean, but well whatever + selected.querySelectorAll("a").forEach(element => { + element.addEventListener('click', (event) => { + remove_selected(event.target.dataset.tagname) + event.preventDefault() + + setTimeout(() => suggest_input.focus(), 2) + }) + hidden_addtag(element.dataset.tagname) + }) suggest_input.removeAttribute('value') // Disable prefill by browser function select_suggestion(tagelement) { diff --git a/yadc/templates/layout/base_sidebar_tags.html b/yadc/templates/layout/base_sidebar_tags.html index a1a49e6..7bcc80d 100644 --- a/yadc/templates/layout/base_sidebar_tags.html +++ b/yadc/templates/layout/base_sidebar_tags.html @@ -26,10 +26,24 @@ -
+
{% for tag in tags %} - +