Custom thumbnail CKFinder 3, custom file type

159 Views Asked by At

I have custom file types, or a file type that doesn't support thumbnails because ckfinder only supports image type.

So file:getThumb only gets called on image file types

finder.on('file:getThumb', function (evt) {
    evt.stop();
    Object.assign(evt.data.templateData, evt.data);
    evt.data.template = `http://example.com/images/{{= it.url }}`;
});
1

There are 1 best solutions below

0
Russell Benton On

So turns out you need to do a little bit of patching to accomplish this.

requireing the CKFinder/Modules/Files/Views/ThumbnailsView/FileRenderer And patching the template string that comes back to force all file types to have a thumbnail.

CKFinder.define(
    ['backbone', 'marionette', 'doT', 'CKFinder/Modules/Files/Views/ThumbnailsView/FileRenderer'],
    CKFinderPlugin
);
function CKFinderPlugin(Backbone, Marionette, doT, fileRenderer) {
    fileRenderer.prototype.preRenderOrigin = fileRenderer.prototype.preRender;
    fileRenderer.prototype.preRender = function () {
        var args = Array.from(arguments);
        var response = fileRenderer.prototype.preRenderOrigin.apply(this, args);
        return response.replace('ckf-file-icon', 'ckf-lazy-thumb');
    };

    return {
        init(finder) {},
        lib: [Backbone, Marionette, doT, fileRenderer],
    };
}