Changeset View
Changeset View
Standalone View
Standalone View
swh/web/templates/includes/content-display.html
{% comment %} | {% comment %} | ||||
Copyright (C) 2017-2020 The Software Heritage developers | Copyright (C) 2017-2021 The Software Heritage developers | ||||
See the AUTHORS file at the top-level directory of this distribution | See the AUTHORS file at the top-level directory of this distribution | ||||
License: GNU Affero General Public License version 3, or any later version | License: GNU Affero General Public License version 3, or any later version | ||||
See top-level LICENSE file for more information | See top-level LICENSE file for more information | ||||
{% endcomment %} | {% endcomment %} | ||||
{% load swh_templatetags %} | {% load swh_templatetags %} | ||||
{% include "includes/revision-info.html" %} | {% include "includes/revision-info.html" %} | ||||
{% if snapshot_context and snapshot_context.is_empty %} | {% if snapshot_context and snapshot_context.is_empty %} | ||||
{% include "includes/empty-snapshot.html" %} | {% include "includes/empty-snapshot.html" %} | ||||
{% else %} | {% else %} | ||||
{% if not iframe_mode %} | |||||
<div class="card"> | <div class="card"> | ||||
{% if filename %} | {% if filename %} | ||||
<div class="swh-content-filename card-header bg-gray-light swh-heading-color"> | <div class="swh-content-filename card-header bg-gray-light swh-heading-color"> | ||||
{{ filename }} | {{ filename }} | ||||
</div> | </div> | ||||
{% endif %} | {% endif %} | ||||
{% endif %} | |||||
<div class="swh-content"> | <div class="swh-content"> | ||||
{% if content_size > max_content_size %} | {% if content_size > max_content_size %} | ||||
Content is too large to be displayed (size is greater than {{ max_content_size|filesizeformat }}). | Content is too large to be displayed (size is greater than {{ max_content_size|filesizeformat }}). | ||||
{% elif "inode/x-empty" == mimetype %} | {% elif "inode/x-empty" == mimetype %} | ||||
<i>File is empty</i> | <i>File is empty</i> | ||||
{% elif filename and filename|default:""|slice:"-5:" == "ipynb" %} | {% elif filename and filename|default:""|slice:"-5:" == "ipynb" %} | ||||
<div class="swh-ipynb"> | <div class="swh-ipynb"> | ||||
</div> | </div> | ||||
Show All 13 Lines | <div class="swh-content"> | ||||
<canvas id="pdf-canvas"></canvas> | <canvas id="pdf-canvas"></canvas> | ||||
</div> | </div> | ||||
{% elif content %} | {% elif content %} | ||||
Content with mime type {{ mimetype }} and encoding {{ encoding }} cannot be displayed. | Content with mime type {{ mimetype }} and encoding {{ encoding }} cannot be displayed. | ||||
{% else %} | {% else %} | ||||
{% include "includes/http-error.html" %} | {% include "includes/http-error.html" %} | ||||
{% endif %} | {% endif %} | ||||
</div> | </div> | ||||
{% if not iframe_mode %} | |||||
</div> | </div> | ||||
{% endif %} | |||||
{% if content %} | {% if content %} | ||||
<script> | <script> | ||||
{% if "application/pdf" == mimetype %} | {% if "application/pdf" == mimetype %} | ||||
swh.webapp.renderPdf({{ top_right_link.url|jsonify }}); | swh.webapp.renderPdf({{ top_right_link.url|jsonify }}); | ||||
{% elif filename and filename|default:""|slice:"-5:" == "ipynb" %} | {% elif filename and filename|default:""|slice:"-5:" == "ipynb" %} | ||||
swh.webapp.renderNotebook({{ top_right_link.url|jsonify }}, '.swh-ipynb'); | swh.webapp.renderNotebook({{ top_right_link.url|jsonify }}, '.swh-ipynb'); | ||||
{% elif content %} | {% elif content %} | ||||
let codeContainer = $('code'); | let codeContainer = $('code'); | ||||
let content = codeContainer.text(); | let content = codeContainer.text(); | ||||
swh.webapp.highlightCode(); | swh.webapp.highlightCode(true, 'code', !{{ iframe_mode|jsonify }}); | ||||
function updateLanguage(language) { | function updateLanguage(language) { | ||||
codeContainer.text(content); | codeContainer.text(content); | ||||
codeContainer.removeClass(); | codeContainer.removeClass(); | ||||
codeContainer.addClass(language); | codeContainer.addClass(language); | ||||
let urlParams = new URLSearchParams(window.location.search); | let urlParams = new URLSearchParams(window.location.search); | ||||
urlParams.set('language', language); | urlParams.set('language', language); | ||||
const newUrl = window.location.pathname + '?' + urlParams.toString() + window.location.hash; | const newUrl = window.location.pathname + '?' + urlParams.toString() + window.location.hash; | ||||
window.history.replaceState('', document.title, newUrl); | window.history.replaceState('', document.title, newUrl); | ||||
swh.webapp.highlightCode(); | swh.webapp.highlightCode(true, 'code', !{{ iframe_mode|jsonify }}); | ||||
} | } | ||||
{% endif %} | {% endif %} | ||||
</script> | </script> | ||||
{% endif %} | {% endif %} | ||||
{% endif %} | {% endif %} |