2
* Xibo - Digital Signage - http://www.xibo.org.uk
3
* Copyright (C) 2009-2016 Daniel Garner
5
* This file is part of Xibo.
7
* Xibo is free software: you can redistribute it and/or modify
8
* it under the terms of the GNU Affero General Public License as published by
9
* the Free Software Foundation, either version 3 of the License, or
12
* Xibo is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU Affero General Public License for more details.
17
* You should have received a copy of the GNU Affero General Public License
18
* along with Xibo. If not, see <http://www.gnu.org/licenses/>.
21
xiboLayoutScaler: function(options) {
22
var width; var height; var newWidth; var newHeight;
31
"widgetDesignWidth": 0,
32
"widgetDesignHeight": 0,
33
"widgetDesignPadding": 0,
37
options = $.extend({}, defaults, options);
39
// Region original width and height
40
var originalWidth = options.originalWidth;
41
var originalHeight = options.originalHeight;
43
if (options.previewWidth === 0 || options.previewHeight === 0) {
44
width = $(window).width();
45
height = $(window).height();
48
width = options.previewWidth;
49
height = options.previewHeight;
52
// Calculate the ratio to apply as a scale transform
53
var ratio = Math.min(width / options.originalWidth, height / options.originalHeight);
55
// The layout designer might provide a scale override, which we need to use because we cannot tell whether
56
// the region has been resized or not. If it has been resized in the designer, but not saved, the original
57
// width and height will be incorrect (the old saved values). Scale override provides the correct
58
// scale in that case.
59
if (options.scaleOverride !== 0) {
60
ratio = options.scaleOverride;
63
newWidth = width / ratio;
64
newHeight = height / ratio;
66
// The widget is scaled according to the layout dimensions
68
// Does the widget have an original design width/height
69
// if so, we need to further scale the widget
70
if (options.widgetDesignWidth > 0 && options.widgetDesignHeight > 0) {
72
if(options.itemsPerPage > 0){
73
if(newWidth > newHeight){
74
//Landscape or square size plus padding
75
options.widgetDesignWidth = (options.itemsPerPage * options.widgetDesignWidth) + (options.widgetDesignPadding * (options.itemsPerPage - 1));
76
options.widgetDesignHeight = options.widgetDesignHeight;
78
//Portrait size plus padding
79
options.widgetDesignHeight = (options.itemsPerPage * options.widgetDesignHeight) + (options.widgetDesignPadding * (options.itemsPerPage - 1));
80
options.widgetDesignWidth = options.widgetDesignWidth;
84
// Calculate the ratio between the new
85
var widgetRatio = Math.min(newWidth / options.widgetDesignWidth, newHeight / options.widgetDesignHeight);
87
ratio = ratio * widgetRatio;
88
newWidth = width / ratio;
89
newHeight = height / ratio;
92
// Apply these details
93
$(this).each(function() {
100
// Handle the scaling
102
if ($("body").hasClass("ie7") || $("body").hasClass("ie8")) {
104
"filter": "progid:DXImageTransform.Microsoft.Matrix(M11=" + ratio + ", M12=0, M21=0, M22=" + ratio + ", SizingMethod=\'auto expand\'"
109
"transform": "scale(" + ratio + ")",
110
"transform-origin": "0 0"
b'\\ No newline at end of file'