Skip to content

Commit

Permalink
Added support for svg_image field type. Allows an image field to be u…
Browse files Browse the repository at this point in the history
…sed for uploading an SVG file, but prevents editing of the image.
  • Loading branch information
anthonyjb committed May 30, 2020
1 parent c22f78c commit 9ddc09d
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 3 deletions.
10 changes: 9 additions & 1 deletion module/field.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,9 @@ export class FileField {

// Set up the viewer
const behaviour = this._behaviours.viewer

console.log(cls.behaviours.viewer, behaviour)

this._viewer = cls.behaviours.viewer[behaviour](this)
this._viewer.init()

Expand Down Expand Up @@ -650,7 +653,12 @@ FileField.css = {
* Applied to the field element when the expected file type is an
* image.
*/
'image': 'mh-file-field--image'
'image': 'mh-file-field--image',

/**
* Applied to the field element when the expected file type is an
* SVG image.
*/
'svg_image': 'mh-file-field--image'
}
}
7 changes: 6 additions & 1 deletion module/gallery.js
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,12 @@ Gallery.css = {
* Applied to the gallery element when the expected file type is an
* image.
*/
'image': 'mh-gallery--image'
'image': 'mh-gallery--image',

/**
* Applied to the gallery element when the expected file type is an
* SVG image.
*/
'svg_image': 'mh-gallery--image',
}
}
11 changes: 11 additions & 0 deletions module/utils/behaviours/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,17 @@ export function viewer(containerAttr, optionsAttr) {
inst.getAssetProp('previewURL')
)

case 'svg_image':
return new ImageViewer(
inst[containerAttr],
inst.getAssetProp('url'),
{
'download': true,
'metadata': true,
'remove': true
}
)

// no default

}
Expand Down
6 changes: 6 additions & 0 deletions module/utils/behaviours/manhattan.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ export function assetProp(assetAttr, optionsAttr) {
}
return transforms

case 'url':
return _asset.url

// no default

}
Expand Down Expand Up @@ -183,6 +186,9 @@ export function metadata(optionsAttr) {
props.push(['Mode', 'imageMode', getProp('imageMode'), true])
props.push(['Size', 'imageSize', getProp('imageSize'), true])
props.push(['Alt', 'alt', getProp('alt'), false])

} else if (options.fileType === 'svg_image') {
props.push(['Alt', 'alt', getProp('alt'), false])
}

return new Metadata(props)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "manhattan-assets",
"version": "1.0.0-beta.18",
"version": "1.0.1",
"description": "File and image uploads for forms.",
"engines": {
"node": ">=8.9.4"
Expand Down

0 comments on commit 9ddc09d

Please sign in to comment.