Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Ajout d'un bouton reload pour les embed (PIX-15418) #10784

Merged
merged 2 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { action } from '@ember/object';
import { htmlSafe } from '@ember/template';
import Component from '@glimmer/component';

Expand All @@ -8,4 +9,30 @@ export default class ChallengeEmbedSimulator extends Component {
const height = this.args.isMediaWithForm ? (baseHeight * itemMedia.offsetWidth) / 710 : baseHeight;
return htmlSafe(`height: ${height}px; max-height: ${baseHeight}px`);
}

@action
setIframeHtmlElement(htmlElement) {
this.iframe = htmlElement;
}

@action
rebootSimulator() {
const iframe = this.iframe;
const tmpSrc = iframe.src;

const loadListener = () => {
if (iframe.src === 'about:blank') {
// First onload: when we reset the iframe
iframe.src = tmpSrc;
} else {
// Second onload: when we re-assign the iframe's src to its original value
iframe.focus();
iframe.removeEventListener('load', loadListener);
}
};

iframe.addEventListener('load', loadListener);

iframe.src = 'about:blank';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@
src="{{@url}}"
title="{{@title}}"
style="{{this.embedDocumentHeightStyle}}"
{{did-render this.setIframeHtmlElement}}
>
</iframe>
{{#if @shouldDisplayRebootButton}}
<div class="reboot-container">
<PixButton
class="link link--grey reboot-container__content"
aria-label={{t "pages.challenge.embed-simulator.actions.reset-label"}}
@iconBefore="refresh"
@variant="tertiary"
@triggerAction={{this.rebootSimulator}}
>
{{t "components.challenge.embed-simulator.actions.reset"}}
</PixButton>
</div>
{{/if}}
</div>
15 changes: 15 additions & 0 deletions junior/app/components/challenge/item/component.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';

export default class Item extends Component {
@tracked isRebootable = false;

constructor() {
super(...arguments);
window.addEventListener('message', ({ data }) => {
if (data?.from === 'pix' && data?.type === 'init') {
this.isRebootable = !!data.rebootable;
}
});
}
get isMediaWithForm() {
return this.args.challenge.hasForm && this.hasMedia && this.args.challenge.type !== undefined;
}
Expand All @@ -12,4 +23,8 @@ export default class Item extends Component {
this.args.challenge.hasWebComponent
);
}

get shouldDisplayRebootButton() {
return this.isRebootable && !this.args.isDisabled;
}
}
1 change: 1 addition & 0 deletions junior/app/components/challenge/item/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
@height={{@challenge.embedHeight}}
@hideSimulator={{@isDisabled}}
@isMediaWithForm={{this.isMediaWithForm}}
@shouldDisplayRebootButton={{this.shouldDisplayRebootButton}}
/>
</div>
{{/if}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,21 @@
width: 100%;
height: 100%;
}

.reboot-container {
display: flex;
justify-content: flex-end;

.pix-button--tertiary {
color: var(--pix-neutral-500);
text-decoration: none;
}

&__content {
display: flex;
align-items: center;
}
}
}


7 changes: 7 additions & 0 deletions junior/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
"play": "J'écoute",
"stop": "Stop",
"label": "Lire la consigne à haute voix"
},
"challenge": {
"embed-simulator": {
"actions": {
"reset": "Recommencer"
}
}
}
},
"pages": {
Expand Down
Loading