Add tag_object html macro to centralize that effort. Still needs work.
This commit is contained in:
parent
aa30d5903d
commit
5ba2ecd38a
4 changed files with 86 additions and 11 deletions
|
@ -2,6 +2,7 @@
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
{% import "header.html" as header %}
|
{% import "header.html" as header %}
|
||||||
|
{% import "tag_object.html" as tag_object %}
|
||||||
<title>Photo {{photo.basename}}</title>
|
<title>Photo {{photo.basename}}</title>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<link rel="stylesheet" href="/static/common.css">
|
<link rel="stylesheet" href="/static/common.css">
|
||||||
|
@ -166,13 +167,7 @@
|
||||||
{% set tags = photo.sorted_tags() %}
|
{% set tags = photo.sorted_tags() %}
|
||||||
{% for tag in tags %}
|
{% for tag in tags %}
|
||||||
<li>
|
<li>
|
||||||
{% set qualified_name=tag.qualified_name() %}
|
{{tag_object.tag_object(tag, qualified_name=True, max_len=30, with_alt_description=True, with_alt_qualified_name=True)}}<!--
|
||||||
{% set display_name=qualified_name %}
|
|
||||||
{% if display_name|length > 30 %}
|
|
||||||
{% set display_name = display_name[-30:] %}
|
|
||||||
{% set display_name = display_name.split(".", 1)[1] %}
|
|
||||||
{% endif %}
|
|
||||||
<a class="tag_object" href="/search?tag_musts={{tag.name}}" title="{{qualified_name}}">{{display_name}}</a><!--
|
|
||||||
--><button
|
--><button
|
||||||
class="remove_tag_button"
|
class="remove_tag_button"
|
||||||
onclick="remove_photo_tag('{{photo.id}}', '{{tag.name}}', receive_callback);">
|
onclick="remove_photo_tag('{{photo.id}}', '{{tag.name}}', receive_callback);">
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
<head>
|
<head>
|
||||||
{% import "photo_card.html" as photo_card %}
|
{% import "photo_card.html" as photo_card %}
|
||||||
{% import "header.html" as header %}
|
{% import "header.html" as header %}
|
||||||
|
{% import "tag_object.html" as tag_object %}
|
||||||
<title>Search</title>
|
<title>Search</title>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<link rel="stylesheet" href="/static/common.css">
|
<link rel="stylesheet" href="/static/common.css">
|
||||||
|
@ -270,7 +271,14 @@ form
|
||||||
<span>Tags on this page (click to join query):</span>
|
<span>Tags on this page (click to join query):</span>
|
||||||
<ul>
|
<ul>
|
||||||
{% for tag in total_tags %}
|
{% for tag in total_tags %}
|
||||||
<li><a href="javascript:void(0)" title="{{tag.description}}" class="tag_object tags_on_this_page">{{tag.name}}</a></li>
|
<li>{{tag_object.tag_object(
|
||||||
|
tag,
|
||||||
|
extra_classes="tags_on_this_page",
|
||||||
|
link='void',
|
||||||
|
qualified_name=False,
|
||||||
|
with_alt_qualified_name=True,
|
||||||
|
with_alt_description=True,
|
||||||
|
)}}</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
71
frontends/etiquette_flask/templates/tag_object.html
Normal file
71
frontends/etiquette_flask/templates/tag_object.html
Normal file
|
@ -0,0 +1,71 @@
|
||||||
|
<!--
|
||||||
|
tag: The Tag object
|
||||||
|
extra_classes:
|
||||||
|
Space-separated string, if you want more than "tag_object".
|
||||||
|
link:
|
||||||
|
None = no link, just a <span>
|
||||||
|
'search' = link to /search?tag_musts=tagname
|
||||||
|
'info' = link to /tags/tagname
|
||||||
|
'void' = javascript:void(0)
|
||||||
|
max_len:
|
||||||
|
None: As long as it needs to be.
|
||||||
|
integer: Rootmost parents are removed until the text fits under
|
||||||
|
this limit.
|
||||||
|
If the tag's own name can't find under the limit, characters are
|
||||||
|
dropped from the right.
|
||||||
|
qualified_name:
|
||||||
|
True: Use the qualified name as the innerhtml
|
||||||
|
False: Use the basic name
|
||||||
|
with_alt_description:
|
||||||
|
True: Include the description in the alt text
|
||||||
|
with_alt_qualified_name:
|
||||||
|
True: Include the qualified name in the alt text
|
||||||
|
-->
|
||||||
|
{% macro tag_object(
|
||||||
|
tag,
|
||||||
|
extra_classes="",
|
||||||
|
link='search',
|
||||||
|
max_len=None,
|
||||||
|
qualified_name=True,
|
||||||
|
with_alt_description=True,
|
||||||
|
with_alt_qualified_name=True
|
||||||
|
) %}
|
||||||
|
{%- if link is not none -%}
|
||||||
|
{%- set closing="</a>" -%}
|
||||||
|
<a
|
||||||
|
{%- if link == 'search' -%}
|
||||||
|
{{' '}}href="/search?tag_musts={{tag.name}}"
|
||||||
|
{%- elif link == 'info' -%}
|
||||||
|
{{' '}}href="/tags/{{tag.name}}"
|
||||||
|
{%- elif link == 'void' -%}
|
||||||
|
{{' '}}href="javascript:void(0)"
|
||||||
|
{%- else -%}
|
||||||
|
{{' '}}href="{{search}}"
|
||||||
|
{%- endif -%}
|
||||||
|
{{' '}}target="_blank" class="tag_object {{extra_classes}}"
|
||||||
|
|
||||||
|
{%- else -%}
|
||||||
|
{% set closing="</span>" %}
|
||||||
|
<span
|
||||||
|
|
||||||
|
{%- endif -%}
|
||||||
|
{% set altlines=[] %}
|
||||||
|
{% if with_alt_qualified_name %}{% do altlines.append(tag.qualified_name()) %}{% endif %}
|
||||||
|
{% if with_alt_description %}{% do altlines.append(tag.description) %}{% endif %}
|
||||||
|
{% set altlines=altlines|join("\n") %}
|
||||||
|
{%- if altlines -%}
|
||||||
|
{{' '}}title="{{altlines}}"
|
||||||
|
{%- endif -%}
|
||||||
|
>
|
||||||
|
{%- if qualified_name -%}
|
||||||
|
{{tag.qualified_name(max_len=max_len)}}
|
||||||
|
{%- else -%}
|
||||||
|
{% if max_len is not none %}
|
||||||
|
{{tag.name[:max_len]}}
|
||||||
|
{% else %}
|
||||||
|
{{tag.name}}
|
||||||
|
{% endif %}
|
||||||
|
{%- endif -%}
|
||||||
|
|
||||||
|
{{- closing|safe -}}
|
||||||
|
{% endmacro %}
|
|
@ -2,6 +2,7 @@
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
{% import "header.html" as header %}
|
{% import "header.html" as header %}
|
||||||
|
{% import "tag_object.html" as tag_object %}
|
||||||
<title>Tags</title>
|
<title>Tags</title>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<link rel="stylesheet" href="/static/common.css">
|
<link rel="stylesheet" href="/static/common.css">
|
||||||
|
@ -75,7 +76,7 @@ body
|
||||||
{% for tag in tags %}
|
{% for tag in tags %}
|
||||||
{% set qualified_name = tag.qualified_name() %}
|
{% set qualified_name = tag.qualified_name() %}
|
||||||
<li>
|
<li>
|
||||||
<a target="_blank" class="tag_object" title="{{tag.description}}" href="/search?tag_musts={{tag.name}}">{{qualified_name}}</a><!--
|
{{tag_object.tag_object(tag, link='search', qualified_name=True, with_alt_qualified_name=False)}}<!--
|
||||||
--><button class="remove_tag_button" onclick="delete_tag('{{tag.name}}', receive_callback);"></button>
|
--><button class="remove_tag_button" onclick="delete_tag('{{tag.name}}', receive_callback);"></button>
|
||||||
</li>
|
</li>
|
||||||
{% if include_synonyms %}
|
{% if include_synonyms %}
|
||||||
|
|
Loading…
Reference in a new issue