Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle newlines and html conversions correctly in area_notes #296

Merged
merged 1 commit into from
Sep 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion signbank/dictionary/templates/dictionary/gloss_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ <h4 class="modal-title" id="glossvideo{{glossvideo.pk}}-ModalLabel">{% blocktran
{# Translators: Information about a Gloss #}
<tr>
<th>{% blocktrans %}Notes:{% endblocktrans %}</th>
<td class='edit edit_area_notes' id='notes'>{% value gloss.notes|linebreaks %}</td>
<td class='edit edit_area_notes' id='notes'>{% value gloss.notes|linebreaksbr %}</td>
</tr>
{# Translators: Information about a Gloss #}
<tr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ <h4>{% blocktrans %}Translation equivalents{% endblocktrans %}</h4>
<header>
<h4>{% blocktrans %}Notes{% endblocktrans %}</h4>
</header>
<p>{% if gloss.notes %}{{gloss.notes|linebreaks}}
<p>{% if gloss.notes %}{{gloss.notes|linebreaksbr}}
{% else %}<em>{% blocktrans %}No notes.{% endblocktrans %}</em>{% endif %}</p>
</section>
</div>
Expand Down
14 changes: 13 additions & 1 deletion signbank/static/js/gloss_edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,19 @@ function configure_edit() {
type : 'textarea',
width : 400,
rows : 3,
onblur : 'ignore',
// onedit & callback & onreset: handle newlines and html conversions in jeditable.
onedit : function(_settings, original) {
// Use innerText which contains newlines `\n`
original.innerHTML = original.innerText;
},
onreset : function(_settings, original) {
// Replace newlines with `<br>` for returned value
original.replace(/\n/g, '<br>');
},
callback : function(value, _settings) {
// Replace newlines with `<br>` for returned value
this.innerHTML = value.replace(/\n/g, '<br>');
},
});
$('.edit_url').editable(edit_post_url, {
type : 'text',
Expand Down