From 64c8d6328a9d0e4fe68a5899e3e8710342f3b7dd Mon Sep 17 00:00:00 2001 From: Eric Bidelman Date: Tue, 17 Apr 2012 18:59:07 -0700 Subject: Basic presenter mode working --- js/slide-controller.js | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 js/slide-controller.js (limited to 'js/slide-controller.js') 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 @@ +function SlideController(slideDeck) { + this.deck_ = slideDeck; + this.win_ = null; + + window.addEventListener('message', this.onMessage_.bind(this), false); + + // Close popups if we reload the main window. + window.addEventListener('beforeunload', function(e) { + this.win_.close() + }.bind(this), false); + + // Only open one new popup. The recursion popup opening! + if (!window.opener) { + this.win_ = window.open(location.href, 'mywindow'); + } +} + +SlideController.MOVE_LEFT = -1; +SlideController.MOVE_RIGHT = 1; + +SlideController.prototype.onMessage_ = function(e) { + var data = e.data; + + // It would be dope if FF implemented location.origin. + if (e.origin != location.protocol + '//' + location.host) { + alert('Someone tried to postMessage from an unknown origin'); + return; + } + + if (e.source.location.hostname != 'localhost') { + alert('Someone tried to postMessage from an unknown origin'); + return; + } + + if ('slideDirection' in data) { + if (data.slideDirection == SlideController.MOVE_LEFT) { + this.deck_.prevSlide(); + } else { + this.deck_.nextSlide(); + } + } +}; + +SlideController.prototype.sendMsg = function(msg) { + // // Send message to popup window. + // if (this.win_) { + // this.win_.postMessage(msg, location.protocol + '//' + location.host); + // } + // Send message to main window. + if (window.opener) { + // It would be dope if FF implemented location.origin. + window.opener.postMessage(msg, location.protocol + '//' + location.host); + } +}; -- cgit v1.2.3