Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitry-kurmanov committed May 23, 2023
2 parents a7e7394 + d61c15c commit 1300e28
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 7 deletions.
2 changes: 2 additions & 0 deletions packages/survey-angular-ui/src/questions/image.component.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<div [class]="model.cssClasses.root" #contentElement>
<img
*ngIf="model.renderedMode === 'image'"
[visible]="!!model.locImageLink.renderedHtml && !model.contentNotLoaded"
[class]="model.getImageCss()"
[attr.src]="model.locImageLink.renderedHtml"
[attr.alt]="model.altText || model.title"
Expand All @@ -12,6 +13,7 @@
/><video
controls
*ngIf="model.renderedMode === 'video'"
[visible]="!!model.locImageLink.renderedHtml && !model.contentNotLoaded"
[class]="model.getImageCss()"
[attr.src]="model.locImageLink.renderedHtml"
[attr.width]="model.renderedWidth"
Expand Down
5 changes: 2 additions & 3 deletions src/defaultV2-theme/blocks/sd-image.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@
.sd-image__no-image {
background: $background-dim-light;
min-width: calcSize(5);
min-height: calcSize(5);
min-height: calcSize(27.5);
width: 100%;
height: 100%;
position: absolute;
inset-block-start: 0;
position: relative;
display: flex;
align-items: center;
justify-content: center;
Expand Down
4 changes: 2 additions & 2 deletions src/knockout/templates/question-image.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<script type="text/html" id="survey-question-image">
<div data-bind="css: question.koCss().root">
<!-- ko if: question.renderedMode === "image" -->
<img data-bind="event: { load: question.onLoadHandler, error: question.onErrorHandler }, css: question.getImageCss(), attr: { src: $data.locImageLink.koRenderedHtml() || null, width: question.renderedWidth, height: question.renderedHeight, alt: question.altText || question.title }, style: { objectFit: question.imageFit }"/>
<img data-bind="event: { load: question.onLoadHandler, error: question.onErrorHandler }, css: question.getImageCss(), attr: { src: $data.locImageLink.koRenderedHtml() || null, width: question.renderedWidth, height: question.renderedHeight, alt: question.altText || question.title }, style: { objectFit: question.imageFit }, visible: $data.locImageLink.koRenderedHtml() && !question.contentNotLoaded"/>
<!-- /ko -->
<!-- ko if: question.renderedMode === "video" -->
<video controls data-bind="event: { load: question.onLoadHandler, error: question.onErrorHandler }, css: question.getImageCss(), attr: { src: $data.locImageLink.koRenderedHtml(), width: question.renderedWidth, height: question.renderedHeight }, style: { objectFit: question.imageFit }"></video>
<video controls data-bind="event: { load: question.onLoadHandler, error: question.onErrorHandler }, css: question.getImageCss(), attr: { src: $data.locImageLink.koRenderedHtml(), width: question.renderedWidth, height: question.renderedHeight }, style: { objectFit: question.imageFit }, visible: $data.locImageLink.koRenderedHtml() && !question.contentNotLoaded"></video>
<!-- /ko -->
<!-- ko if: question.renderedMode === "youtube" -->
<iframe data-bind=" css: question.getImageCss(), attr: { src: $data.locImageLink.koRenderedHtml(), width: question.renderedWidth, height: question.renderedHeight }, style: { objectFit: question.imageFit }"></iframe>
Expand Down
3 changes: 3 additions & 0 deletions src/react/image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ export class SurveyQuestionImage extends SurveyQuestionElementBase {
protected renderElement(): JSX.Element {
var cssClasses = this.question.getImageCss();
var style: any = { objectFit: this.question.imageFit };
if(!this.question.imageLink || this.question.contentNotLoaded) {
style["display"] = "none";
}
var control: JSX.Element | null = null;
if (this.question.renderedMode === "image") {
control = (
Expand Down
2 changes: 2 additions & 0 deletions src/vue/image.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<div :class="question.cssClasses.root">
<img
v-if="question.renderedMode === 'image'"
v-show="question.imageLink && !question.contentNotLoaded"
:class="question.getImageCss()"
:src="question.locImageLink.renderedHtml"
:alt="question.altText || question.title"
Expand All @@ -13,6 +14,7 @@
/><video
controls
v-if="question.renderedMode === 'video'"
v-show="question.imageLink && !question.contentNotLoaded"
:class="question.getImageCss()"
:src="question.locImageLink.renderedHtml"
:width="question.renderedWidth"
Expand Down
17 changes: 16 additions & 1 deletion tests/markup/etalon_image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@ registerMarkupTest(
snapshot: "image"
}
);
registerMarkupTest(
{
name: "Test Image question empty",
json: {
questions: [
{
"type": "image",
"name": "banner",
}
]
},
snapshot: "image-empty"
}
);
registerMarkupTest(
{
name: "Test Image Video question markup",
Expand Down Expand Up @@ -55,7 +69,8 @@ registerMarkupTest(
},
timeout: 500,
initSurvey: survey => {
survey.getAllQuestions()[0]["onErrorHandler"] = function() { this["contentNotLoaded"] = false; };
survey.getAllQuestions()[0]["contentNotLoaded"] = true;
survey.getAllQuestions()[0]["onErrorHandler"] = function() { this["contentNotLoaded"] = true; };
},
snapshot: "image-not-load-content"
}
Expand Down
3 changes: 3 additions & 0 deletions tests/markup/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,9 @@ function clearAttributes(el: Element, removeIds = false) {
if(el.getAttribute("style") === "") {
el.removeAttribute("style");
}
if(el.getAttribute("src") === "") {
el.removeAttribute("src");
}
if(el.getAttribute("name") !== "name")
el.removeAttribute("name");
if((<any>el).checked) {
Expand Down
9 changes: 9 additions & 0 deletions tests/markup/snapshots/image-empty.snap.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<div class="sv_q_image">
<img alt="banner" class="sv_image_image" height="150px" style="display:none; object-fit:contain;" width="200px">
<div class="sv-image__no-image">
<svg class="sv-svg-icon" role="img" style="height:48px; width:48px;">
<use xlink:href="#icon-no-image" class="">
</use>
</svg>
</div>
</div>
8 changes: 7 additions & 1 deletion tests/markup/snapshots/image-not-load-content.snap.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
<div class="sv_q_image">
<img alt="banner" class="sv_image_image" height="150px" src="#item1.jpg" style="object-fit: contain;" width="200px">
<img alt="banner" class="sv_image_image" height="150px" src="#item1.jpg" style="display:none; object-fit:contain;" width="200px">
<div class="sv-image__no-image">
<svg class="sv-svg-icon" role="img" style="height:48px; width:48px;">
<use xlink:href="#icon-no-image" class="">
</use>
</svg>
</div>
</div>
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 1300e28

Please sign in to comment.