Skip to content
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
24 changes: 14 additions & 10 deletions demo/scripts/slides.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ console.log('Reveal version', Reveal.VERSION);
console.log('Reveal instance', Reveal);

// One method per module
function schoolSlides() {
function schoolSlides(showType) {
const dir = '01-classics';
return [
'00_intro.md',
`${dir}/10_chapter1.md`,
`${dir}/20_transitions.md`,
`${dir}/30_code_slides.md`,
!showType || showType === 'custom'
? undefined
: `${dir}/30_code_slides.md`,
`${dir}/40_custom_bg_slides.md`,
];
}
Expand Down Expand Up @@ -53,17 +55,19 @@ function toolsSlides() {
];
}

function formation() {
function formation(showType) {
return [
//
...schoolSlides(),
...speakerSlides(),
...layoutsSlides(),
...helpersSlides(),
...toolsSlides(),
].map((slidePath) => {
return { path: slidePath };
});
...(!showType || showType === 'speakers' ? speakerSlides() : []),
...(!showType || showType === 'layouts' ? layoutsSlides() : []),
...(!showType || showType === 'helpers' ? helpersSlides() : []),
...(!showType || showType === 'tools' ? toolsSlides() : []),
]
.filter((element) => element !== undefined)
.map((slidePath) => {
return { path: slidePath };
});
}

await ThemeInitializer.init({
Expand Down
46 changes: 44 additions & 2 deletions src/addons/tc-data-type.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
/**
* @vitest-environment jsdom
*/
import { beforeEach, describe, expect, it } from 'vitest';
import { afterAll, beforeEach, describe, expect, it } from 'vitest';
import { getShowType, manageShowTypeContent } from './tc-data-type';
import { DEFAULT_TYPE } from '../utils/const';

import { manageShowTypeContent } from './tc-data-type';
// Mock window.location
const mockLocation = {
search: '',
href: '',
origin: 'http://localhost',
pathname: '/',
hash: '',
};

Object.defineProperty(window, 'location', {
value: mockLocation,
writable: true,
});

const HTML = `
<div class="reveal">
Expand All @@ -30,6 +44,34 @@ const HTML = `
</div>
`;

describe(getShowType.name, () => {
afterAll(async () => {
window.location.search = '';
});
it('should use default type if nothing is specified', () => {
document.body.innerHTML = `<div class="reveal">
<div class="slides"></div>
</div>`;
const type = getShowType();
expect(type).toBe(DEFAULT_TYPE);
});
it('should use type if specified in HTML', () => {
document.body.innerHTML = `<div class="reveal">
<div class="slides" data-type="test"></div>
</div>`;
const type = getShowType();
expect(type).toBe('test');
});

it('should use type if specified in URL', () => {
window.location.search = 'data-type=test2';
document.body.innerHTML = `<div class="reveal">
<div class="slides"></div>
</div>`;
const type = getShowType();
expect(type).toBe('test2');
});
});
describe(manageShowTypeContent.name, () => {
beforeEach(async () => {
document.body.innerHTML = HTML;
Expand Down
14 changes: 10 additions & 4 deletions src/addons/tc-data-type.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
import { DEFAULT_TYPE } from '../utils/const';
import { _handle_parameter } from '../utils/helper';

export function manageShowTypeContent(
defaultType: string = DEFAULT_TYPE
): void {
export function getShowType(defaultType: string = DEFAULT_TYPE): string {
const urlParams = new URLSearchParams(window.location.search);
const slidesElement: HTMLElement =
document.querySelector('.reveal .slides')!;
const slidesType = _handle_parameter(
return _handle_parameter(
urlParams,
'data-type',
slidesElement,
'data-type',
defaultType
);
}

export function manageShowTypeContent(
defaultType: string = DEFAULT_TYPE
): void {
const slidesType = getShowType(defaultType);

if (slidesType !== 'all') {
const slidesElement: HTMLElement =
document.querySelector('.reveal .slides')!;
Array.from(slidesElement.querySelectorAll('section[data-type-show]'))
.filter(
(el) =>
Expand Down
6 changes: 5 additions & 1 deletion src/theme-initializer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
* @vitest-environment jsdom
*/
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { DEFAULT_TYPE } from './utils/const';
import Reveal from 'reveal.js';
import { ThemeInitializer } from './theme-initializer';
import { render } from 'lit-html';

// Mocks
vi.mock('reveal.js', () => ({
default: {
Expand Down Expand Up @@ -56,6 +56,10 @@ vi.mock('./utils/storage-service', () => ({
]),
}));

vi.mock('./addons/tc-data-type', () => ({
getShowType: vi.fn().mockImplementation(() => DEFAULT_TYPE),
}));

vi.mock('./addons/tc-ui-config');

// Get a representation of this mock class
Expand Down
8 changes: 6 additions & 2 deletions src/theme-initializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ import { SlidePath } from './models';
import { TcCustomBackgroundOptions } from './addons/tc-custom-background';
import { TcThemeOptions } from './addons/tc-theme';
import { TcUiConfig } from './addons/tc-ui-config';
import { getShowType } from './addons/tc-data-type';
import { getSlidesToUse } from './utils/storage-service';

/**
*
*/
export interface ThemeInitializerOptions {
slidesFactory: () => SlidePath[]; // Function to retrieve the slides informations
slidesFactory: (showType?: string) => SlidePath[]; // Function to retrieve the slides informations
activeCopyClipboard?: boolean; // Default applied is true
tcMarkedOptions: TalkControlMarkedOptions; // Deal with the font icons
tcI18nOptions: TcI18nConfig; // Deal with the i18n options
Expand Down Expand Up @@ -50,8 +51,11 @@ export const ThemeInitializer = {
document.querySelector('.slides');
if (importSlideElement == null) return;

// Retrieve the data type parameter to apply to a subset of slides
const showType = getShowType(defaultSlidesType);

// Retrieve the slide path list
const slides = slidesFactory();
const slides = slidesFactory(showType);

// Init the uiConfig
new TcUiConfig(
Expand Down