Skip to content

Commit

Permalink
Widgets: Fix scaling issue for static widgets and elements (#2227)
Browse files Browse the repository at this point in the history
* do not apply default scaling if static widgets don't have onRender
* fix onRender for analogue clock/embedded
* apply scaling once to elements
* fix for refreshing preview source

relates to xibosignage/xibo#3239
  • Loading branch information
rubenberttpingol authored Nov 16, 2023
1 parent 6437f57 commit d4d8b52
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 37 deletions.
4 changes: 4 additions & 0 deletions modules/clock-analogue.xml
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ if (typeof updateClock === 'function') {
setInterval(updateClock, 1000);
}
]]></onVisible>
<onRender><![CDATA[
// Scale the content
$(target).xiboLayoutScaler(properties);
]]></onRender>
<assets>
<asset id="clock-analogue-thumb" type="path" cmsOnly="true" mimeType="image/png" path="/modules/assets/template-thumbnails/clock/clock-analogue-thumb.png" />
<asset id="clock_bg_modern_dark" type="path" mime="image/png" path="/modules/assets/clock_bg_modern_dark.png"></asset>
Expand Down
7 changes: 4 additions & 3 deletions modules/embedded.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,11 @@
if(typeof EmbedInit === 'function') {
EmbedInit();
}
]]></onInitialize>
<onRender><![CDATA[
if(properties.scaleContent) {
window.scaleContent = true;
$('body').xiboLayoutScaler(globalOptions);
$(target).xiboLayoutScaler(globalOptions);
}
]]></onInitialize>
]]></onRender>
</module>
4 changes: 2 additions & 2 deletions modules/pdf.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ var pdfDoc = null,
var canvas = document.getElementById('the-canvas');
var ctx = canvas.getContext('2d');
width = $('body').width();
height = $('body').height();
width = $(window).width();
height = $(window).height();
canvas.width = width;
canvas.height = height;
Expand Down
37 changes: 15 additions & 22 deletions modules/src/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,6 @@ $(function() {
window.renders.push(window.onRender);
}

// If there's no elements in renders, use the default scaler
if (window.renders.length === 0) {
window.renders.push(defaultScaler);
}

// If we have a custom template, run the legacy template render first
if (customTemplate) {
const newOptions =
Expand Down Expand Up @@ -270,7 +265,6 @@ $(function() {
url,
meta,
} = widget;
widget.items = [];

if (Object.keys(elements.groups).length > 0 ||
Object.keys(elements.standalone).length > 0) {
Expand Down Expand Up @@ -715,28 +709,14 @@ $(function() {
}
});
}

if (templateId !== null && url !== null) {
// Run defaultScaler for global elements
defaultScaler(
widget.widgetId,
$content,
widget.items,
Object.assign(
widget.properties,
globalOptions,
{duration: widget.duration},
),
meta,
);
}
}
}

PlayerHelper
.init(widgetData, elements)
.then(({widgets}) => {
.then(({widgets, countWidgetElements}) => {
if (Object.keys(widgets).length > 0) {
let _countWidgetElements = 0;
Object.keys(widgets).forEach(function(widgetKey) {
const widget = widgets[widgetKey];

Expand Down Expand Up @@ -767,7 +747,20 @@ $(function() {
Object.keys(widget.elements.groups).length > 0 ||
Object.keys(widget.elements.standalone).length > 0
))) && typeof widget.elements !== 'undefined') {
widget.items = [];

_countWidgetElements++;

initPlayerElements(widget);

if (countWidgetElements === _countWidgetElements) {
// Run xiboLayoutScaler to scale the content
$content.xiboLayoutScaler(Object.assign(
widget.properties,
globalOptions,
{duration: widget.duration},
));
}
} else {
initStaticTemplates(
$template,
Expand Down
13 changes: 9 additions & 4 deletions modules/src/xibo-layout-scaler.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,19 @@ jQuery.fn.extend({

mElOptions.contentScaleX = width / mElOptions.contentWidth;
mElOptions.contentScaleY = height / mElOptions.contentHeight;

// calculate/update ratio
ratio = Math.min(mElOptions.contentScaleX, mElOptions.contentScaleY);
}

// Do nothing and return $(this) when ratio = 1
if (ratio == 1) {
return $(this);
}

// Apply these details
$(this).each(function(_idx, el) {
if (!$.isEmptyObject(mElOptions)) {
// calculate/update ratio
ratio = Math.min(mElOptions.contentScaleX, mElOptions.contentScaleY);

$(el).css('transform-origin', '0 0');
$(el).css('transform', 'scale(' + ratio + ')');
$(el).width(mElOptions.contentWidth);
Expand Down Expand Up @@ -148,7 +153,7 @@ jQuery.fn.extend({
}

// Set ratio on the body incase we want to get it easily
$(el).data('ratio', ratio);
$(el).attr('data-ratio', ratio);

// Handle alignment (do not add position absolute unless needed)
if (!options.type || options.type !== 'text') {
Expand Down
24 changes: 23 additions & 1 deletion ui/src/helpers/player-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@ const PlayerHelper = function() {
const _self = this;
const urlParams = new URLSearchParams(window.location.search);
const isPreview = urlParams.get('preview') === '1';
let countWidgetElements = 0;
let countWidgetStatic = 0;

/**
* Initialize player with the available widgetData and elements
* @param {array} widgetData
* @param {array} elements
* @return {Promise<object>}
*/
this.init = (widgetData, elements) => new Promise((resolve) => {
if (Array.isArray(widgetData)) {
const _widgetData = [...widgetData];
Expand Down Expand Up @@ -46,6 +54,16 @@ const PlayerHelper = function() {
}
}

if (_widget.templateId === 'elements' ||
(_widget.templateId === null && (
Object.keys(_elements.groups).length > 0 ||
Object.keys(_elements.standalone).length > 0
))) {
countWidgetElements++;
} else {
countWidgetStatic++;
}

widgets[_widget.widgetId] = {
..._widget,
data: dataItems,
Expand All @@ -55,7 +73,11 @@ const PlayerHelper = function() {
};
});

resolve({widgets});
resolve({
widgets,
countWidgetElements,
countWidgetStatic,
});
});
}
});
Expand Down
10 changes: 5 additions & 5 deletions ui/src/preview/html-preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -652,9 +652,8 @@ function media(parent, id, xml, options, preload) {
if(self.checkIframeStatus) {
// Reload iframe
var iframeDOM = $("#" + self.containerName + ' #' + self.iframeName);
// We remove this line because of flickering and
// We will need to address the duration
// iframeDOM[0].src = iframeDOM[0].src;
iframeDOM.css({visibility: 'hidden'});
iframeDOM[0].src = iframeDOM[0].src;
} else {
$("#" + self.containerName).empty().append(self.iframe);
}
Expand Down Expand Up @@ -786,7 +785,7 @@ function media(parent, id, xml, options, preload) {

if (self.render == "html" || self.mediaType == "ticker") {
self.checkIframeStatus = true;
self.iframe = $('<iframe scrolling="no" id="' + self.iframeName + '" src="' + tmpUrl + '&width=' + self.divWidth + '&height=' + self.divHeight + '" width="' + self.divWidth + 'px" height="' + self.divHeight + 'px" style="border:0;"></iframe>');
self.iframe = $('<iframe scrolling="no" id="' + self.iframeName + '" src="' + tmpUrl + '&width=' + self.divWidth + '&height=' + self.divHeight + '" width="' + self.divWidth + 'px" height="' + self.divHeight + 'px" style="border:0; visibility: hidden;"></iframe>');
/* Check if the ticker duration is based on the number of items in the feed */
if(self.options['durationisperitem'] == '1' || self.options['durationisperpage'] == '1') {
var regex = new RegExp("<!-- NUMITEMS=(.*?) -->");
Expand Down Expand Up @@ -820,7 +819,7 @@ function media(parent, id, xml, options, preload) {
}
else if (self.mediaType == "text" || self.mediaType == "datasetview" || self.mediaType == "webpage" || self.mediaType == "embedded") {
self.checkIframeStatus = true;
self.iframe = $('<iframe scrolling="no" id="' + self.iframeName + '" src="' + tmpUrl + '&width=' + self.divWidth + '&height=' + self.divHeight + '" width="' + self.divWidth + 'px" height="' + self.divHeight + 'px" style="border:0;"></iframe>');
self.iframe = $('<iframe scrolling="no" id="' + self.iframeName + '" src="' + tmpUrl + '&width=' + self.divWidth + '&height=' + self.divHeight + '" width="' + self.divWidth + 'px" height="' + self.divHeight + 'px" style="border:0; visibility: hidden;"></iframe>');
}
else if (self.mediaType == "video") {
preload.addFiles(tmpUrl);
Expand Down Expand Up @@ -858,6 +857,7 @@ function media(parent, id, xml, options, preload) {
// On iframe load, set state as ready to play full preview
$(self.iframe).on('load', function(){
self.ready = true;
$(self.iframe).css({visibility: 'visible'});
});
}

Expand Down

0 comments on commit d4d8b52

Please sign in to comment.