Skip to content

Commit 318eb9d

Browse files
committed
Revert back to opening in new windows
1 parent 20c5462 commit 318eb9d

File tree

3 files changed

+47
-37
lines changed

3 files changed

+47
-37
lines changed

src/templates/bespoke/overview/normal-view.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import { generateURLfromParams, storage } from '../utils'
1+
import { classPrefix, generateURLfromParams, storage } from '../utils'
2+
3+
export const overviewPrefix = `${classPrefix}overview-` as const
24

35
interface BespokeForOverview {
46
syncKey: string
@@ -26,7 +28,15 @@ const normalView = (deck) => {
2628
}
2729

2830
function openOverviewView(this: BespokeForOverview) {
29-
location.href = this.overviewUrl
31+
const { max, floor } = Math
32+
const w = max(floor(window.innerWidth * 0.85), 640)
33+
const h = max(floor(window.innerHeight * 0.85), 360)
34+
35+
return window.open(
36+
this.overviewUrl,
37+
overviewPrefix + this.syncKey,
38+
`width=${w},height=${h},menubar=no,toolbar=no`
39+
)
3040
}
3141

3242
function overviewUrl(this: BespokeForOverview) {

src/templates/bespoke/overview/overview-view.ts

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,7 @@
1-
import { classPrefix, generateURLfromParams } from '../utils'
1+
import { classPrefix } from '../utils'
22

33
const overviewActiveClass = `${classPrefix}overview-active`
44

5-
const navigateBack = (slideIndex: number) => {
6-
const params = new URLSearchParams(location.search)
7-
8-
params.delete('view')
9-
params.delete('sync')
10-
11-
location.href = generateURLfromParams(params, {
12-
...location,
13-
hash: `#${slideIndex + 1}`,
14-
})
15-
}
16-
175
const overviewView = () => (deck) => {
186
const { title } = document
197
document.title = `[Overview]${title ? ` - ${title}` : ''}`
@@ -55,25 +43,19 @@ const overviewView = () => (deck) => {
5543
})
5644
}
5745

58-
// Click a slide to navigate back to normal view at that slide
46+
// Click a slide to navigate (syncs to other windows via bespokeSync)
5947
slides().forEach((slide, i) => {
6048
slide.addEventListener('click', () => {
61-
navigateBack(i)
49+
deck.slide(i)
6250
})
6351
})
6452

65-
// Arrow key navigation within the grid, Escape/Enter to go back
53+
// Arrow key navigation within the grid
6654
document.addEventListener('keydown', (e) => {
6755
const cols = columns()
6856
const current = deck.slide()
6957

70-
if (e.key === 'Escape' || e.key === 'o') {
71-
e.preventDefault()
72-
navigateBack(current)
73-
} else if (e.key === 'Enter') {
74-
e.preventDefault()
75-
navigateBack(current)
76-
} else if (e.key === 'ArrowRight') {
58+
if (e.key === 'ArrowRight') {
7759
e.preventDefault()
7860
deck.slide(Math.min(current + 1, slideCount() - 1))
7961
} else if (e.key === 'ArrowLeft') {

test/templates/bespoke.ts

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1856,6 +1856,7 @@ describe("Bespoke template's browser context", () => {
18561856
describe('Overview', () => {
18571857
describe('In normal view mode', () => {
18581858
beforeEach(() => {
1859+
jest.spyOn(window, 'open').mockImplementation()
18591860
render()
18601861
})
18611862

@@ -1869,27 +1870,36 @@ describe("Bespoke template's browser context", () => {
18691870
})
18701871
})
18711872

1872-
it('injects deck.openOverviewView() to navigate to overview view', () => {
1873+
it('injects deck.openOverviewView() to open overview view', () => {
18731874
replaceLocation('/?sync=synckey', () => {
18741875
const deck = bespoke()
18751876
expect(deck.openOverviewView).toBeInstanceOf(Function)
1877+
1878+
deck.openOverviewView()
1879+
expect(window.open).toHaveBeenCalledWith(
1880+
deck.overviewUrl,
1881+
'bespoke-marp-overview-synckey',
1882+
expect.stringContaining('menubar=no,toolbar=no')
1883+
)
18761884
})
18771885
})
18781886

1879-
it('does not open overview with modifier keys', () => {
1880-
replaceLocation('/?sync=xxx', () => {
1881-
bespoke()
1882-
const hrefBefore = location.href
1887+
it('opens overview view by hitting o key', () => {
1888+
bespoke()
1889+
keydown({ key: 'o' })
1890+
expect(window.open).toHaveBeenCalled()
1891+
1892+
// Ignore hitting o key with modifier
1893+
;(window.open as jest.Mock).mockClear()
18831894

1884-
keydown({ key: 'o', ctrlKey: true })
1885-
expect(location.href).toBe(hrefBefore)
1895+
keydown({ key: 'o', ctrlKey: true })
1896+
expect(window.open).not.toHaveBeenCalled()
18861897

1887-
keydown({ key: 'o', metaKey: true })
1888-
expect(location.href).toBe(hrefBefore)
1898+
keydown({ key: 'o', metaKey: true })
1899+
expect(window.open).not.toHaveBeenCalled()
18891900

1890-
keydown({ key: 'o', altKey: true })
1891-
expect(location.href).toBe(hrefBefore)
1892-
})
1901+
keydown({ key: 'o', altKey: true })
1902+
expect(window.open).not.toHaveBeenCalled()
18931903
})
18941904
})
18951905

@@ -1967,6 +1977,14 @@ describe("Bespoke template's browser context", () => {
19671977
expect(deck.slide()).toBe(2)
19681978
}))
19691979

1980+
it('navigates to clicked slide', () =>
1981+
testOverviewView(({ deck }) => {
1982+
deck.slides[2].dispatchEvent(
1983+
new MouseEvent('click', { bubbles: true })
1984+
)
1985+
expect(deck.slide()).toBe(2)
1986+
}))
1987+
19701988
it('recalculates layout on window resize', () =>
19711989
testOverviewView(({ deck }) => {
19721990
const transformBefore = deck.slides[0].style.transform

0 commit comments

Comments
 (0)