Question Editor API Initialization
assetRequest()
If defined the Editor will display a directory/file icon.
For instance, "..." in fields where media is supported, as well as binding to the "insert image" button in the html WYSIWIG editor. If the icon is clicked by an author the function is called.
Examples
"assetRequest": function(
mediaRequested,
returnType,
callback ,
attributes
) {
// myfunction that opens an asset
// browser or uploader and then calls
// callback(URL|HTML|UrlHeightWidth)
},
// example function to be called by assetRequest
var assetRequestFunction = function(mediaRequested, returnType, callback) {
if (mediaRequested === 'image') {
var $modal = $('.modal.img-upload'),
$images = $('.asset-img-gallery img'),
imgClickHandler = function () {
if (returnType === 'HTML') {
callback('<img src="' + $(this).data('img') + '" alt="">');
} else {
callback($(this).data('img'));
}
$modal.modal('hide');
$images.off('click', imgClickHandler);
};
$images.on('click', imgClickHandler);
$modal.modal({
backdrop: 'static'
});
}
Arguments
-
mediaRequested string
-
returnType string
Let the function know whether to supply HTML or a URL or an object that contains image's url, width and height.
-
callback callback
Function that must be executed once the
HTML
,URL
orUrlHeightWidth
is ascertained. -
attributes object
Return value
None (undefined
).