diff --git a/web/js/uoj.js b/web/js/uoj.js
index cec7c0e..c4f2332 100644
--- a/web/js/uoj.js
+++ b/web/js/uoj.js
@@ -1291,53 +1291,55 @@ $(document).ready(function() {
);
});
- $LAB.script('/js/pdf.js').wait(function() {
- pdfjsLib.GlobalWorkerOptions.workerSrc = '/js/pdf.worker.js';
+ if ($('div[data-pdf]').length > 0) {
+ $LAB.script('/js/pdf.js').wait(function() {
+ pdfjsLib.GlobalWorkerOptions.workerSrc = '/js/pdf.worker.js';
- // Support HiDPI-screens.
- var outputScale = window.devicePixelRatio || 1;
+ // Support HiDPI-screens.
+ var outputScale = window.devicePixelRatio || 1;
- $('div[data-pdf]').each(function() {
- var _this = $(this);
- var pdf_src = $(this).data('src');
+ $('div[data-pdf]').each(function() {
+ var _this = $(this);
+ var pdf_src = $(this).data('src');
- $(this).css('width', '100%').css('height', '100%');
+ $(this).css('width', '100%').css('height', '100%');
- var task = pdfjsLib.getDocument(pdf_src);
- var id = 'pdf_' + task.docId;
+ var task = pdfjsLib.getDocument(pdf_src);
+ var id = 'pdf_' + task.docId;
- $(this).attr('id', id + '_container');
+ $(this).attr('id', id + '_container');
- task.promise.then(function(pdf) {
- for (var i = 1; i <= pdf.numPages; i++) {
- $(_this).append('');
+ task.promise.then(function(pdf) {
+ for (var i = 1; i <= pdf.numPages; i++) {
+ $(_this).append('');
- pdf.getPage(i).then(function(page) {
- var viewport = page.getViewport({
- scale: 2.5,
+ pdf.getPage(i).then(function(page) {
+ var viewport = page.getViewport({
+ scale: 2.5,
+ });
+
+ var canvas = document.getElementById(id + '_page_' + page.pageNumber);
+
+ canvas.height = Math.floor(viewport.height * outputScale);
+ canvas.width = Math.floor(viewport.width * outputScale);
+
+ var transform = outputScale !== 1
+ ? [outputScale, 0, 0, outputScale, 0, 0]
+ : null;
+
+ page.render({
+ canvasContext: canvas.getContext('2d'),
+ viewport: viewport,
+ transform: transform,
+ });
});
+ }
- var canvas = document.getElementById(id + '_page_' + page.pageNumber);
-
- canvas.height = Math.floor(viewport.height * outputScale);
- canvas.width = Math.floor(viewport.width * outputScale);
-
- var transform = outputScale !== 1
- ? [outputScale, 0, 0, outputScale, 0, 0]
- : null;
-
- page.render({
- canvasContext: canvas.getContext('2d'),
- viewport: viewport,
- transform: transform,
- });
- });
- }
-
- $('.uoj-pdf-loading-spinner', _this).remove();
+ $('.uoj-pdf-loading-spinner', _this).remove();
+ });
});
});
- });
+ }
});
// Tooltip