Assets rendering
Question
I try to create a video thumbnail, when I add it like a tag it's working fine but when this an array or an object, it doesn't render it.
let assetManager = this.editor.AssetManager;
assetManager.addType('video', {
view: {
getPreview() {
debugger;
return `<div style="text-align: center">video</div>`;
},
getInfo() {
return '<div>video description</div>';
}
},
isType(value) {
return value;
}
});
assetManager.add('<video src="http://localhost:2195/malls/78620a57-d32f-40a5-9b06-003c2338c377/SampleVideo_1280x720_1mb.mp4" class="gjs-no-pointer" style="height: 100%; width: 100%;"></video>');
assetManager.add([
{ type: 'video', src: 'http://localhost:2195/malls/78620a57-d32f-40a5-9b06-003c2338c377/SampleVideo_1280x720_1mb.mp4' },
{ type: 'video', src: 'http://localhost:2195/malls/78620a57-d32f-40a5-9b06-003c2338c377/SampleVideo_1280x720_1mb.mp4' }]);
Answers (3)
@goldengrisha - I had an unrelated issue w/ thumbnails, as the asset manager simply loads in the full file for the thumbnail. When adding an asset, I now pass a thumbnail parameter and display that instead.
getPreview: function getPreview() {
var pfx = this.pfx;
var src = this.model.get('src');
var thumbnail = this.model.get('thumbnail');
return '\n <div class="' + pfx + 'preview" style="background-image: url("' + thumbnail + '");"></div>\n <div class="' + pfx + 'preview-bg ' + this.ppfx + 'checker-bg"></div>\n ';
},
thank you for answer, but point is why this code work in proper way
assetManager.add('<video src="http://localhost:2195/malls/78620a57-d32f-40a5-9b06-003c2338c377/SampleVideo_1280x720_1mb.mp4" class="gjs-no-pointer" style="height: 100%; width: 100%;"></video>');
and this piece of code not :
assetManager.add([ { type: 'video', src: 'http://localhost:2195/malls/78620a57-d32f-40a5-9b06-003c2338c377/SampleVideo_1280x720_1mb.mp4' }, { type: 'video', src: 'http://localhost:2195/malls/78620a57-d32f-40a5-9b06-003c2338c377/SampleVideo_1280x720_1mb.mp4' }]);
@goldengrisha first of all, your isType(value) is not correct
If you pass a string in assetManager.add the value will be that string and just by returning it you say nothing about its type (isType should return a Boolean or { type: 'something', ... }), moreover I think this doesn't make sense
assetManager.add('<video src="http://localhost:2195/malls/78620a57-d32f-40a5-9b06-003c2338c377/SampleVideo_1280x720_1mb.mp4" class="gjs-no-pointer" style="height: 100%; width: 100%;"></video>');
you're working with assets not Components, probably what you're looking for is something like this
assetManager.addType('video', {
...
view: {
getPreview() {
const src = this.model.get('src');
return `<div>
<video
class="gjs-no-pointer"
style="height: 100%; width: 100%;"
src="${src}">
</video></div>`;
},
...
},
isType(value) {
// eg. here you might check/parse/fetch url and try to
// understand the type
if (isString(value) && propablyVideoUrl(value)) {
return { type: 'video', src: value }
}
}
});
assetManager.add('http://local ... 1mb.mp4');
If you add your assets via objects (eg. { type: 'video', src: '...', ... }) you don't even need isType as you're declaring it explicitly
Another good question, why you don't see your assetManager.add([ { type: 'video', src: ... which are actually correct?!?
Well this is because by default OpenAssets command shows only images
You can extend that Command and just rendering them in this way
const assets = assetManager.getAll();
assetManager.render(assets.filter(asset => asset.get('type') == 'video'))
Related Questions and Answers
Continue research with similar issue discussions.
Issue #1722
[QUESTION] how to make my custom tag as selectable and editable inside of canvas ?
Hi, I try to change my custom tag of ion-item has div in view properties but It doesn't work for me as I expected. my custom Blocks is my c...
Issue #1200
Modify grapes.min.js to allow video types on AssetManager
Please, I would like to modify my grapes.min.js because I would like to add the video type to my assetManager. For some reason, the am.addT...
Issue #1763
Add <Style> tag in block content objects (not a string)
Browser = ChromeGrapesJS = Latest version ( 0.14.52 ) I am trying to create a block includes nesting content object with script, style, typ...
Issue #725
CSS Editor
Hello, I would like to know what would be the best route to take to extend the Editor. There is a few features i would like to add for my p...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.