Skip to content

Commit

Permalink
Allow using media:// 'protocol' for media-relative image fields
Browse files Browse the repository at this point in the history
  • Loading branch information
GarboMuffin committed Dec 31, 2023
1 parent 111ad0b commit 7413542
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
7 changes: 7 additions & 0 deletions core/field_image.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,13 @@ Blockly.FieldImage.prototype.setValue = function(src) {
}
this.src_ = src;
if (this.imageElement_) {
// Extension blocks can't rely on having access to pathToMedia, so we allow this fake URL
// protocol instead.
var mediaPrefix = 'media://';
if (src.startsWith(mediaPrefix)) {
var pathToMedia = this.sourceBlock_.workspace.options.pathToMedia;
src = pathToMedia + src.substring(mediaPrefix.length);
}
this.imageElement_.setAttributeNS('http://www.w3.org/1999/xlink',
'xlink:href', src || '');
}
Expand Down
3 changes: 2 additions & 1 deletion core/toolbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ Blockly.Toolbox.prototype.createFlyout_ = function() {
oneBasedIndex: workspace.options.oneBasedIndex,
horizontalLayout: workspace.horizontalLayout,
toolboxPosition: workspace.options.toolboxPosition,
stackGlowFilterId: workspace.options.stackGlowFilterId
stackGlowFilterId: workspace.options.stackGlowFilterId,
pathToMedia: workspace.options.pathToMedia
};

if (workspace.horizontalLayout) {
Expand Down

0 comments on commit 7413542

Please sign in to comment.