First rough take at scaling
[deck.js.git] / extensions / scale / deck.scale.js
blob510e6cf5e20a35f03baee04f1e022959d9ee882a
1 /*!
2 Deck JS - deck.scale - v1.0
3 Copyright (c) 2011 Caleb Troughton
4 Dual licensed under the MIT license and GPL license.
5 https://github.com/imakewebthings/deck.js/blob/master/MIT-license.txt
6 https://github.com/imakewebthings/deck.js/blob/master/GPL-license.txt
7 */
9 /*
12 (function($, deck, window, undefined) {
13         var $d = $(document),
14         $w = $(window),
15         baseHeight,
16         didResize,
17         
18         scaleDeck = function() {
19                 var obh = $[deck]('getOptions').baseHeight,
20                 container = $[deck]('getContainer'),
21                 height = $w.height(),
22                 slides = $[deck]('getSlides'),
23                 scale;
24                 
25                 // Use tallest slide as base height if not set manually
26                 baseHeight = obh ? obh : (function() {
27                         var greatest = 0;
28                         
29                         $.each(slides, function(i, $slide) {
30                                 greatest = Math.max(greatest, $slide.outerHeight());
31                         });
32                         
33                         return greatest;
34                 })();
35                 
36                 scale = height / baseHeight;
37                 
38                 if (!$[deck]('getOptions').scaleUp && scale > 1) {
39                         scale = 1;
40                 }
41                 
42                 $.each('Webkit Moz O ms Khtml'.split(' '), function(i, prefix) {
43                         container.css(prefix + 'Transform', 'scale(' + scale + ')');
44                 });
45         };
47         /*
48         Extends defaults/options.
49         
50         
51         */
52         $.extend(true, $[deck].defaults, {
53                 classes: {
54                         scale: 'deck-scale'
55                 },
56                 baseHeight: 0,
57                 scaleThrottle: 500,
58                 scaleUp: false
59         });
61         $d.bind('deck.init', function() {
62                 // Only care about scaling non-embedded presentations
63                 if (!$[deck]('getContainer').is('body')) return;
64                 
65                 $[deck]('getContainer').addClass($[deck]('getOptions').classes.scale);
66                 
67                 // Throttle scaling on resize
68                 $w.unbind('resize.deckscale').bind('resize.deckscale', function() {
69                         if (!didResize) {
70                                 didResize = true;
71                                 window.setTimeout(function() {
72                                         scaleDeck();
73                                         didResize = false;
74                                 }, $[deck]('getOptions').scaleThrottle);
75                         }
76                 })
77                 // Scale once on load, in case images or something change layout
78                 .unbind('load.deckscale').bind('load.deckscale', scaleDeck);
79                 
80                 // Scale once on init
81                 scaleDeck();
82         });
83         
84         // Scale again on load, in case images or anything else changed layout
85 })(jQuery, 'deck', this);