@xibosignage/xibo-layout-renderer 1.0.1 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/Modules/ActionController/ActionController.d.ts +32 -0
- package/dist/src/Modules/ActionController/index.d.ts +1 -0
- package/dist/src/Modules/Generators/Generators.d.ts +4 -0
- package/dist/src/Types/Layout/Layout.types.d.ts +7 -2
- package/dist/src/Types/Region/Region.types.d.ts +3 -1
- package/dist/styles.css +106 -1
- package/dist/xibo-layout-renderer.cjs.js +428 -7
- package/dist/xibo-layout-renderer.cjs.js.map +1 -1
- package/dist/xibo-layout-renderer.d.ts +40 -3
- package/dist/xibo-layout-renderer.esm.js +428 -7
- package/dist/xibo-layout-renderer.esm.js.map +1 -1
- package/dist/xibo-layout-renderer.js +428 -7
- package/dist/xibo-layout-renderer.min.js +1 -1
- package/dist/xibo-layout-renderer.min.js.map +1 -1
- package/package.json +1 -1
|
@@ -77,9 +77,10 @@ interface IRegion {
|
|
|
77
77
|
layout: ILayout;
|
|
78
78
|
id: string;
|
|
79
79
|
regionId: string;
|
|
80
|
+
uniqueId: string;
|
|
80
81
|
xml: null | Element;
|
|
81
82
|
mediaObjects: IMedia[];
|
|
82
|
-
mediaObjectsActions:
|
|
83
|
+
mediaObjectsActions: IMedia[];
|
|
83
84
|
currentMedia: number;
|
|
84
85
|
complete: boolean;
|
|
85
86
|
containerName: string;
|
|
@@ -104,6 +105,7 @@ interface IRegion {
|
|
|
104
105
|
emitter?: Emitter<DefaultEvents>;
|
|
105
106
|
prepareRegion(): void;
|
|
106
107
|
playNextMedia(): void;
|
|
108
|
+
playPreviousMedia(): void;
|
|
107
109
|
transitionNodes(oldMedia: IMedia | undefined, newMedia: IMedia | undefined): void;
|
|
108
110
|
finished(): void;
|
|
109
111
|
run(): void;
|
|
@@ -121,6 +123,37 @@ interface ILayoutEvents {
|
|
|
121
123
|
end: (layout: ILayout) => void;
|
|
122
124
|
}
|
|
123
125
|
|
|
126
|
+
declare class Action {
|
|
127
|
+
readonly id: string;
|
|
128
|
+
readonly xml: Element;
|
|
129
|
+
constructor(id: string, xml: Element);
|
|
130
|
+
}
|
|
131
|
+
declare class ActionsWrapper extends HTMLDivElement {
|
|
132
|
+
constructor();
|
|
133
|
+
}
|
|
134
|
+
type InactOptions = {
|
|
135
|
+
[k: string]: any;
|
|
136
|
+
} & OptionsType['previewTranslations'];
|
|
137
|
+
declare class ActionController {
|
|
138
|
+
readonly parent: ILayout;
|
|
139
|
+
readonly actions: Action[];
|
|
140
|
+
readonly options: InactOptions;
|
|
141
|
+
readonly $actionController: ActionsWrapper;
|
|
142
|
+
readonly $actionListContainer: Element | null;
|
|
143
|
+
translations: any;
|
|
144
|
+
constructor(parent: ILayout, actions: Action[], options: InactOptions);
|
|
145
|
+
init(): void;
|
|
146
|
+
openLayoutInNewTab(layoutCode: string, options: InactOptions): void;
|
|
147
|
+
/** Change media in region (next/previous) */
|
|
148
|
+
nextMediaInRegion(regionId: string, actionType: string): void;
|
|
149
|
+
loadMediaInRegion(regionId: string, widgetId: string): void;
|
|
150
|
+
/** Run action based on action data */
|
|
151
|
+
runAction(actionData: {
|
|
152
|
+
[k: string]: any;
|
|
153
|
+
}, options: InactOptions): void;
|
|
154
|
+
initTouchActions(): void;
|
|
155
|
+
}
|
|
156
|
+
|
|
124
157
|
type InputLayoutType = {
|
|
125
158
|
layoutId: number | null;
|
|
126
159
|
path?: string;
|
|
@@ -142,6 +175,9 @@ type OptionsType = {
|
|
|
142
175
|
cmsKey: string | null;
|
|
143
176
|
hardwareKey: string | null;
|
|
144
177
|
};
|
|
178
|
+
previewTranslations?: {
|
|
179
|
+
[k: string]: any;
|
|
180
|
+
};
|
|
145
181
|
};
|
|
146
182
|
interface ILayout {
|
|
147
183
|
id: number | null;
|
|
@@ -164,10 +200,10 @@ interface ILayout {
|
|
|
164
200
|
regionMaxZIndex: number;
|
|
165
201
|
ready: boolean;
|
|
166
202
|
regionObjects: IRegion[];
|
|
167
|
-
drawer:
|
|
203
|
+
drawer: Element | null;
|
|
168
204
|
allExpired: boolean;
|
|
169
205
|
regions: IRegion[];
|
|
170
|
-
actions:
|
|
206
|
+
actions: Action[];
|
|
171
207
|
options: OptionsType;
|
|
172
208
|
done: boolean;
|
|
173
209
|
allEnded: boolean;
|
|
@@ -183,6 +219,7 @@ interface ILayout {
|
|
|
183
219
|
stopAllMedia(): Promise<void>;
|
|
184
220
|
resetLayout(): Promise<void>;
|
|
185
221
|
index: number;
|
|
222
|
+
actionController: ActionController | undefined;
|
|
186
223
|
}
|
|
187
224
|
declare const initialLayout: ILayout;
|
|
188
225
|
type GetLayoutParamType = {
|
|
@@ -1,3 +1,21 @@
|
|
|
1
|
+
function _callSuper(t, o, e) {
|
|
2
|
+
return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, [], _getPrototypeOf(t).constructor) : o.apply(t, e));
|
|
3
|
+
}
|
|
4
|
+
function _construct(t, e, r) {
|
|
5
|
+
if (_isNativeReflectConstruct()) return Reflect.construct.apply(null, arguments);
|
|
6
|
+
var o = [null];
|
|
7
|
+
o.push.apply(o, e);
|
|
8
|
+
var p = new (t.bind.apply(t, o))();
|
|
9
|
+
return r && _setPrototypeOf(p, r.prototype), p;
|
|
10
|
+
}
|
|
11
|
+
function _isNativeReflectConstruct() {
|
|
12
|
+
try {
|
|
13
|
+
var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
|
|
14
|
+
} catch (t) {}
|
|
15
|
+
return (_isNativeReflectConstruct = function () {
|
|
16
|
+
return !!t;
|
|
17
|
+
})();
|
|
18
|
+
}
|
|
1
19
|
function ownKeys(e, r) {
|
|
2
20
|
var t = Object.keys(e);
|
|
3
21
|
if (Object.getOwnPropertySymbols) {
|
|
@@ -364,6 +382,27 @@ function _asyncToGenerator(fn) {
|
|
|
364
382
|
});
|
|
365
383
|
};
|
|
366
384
|
}
|
|
385
|
+
function _classCallCheck(instance, Constructor) {
|
|
386
|
+
if (!(instance instanceof Constructor)) {
|
|
387
|
+
throw new TypeError("Cannot call a class as a function");
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
function _defineProperties(target, props) {
|
|
391
|
+
for (var i = 0; i < props.length; i++) {
|
|
392
|
+
var descriptor = props[i];
|
|
393
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
394
|
+
descriptor.configurable = true;
|
|
395
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
396
|
+
Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
function _createClass(Constructor, protoProps, staticProps) {
|
|
400
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
401
|
+
Object.defineProperty(Constructor, "prototype", {
|
|
402
|
+
writable: false
|
|
403
|
+
});
|
|
404
|
+
return Constructor;
|
|
405
|
+
}
|
|
367
406
|
function _defineProperty(obj, key, value) {
|
|
368
407
|
key = _toPropertyKey(key);
|
|
369
408
|
if (key in obj) {
|
|
@@ -378,6 +417,82 @@ function _defineProperty(obj, key, value) {
|
|
|
378
417
|
}
|
|
379
418
|
return obj;
|
|
380
419
|
}
|
|
420
|
+
function _inherits(subClass, superClass) {
|
|
421
|
+
if (typeof superClass !== "function" && superClass !== null) {
|
|
422
|
+
throw new TypeError("Super expression must either be null or a function");
|
|
423
|
+
}
|
|
424
|
+
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
|
425
|
+
constructor: {
|
|
426
|
+
value: subClass,
|
|
427
|
+
writable: true,
|
|
428
|
+
configurable: true
|
|
429
|
+
}
|
|
430
|
+
});
|
|
431
|
+
Object.defineProperty(subClass, "prototype", {
|
|
432
|
+
writable: false
|
|
433
|
+
});
|
|
434
|
+
if (superClass) _setPrototypeOf(subClass, superClass);
|
|
435
|
+
}
|
|
436
|
+
function _getPrototypeOf(o) {
|
|
437
|
+
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) {
|
|
438
|
+
return o.__proto__ || Object.getPrototypeOf(o);
|
|
439
|
+
};
|
|
440
|
+
return _getPrototypeOf(o);
|
|
441
|
+
}
|
|
442
|
+
function _setPrototypeOf(o, p) {
|
|
443
|
+
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
|
|
444
|
+
o.__proto__ = p;
|
|
445
|
+
return o;
|
|
446
|
+
};
|
|
447
|
+
return _setPrototypeOf(o, p);
|
|
448
|
+
}
|
|
449
|
+
function _isNativeFunction(fn) {
|
|
450
|
+
try {
|
|
451
|
+
return Function.toString.call(fn).indexOf("[native code]") !== -1;
|
|
452
|
+
} catch (e) {
|
|
453
|
+
return typeof fn === "function";
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
function _wrapNativeSuper(Class) {
|
|
457
|
+
var _cache = typeof Map === "function" ? new Map() : undefined;
|
|
458
|
+
_wrapNativeSuper = function _wrapNativeSuper(Class) {
|
|
459
|
+
if (Class === null || !_isNativeFunction(Class)) return Class;
|
|
460
|
+
if (typeof Class !== "function") {
|
|
461
|
+
throw new TypeError("Super expression must either be null or a function");
|
|
462
|
+
}
|
|
463
|
+
if (typeof _cache !== "undefined") {
|
|
464
|
+
if (_cache.has(Class)) return _cache.get(Class);
|
|
465
|
+
_cache.set(Class, Wrapper);
|
|
466
|
+
}
|
|
467
|
+
function Wrapper() {
|
|
468
|
+
return _construct(Class, arguments, _getPrototypeOf(this).constructor);
|
|
469
|
+
}
|
|
470
|
+
Wrapper.prototype = Object.create(Class.prototype, {
|
|
471
|
+
constructor: {
|
|
472
|
+
value: Wrapper,
|
|
473
|
+
enumerable: false,
|
|
474
|
+
writable: true,
|
|
475
|
+
configurable: true
|
|
476
|
+
}
|
|
477
|
+
});
|
|
478
|
+
return _setPrototypeOf(Wrapper, Class);
|
|
479
|
+
};
|
|
480
|
+
return _wrapNativeSuper(Class);
|
|
481
|
+
}
|
|
482
|
+
function _assertThisInitialized(self) {
|
|
483
|
+
if (self === void 0) {
|
|
484
|
+
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
485
|
+
}
|
|
486
|
+
return self;
|
|
487
|
+
}
|
|
488
|
+
function _possibleConstructorReturn(self, call) {
|
|
489
|
+
if (call && (typeof call === "object" || typeof call === "function")) {
|
|
490
|
+
return call;
|
|
491
|
+
} else if (call !== void 0) {
|
|
492
|
+
throw new TypeError("Derived constructors may only return object or undefined");
|
|
493
|
+
}
|
|
494
|
+
return _assertThisInitialized(self);
|
|
495
|
+
}
|
|
381
496
|
function _toConsumableArray(arr) {
|
|
382
497
|
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
|
|
383
498
|
}
|
|
@@ -520,7 +635,7 @@ var initialLayout = {
|
|
|
520
635
|
regionMaxZIndex: 0,
|
|
521
636
|
ready: false,
|
|
522
637
|
regionObjects: [],
|
|
523
|
-
drawer:
|
|
638
|
+
drawer: null,
|
|
524
639
|
allExpired: false,
|
|
525
640
|
regions: [],
|
|
526
641
|
actions: [],
|
|
@@ -544,7 +659,8 @@ var initialLayout = {
|
|
|
544
659
|
return Promise.resolve();
|
|
545
660
|
},
|
|
546
661
|
emitter: {},
|
|
547
|
-
index: -1
|
|
662
|
+
index: -1,
|
|
663
|
+
actionController: undefined
|
|
548
664
|
};
|
|
549
665
|
|
|
550
666
|
function nextId(options) {
|
|
@@ -712,6 +828,9 @@ function composeResourceUrl(options, params) {
|
|
|
712
828
|
var serverKey = options && ((_options$config3 = options.config) === null || _options$config3 === void 0 ? void 0 : _options$config3.cmsKey);
|
|
713
829
|
return '/pwa/getResource' + '?v=' + schemaVersion + '&serverKey=' + serverKey + '&hardwareKey=' + hardwareKey + '&layoutId=' + params.layoutId + '®ionId=' + params.regionId + '&mediaId=' + params.mediaId;
|
|
714
830
|
}
|
|
831
|
+
function composeVideoUrl(params) {
|
|
832
|
+
return '/xmds.php?file=' + params.uri;
|
|
833
|
+
}
|
|
715
834
|
function composeBgUrlByPlatform(platform, params) {
|
|
716
835
|
var bgImageUrl = params.layoutBackgroundDownloadUrl.replace(":id", params.layout.id) + '?preview=1&width=' + params.layout.sWidth + '&height=' + params.layout.sHeight + '&dynamic&proportional=0';
|
|
717
836
|
if (platform === 'chromeOS') {
|
|
@@ -737,11 +856,22 @@ function getIndexByLayoutId(layoutsInput, layoutId) {
|
|
|
737
856
|
index: 0
|
|
738
857
|
};
|
|
739
858
|
}
|
|
859
|
+
function getAllAttributes(elem) {
|
|
860
|
+
if (!elem || elem === null) {
|
|
861
|
+
return {};
|
|
862
|
+
}
|
|
863
|
+
return elem.getAttributeNames().reduce(function (obj, name) {
|
|
864
|
+
return _objectSpread2(_objectSpread2({}, obj), {}, _defineProperty({}, name, {
|
|
865
|
+
value: elem.getAttribute(name)
|
|
866
|
+
}));
|
|
867
|
+
}, {});
|
|
868
|
+
}
|
|
740
869
|
|
|
741
870
|
var initialRegion = {
|
|
742
871
|
layout: initialLayout,
|
|
743
872
|
id: '',
|
|
744
873
|
regionId: '',
|
|
874
|
+
uniqueId: '',
|
|
745
875
|
xml: null,
|
|
746
876
|
mediaObjects: [],
|
|
747
877
|
mediaObjectsActions: [],
|
|
@@ -766,6 +896,7 @@ var initialRegion = {
|
|
|
766
896
|
index: -1,
|
|
767
897
|
prepareRegion: function prepareRegion() {},
|
|
768
898
|
playNextMedia: function playNextMedia() {},
|
|
899
|
+
playPreviousMedia: function playPreviousMedia() {},
|
|
769
900
|
transitionNodes: function transitionNodes() {},
|
|
770
901
|
finished: function finished() {},
|
|
771
902
|
run: function run() {},
|
|
@@ -1285,6 +1416,9 @@ function Media(region, mediaId, xml, options, xlr) {
|
|
|
1285
1416
|
tmpUrl = composeResourceUrlByPlatform(xlr.config, resourceUrlParams);
|
|
1286
1417
|
} else if (xlr.config.platform === 'chromeOS') {
|
|
1287
1418
|
tmpUrl = composeResourceUrl(xlr.config, resourceUrlParams);
|
|
1419
|
+
if (self.mediaType === 'video') {
|
|
1420
|
+
tmpUrl = composeVideoUrl(resourceUrlParams);
|
|
1421
|
+
}
|
|
1288
1422
|
}
|
|
1289
1423
|
self.url = tmpUrl;
|
|
1290
1424
|
// Loop if media has loop, or if region has loop and a single media
|
|
@@ -1596,7 +1730,7 @@ function Region(layout, xml, regionId, options, xlr) {
|
|
|
1596
1730
|
var emitter = createNanoEvents();
|
|
1597
1731
|
var regionObject = _objectSpread2(_objectSpread2({}, initialRegion), props);
|
|
1598
1732
|
regionObject.prepareRegion = function () {
|
|
1599
|
-
var _self$xml, _self$xml2, _self$xml3, _self$xml4, _self$xml5, _self$xml6;
|
|
1733
|
+
var _self$xml, _self$xml2, _self$xml3, _self$xml4, _self$xml5, _self$xml6, _self$layout$actionCo;
|
|
1600
1734
|
var self = regionObject;
|
|
1601
1735
|
var layout = self.layout,
|
|
1602
1736
|
options = self.options;
|
|
@@ -1604,8 +1738,9 @@ function Region(layout, xml, regionId, options, xlr) {
|
|
|
1604
1738
|
self.ending = false;
|
|
1605
1739
|
self.ended = false;
|
|
1606
1740
|
self.id = props.regionId;
|
|
1741
|
+
self.uniqueId = "".concat(nextId(self.options));
|
|
1607
1742
|
self.options = _objectSpread2(_objectSpread2({}, platform), props.options);
|
|
1608
|
-
self.containerName = "R-".concat(self.id, "-").concat(
|
|
1743
|
+
self.containerName = "R-".concat(self.id, "-").concat(self.uniqueId);
|
|
1609
1744
|
self.xml = props.xml;
|
|
1610
1745
|
self.mediaObjects = [];
|
|
1611
1746
|
self.sWidth = self.xml && Number((_self$xml = self.xml) === null || _self$xml === void 0 ? void 0 : _self$xml.getAttribute('width')) * layout.scaleFactor;
|
|
@@ -1644,6 +1779,20 @@ function Region(layout, xml, regionId, options, xlr) {
|
|
|
1644
1779
|
mediaObj.index = indx;
|
|
1645
1780
|
self.mediaObjects.push(mediaObj);
|
|
1646
1781
|
});
|
|
1782
|
+
// Add media to region for targetted actions
|
|
1783
|
+
(_self$layout$actionCo = self.layout.actionController) === null || _self$layout$actionCo === void 0 || _self$layout$actionCo.actions.forEach(function (action) {
|
|
1784
|
+
var attributes = getAllAttributes(action.xml);
|
|
1785
|
+
if (attributes.target.value === 'region' && attributes.actionType.value === 'navWidget' && attributes.targetId.value == self.id) {
|
|
1786
|
+
var _self$layout$drawer;
|
|
1787
|
+
var drawerMediaItems = Array.from(((_self$layout$drawer = self.layout.drawer) === null || _self$layout$drawer === void 0 ? void 0 : _self$layout$drawer.getElementsByTagName('media')) || []);
|
|
1788
|
+
drawerMediaItems.forEach(function (drawerMedia) {
|
|
1789
|
+
if (drawerMedia.id === attributes.widgetId.value) {
|
|
1790
|
+
// Add drawer media to the region
|
|
1791
|
+
self.mediaObjectsActions.push(Media(self, (drawerMedia === null || drawerMedia === void 0 ? void 0 : drawerMedia.getAttribute('id')) || '', drawerMedia, options, xlr));
|
|
1792
|
+
}
|
|
1793
|
+
});
|
|
1794
|
+
}
|
|
1795
|
+
});
|
|
1647
1796
|
self.prepareMediaObjects();
|
|
1648
1797
|
};
|
|
1649
1798
|
regionObject.finished = function () {
|
|
@@ -1801,6 +1950,18 @@ function Region(layout, xml, regionId, options, xlr) {
|
|
|
1801
1950
|
console.debug('region::playNextMedia', self);
|
|
1802
1951
|
self.transitionNodes(self.oldMedia, self.curMedia);
|
|
1803
1952
|
};
|
|
1953
|
+
regionObject.playPreviousMedia = function () {
|
|
1954
|
+
var self = regionObject;
|
|
1955
|
+
self.currentMediaIndex = self.currentMediaIndex - 1;
|
|
1956
|
+
if (self.currentMediaIndex < 0 || self.ended) {
|
|
1957
|
+
self.currentMediaIndex = 0;
|
|
1958
|
+
return;
|
|
1959
|
+
}
|
|
1960
|
+
self.prepareMediaObjects();
|
|
1961
|
+
console.debug('region::playPreviousMedia', self);
|
|
1962
|
+
/* Do the transition */
|
|
1963
|
+
self.transitionNodes(self.oldMedia, self.curMedia);
|
|
1964
|
+
};
|
|
1804
1965
|
regionObject.end = function () {
|
|
1805
1966
|
var self = regionObject;
|
|
1806
1967
|
self.ending = true;
|
|
@@ -1841,6 +2002,251 @@ function Region(layout, xml, regionId, options, xlr) {
|
|
|
1841
2002
|
return regionObject;
|
|
1842
2003
|
}
|
|
1843
2004
|
|
|
2005
|
+
var Action = /*#__PURE__*/_createClass(function Action(id, xml) {
|
|
2006
|
+
_classCallCheck(this, Action);
|
|
2007
|
+
_defineProperty(this, "id", void 0);
|
|
2008
|
+
_defineProperty(this, "xml", void 0);
|
|
2009
|
+
this.id = id;
|
|
2010
|
+
this.xml = xml;
|
|
2011
|
+
});
|
|
2012
|
+
var ActionsWrapper = /*#__PURE__*/function (_HTMLDivElement) {
|
|
2013
|
+
function ActionsWrapper() {
|
|
2014
|
+
var _this;
|
|
2015
|
+
_classCallCheck(this, ActionsWrapper);
|
|
2016
|
+
_this = _callSuper(this, ActionsWrapper);
|
|
2017
|
+
_this.classList.add('action-controller', 'noselect');
|
|
2018
|
+
return _this;
|
|
2019
|
+
}
|
|
2020
|
+
_inherits(ActionsWrapper, _HTMLDivElement);
|
|
2021
|
+
return _createClass(ActionsWrapper);
|
|
2022
|
+
}( /*#__PURE__*/_wrapNativeSuper(HTMLDivElement));
|
|
2023
|
+
customElements.define('action-controller', ActionsWrapper, {
|
|
2024
|
+
"extends": 'div'
|
|
2025
|
+
});
|
|
2026
|
+
var ActionController = /*#__PURE__*/function () {
|
|
2027
|
+
function ActionController(parent, actions, options) {
|
|
2028
|
+
_classCallCheck(this, ActionController);
|
|
2029
|
+
_defineProperty(this, "parent", void 0);
|
|
2030
|
+
_defineProperty(this, "actions", void 0);
|
|
2031
|
+
_defineProperty(this, "options", void 0);
|
|
2032
|
+
_defineProperty(this, "$actionController", void 0);
|
|
2033
|
+
_defineProperty(this, "$actionListContainer", void 0);
|
|
2034
|
+
_defineProperty(this, "translations", {});
|
|
2035
|
+
this.parent = parent;
|
|
2036
|
+
this.actions = actions;
|
|
2037
|
+
this.options = options;
|
|
2038
|
+
this.$actionController = document.createElement('div', {
|
|
2039
|
+
is: 'action-controller'
|
|
2040
|
+
});
|
|
2041
|
+
this.$actionListContainer = null;
|
|
2042
|
+
this.init();
|
|
2043
|
+
}
|
|
2044
|
+
return _createClass(ActionController, [{
|
|
2045
|
+
key: "init",
|
|
2046
|
+
value: function init() {
|
|
2047
|
+
var self = this;
|
|
2048
|
+
var previewTranslations = {};
|
|
2049
|
+
// get preview translations
|
|
2050
|
+
if ('previewTranslations' in window) {
|
|
2051
|
+
previewTranslations = window['previewTranslations'];
|
|
2052
|
+
self.translations = previewTranslations;
|
|
2053
|
+
}
|
|
2054
|
+
var $container = document.getElementById(this.parent.containerName);
|
|
2055
|
+
var $actionTitle = document.createElement('div');
|
|
2056
|
+
var $actionsContainer = document.createElement('div');
|
|
2057
|
+
$actionTitle.classList.add('action-controller-title');
|
|
2058
|
+
$actionTitle.innerHTML = "\n <button class=\"toggle\"></button>\n <span class=\"title\">".concat(previewTranslations.actionControllerTitle, "</span>\n ");
|
|
2059
|
+
$actionsContainer.classList.add('actions-container');
|
|
2060
|
+
if ($container) {
|
|
2061
|
+
$container.insertBefore(this.$actionController, $container.firstElementChild);
|
|
2062
|
+
this.$actionController.appendChild($actionTitle);
|
|
2063
|
+
this.$actionController.appendChild($actionsContainer);
|
|
2064
|
+
// Loop through actions
|
|
2065
|
+
Array.from(this.actions).forEach(function (newAction) {
|
|
2066
|
+
// Create new action object
|
|
2067
|
+
var $newAction = document.createElement('div');
|
|
2068
|
+
// Copy element attributes
|
|
2069
|
+
var attributes = getAllAttributes(newAction.xml);
|
|
2070
|
+
Array.from(Object.keys(attributes)).forEach(function (attribKey) {
|
|
2071
|
+
$newAction.setAttribute("data-".concat(attribKey), attributes[attribKey].value);
|
|
2072
|
+
$newAction.setAttribute(attribKey, attributes[attribKey].value);
|
|
2073
|
+
});
|
|
2074
|
+
// Build html for the new action
|
|
2075
|
+
var html = '';
|
|
2076
|
+
// Add action type
|
|
2077
|
+
html += '<span class="action-row-title">' + previewTranslations[$newAction.getAttribute('actiontype') || ''];
|
|
2078
|
+
if ($newAction.getAttribute('actiontype') == 'navWidget') {
|
|
2079
|
+
html += ' <span title="' + previewTranslations.widgetId + '">[' + $newAction.getAttribute('widgetid') + ']</span>';
|
|
2080
|
+
} else if ($newAction.getAttribute('actiontype') == 'navLayout') {
|
|
2081
|
+
html += ' <span title="' + previewTranslations.layoutCode + '">[' + $newAction.getAttribute('layoutcode') + ']</span>';
|
|
2082
|
+
}
|
|
2083
|
+
html += '</span>';
|
|
2084
|
+
// Add target
|
|
2085
|
+
html += '<span class="action-row-target" title="' + previewTranslations.target + '">' + $newAction.getAttribute('target');
|
|
2086
|
+
if ($newAction.getAttribute('targetid') != '') {
|
|
2087
|
+
html += '(' + $newAction.getAttribute('targetid') + $newAction.getAttribute('layoutcode') + ')';
|
|
2088
|
+
}
|
|
2089
|
+
html += '</span>';
|
|
2090
|
+
// Add HTML string to the action
|
|
2091
|
+
$newAction.innerHTML = html;
|
|
2092
|
+
// Append new action to the controller
|
|
2093
|
+
$newAction.classList.add('action');
|
|
2094
|
+
$newAction.setAttribute('originalid', newAction.id);
|
|
2095
|
+
$newAction.setAttribute('id', 'A-' + newAction.id + '-' + nextId(self.options));
|
|
2096
|
+
$actionsContainer.insertBefore($newAction, $actionsContainer.lastElementChild);
|
|
2097
|
+
});
|
|
2098
|
+
//
|
|
2099
|
+
// Enable dragging
|
|
2100
|
+
// const $draggableContainer = new Moveable($container, {
|
|
2101
|
+
// target: this.$actionController,
|
|
2102
|
+
// draggable: true,
|
|
2103
|
+
// });
|
|
2104
|
+
// Toggle actions visibility
|
|
2105
|
+
var $actionsToggler = this.$actionController.querySelector('.toggle');
|
|
2106
|
+
if ($actionsToggler) {
|
|
2107
|
+
$actionsToggler.onclick = function () {
|
|
2108
|
+
self.$actionController.classList.toggle('d-none');
|
|
2109
|
+
};
|
|
2110
|
+
}
|
|
2111
|
+
var $webhookActions = this.$actionController.querySelectorAll('.action[triggertype="webhook"]');
|
|
2112
|
+
// Display according to the number of clickable actions
|
|
2113
|
+
this.$actionController.style.setProperty('display', $webhookActions.length === 0 ? 'none' : 'flex');
|
|
2114
|
+
// Handle webhook action trigger click
|
|
2115
|
+
if ($webhookActions.length > 0) {
|
|
2116
|
+
$webhookActions.forEach(function ($webhookAction) {
|
|
2117
|
+
$webhookAction.onclick = function (event) {
|
|
2118
|
+
event.stopPropagation();
|
|
2119
|
+
self.runAction($webhookAction.dataset, self.options);
|
|
2120
|
+
};
|
|
2121
|
+
$webhookAction.classList.add('clickable');
|
|
2122
|
+
});
|
|
2123
|
+
}
|
|
2124
|
+
}
|
|
2125
|
+
}
|
|
2126
|
+
}, {
|
|
2127
|
+
key: "openLayoutInNewTab",
|
|
2128
|
+
value: function openLayoutInNewTab(layoutCode, options) {
|
|
2129
|
+
if (confirm(this.translations.navigateToLayout.replace('[layoutTag]', layoutCode))) {
|
|
2130
|
+
var url = options.layoutPreviewUrl.replace('[layoutCode]', layoutCode) + '?findByCode=1';
|
|
2131
|
+
window.open(url, '_blank');
|
|
2132
|
+
}
|
|
2133
|
+
}
|
|
2134
|
+
/** Change media in region (next/previous) */
|
|
2135
|
+
}, {
|
|
2136
|
+
key: "nextMediaInRegion",
|
|
2137
|
+
value: function nextMediaInRegion(regionId, actionType) {
|
|
2138
|
+
// Find target region
|
|
2139
|
+
this.parent.regions.forEach(function (regionObj) {
|
|
2140
|
+
if (regionObj.id === regionId) {
|
|
2141
|
+
if (actionType === 'next') {
|
|
2142
|
+
regionObj.playNextMedia();
|
|
2143
|
+
} else {
|
|
2144
|
+
regionObj.playPreviousMedia();
|
|
2145
|
+
}
|
|
2146
|
+
}
|
|
2147
|
+
});
|
|
2148
|
+
}
|
|
2149
|
+
}, {
|
|
2150
|
+
key: "loadMediaInRegion",
|
|
2151
|
+
value: function loadMediaInRegion(regionId, widgetId) {
|
|
2152
|
+
var _targetRegion, _targetRegion2, _targetRegion3;
|
|
2153
|
+
var self = this;
|
|
2154
|
+
// Find target region
|
|
2155
|
+
var targetRegion;
|
|
2156
|
+
self.parent.regions.forEach(function (regionObj) {
|
|
2157
|
+
if (regionObj.id === regionId) {
|
|
2158
|
+
targetRegion = regionObj;
|
|
2159
|
+
}
|
|
2160
|
+
});
|
|
2161
|
+
// Find media in actions
|
|
2162
|
+
var targetMedia;
|
|
2163
|
+
if (targetRegion) {
|
|
2164
|
+
targetRegion.mediaObjectsActions.forEach(function (media) {
|
|
2165
|
+
if (media.id === widgetId) {
|
|
2166
|
+
targetMedia = media;
|
|
2167
|
+
}
|
|
2168
|
+
});
|
|
2169
|
+
}
|
|
2170
|
+
// Mark media as temporary (removed after region stop playing or loops)
|
|
2171
|
+
if (targetMedia) {
|
|
2172
|
+
targetMedia.singlePlay = true;
|
|
2173
|
+
}
|
|
2174
|
+
// If region is empty, remove the background color and empty message
|
|
2175
|
+
if (((_targetRegion = targetRegion) === null || _targetRegion === void 0 ? void 0 : _targetRegion.mediaObjects.length) === 0) {
|
|
2176
|
+
targetRegion.complete = false;
|
|
2177
|
+
}
|
|
2178
|
+
// Create media in region and play it next
|
|
2179
|
+
(_targetRegion2 = targetRegion) === null || _targetRegion2 === void 0 || _targetRegion2.mediaObjects.splice(targetRegion.currentMediaIndex + 1, 0, targetMedia);
|
|
2180
|
+
(_targetRegion3 = targetRegion) === null || _targetRegion3 === void 0 || _targetRegion3.playNextMedia();
|
|
2181
|
+
}
|
|
2182
|
+
/** Run action based on action data */
|
|
2183
|
+
}, {
|
|
2184
|
+
key: "runAction",
|
|
2185
|
+
value: function runAction(actionData, options) {
|
|
2186
|
+
if (actionData.actiontype == 'navLayout') {
|
|
2187
|
+
// Open layout preview in a new tab
|
|
2188
|
+
this.openLayoutInNewTab(actionData.layoutcode, options);
|
|
2189
|
+
} else if ((actionData.actiontype == 'previous' || actionData.actiontype == 'next') && actionData.target == 'region') {
|
|
2190
|
+
this.nextMediaInRegion(actionData.targetid, actionData.actiontype);
|
|
2191
|
+
} else if (actionData.actiontype == 'navWidget' && actionData.target == 'region') {
|
|
2192
|
+
this.loadMediaInRegion(actionData.targetid, actionData.widgetid);
|
|
2193
|
+
} else {
|
|
2194
|
+
// TODO Handle other action types ( later? )
|
|
2195
|
+
console.log(actionData.actiontype + ' > ' + actionData.target + '[' + actionData.targetid + ']');
|
|
2196
|
+
}
|
|
2197
|
+
}
|
|
2198
|
+
}, {
|
|
2199
|
+
key: "initTouchActions",
|
|
2200
|
+
value: function initTouchActions() {
|
|
2201
|
+
var self = this;
|
|
2202
|
+
this.$actionController.querySelectorAll('.action[triggerType="touch"]').forEach(function ($el) {
|
|
2203
|
+
var dataset = $el.dataset;
|
|
2204
|
+
// Find source object
|
|
2205
|
+
var $sourceObj;
|
|
2206
|
+
if (dataset.source === 'layout') {
|
|
2207
|
+
$sourceObj = document.getElementById(self.parent.containerName);
|
|
2208
|
+
} else {
|
|
2209
|
+
var regionObjects = Array.from(self.parent.regions);
|
|
2210
|
+
// Loop through layout regions
|
|
2211
|
+
for (var _i = 0, _regionObjects = regionObjects; _i < _regionObjects.length; _i++) {
|
|
2212
|
+
var regionObj = _regionObjects[_i];
|
|
2213
|
+
if (dataset.source === 'region') {
|
|
2214
|
+
// Try to find the region
|
|
2215
|
+
if (regionObj.id === dataset.sourceid) {
|
|
2216
|
+
$sourceObj = document.getElementById(regionObj.containerName);
|
|
2217
|
+
break;
|
|
2218
|
+
}
|
|
2219
|
+
} else if (dataset.source === 'widget') {
|
|
2220
|
+
// Try to find widget/media
|
|
2221
|
+
var mediaObjects = Array.from(regionObj.mediaObjects);
|
|
2222
|
+
for (var _i2 = 0, _mediaObjects = mediaObjects; _i2 < _mediaObjects.length; _i2++) {
|
|
2223
|
+
var mediaObject = _mediaObjects[_i2];
|
|
2224
|
+
if (mediaObject.id === dataset.sourceid) {
|
|
2225
|
+
$sourceObj = document.getElementById(mediaObject.containerName);
|
|
2226
|
+
break;
|
|
2227
|
+
}
|
|
2228
|
+
}
|
|
2229
|
+
}
|
|
2230
|
+
// Break loop if we already have a $sourceObj
|
|
2231
|
+
if ($sourceObj != undefined) {
|
|
2232
|
+
break;
|
|
2233
|
+
}
|
|
2234
|
+
}
|
|
2235
|
+
}
|
|
2236
|
+
// Handle source click
|
|
2237
|
+
// FIXME: We need to handle the case where a drawer widget has an action and it has been loaded to the preview
|
|
2238
|
+
if ($sourceObj != undefined) {
|
|
2239
|
+
$sourceObj.onclick = function (ev) {
|
|
2240
|
+
ev.stopPropagation();
|
|
2241
|
+
self.runAction(dataset, self.options);
|
|
2242
|
+
};
|
|
2243
|
+
$sourceObj.classList.add('clickable');
|
|
2244
|
+
}
|
|
2245
|
+
});
|
|
2246
|
+
}
|
|
2247
|
+
}]);
|
|
2248
|
+
}();
|
|
2249
|
+
|
|
1844
2250
|
var playAgainClickHandle = function playAgainClickHandle(ev) {
|
|
1845
2251
|
ev.preventDefault();
|
|
1846
2252
|
history.go(0);
|
|
@@ -2052,7 +2458,7 @@ function Layout(data, options, xlr, layout) {
|
|
|
2052
2458
|
layoutObject.parseXlf();
|
|
2053
2459
|
};
|
|
2054
2460
|
layoutObject.parseXlf = function () {
|
|
2055
|
-
var _layout$layoutNode, _layout$layoutNode2, _layout$layoutNode3, _layout$layoutNode4, _layout$layoutNode5, _layout$layoutNode6;
|
|
2461
|
+
var _layout$layoutNode, _layout$layoutNode2, _layout$layoutNode3, _layout$layoutNode4, _layout$layoutNode5, _layout$layoutNode6, _layout$layoutNode7, _layout$layoutNode8;
|
|
2056
2462
|
var layout = this;
|
|
2057
2463
|
var options = layout.options;
|
|
2058
2464
|
layout.done = false;
|
|
@@ -2070,7 +2476,9 @@ function Layout(data, options, xlr, layout) {
|
|
|
2070
2476
|
$screen && $screen.appendChild($layout);
|
|
2071
2477
|
if ($layout) {
|
|
2072
2478
|
$layout.style.display = 'none';
|
|
2073
|
-
|
|
2479
|
+
if (xlr.config.platform === 'CMS') {
|
|
2480
|
+
$layout.style.outline = 'red solid thin';
|
|
2481
|
+
}
|
|
2074
2482
|
}
|
|
2075
2483
|
layout.layoutNode = props.data;
|
|
2076
2484
|
/* Calculate the screen size */
|
|
@@ -2120,13 +2528,26 @@ function Layout(data, options, xlr, layout) {
|
|
|
2120
2528
|
if ($layout && xlr.currentLayoutId !== undefined && xlr.currentLayoutId !== layout.id) {
|
|
2121
2529
|
$layout.style.display = 'none';
|
|
2122
2530
|
}
|
|
2531
|
+
// Create actions
|
|
2532
|
+
var layoutActions = Array.from((layout === null || layout === void 0 || (_layout$layoutNode6 = layout.layoutNode) === null || _layout$layoutNode6 === void 0 ? void 0 : _layout$layoutNode6.getElementsByTagName('action')) || []);
|
|
2533
|
+
Array.from(layoutActions).forEach(function (actionXml, indx) {
|
|
2534
|
+
layout.actions.push(new Action((actionXml === null || actionXml === void 0 ? void 0 : actionXml.getAttribute('id')) || '', actionXml));
|
|
2535
|
+
});
|
|
2536
|
+
// Create interactive actions
|
|
2537
|
+
layout.actionController = new ActionController(layout, layout.actions, options);
|
|
2538
|
+
// Create drawer
|
|
2539
|
+
var layoutDrawers = Array.from((layout === null || layout === void 0 || (_layout$layoutNode7 = layout.layoutNode) === null || _layout$layoutNode7 === void 0 ? void 0 : _layout$layoutNode7.getElementsByTagName('drawer')) || []);
|
|
2540
|
+
Array.from(layoutDrawers).forEach(function (layoutDrawerXml) {
|
|
2541
|
+
layout.drawer = layoutDrawerXml;
|
|
2542
|
+
});
|
|
2123
2543
|
// Create regions
|
|
2124
|
-
var layoutRegions = Array.from((layout === null || layout === void 0 || (_layout$
|
|
2544
|
+
var layoutRegions = Array.from((layout === null || layout === void 0 || (_layout$layoutNode8 = layout.layoutNode) === null || _layout$layoutNode8 === void 0 ? void 0 : _layout$layoutNode8.getElementsByTagName('region')) || []);
|
|
2125
2545
|
Array.from(layoutRegions).forEach(function (regionXml, indx) {
|
|
2126
2546
|
var regionObj = Region(layout, regionXml, (regionXml === null || regionXml === void 0 ? void 0 : regionXml.getAttribute('id')) || '', options, xlr);
|
|
2127
2547
|
regionObj.index = indx;
|
|
2128
2548
|
layout.regions.push(regionObj);
|
|
2129
2549
|
});
|
|
2550
|
+
layout.actionController.initTouchActions();
|
|
2130
2551
|
};
|
|
2131
2552
|
layoutObject.regionExpired = function () {
|
|
2132
2553
|
var self = layoutObject;
|