~xibo-maintainers/xibo/tempel

« back to all changes in this revision

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

  • Committer: Dan Garner
  • Date: 2015-08-11 09:29:02 UTC
  • mto: This revision was merged to the branch mainline in revision 453.
  • Revision ID: git-v1:a86fb4369b7395c13367577d23b14c0ab4528c1a
Transitions fixes.

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-2014 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;
 
23
 
 
24
        var originalWidth = options.originalWidth;
 
25
        var originalHeight = options.originalHeight;
 
26
 
 
27
        if (options.previewWidth === 0 || options.previewHeight === 0) {
 
28
            width = $(window).width();
 
29
            height = $(window).height();
 
30
        }
 
31
        else {
 
32
            width = options.previewWidth;
 
33
            height = options.previewHeight;
 
34
        }
 
35
 
 
36
        var ratio = Math.min(width / options.originalWidth, height / options.originalHeight);
 
37
 
 
38
        if (options.scaleOverride !== 0) {
 
39
            //console.log("Scale Override is set, meaning we want to scale according to the provided scale of " + options.scaleOverride + ". Provided Width is " + width + ". Provided Height is " + height + ".");
 
40
            ratio = options.scaleOverride;
 
41
            originalWidth = width / ratio;
 
42
            originalHeight = height / ratio;
 
43
        }
 
44
 
 
45
        $(this).each(function() {
 
46
 
 
47
            $(this).css({
 
48
                width: originalWidth,
 
49
                height: originalHeight
 
50
            });
 
51
            
 
52
            // Handle the scaling
 
53
            // What IE are we?
 
54
            if ($("body").hasClass("ie7") || $("body").hasClass("ie8")) {
 
55
                $(this).css({
 
56
                    "filter": "progid:DXImageTransform.Microsoft.Matrix(M11=" + ratio + ", M12=0, M21=0, M22=" + ratio + ", SizingMethod=\'auto expand\'"
 
57
                });
 
58
            }
 
59
            else {
 
60
                $(this).css({
 
61
                    "transform": "scale(" + ratio + ")",
 
62
                    "transform-origin": "0 0"
 
63
                });
 
64
            }
 
65
        });
 
66
 
 
67
        return $(this);
 
68
    }
 
69
});