@@ -7,6 +7,8 @@ import cloneWithProps from "react/lib/cloneWithProps";
77import Radium from "radium" ;
88import _ from "lodash" ;
99import Presenter from "./presenter" ;
10+ import Export from "./export" ;
11+ import Overview from "./overview" ;
1012
1113React . initializeTouchEvents ( true ) ;
1214
@@ -27,8 +29,7 @@ class Deck extends React.Component {
2729 } ;
2830 }
2931 componentDidMount ( ) {
30- const slide = "slide" in this . context . router . state . params ?
31- parseInt ( this . context . router . state . params . slide ) : 0 ;
32+ const slide = this . context . slide ;
3233 this . setState ( {
3334 lastSlide : slide
3435 } ) ;
@@ -57,31 +58,50 @@ class Deck extends React.Component {
5758 if ( event . keyCode === 39 || event . keyCode === 34 ) {
5859 this . _nextSlide ( ) ;
5960 }
61+ if ( event . keyCode === 79 ) { // o
62+ this . _toggleOverviewMode ( ) ;
63+ }
64+ if ( event . keyCode === 80 ) { // o
65+ this . _togglePresenterMode ( ) ;
66+ }
67+ }
68+ _toggleOverviewMode ( ) {
69+ const suffix = this . context . overview ? "" : "?overview" ;
70+ this . context . router . replaceWith ( "/" + ( this . context . slide ) + suffix ) ;
71+ }
72+ _togglePresenterMode ( ) {
73+ const suffix = this . context . presenter ? "" : "?presenter" ;
74+ this . context . router . replaceWith ( "/" + ( this . context . slide ) + suffix ) ;
75+ }
76+ _getSuffix ( ) {
77+ if ( this . context . presenter ) {
78+ return "?presenter" ;
79+ } else if ( this . context . overview ) {
80+ return "?overview" ;
81+ } else {
82+ return "" ;
83+ }
6084 }
6185 _goToSlide ( e ) {
6286 if ( e . key === "spectacle-slide" ) {
6387 const data = JSON . parse ( e . newValue ) ;
64- const presenter = this . context . presenter ? "?presenter" : "" ;
65- const slide = "slide" in this . context . router . state . params ?
66- parseInt ( this . context . router . state . params . slide ) : 0 ;
88+ const slide = this . context . slide ;
6789 this . setState ( {
6890 lastSlide : slide || 0
6991 } ) ;
7092 if ( this . _checkFragments ( slide , data . forward ) ) {
71- this . context . router . replaceWith ( "/" + ( data . slide ) + presenter ) ;
93+ this . context . router . replaceWith ( "/" + ( data . slide ) + this . _getSuffix ( ) ) ;
7294 }
7395 }
7496 }
7597 _prevSlide ( ) {
76- const slide = "slide" in this . context . router . state . params ?
77- parseInt ( this . context . router . state . params . slide ) : 0 ;
78- const presenter = this . context . presenter ? "?presenter" : "" ;
98+ const slide = this . context . slide ;
7999 this . setState ( {
80100 lastSlide : slide
81101 } ) ;
82- if ( this . _checkFragments ( slide , false ) ) {
102+ if ( this . _checkFragments ( slide , false ) || this . context . overview ) {
83103 if ( slide > 0 ) {
84- this . context . router . replaceWith ( "/" + ( slide - 1 ) + presenter ) ;
104+ this . context . router . replaceWith ( "/" + ( slide - 1 ) + this . _getSuffix ( ) ) ;
85105 localStorage . setItem ( "spectacle-slide" ,
86106 JSON . stringify ( { slide : slide - 1 , forward : false , time : Date . now ( ) } ) ) ;
87107 }
@@ -91,15 +111,13 @@ class Deck extends React.Component {
91111 }
92112 }
93113 _nextSlide ( ) {
94- const slide = "slide" in this . context . router . state . params ?
95- parseInt ( this . context . router . state . params . slide ) : 0 ;
96- const presenter = this . context . presenter ? "?presenter" : "" ;
114+ const slide = this . context . slide ;
97115 this . setState ( {
98116 lastSlide : slide
99117 } ) ;
100- if ( this . _checkFragments ( slide , true ) ) {
118+ if ( this . _checkFragments ( slide , true ) || this . context . overview ) {
101119 if ( slide < this . props . children . length - 1 ) {
102- this . context . router . replaceWith ( "/" + ( slide + 1 ) + presenter ) ;
120+ this . context . router . replaceWith ( "/" + ( slide + 1 ) + this . _getSuffix ( ) ) ;
103121 localStorage . setItem ( "spectacle-slide" ,
104122 JSON . stringify ( { slide : slide + 1 , forward : true , time : Date . now ( ) } ) ) ;
105123 }
@@ -235,52 +253,22 @@ class Deck extends React.Component {
235253 return 0 ;
236254 }
237255 _renderSlide ( ) {
238- const slide = "slide" in this . context . router . state . params ?
239- parseInt ( this . context . router . state . params . slide ) : 0 ;
240- if ( this . context . router . state . location . query &&
241- "export" in this . context . router . state . location . query ) {
242- return this . props . children . map ( ( child , index ) => {
243- return cloneWithProps ( child , {
244- key : index ,
245- slideIndex : slide ,
246- lastSlide : this . state . lastSlide ,
247- transition : child . props . transition . length ?
248- child . props . transition :
249- this . props . transition ,
250- transitionDuration : child . props . transition . transitionDuration ?
251- child . props . transitionDuration :
252- this . props . transitionDuration
253- } ) ;
254- } ) ;
255- } else {
256- const child = this . props . children [ slide ] ;
257- return cloneWithProps ( child , {
258- key : slide ,
259- slideIndex : slide ,
260- lastSlide : this . state . lastSlide ,
261- transition : child . props . transition . length ?
262- child . props . transition :
263- this . props . transition ,
264- transitionDuration : child . props . transition . transitionDuration ?
265- child . props . transitionDuration :
266- this . props . transitionDuration
267- } ) ;
268- }
256+ const slide = this . context . slide ;
257+ const child = this . props . children [ slide ] ;
258+ return cloneWithProps ( child , {
259+ key : slide ,
260+ slideIndex : slide ,
261+ lastSlide : this . state . lastSlide ,
262+ transition : child . props . transition . length ?
263+ child . props . transition :
264+ this . props . transition ,
265+ transitionDuration : child . props . transition . transitionDuration ?
266+ child . props . transitionDuration :
267+ this . props . transitionDuration
268+ } ) ;
269269 }
270270 render ( ) {
271- let exportMode = false ;
272- let showProgress = true ;
273-
274- if ( this . context . router . state . location . query &&
275- "export" in this . context . router . state . location . query ) {
276- exportMode = true ;
277- showProgress = false ;
278- }
279-
280- const slide = "slide" in this . context . router . state . params ?
281- parseInt ( this . context . router . state . params . slide ) : 0 ;
282-
283- const globals = exportMode ? {
271+ const globals = this . context . export ? {
284272 body : {
285273 minWidth : 1100 ,
286274 minHeight : 850 ,
@@ -290,7 +278,7 @@ class Deck extends React.Component {
290278
291279 const styles = {
292280 deck : {
293- backgroundColor : this . context . presenter ? "black" : "" ,
281+ backgroundColor : this . context . presenter || this . context . overview ? "black" : "" ,
294282 position : "absolute" ,
295283 top : 0 ,
296284 left : 0 ,
@@ -305,26 +293,30 @@ class Deck extends React.Component {
305293 }
306294 } ;
307295
308- const currentSlide = "slide" in this . context . router . state . params ?
309- parseInt ( this . context . router . state . params . slide ) : 0 ;
310- const slides = this . props . children ;
296+ let componentToRender ;
297+ if ( this . context . presenter ) {
298+ componentToRender = ( < Presenter slides = { this . props . children }
299+ slide = { this . context . slide } lastSlide = { this . state . lastSlide } /> ) ;
300+ } else if ( this . context . export ) {
301+ componentToRender = < Export slides = { this . props . children } /> ;
302+ } else if ( this . context . overview ) {
303+ componentToRender = < Overview slides = { this . props . children } slide = { this . context . slide } /> ;
304+ } else {
305+ componentToRender = ( < TransitionGroup component = "div" style = { [ styles . transition ] } >
306+ { this . _renderSlide ( ) }
307+ </ TransitionGroup > ) ;
308+ }
311309
312310 return (
313311 < div
314312 className = "spectacle-deck"
315313 style = { [ styles . deck ] }
316314 onClick = { this . _handleClick }
317315 { ...this . _getTouchEvents ( ) } >
318- { this . context . presenter ?
319- < Presenter slides = { this . props . children }
320- slide = { slide } lastSlide = { this . state . lastSlide } /> :
321- < TransitionGroup
322- component = "div"
323- className = "spectacle-transition"
324- style = { [ styles . transition ] } >
325- { this . _renderSlide ( ) }
326- </ TransitionGroup > }
327- { showProgress ? < Progress items = { slides } currentSlide = { currentSlide }
316+ { componentToRender }
317+ { ! this . context . export ? < Progress
318+ items = { this . props . children }
319+ currentSlide = { this . context . slide }
328320 type = { this . props . progress } /> : "" }
329321 < Style rules = { assign ( this . context . styles . global , globals ) } />
330322 </ div >
@@ -350,7 +342,10 @@ Deck.contextTypes = {
350342 styles : React . PropTypes . object ,
351343 router : React . PropTypes . object ,
352344 flux : React . PropTypes . object ,
353- presenter : React . PropTypes . bool
345+ presenter : React . PropTypes . bool ,
346+ export : React . PropTypes . bool ,
347+ overview : React . PropTypes . bool ,
348+ slide : React . PropTypes . number
354349} ;
355350
356351export default Deck ;
0 commit comments