blob: e2f8bf273ffad43ddfb96363c671cb11e6bdcf78 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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);
}
};
|