Skip to content
Snippets Groups Projects
Commit f15e17c4 authored by Antoine Lambert's avatar Antoine Lambert
Browse files

templates/content-display: Remove script tag when no content to display

When a content cannot be displayed (for instance due to a too large size),
remove script tag from template to prevent execution errors.

Closes T3454
parent 9f358af9
No related branches found
No related tags found
No related merge requests found
......@@ -49,31 +49,33 @@ See top-level LICENSE file for more information
</div>
</div>
<script>
{% if "application/pdf" == mimetype %}
swh.webapp.renderPdf({{ top_right_link.url|jsonify }});
{% elif filename and filename|default:""|slice:"-5:" == "ipynb" %}
swh.webapp.renderNotebook({{ top_right_link.url|jsonify }}, '.swh-ipynb');
{% elif content %}
let codeContainer = $('code');
let content = codeContainer.text();
{% if content %}
<script>
{% if "application/pdf" == mimetype %}
swh.webapp.renderPdf({{ top_right_link.url|jsonify }});
{% elif filename and filename|default:""|slice:"-5:" == "ipynb" %}
swh.webapp.renderNotebook({{ top_right_link.url|jsonify }}, '.swh-ipynb');
{% elif content %}
let codeContainer = $('code');
let content = codeContainer.text();
swh.webapp.highlightCode();
swh.webapp.highlightCode();
function updateLanguage(language) {
codeContainer.text(content);
codeContainer.removeClass();
codeContainer.addClass(language);
function updateLanguage(language) {
codeContainer.text(content);
codeContainer.removeClass();
codeContainer.addClass(language);
let urlParams = new URLSearchParams(window.location.search);
urlParams.set('language', language);
let urlParams = new URLSearchParams(window.location.search);
urlParams.set('language', language);
const newUrl = window.location.pathname + '?' + urlParams.toString() + window.location.hash;
window.history.replaceState('', document.title, newUrl);
const newUrl = window.location.pathname + '?' + urlParams.toString() + window.location.hash;
window.history.replaceState('', document.title, newUrl);
swh.webapp.highlightCode();
}
swh.webapp.highlightCode();
}
{% endif %}
</script>
{% endif %}
</script>
{% endif %}
{% endif %}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment