aboutsummaryrefslogtreecommitdiff
path: root/js/slide-controller.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/slide-controller.js')
-rw-r--r--js/slide-controller.js41
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
3var ORIGIN = location.protocol + '//' + location.host;
4
1function SlideController(slideDeck) { 5function 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;
21SlideController.prototype.onMessage_ = function(e) { 25SlideController.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
44SlideController.prototype.sendMsg = function(msg) { 49SlideController.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
62window.SlideController = SlideController;
63
64})(window);
65