mirror of
https://github.com/renbaoshuo/S2OJ.git
synced 2024-11-08 13:38:41 +00:00
chore: load pdf.js only if have pdf content
This commit is contained in:
parent
cd36b3d209
commit
d4d98f6d55
@ -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('<canvas id="' + id + '_page_' + i + '" class="pdf-page-canvas"></canvas>');
|
||||
task.promise.then(function(pdf) {
|
||||
for (var i = 1; i <= pdf.numPages; i++) {
|
||||
$(_this).append('<canvas id="' + id + '_page_' + i + '" class="pdf-page-canvas"></canvas>');
|
||||
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user