~xibo-maintainers/xibo/tempel

« back to all changes in this revision

Viewing changes to modules/xibo-layout-scaler.js

  • Committer: Dan Garner
  • Date: 2016-02-12 10:41:25 UTC
  • mto: (454.4.130)
  • mto: This revision was merged to the branch mainline in revision 484.
  • Revision ID: git-v1:ca673f8ea522eac5f311ed779b0fbfeb35a0e4dd
Handle duration changes in XLF generation. Fixed region option factory.
xibosignage/xibo#721

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**
2
 
* Xibo - Digital Signage - http://www.xibo.org.uk
3
 
* Copyright (C) 2009-2016 Daniel Garner
4
 
*
5
 
* This file is part of Xibo.
6
 
*
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
10
 
* any later version.
11
 
*
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.
16
 
*
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/>.
19
 
*/
20
 
jQuery.fn.extend({
21
 
    xiboLayoutScaler: function(options) {
22
 
        var width; var height; var newWidth; var newHeight;
23
 
        
24
 
        // Default options
25
 
        var defaults = {
26
 
          "originalWidth": 0,
27
 
          "originalHeight": 0,
28
 
          "previewWidth": 0,
29
 
          "previewHeight": 0,
30
 
          "scaleOverride": 0,
31
 
          "widgetDesignWidth": 0,
32
 
          "widgetDesignHeight": 0,
33
 
          "widgetDesignPadding": 0,
34
 
          "itemsPerPage": 0
35
 
        };
36
 
 
37
 
        options = $.extend({}, defaults, options);
38
 
 
39
 
        // Region original width and height
40
 
        var originalWidth = options.originalWidth;
41
 
        var originalHeight = options.originalHeight;
42
 
 
43
 
        if (options.previewWidth === 0 || options.previewHeight === 0) {
44
 
            width = $(window).width();
45
 
            height = $(window).height();
46
 
        }
47
 
        else {
48
 
            width = options.previewWidth;
49
 
            height = options.previewHeight;
50
 
        }
51
 
 
52
 
        // Calculate the ratio to apply as a scale transform
53
 
        var ratio = Math.min(width / options.originalWidth, height / options.originalHeight);
54
 
 
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;
61
 
        }
62
 
 
63
 
        newWidth = width / ratio;
64
 
        newHeight = height / ratio;
65
 
 
66
 
        // The widget is scaled according to the layout dimensions
67
 
 
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) {
71
 
            
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;
77
 
              } else {
78
 
                //Portrait size plus padding
79
 
                options.widgetDesignHeight = (options.itemsPerPage * options.widgetDesignHeight) + (options.widgetDesignPadding * (options.itemsPerPage - 1));
80
 
                options.widgetDesignWidth = options.widgetDesignWidth;
81
 
              }
82
 
            }
83
 
            
84
 
            // Calculate the ratio between the new
85
 
            var widgetRatio = Math.min(newWidth / options.widgetDesignWidth, newHeight / options.widgetDesignHeight);
86
 
 
87
 
            ratio = ratio * widgetRatio;
88
 
            newWidth = width / ratio;
89
 
            newHeight = height / ratio;
90
 
        }
91
 
 
92
 
        // Apply these details
93
 
        $(this).each(function() {
94
 
 
95
 
            $(this).css({
96
 
                width: newWidth,
97
 
                height: newHeight
98
 
            });
99
 
            
100
 
            // Handle the scaling
101
 
            // What IE are we?
102
 
            if ($("body").hasClass("ie7") || $("body").hasClass("ie8")) {
103
 
                $(this).css({
104
 
                    "filter": "progid:DXImageTransform.Microsoft.Matrix(M11=" + ratio + ", M12=0, M21=0, M22=" + ratio + ", SizingMethod=\'auto expand\'"
105
 
                });
106
 
            }
107
 
            else {
108
 
                $(this).css({
109
 
                    "transform": "scale(" + ratio + ")",
110
 
                    "transform-origin": "0 0"
111
 
                });
112
 
            }
113
 
        });
114
 
 
115
 
        return $(this);
116
 
    }
117
 
});
 
 
b'\\ No newline at end of file'