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

Add bespoke load plugin #154

Merged
merged 3 commits into from
Sep 15, 2019
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## [Unreleased]

### Fixed

- Vanished auto-fitting elements when exporting to PDF, PPTX, and images ([#153](https://github.com/marp-team/marp-cli/issues/153), [#154](https://github.com/marp-team/marp-cli/pull/154))

## v0.14.0 - 2019-09-12

### Fixed
Expand Down
8 changes: 3 additions & 5 deletions src/templates/bespoke/bespoke.scss
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,10 @@ $progressHeight: 5px;
z-index: 0;
}

@at-root {
body.loaded & {
display: none;
}
&[data-bespoke-marp-load='hideable'] {
display: none;

body.loaded &.bespoke-marp-active {
&.bespoke-marp-active {
display: block;
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/templates/bespoke/bespoke.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import bespoke from 'bespoke'
import bespokeForms from 'bespoke-forms'
import bespokeClasses from './classes'
import bespokeInactive from './inactive'
import bespokeLoad from './load'
import bespokeFragments from './fragments'
import bespokeFullscreen from './fullscreen'
import bespokeNavigation from './navigation'
Expand All @@ -13,12 +14,11 @@ import bespokeTouch from './touch'
import { readQuery } from './utils'

export default function(target = document.getElementById('p')!) {
window.addEventListener('load', () => document.body.classList.add('loaded'))

const deck = bespoke.from(target, [
bespokeForms(),
bespokeClasses,
bespokeInactive(),
bespokeLoad,
bespokeState({ history: false }),
bespokeNavigation(),
bespokeFullscreen,
Expand All @@ -30,6 +30,5 @@ export default function(target = document.getElementById('p')!) {
])

window.addEventListener('unload', () => deck.destroy())

return deck
}
11 changes: 11 additions & 0 deletions src/templates/bespoke/load.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export default function bespokeLoad(deck) {
window.addEventListener('load', () => {
for (const slide of deck.slides) {
// Slides contained Marp Core's fitting elements must not hide via `display: none;`.
// https://github.com/marp-team/marp-cli/issues/153
const type = slide.querySelector('[data-marp-fitting]') ? '' : 'hideable'

slide.setAttribute('data-bespoke-marp-load', type)
}
})
}
13 changes: 13 additions & 0 deletions test/templates/bespoke.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,19 @@ describe("Bespoke template's browser context", () => {
})
})

describe('Load', () => {
it('adds data attribute to each slides after loaded', () => {
render('# Regular\n\n---\n\n```\nnot-hideable\n```')
const deck = bespoke()

window.dispatchEvent(new Event('load'))

const [first, second] = deck.slides
expect(first.getAttribute('data-bespoke-marp-load')).toBe('hideable')
expect(second.getAttribute('data-bespoke-marp-load')).toBe('')
})
})

describe('Navigation', () => {
let parent: HTMLElement
let deck
Expand Down