Skip to content

Commit

Permalink
Merge pull request #368 from ChristianMayer/feature_image_shrink_to_fit
Browse files Browse the repository at this point in the history
New feature for Image widget: shrink to fit width
  • Loading branch information
peuter committed Aug 21, 2016
2 parents c0976f4 + 4e13779 commit 5c3173b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/structure/pure/Image.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ define( ['_common'], function( design ) {
if (data.width) {
imgStyle += 'width:' + data.width + ';';
}
else {
imgStyle += 'width: 100%;';
if( $e.attr('widthfit') === 'true' ) {
imgStyle += 'max-width:100%;';
}
if (data.height) {
imgStyle += 'height:' + data.height + ';';
Expand Down
7 changes: 4 additions & 3 deletions src/visu_config.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -1005,9 +1005,10 @@
<xsd:element name="label" type="label" minOccurs="0" maxOccurs="1"/>
</xsd:sequence>
<xsd:attribute name="src" type="uri" use="required" />
<xsd:attribute name="width" type="dimension" />
<xsd:attribute name="height" type="dimension" />
<xsd:attribute name="refresh" type="xsd:decimal" />
<xsd:attribute name="width" type="dimension" use="optional" />
<xsd:attribute name="height" type="dimension" use="optional" />
<xsd:attribute name="widthfit" type="xsd:boolean" use="optional" />
<xsd:attribute name="refresh" type="xsd:decimal" use="optional" />
<xsd:attribute ref="flavour" use="optional" />
</xsd:complexType>

Expand Down
9 changes: 8 additions & 1 deletion test/karma/structure/pure/Image-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ define( ['jquery','TemplateEngine', '_common', 'widget_image'], function($, engi
var data = templateEngine.widgetDataGet('id_0');
expect(data.path).toBe("id_0");

expect(widget.find("img").get(0).getAttribute("style")).toBe('width: 100%;');
expect(widget.find("img").get(0).getAttribute("style")).toBe('');

image.setAttribute("width", "50%");
image.setAttribute("height", "51%");
Expand All @@ -40,6 +40,13 @@ define( ['jquery','TemplateEngine', '_common', 'widget_image'], function($, engi
});
expect(templateEngine.setupRefreshAction).toHaveBeenCalled();
expect(widget.find("img").get(0).getAttribute("style")).toBe('width:50%;height:51%;');

image.removeAttribute("width");
image.removeAttribute("height");
image.removeAttribute("refresh");
image.setAttribute("widthfit", "true");
widget = $(creator.create(xml.firstChild.firstChild, 'id_0', null, 'image'));
expect(widget.find("img").get(0).getAttribute("style")).toBe('max-width:100%;');
});
});
});

0 comments on commit 5c3173b

Please sign in to comment.