~xibo-maintainers/xibo/tempel

« back to all changes in this revision

Viewing changes to modules/xibo-finance-render.js

  • Committer: Dan Garner
  • Date: 2015-03-26 14:08:33 UTC
  • Revision ID: git-v1:70d14044444f8dc5d602b99890d59dea46d9470c
Moved web servable files to web folder

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
 
    xiboFinanceRender: function(options, items, body) {
22
 
 
23
 
        // Default options
24
 
        var defaults = {
25
 
            "fx": "none",
26
 
            "speed": "2",
27
 
            "duration": "30",
28
 
            "durationIsPerPage": false,
29
 
            "numItems": 0,
30
 
            "maxItemsPerPage": 5,
31
 
            "previewWidth": 0,
32
 
            "previewHeight": 0,
33
 
            "scaleOverride": 0
34
 
        };
35
 
 
36
 
        options = $.extend({}, defaults, options);
37
 
 
38
 
        // Calculate the dimensions of this item based on the preview/original dimensions
39
 
        var width = height = 0;
40
 
        if (options.previewWidth === 0 || options.previewHeight === 0) {
41
 
            width = options.originalWidth;
42
 
            height = options.originalHeight;
43
 
        } else {
44
 
            width = options.previewWidth;
45
 
            height = options.previewHeight;
46
 
        }
47
 
 
48
 
        if (options.scaleOverride !== 0) {
49
 
            width = width / options.scaleOverride;
50
 
            height = height / options.scaleOverride;
51
 
        }
52
 
 
53
 
        if (options.widgetDesignWidth > 0 && options.widgetDesignHeight > 0) {
54
 
            options.widgetDesignWidth = options.widgetDesignWidth;
55
 
            options.widgetDesignHeight = options.widgetDesignHeight;
56
 
            width = options.widgetDesignWidth;
57
 
            height = options.widgetDesignHeight;
58
 
        }
59
 
 
60
 
        // For each matched element
61
 
        this.each(function() {
62
 
            // How many pages to we need?
63
 
            var numberOfPages = (options.numItems > options.maxItemsPerPage) ? Math.ceil(options.numItems / options.maxItemsPerPage) : 1;
64
 
 
65
 
            var mainHTML = body;
66
 
            var itemsHTML = '';
67
 
 
68
 
            // Create the pages
69
 
            for (var i = 0; i < numberOfPages; i++) {
70
 
                itemsHTML += "<div class='page'>";
71
 
                for (var j = 0; j < options.maxItemsPerPage; j++) {
72
 
                    if (((i * options.maxItemsPerPage) + j) < options.numItems)
73
 
                        itemsHTML += items[(i * options.maxItemsPerPage) + j];
74
 
                }
75
 
                itemsHTML += "</div>"
76
 
            }
77
 
 
78
 
            mainHTML = mainHTML.replace('[itemsTemplate]', itemsHTML);
79
 
            $("#content").append(mainHTML);
80
 
 
81
 
            var duration = (options.durationIsPerPage) ? options.duration : options.duration / numberOfPages;
82
 
 
83
 
            // Make sure the speed is something sensible
84
 
            options.speed = (options.speed <= 200) ? 1000 : options.speed;
85
 
 
86
 
            // Timeout is the duration in ms
87
 
            var timeout = (duration * 1000) - (options.speed * 0.7);
88
 
 
89
 
            var slides = (numberOfPages > 1) ? ".page" : ".item";
90
 
 
91
 
            // Set the content div to the height of the original window
92
 
            $("#cycle-container").css("height", height);
93
 
 
94
 
            // Set the width on the cycled slides
95
 
            $(slides, "#cycle-container").css({
96
 
                width: width,
97
 
                height: height
98
 
            });
99
 
 
100
 
            // Cycle handles this for us
101
 
            $("#cycle-container").cycle({
102
 
                fx: options.fx,
103
 
                speed: options.speed,
104
 
                timeout: timeout,
105
 
                slides: "> " + slides
106
 
            });
107
 
 
108
 
            // Protect against images that don't load
109
 
            $(this).find("img").error(function() {
110
 
                $(this).unbind("error").attr("src", "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR4nGNiYAAAAAkAAxkR2eQAAAAASUVORK5CYII=");
111
 
            });
112
 
        });
113
 
 
114
 
        return $(this);
115
 
    }
116
 
});
 
 
b'\\ No newline at end of file'