diff options
Diffstat (limited to 'js')
-rw-r--r-- | js/slide-controller.js | 54 | ||||
-rw-r--r-- | js/slides.js | 44 |
2 files changed, 87 insertions, 11 deletions
diff --git a/js/slide-controller.js b/js/slide-controller.js new file mode 100644 index 0000000..e2f8bf2 --- /dev/null +++ b/js/slide-controller.js | |||
@@ -0,0 +1,54 @@ | |||
1 | function SlideController(slideDeck) { | ||
2 | this.deck_ = slideDeck; | ||
3 | this.win_ = null; | ||
4 | |||
5 | window.addEventListener('message', this.onMessage_.bind(this), false); | ||
6 | |||
7 | // Close popups if we reload the main window. | ||
8 | window.addEventListener('beforeunload', function(e) { | ||
9 | this.win_.close() | ||
10 | }.bind(this), false); | ||
11 | |||
12 | // Only open one new popup. The recursion popup opening! | ||
13 | if (!window.opener) { | ||
14 | this.win_ = window.open(location.href, 'mywindow'); | ||
15 | } | ||
16 | } | ||
17 | |||
18 | SlideController.MOVE_LEFT = -1; | ||
19 | SlideController.MOVE_RIGHT = 1; | ||
20 | |||
21 | SlideController.prototype.onMessage_ = function(e) { | ||
22 | var data = e.data; | ||
23 | |||
24 | // It would be dope if FF implemented location.origin. | ||
25 | if (e.origin != location.protocol + '//' + location.host) { | ||
26 | alert('Someone tried to postMessage from an unknown origin'); | ||
27 | return; | ||
28 | } | ||
29 | |||
30 | if (e.source.location.hostname != 'localhost') { | ||
31 | alert('Someone tried to postMessage from an unknown origin'); | ||
32 | return; | ||
33 | } | ||
34 | |||
35 | if ('slideDirection' in data) { | ||
36 | if (data.slideDirection == SlideController.MOVE_LEFT) { | ||
37 | this.deck_.prevSlide(); | ||
38 | } else { | ||
39 | this.deck_.nextSlide(); | ||
40 | } | ||
41 | } | ||
42 | }; | ||
43 | |||
44 | SlideController.prototype.sendMsg = function(msg) { | ||
45 | // // Send message to popup window. | ||
46 | // if (this.win_) { | ||
47 | // this.win_.postMessage(msg, location.protocol + '//' + location.host); | ||
48 | // } | ||
49 | // Send message to main window. | ||
50 | if (window.opener) { | ||
51 | // It would be dope if FF implemented location.origin. | ||
52 | window.opener.postMessage(msg, location.protocol + '//' + location.host); | ||
53 | } | ||
54 | }; | ||
diff --git a/js/slides.js b/js/slides.js index 20bb1bd..0faf06b 100644 --- a/js/slides.js +++ b/js/slides.js | |||
@@ -13,6 +13,7 @@ function SlideDeck() { | |||
13 | this.prevSlide_ = 0; | 13 | this.prevSlide_ = 0; |
14 | this.slides = []; | 14 | this.slides = []; |
15 | this.config_ = null; | 15 | this.config_ = null; |
16 | this.controller_ = null; | ||
16 | 17 | ||
17 | this.getCurrentSlideFromHash_(); | 18 | this.getCurrentSlideFromHash_(); |
18 | 19 | ||
@@ -52,6 +53,9 @@ SlideDeck.prototype.getCurrentSlideFromHash_ = function() { | |||
52 | * @private | 53 | * @private |
53 | */ | 54 | */ |
54 | SlideDeck.prototype.onDomLoaded_ = function(e) { | 55 | SlideDeck.prototype.onDomLoaded_ = function(e) { |
56 | // Fade in deck. | ||
57 | document.body.classList.add('loaded'); | ||
58 | |||
55 | this.slides_ = document.querySelectorAll('slide:not([hidden]):not(.backdrop)'); | 59 | this.slides_ = document.querySelectorAll('slide:not([hidden]):not(.backdrop)'); |
56 | 60 | ||
57 | // If we're on a smartphone device, load phone.css. | 61 | // If we're on a smartphone device, load phone.css. |
@@ -148,11 +152,11 @@ SlideDeck.prototype.onBodyKeyDown_ = function(e) { | |||
148 | document.body.classList.toggle('highlight-code'); | 152 | document.body.classList.toggle('highlight-code'); |
149 | break; | 153 | break; |
150 | 154 | ||
151 | case 78: // N | 155 | case 80: // P |
152 | // If this slide contains notes, toggle them. | 156 | // If this slide contains notes, toggle them. |
153 | if (this.slides_[this.curSlide_].querySelector('.note')) { | 157 | //if (this.slides_[this.curSlide_].querySelector('.note')) { |
154 | document.body.classList.toggle('with-notes'); | 158 | document.body.classList.toggle('with-notes'); |
155 | } | 159 | //} |
156 | break; | 160 | break; |
157 | 161 | ||
158 | case 27: // ESC | 162 | case 27: // ESC |
@@ -283,6 +287,10 @@ SlideDeck.prototype.loadConfig_ = function(config) { | |||
283 | } | 287 | } |
284 | }; | 288 | }; |
285 | } | 289 | } |
290 | |||
291 | if (!!('enableSpeakerNotes' in settings) && settings.enableSpeakerNotes) { | ||
292 | this.controller_ = new SlideController(this); | ||
293 | } | ||
286 | }; | 294 | }; |
287 | 295 | ||
288 | /** | 296 | /** |
@@ -335,10 +343,17 @@ SlideDeck.prototype.buildNextItem_ = function() { | |||
335 | */ | 343 | */ |
336 | SlideDeck.prototype.prevSlide = function(opt_dontPush) { | 344 | SlideDeck.prototype.prevSlide = function(opt_dontPush) { |
337 | if (this.curSlide_ > 0) { | 345 | if (this.curSlide_ > 0) { |
338 | // Toggle off speaker notes and/or highlighted code if they're showing. | 346 | // Toggle off speaker notes and/or highlighted code if they're showing |
339 | var bodyClassList = document.body.classList; | 347 | // when we advanced. If we're the speaker notes popup, leave this put. |
340 | bodyClassList.remove('with-notes'); | 348 | if (this.controller_ && !window.opener) { |
341 | bodyClassList.remove('highlight-code'); | 349 | var bodyClassList = document.body.classList; |
350 | bodyClassList.remove('with-notes'); | ||
351 | bodyClassList.remove('highlight-code'); | ||
352 | } | ||
353 | |||
354 | if (this.controller_) { | ||
355 | this.controller_.sendMsg({slideDirection: SlideController.MOVE_LEFT}); | ||
356 | } | ||
342 | 357 | ||
343 | this.prevSlide_ = this.curSlide_; | 358 | this.prevSlide_ = this.curSlide_; |
344 | this.curSlide_--; | 359 | this.curSlide_--; |
@@ -352,15 +367,22 @@ SlideDeck.prototype.prevSlide = function(opt_dontPush) { | |||
352 | */ | 367 | */ |
353 | SlideDeck.prototype.nextSlide = function(opt_dontPush) { | 368 | SlideDeck.prototype.nextSlide = function(opt_dontPush) { |
354 | 369 | ||
370 | if (this.controller_) { | ||
371 | this.controller_.sendMsg({slideDirection: SlideController.MOVE_RIGHT}); | ||
372 | } | ||
373 | |||
355 | if (this.buildNextItem_()) { | 374 | if (this.buildNextItem_()) { |
356 | return; | 375 | return; |
357 | } | 376 | } |
358 | 377 | ||
359 | if (this.curSlide_ < this.slides_.length - 1) { | 378 | if (this.curSlide_ < this.slides_.length - 1) { |
360 | // Toggle off speaker notes and/or highlighted code if they're showing. | 379 | // Toggle off speaker notes and/or highlighted code if they're showing |
361 | var bodyClassList = document.body.classList; | 380 | // when we advanced. If we're the speaker notes popup, leave this put. |
362 | bodyClassList.remove('with-notes'); | 381 | if (this.controller_ && !window.opener) { |
363 | bodyClassList.remove('highlight-code'); | 382 | var bodyClassList = document.body.classList; |
383 | bodyClassList.remove('with-notes'); | ||
384 | bodyClassList.remove('highlight-code'); | ||
385 | } | ||
364 | 386 | ||
365 | this.prevSlide_ = this.curSlide_; | 387 | this.prevSlide_ = this.curSlide_; |
366 | this.curSlide_++; | 388 | this.curSlide_++; |