mirror of https://github.com/xwiki-labs/cryptpad
Merge branch 'staging' of github.com:xwiki-labs/cryptpad into staging
This commit is contained in:
commit
027b9fa383
|
@ -11,7 +11,8 @@ define([
|
|||
'image/jpeg',
|
||||
'image/jpg',
|
||||
'image/gif',
|
||||
'video/'
|
||||
'video/',
|
||||
'application/pdf'
|
||||
];
|
||||
|
||||
Thumb.isSupportedType = function (type) {
|
||||
|
@ -123,10 +124,43 @@ define([
|
|||
cb('ERROR');
|
||||
});
|
||||
};
|
||||
Thumb.fromPdfBlob = function (blob, cb) {
|
||||
require.config({paths: {'pdfjs-dist': '/common/pdfjs'}});
|
||||
require(['pdfjs-dist/build/pdf'], function (PDFJS) {
|
||||
var url = URL.createObjectURL(blob);
|
||||
var makeThumb = function (page) {
|
||||
var vp = page.getViewport(1);
|
||||
var canvas = document.createElement("canvas");
|
||||
canvas.width = canvas.height = Thumb.dimension;
|
||||
var scale = Math.min(canvas.width / vp.width, canvas.height / vp.height);
|
||||
canvas.width = Math.floor(vp.width * scale);
|
||||
canvas.height = Math.floor(vp.height * scale);
|
||||
return page.render({
|
||||
canvasContext: canvas.getContext("2d"),
|
||||
viewport: page.getViewport(scale)
|
||||
}).promise.then(function () {
|
||||
return canvas;
|
||||
});
|
||||
};
|
||||
PDFJS.getDocument(url).promise
|
||||
.then(function (doc) {
|
||||
return doc.getPage(1).then(makeThumb).then(function (canvas) {
|
||||
canvas.toBlob(function (blob) {
|
||||
cb(void 0, blob);
|
||||
});
|
||||
});
|
||||
}).catch(function () {
|
||||
cb('ERROR');
|
||||
});
|
||||
});
|
||||
};
|
||||
Thumb.fromBlob = function (blob, cb) {
|
||||
if (blob.type.indexOf('video/') !== -1) {
|
||||
return void Thumb.fromVideoBlob(blob, cb);
|
||||
}
|
||||
if (blob.type.indexOf('application/pdf') !== -1) {
|
||||
return void Thumb.fromPdfBlob(blob, cb);
|
||||
}
|
||||
Thumb.fromImageBlob(blob, cb);
|
||||
};
|
||||
|
||||
|
|
|
@ -685,7 +685,9 @@ define([
|
|||
});
|
||||
};
|
||||
|
||||
var ready = false;
|
||||
realtimeOptions.onReady = function (info) {
|
||||
if (ready) { return; }
|
||||
// create your patcher
|
||||
if (realtime !== info.realtime) {
|
||||
realtime = rt.realtime = info.realtime;
|
||||
|
@ -709,6 +711,7 @@ define([
|
|||
DeepProxy.checkLocalChange(proxy, onLocal);
|
||||
|
||||
initializing = false;
|
||||
ready = true;
|
||||
};
|
||||
|
||||
realtimeOptions.onAbort = function (info) {
|
||||
|
|
Loading…
Reference in New Issue