Skip to content

Commit

Permalink
Implement VAR for C24_WMDE_Desktop_DE_21
Browse files Browse the repository at this point in the history
- adds "minimise banner on scroll" for VAR

- there are now multiple emits of "bannerContentChanged" due to the resizing into Minimize banner,
so the softclose test needs to be a little more flexible in its expectation

- add tests for autoscroll feature on desktop
https://phabricator.wikimedia.org/T381952
  • Loading branch information
moiikana committed Dec 16, 2024
1 parent eccd360 commit 178387f
Show file tree
Hide file tree
Showing 11 changed files with 375 additions and 53 deletions.
43 changes: 39 additions & 4 deletions banners/desktop/C24_WMDE_Desktop_DE_21/components/BannerVar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
:bannerState="bannerState"
>
<template #close-button>
<ButtonClose @close="onCloseMain"/>
<ButtonClose @close="onCloseMain( 'MainBanner', CloseChoices.Close )"/>
</template>

<template #banner-title>
Expand Down Expand Up @@ -58,6 +58,20 @@

</MainBanner>

<MinimisedBanner
v-if="contentState === ContentStates.Minimised"
@maximise="() => onMaximiseBanner( 'maximise' )"
@maximise-cta="() => onMaximiseBanner( 'cta' )"
@close="() => onCloseMain( 'MinimisedBanner', CloseChoices.Close )"
>
<template #footer>
<FooterAlreadyDonated
@showFundsModal="isFundsModalVisible = true"
@clickedAlreadyDonatedLink="onClose( 'AlreadyDonated', CloseChoices.AlreadyDonated )"
/>
</template>
</MinimisedBanner>

<SoftClose
v-if="contentState === ContentStates.SoftClosing"
:show-close-icon="true"
Expand All @@ -83,7 +97,7 @@
import { BannerStates } from '@src/components/BannerConductor/StateMachine/BannerStates';
import { inject, ref, watch } from 'vue';
import { UseOfFundsContent as useOfFundsContentInterface } from '@src/domain/UseOfFunds/UseOfFundsContent';
import MainBanner from './MainBanner_var.vue';
import MainBanner from './MainBanner.vue';
import FundsModal from '@src/components/UseOfFunds/FundsModal.vue';
import BannerText from '../content/BannerText.vue';
import BannerSlides from '../content/BannerSlides.vue';
Expand Down Expand Up @@ -111,9 +125,14 @@ import { BannerSubmitOnReturnEvent } from '@src/tracking/events/BannerSubmitOnRe
import { Tracker } from '@src/tracking/Tracker';
import { useBannerHider } from '@src/components/composables/useBannerHider';
import BannerTitle from '@banners/desktop/C24_WMDE_Desktop_DE_15/content/BannerTitle.vue';
import MinimisedBanner from '@banners/desktop/C24_WMDE_Desktop_DE_21/components/MinimisedBanner.vue';
import { useScrollMinimiser } from '@banners/desktop/C24_WMDE_Desktop_DE_21/useScrollMinimiser';
import { BannerMinimisedEvent } from '@banners/desktop/C24_WMDE_Desktop_DE_00/events/BannerMinimisedEvent';
import { BannerMaximisedEvent } from '@banners/desktop/C24_WMDE_Desktop_DE_00/events/BannerMaximisedEvent';
enum ContentStates {
Main = 'wmde-banner-wrapper--main',
Minimised = 'wmde-banner-wrapper--minimised',
SoftClosing = 'wmde-banner-wrapper--soft-closing',
}
Expand Down Expand Up @@ -142,11 +161,20 @@ const stepControllers = [
createSubmittableMainDonationForm( formModel, FormStepNames.UpgradeToYearlyFormStep ),
createSubmittableUpgradeToYearly( formModel, FormStepNames.MainDonationFormStep, FormStepNames.MainDonationFormStep )
];
const wasMinimised = ref<boolean>( false );
watch( contentState, async () => {
emit( 'bannerContentChanged' );
} );
useScrollMinimiser( 500, wasMinimised, () => {
if ( props.bannerState === BannerStates.Visible && contentState.value === ContentStates.Main ) {
contentState.value = ContentStates.Minimised;
wasMinimised.value = true;
tracker.trackEvent( new BannerMinimisedEvent() );
}
} );
const onSubmit = (): void => {
// special callback function: asking for previous close choices
const closeChoice = props.localCloseTracker.getItem();
Expand All @@ -155,18 +183,25 @@ const onSubmit = (): void => {
}
};
function onCloseMain(): void {
function onCloseMain( feature: TrackingFeatureName, userChoice: CloseChoices ): void {
if ( props.remainingImpressions > 0 ) {
contentState.value = ContentStates.SoftClosing;
emit( 'bannerContentChanged' );
} else {
onClose( 'MainBanner', CloseChoices.Close );
onClose( feature, userChoice );
}
}
function onClose( feature: TrackingFeatureName, userChoice: CloseChoices ): void {
emit( 'bannerClosed', new CloseEvent( feature, userChoice ) );
}
function onMaximiseBanner( userChoice: string ): void {
contentState.value = ContentStates.Main;
tracker.trackEvent( new BannerMaximisedEvent( userChoice ) );
emit( 'bannerContentChanged' );
}
function onHideFundsModal(): void {
isFundsModalVisible.value = false;
emit( 'modalClosed' );
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<template>
<div class="wmde-banner-minimised">

<div class="wmde-banner-minimised-button-group">
<button class="wmde-banner-minimised-maximise" @click.prevent="$emit( 'maximise' )">Vergrößern <ChevronDownIcon/></button>
<ButtonClose @close="$emit( 'close' )"/>
</div>

<div class="wmde-banner-minimised-content">
<div class="wmde-banner-minimised-content-message">
<MinimisedText/>
</div>
<div class="wmde-banner-minimised-content-button">
<button class="wmde-banner-minimised-submit-button" @click.prevent="$emit( 'maximise-cta' )">
Jetzt spenden
</button>
</div>
</div>

<slot name="footer"/>
</div>
</template>

<script setup lang="ts">
import MinimisedText from '../content/MinimisedText.vue';
import ButtonClose from '@src/components/ButtonClose/ButtonClose.vue';
import ChevronDownIcon from '@src/components/Icons/ChevronDownIcon.vue';
defineEmits( [ 'close', 'maximise', 'maximise-cta' ] );
</script>
26 changes: 26 additions & 0 deletions banners/desktop/C24_WMDE_Desktop_DE_21/content/MinimisedText.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<template>
<div class="wmde-banner-minimised-message">
<InfoIconItalic/>
<p class="wmde-banner-minimised-title">
{{ liveDateAndTime.currentDate }}, {{ liveDateAndTime.currentTime }} - An alle, die Wikipedia in Deutschland nutzen. Die Zeit wird knapp!
</p>
<p>
Hat Wikipedia Ihnen in diesem Jahr Wissen im Wert einer Tasse Kaffee geschenkt? Dann geben Sie jetzt etwas zurück.
</p>
</div>
</template>

<script setup lang="ts">
import { inject, onMounted, onUnmounted } from 'vue';
import { DynamicContent } from '@src/utils/DynamicContent/DynamicContent';
import { useLiveDateAndTime } from '@src/components/composables/useLiveDateAndTime';
import InfoIconItalic from '@src/components/Icons/InfoIconItalic.vue';
const { getCurrentDateAndTime } = inject<DynamicContent>( 'dynamicCampaignText' );
const { liveDateAndTime, startTimer, stopTimer } = useLiveDateAndTime( getCurrentDateAndTime );
onMounted( startTimer );
onUnmounted( stopTimer );
</script>
10 changes: 10 additions & 0 deletions banners/desktop/C24_WMDE_Desktop_DE_21/event_map_var.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import { FallbackBannerSubmitEvent } from '@src/tracking/events/FallbackBannerSu
import { ShownEvent } from '@src/tracking/events/ShownEvent';
import { mapShownEvent } from '@src/tracking/LegacyEventTracking/mapShownEvent';
import { BannerSubmitOnReturnEvent } from '@src/tracking/events/BannerSubmitOnReturnEvent';
import { BannerMinimisedEvent } from '@banners/desktop/C24_WMDE_Desktop_DE_00/events/BannerMinimisedEvent';
import { BannerMaximisedEvent } from '@banners/desktop/C24_WMDE_Desktop_DE_00/events/BannerMaximisedEvent';

export default new Map<string, TrackingEventConverterFactory>( [
[ ShownEvent.EVENT_NAME, mapShownEvent ],
Expand Down Expand Up @@ -43,5 +45,13 @@ export default new Map<string, TrackingEventConverterFactory>( [
[ BannerSubmitOnReturnEvent.EVENT_NAME,
( e: BannerSubmitOnReturnEvent ): WMDELegacyBannerEvent =>
new WMDELegacyBannerEvent( e.eventName + ( e.userChoice !== '' ? `-${e.userChoice}` : '' ), 1 )
],
[ BannerMinimisedEvent.EVENT_NAME,
( e: BannerMinimisedEvent ): WMDELegacyBannerEvent =>
new WMDELegacyBannerEvent( e.eventName, 1 )
],
[ BannerMaximisedEvent.EVENT_NAME,
( e: BannerMaximisedEvent ): WMDELegacyBannerEvent =>
new WMDELegacyBannerEvent( `${e.eventName}-${e.userChoice}`, 1 )
]
] );
102 changes: 102 additions & 0 deletions banners/desktop/C24_WMDE_Desktop_DE_21/styles/MinimisedBanner.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
@use '../../../../src/themes/Treedip/variables/globals';
@use '../../../../src/themes/Treedip/variables/fonts';

.wmde-banner {
&-minimised {
--chevron-color: var( --minimised-control-fill );

padding: 12px 24px 0;

&-content {
display: flex;

&-message {
display: flex;
flex: 1 1 auto;
flex-direction: column;
justify-content: center;
padding: 11px 15px 11px 34px;
font-size: 14px;

border: 5px solid var( --message-border );
border-radius: 9px;

svg {
float: left;
margin: 10px 0 0 -22px;
}
}

&-button {
flex: 0 0 auto;
display: flex;
flex-direction: column;
justify-content: end;
padding-left: 30px;
}
}

&-title {
font-family: fonts.$content;
font-size: 18px;
font-weight: bold;
}

&-submit-button {
width: 300px;
background: var( --minimised-button-background );
color: var( --minimised-button-color );
font-weight: bold;
line-height: 36px;
border: 0;
border-radius: 18px;
padding: 0 10px;
transition: background-color 500ms globals.$banner-easing;
cursor: pointer;

&:hover,
&:focus {
background: var( --minimised-button-background-hover );
}
}

&-button-group {
position: absolute;
z-index: 2;
top: 12px;
right: 24px;
height: 30px;
width: 300px;
display: flex;
justify-content: space-between;

.wmde-banner-close {
position: static;
}
}

&-minimise,
&-maximise {
background: none;
border: 2px solid var( --minimised-control-border );
border-radius: 15px;
cursor: pointer;
color: var( --minimised-control-color );
padding-right: 8px;
margin-right: 8px;
font-size: 14px;
font-weight: bold;

svg {
width: 20px;
}
}

&-minimise {
svg {
transform: rotate( 180deg );
margin-left: 3px;
}
}
}
}
2 changes: 2 additions & 0 deletions banners/desktop/C24_WMDE_Desktop_DE_21/styles/styles_var.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
$fallback-banner: true,
$progress-bar: true,
$soft-close: true,
$minimised-banner: true,
);
@use 'src/components/BannerConductor/banner-transition';
@use 'src/themes/UseOfFunds/swatches/skin_default' as uof-default;
Expand All @@ -15,6 +16,7 @@
$banner-height: 357px,
$form-width: 300px
);
@use 'MinimisedBanner';
@use 'src/themes/Treedip/defaults';
@use 'src/themes/Treedip/ButtonClose/ButtonClose';
@use 'src/themes/Treedip/ProgressBar/ProgressBarAlternative' with (
Expand Down
21 changes: 21 additions & 0 deletions banners/desktop/C24_WMDE_Desktop_DE_21/useScrollMinimiser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { onMounted, onUnmounted, Ref, watch } from 'vue';

export function useScrollMinimiser( switchThreshold: number, hasMinimised: Ref<boolean>, onScrollBelowThreshold: () => void ): void {
const scrollHandler = (): void => {
if ( window.scrollY > switchThreshold ) {
onScrollBelowThreshold();
}
};

onMounted( () => {
window.addEventListener( 'scroll', scrollHandler );
} );

onUnmounted( () => {
window.removeEventListener( 'scroll', scrollHandler );
} );

watch( hasMinimised, () => {
window.removeEventListener( 'scroll', scrollHandler );
} );
}
Loading

0 comments on commit 178387f

Please sign in to comment.