diff options
author | Eric Bidelman | 2012-04-18 01:01:02 -0700 |
---|---|---|
committer | Eric Bidelman | 2012-04-18 01:01:02 -0700 |
commit | 6ca44eaadf9787260a87be1baabcd9bc9a306afd (patch) | |
tree | a7ae7f18a0acb764b68cf0bb978a727dbe922b5e /js/slide-controller.js | |
parent | 64c8d6328a9d0e4fe68a5899e3e8710342f3b7dd (diff) | |
download | io-slides-remote-6ca44eaadf9787260a87be1baabcd9bc9a306afd.tar.gz |
More presenter mode. Working now
Diffstat (limited to 'js/slide-controller.js')
-rw-r--r-- | js/slide-controller.js | 41 |
1 files changed, 26 insertions, 15 deletions
diff --git a/js/slide-controller.js b/js/slide-controller.js index e2f8bf2..bdbb670 100644 --- a/js/slide-controller.js +++ b/js/slide-controller.js | |||
@@ -1,3 +1,7 @@ | |||
1 | (function(window) { | ||
2 | |||
3 | var ORIGIN = location.protocol + '//' + location.host; | ||
4 | |||
1 | function SlideController(slideDeck) { | 5 | function SlideController(slideDeck) { |
2 | this.deck_ = slideDeck; | 6 | this.deck_ = slideDeck; |
3 | this.win_ = null; | 7 | this.win_ = null; |
@@ -21,34 +25,41 @@ SlideController.MOVE_RIGHT = 1; | |||
21 | SlideController.prototype.onMessage_ = function(e) { | 25 | SlideController.prototype.onMessage_ = function(e) { |
22 | var data = e.data; | 26 | var data = e.data; |
23 | 27 | ||
24 | // It would be dope if FF implemented location.origin. | 28 | // Restrict messages to being from this origin. Allow local developmet |
25 | if (e.origin != location.protocol + '//' + location.host) { | 29 | // from file:// though. |
30 | // TODO: It would be dope if FF implemented location.origin! | ||
31 | if (e.origin != ORIGIN && ORIGIN != 'file://') { | ||
26 | alert('Someone tried to postMessage from an unknown origin'); | 32 | alert('Someone tried to postMessage from an unknown origin'); |
27 | return; | 33 | return; |
28 | } | 34 | } |
29 | 35 | ||
30 | if (e.source.location.hostname != 'localhost') { | 36 | // if (e.source.location.hostname != 'localhost') { |
31 | alert('Someone tried to postMessage from an unknown origin'); | 37 | // alert('Someone tried to postMessage from an unknown origin'); |
32 | return; | 38 | // return; |
33 | } | 39 | // } |
34 | 40 | ||
35 | if ('slideDirection' in data) { | 41 | if ('keyCode' in data) { |
36 | if (data.slideDirection == SlideController.MOVE_LEFT) { | 42 | var evt = document.createEvent('Event'); |
37 | this.deck_.prevSlide(); | 43 | evt.initEvent('keydown', true, true); |
38 | } else { | 44 | evt.keyCode = data.keyCode; |
39 | this.deck_.nextSlide(); | 45 | document.dispatchEvent(evt); |
40 | } | ||
41 | } | 46 | } |
42 | }; | 47 | }; |
43 | 48 | ||
44 | SlideController.prototype.sendMsg = function(msg) { | 49 | SlideController.prototype.sendMsg = function(msg) { |
45 | // // Send message to popup window. | 50 | // // Send message to popup window. |
46 | // if (this.win_) { | 51 | // if (this.win_) { |
47 | // this.win_.postMessage(msg, location.protocol + '//' + location.host); | 52 | // this.win_.postMessage(msg, ORIGIN); |
48 | // } | 53 | // } |
54 | |||
49 | // Send message to main window. | 55 | // Send message to main window. |
50 | if (window.opener) { | 56 | if (window.opener) { |
51 | // It would be dope if FF implemented location.origin. | 57 | // TODO: It would be dope if FF implemented location.origin. |
52 | window.opener.postMessage(msg, location.protocol + '//' + location.host); | 58 | window.opener.postMessage(msg, '*'); |
53 | } | 59 | } |
54 | }; | 60 | }; |
61 | |||
62 | window.SlideController = SlideController; | ||
63 | |||
64 | })(window); | ||
65 | |||