init.js
4.23 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
* ADOBE CONFIDENTIAL
*
* Copyright 2015 Adobe Systems Incorporated
* All Rights Reserved.
*
* NOTICE: All information contained herein is, and remains
* the property of Adobe Systems Incorporated and its suppliers,
* if any. The intellectual and technical concepts contained
* herein are proprietary to Adobe Systems Incorporated and its
* suppliers and may be covered by U.S. and Foreign Patents,
* patents in process, and are protected by trade secret or copyright law.
* Dissemination of this information or reproduction of this material
* is strictly forbidden unless prior written permission is obtained
* from Adobe Systems Incorporated.
*/
/* globals require */
(function($) {
'use strict';
var SEQUENCE_ITEMS_SELECTOR = '[data-strategy]';
window.ScreensPlayer = window.ScreensPlayer || {
strategies: {},
transitions: {}
};
/**
* Initialize the sequences
*
* @param {WindowIO} wio The window.io object
* @param {boolean} immediateStart true to start the sequence immediately
* @returns {Function} a function for the array iterator
*/
function initSequence(wio, immediateStart) {
return function(i, el) {
var newSequence = new window.ScreensPlayer.Sequence(wio, el);
wio.on('channel-show', function(payload, origin) {
console.log('[Sequence#init] Reveiced channel-show for origin ' + origin);
if (origin === 'single') { // message from firmware
newSequence.start();
}
});
wio.on('channel-hide', function(payload, origin) {
console.log('[Sequence#init] Reveiced channel-hide for origin ' + origin);
if (origin === 'single') { // message from firmware
newSequence.stop();
}
});
if (immediateStart) {
newSequence.start();
}
};
}
if (window === window.top) {
require(['window.io'], function(WindowIO) {
$(document).ready(function() {
// only autostart the sequence in the authoring case (no orchestrator that triggers the plaback)
$(SEQUENCE_ITEMS_SELECTOR).each(initSequence(new WindowIO(), true));
});
});
return;
}
// The firmware is supposed to start the sequence
// with a channel-start event through Window.IO.
// In preview mode we will need to cover the following cases with autostart
// * Preview in editor
// * Preview of the channel
// * Preview of the display
// * Preview of the device
require(['util/ScreensDisplay', 'window.io'], function(ScreensDisplay, WindowIO) {
var wio = ScreensDisplay.getWindowIO();
// To start the preview in editor
// we check if the channel is loaded in the editor
var isInAuthoring = false;
try {
isInAuthoring = !!(window.parent !== window && window.parent.Granite && window.parent.Granite.author && window.parent.Granite.author.layerManager);
}
catch (securityException) {
// If a security exception happens, the parent window is on a different domain / protocol, this is most likely not the authoring mode.
}
if (!wio) { // is not executed in firmware
wio = new WindowIO();
}
if (Object.values(wio.targetWindows).indexOf(window.parent) === -1 || wio.targetWindows.single === window.parent) {
// Post message to parent window only if current sequence is a subsequence.
// Root sequence does need to post to parent firmware twice (already in wio)
// Chrome case: window might already be there as single if WindowIO is mapped to top channel frame (second part of the test)
wio.addWindow('parentSequence', window.parent);
}
$(document).ready(function() {
// only autostart the sequence in the authoring case (no orchestrator that triggers the plaback)
$(SEQUENCE_ITEMS_SELECTOR).each(initSequence(wio, isInAuthoring));
// to be sure the channel has not missed any event
wio.postMessage('channel-status-ready');
});
});
}(window.jQuery));