aboutsummaryrefslogtreecommitdiff
path: root/js/slide-controller.js
diff options
context:
space:
mode:
authorEric Bidelman2012-04-17 18:59:07 -0700
committerEric Bidelman2012-04-17 18:59:07 -0700
commit64c8d6328a9d0e4fe68a5899e3e8710342f3b7dd (patch)
treecc30183c85cbdadac0607b4c370f94e981708564 /js/slide-controller.js
parent5a15dcab5fd3bf90915f811bc7072f6ef8c34a07 (diff)
downloadio-slides-remote-64c8d6328a9d0e4fe68a5899e3e8710342f3b7dd.tar.gz
Basic presenter mode working
Diffstat (limited to 'js/slide-controller.js')
-rw-r--r--js/slide-controller.js54
1 files changed, 54 insertions, 0 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 @@
1function 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
18SlideController.MOVE_LEFT = -1;
19SlideController.MOVE_RIGHT = 1;
20
21SlideController.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
44SlideController.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};