Browse Source

Add explicit label name attr to label buttons

Using textContent for this wasn't a good idea (and caused this to
break), so this adds an explicit attr for it so the textContent doesn't
matter.
merge-requests/40/head
Deimos 6 years ago
parent
commit
8407c15d75
  1. 7
      tildes/static/js/behaviors/comment-label-button.js
  2. 5
      tildes/tildes/templates/macros/comments.jinja2

7
tildes/static/js/behaviors/comment-label-button.js

@ -24,7 +24,7 @@ $.onmount('[data-js-comment-label-button]', function() {
for (i = 0; i < options.length; i++) { for (i = 0; i < options.length; i++) {
var label = options[i]; var label = options[i];
var labelName = label.textContent;
var labelName = label.getAttribute("data-js-label-name");
var labelOptionActive = false; var labelOptionActive = false;
if (userLabels.indexOf(labelName) !== -1) { if (userLabels.indexOf(labelName) !== -1) {
@ -44,7 +44,8 @@ $.onmount('[data-js-comment-label-button]', function() {
} }
$(label).on('after.success.ic', function(evt) { $(label).on('after.success.ic', function(evt) {
Tildes.removeUserLabel(commentID, evt.target.textContent);
var labelName = evt.target.getAttribute("data-js-label-name");
Tildes.removeUserLabel(commentID, labelName);
}); });
} else { } else {
label.setAttribute('data-ic-put-to', labelURL + labelName); label.setAttribute('data-ic-put-to', labelURL + labelName);
@ -55,7 +56,7 @@ $.onmount('[data-js-comment-label-button]', function() {
} }
$(label).on('after.success.ic', function(evt) { $(label).on('after.success.ic', function(evt) {
var labelName = evt.target.textContent;
var labelName = evt.target.getAttribute("data-js-label-name");
Tildes.addUserLabel(commentID, labelName); Tildes.addUserLabel(commentID, labelName);
// if the applied label was Exemplary, remove the button from the // if the applied label was Exemplary, remove the button from the

5
tildes/tildes/templates/macros/comments.jinja2

@ -257,12 +257,11 @@
{% for label in options if request.user.is_label_available(label) %} {% for label in options if request.user.is_label_available(label) %}
<li> <li>
<a class="btn-comment-label btn-comment-label-{{ label.name|lower }}" <a class="btn-comment-label btn-comment-label-{{ label.name|lower }}"
data-js-label-name="{{ label.name|lower }}"
{% if label.reason_prompt %} {% if label.reason_prompt %}
data-js-reason-prompt="{{ label.reason_prompt }}" data-js-reason-prompt="{{ label.reason_prompt }}"
{% endif %} {% endif %}
>
{{ label.name|lower }}{% if label.reason_prompt %}...{% endif %}
</a>
>{{ label.name|lower }}{% if label.reason_prompt %}...{% endif %}</a>
</li> </li>
{% endfor %} {% endfor %}
</ul> </ul>

Loading…
Cancel
Save