feature detect zoom with fallback on transform, allow percent units for deck width/height (#310)
This commit is contained in:
1 parent
d1c74523a4
commit
312eafe2e0
2 files changed
+46
-10
No files matched your search
+44
-8
@@ -17,8 +17,11 @@ var Reveal = (function(){
|
||||
// Configurations defaults, can be overridden at initialization time
|
||||
config = {
|
||||
|
||||
// The "normal" size of the presentation, aspect ratio will be preserved
|
||||
// when the presentation is scaled to fit different resolutions
|
||||
width: 1024,
|
||||
height: 768,
|
||||
|
||||
padding: 0.1,
|
||||
|
||||
// Display controls in the bottom right corner
|
||||
@@ -552,16 +555,49 @@ var Reveal = (function(){
|
||||
*/
|
||||
function layout() {
|
||||
|
||||
dom.slides.style.width = config.width + 'px';
|
||||
dom.slides.style.height = config.height + 'px';
|
||||
// Available space to scale within
|
||||
var availableWidth = dom.wrapper.offsetWidth,
|
||||
availableHeight = dom.wrapper.offsetHeight;
|
||||
|
||||
var availableWidth = window.innerWidth - ( window.innerWidth * config.padding * 2 ),
|
||||
availableHeight = window.innerHeight - ( window.innerHeight * config.padding * 2 );
|
||||
// Dimensions of the content
|
||||
var slideWidth = config.width,
|
||||
slideHeight = config.height;
|
||||
|
||||
var scale = Math.min( availableWidth / config.width, availableHeight / config.height );
|
||||
// Slide width may be a percentage of available width
|
||||
if( typeof slideWidth === 'string' && /%$/.test( slideWidth ) ) {
|
||||
slideWidth = parseInt( slideWidth, 10 ) / 100 * availableWidth;
|
||||
}
|
||||
|
||||
// dom.slides.style.WebkitTransform = 'translate(-50%, -50%) scale('+ scale +') translate(50%, 50%)';
|
||||
dom.slides.style.zoom = scale;
|
||||
// Slide height may be a percentage of available height
|
||||
if( typeof slideHeight === 'string' && /%$/.test( slideHeight ) ) {
|
||||
slideHeight = parseInt( slideHeight, 10 ) / 100 * availableHeight;
|
||||
}
|
||||
|
||||
dom.slides.style.width = slideWidth + 'px';
|
||||
dom.slides.style.height = slideHeight + 'px';
|
||||
|
||||
// Reduce availabe space by padding
|
||||
availableWidth = availableWidth - ( availableHeight * config.padding * 2 );
|
||||
availableHeight = availableHeight - ( availableHeight * config.padding * 2 );
|
||||
|
||||
// Determine scale of content to fit within available space
|
||||
var scale = Math.min( availableWidth / slideWidth, availableHeight / slideHeight );
|
||||
|
||||
// Prefer applying scale via zoom since Chrome blurs scaled content
|
||||
// with nested transforms
|
||||
if( typeof dom.slides.style.zoom !== 'undefined' ) {
|
||||
dom.slides.style.zoom = scale;
|
||||
}
|
||||
// Apply scale transform as a fallback
|
||||
else {
|
||||
var transform = 'translate(-50%, -50%) scale('+ scale +') translate(50%, 50%)';
|
||||
|
||||
dom.slides.style.WebkitTransform = transform;
|
||||
dom.slides.style.MozTransform = transform;
|
||||
dom.slides.style.msTransform = transform;
|
||||
dom.slides.style.OTransform = transform;
|
||||
dom.slides.style.transform = transform;
|
||||
}
|
||||
|
||||
if( config.center ) {
|
||||
|
||||
@@ -569,7 +605,7 @@ var Reveal = (function(){
|
||||
var slides = toArray( document.querySelectorAll( SLIDES_SELECTOR ) );
|
||||
|
||||
// Determine the minimum top offset for slides
|
||||
var minTop = -dom.wrapper.offsetHeight / 2;
|
||||
var minTop = -slideHeight / 2;
|
||||
|
||||
for( var i = 0, len = slides.length; i < len; i++ ) {
|
||||
var slide = slides[ i ];
|
||||
|
||||
Vendored
+2
-2
@@ -1,8 +1,8 @@
|
||||
/*!
|
||||
* reveal.js 2.3 (2013-01-27, 23:26)
|
||||
* reveal.js 2.3 (2013-01-28, 18:56)
|
||||
* http://lab.hakim.se/reveal-js
|
||||
* MIT licensed
|
||||
*
|
||||
* Copyright (C) 2011-2012 Hakim El Hattab, http://hakim.se
|
||||
*/
|
||||
var Reveal=function(){"use strict";function w(e){if(!p&&!h){document.body.setAttribute("class","no-transforms");return}window.addEventListener("load",H,!1),L(i,e),S(),x()}function E(){c.theme=document.querySelector("#theme"),c.wrapper=document.querySelector(".reveal"),c.slides=document.querySelector(".reveal .slides");if(!c.wrapper.querySelector(".progress")&&i.progress){var e=document.createElement("div");e.classList.add("progress"),e.innerHTML="<span></span>",c.wrapper.appendChild(e)}if(!c.wrapper.querySelector(".controls")&&i.controls){var t=document.createElement("aside");t.classList.add("controls"),t.innerHTML='<div class="navigate-left"></div><div class="navigate-right"></div><div class="navigate-up"></div><div class="navigate-down"></div>',c.wrapper.appendChild(t)}if(!c.wrapper.querySelector(".state-background")){var n=document.createElement("div");n.classList.add("state-background"),c.wrapper.appendChild(n)}if(!c.wrapper.querySelector(".pause-overlay")){var r=document.createElement("div");r.classList.add("pause-overlay"),c.wrapper.appendChild(r)}c.progress=document.querySelector(".reveal .progress"),c.progressbar=document.querySelector(".reveal .progress span"),i.controls&&(c.controls=document.querySelector(".reveal .controls"),c.controlsLeft=A(document.querySelectorAll(".navigate-left")),c.controlsRight=A(document.querySelectorAll(".navigate-right")),c.controlsUp=A(document.querySelectorAll(".navigate-up")),c.controlsDown=A(document.querySelectorAll(".navigate-down")),c.controlsPrev=A(document.querySelectorAll(".navigate-prev")),c.controlsNext=A(document.querySelectorAll(".navigate-next")))}function S(){navigator.userAgent.match(/(iphone|ipod)/i)&&(document.documentElement.style.overflow="scroll",document.body.style.height="120%",window.addEventListener("load",_,!1),window.addEventListener("orientationchange",_,!1))}function x(){function o(){t.length&&head.js.apply(null,t),T()}var e=[],t=[];for(var n=0,r=i.dependencies.length;n<r;n++){var s=i.dependencies[n];if(!s.condition||s.condition())s.async?t.push(s.src):e.push(s.src),typeof s.callback=="function"&&head.ready(s.src.match(/([\w\d_\-]*)\.?js$|[^\\\/]*$/i)[0],s.callback)}e.length?(head.ready(o),head.js.apply(null,e)):o()}function T(){E(),C(),N(),H(),Y(),rt(),setTimeout(function(){D("ready",{indexh:o,indexv:u,currentSlide:f})},1)}function N(){h===!1&&(i.transition="linear"),i.controls&&c.controls&&(c.controls.style.display="block"),i.progress&&c.progress&&(c.progress.style.display="block"),i.transition!=="default"&&c.wrapper.classList.add(i.transition),i.rtl&&c.wrapper.classList.add("rtl"),i.center&&c.wrapper.classList.add("center"),i.mouseWheel&&(document.addEventListener("DOMMouseScroll",dt,!1),document.addEventListener("mousewheel",dt,!1)),i.rollingLinks&&P();if(i.theme&&c.theme){var e=c.theme.getAttribute("href"),t=/[^\/]*?(?=\.css)/,n=e.match(t)[0];i.theme!==n&&(e=e.replace(t,i.theme),c.theme.setAttribute("href",e))}}function C(){window.addEventListener("hashchange",mt,!1),window.addEventListener("resize",gt,!1),i.touch&&(document.addEventListener("touchstart",ct,!1),document.addEventListener("touchmove",ht,!1),document.addEventListener("touchend",pt,!1)),i.keyboard&&document.addEventListener("keydown",lt,!1),i.progress&&c.progress&&c.progress.addEventListener("click",M(vt),!1);if(i.controls&&c.controls){var e="ontouchstart"in window?"touchstart":"click";c.controlsLeft.forEach(function(t){t.addEventListener(e,M(it),!1)}),c.controlsRight.forEach(function(t){t.addEventListener(e,M(st),!1)}),c.controlsUp.forEach(function(t){t.addEventListener(e,M(ot),!1)}),c.controlsDown.forEach(function(t){t.addEventListener(e,M(ut),!1)}),c.controlsPrev.forEach(function(t){t.addEventListener(e,M(at),!1)}),c.controlsNext.forEach(function(t){t.addEventListener(e,M(ft),!1)})}}function k(){document.removeEventListener("keydown",lt,!1),window.removeEventListener("hashchange",mt,!1),window.removeEventListener("resize",gt,!1),i.touch&&(document.removeEventListener("touchstart",ct,!1),document.removeEventListener("touchmove",ht,!1),document.removeEventListener("touchend",pt,!1)),i.progress&&c.progress&&c.progress.removeEventListener("click",M(vt),!1);if(i.controls&&c.controls){var e="ontouchstart"in window?"touchstart":"click";c.controlsLeft.forEach(function(t){t.removeEventListener(e,M(it),!1)}),c.controlsRight.forEach(function(t){t.removeEventListener(e,M(st),!1)}),c.controlsUp.forEach(function(t){t.removeEventListener(e,M(ot),!1)}),c.controlsDown.forEach(function(t){t.removeEventListener(e,M(ut),!1)}),c.controlsPrev.forEach(function(t){t.removeEventListener(e,M(at),!1)}),c.controlsNext.forEach(function(t){t.removeEventListener(e,M(ft),!1)})}}function L(e,t){for(var n in t)e[n]=t[n]}function A(e){return Array.prototype.slice.call(e)}function O(e,t){var n=e.x-t.x,r=e.y-t.y;return Math.sqrt(n*n+r*r)}function M(e){return function(t){t.preventDefault(),e.call(null,t)}}function _(){setTimeout(function(){window.scrollTo(0,1)},0)}function D(e,t){var n=document.createEventLine truncated
|
||||
var Reveal=function(){"use strict";function w(e){if(!p&&!h){document.body.setAttribute("class","no-transforms");return}window.addEventListener("load",H,!1),L(i,e),S(),x()}function E(){c.theme=document.querySelector("#theme"),c.wrapper=document.querySelector(".reveal"),c.slides=document.querySelector(".reveal .slides");if(!c.wrapper.querySelector(".progress")&&i.progress){var e=document.createElement("div");e.classList.add("progress"),e.innerHTML="<span></span>",c.wrapper.appendChild(e)}if(!c.wrapper.querySelector(".controls")&&i.controls){var t=document.createElement("aside");t.classList.add("controls"),t.innerHTML='<div class="navigate-left"></div><div class="navigate-right"></div><div class="navigate-up"></div><div class="navigate-down"></div>',c.wrapper.appendChild(t)}if(!c.wrapper.querySelector(".state-background")){var n=document.createElement("div");n.classList.add("state-background"),c.wrapper.appendChild(n)}if(!c.wrapper.querySelector(".pause-overlay")){var r=document.createElement("div");r.classList.add("pause-overlay"),c.wrapper.appendChild(r)}c.progress=document.querySelector(".reveal .progress"),c.progressbar=document.querySelector(".reveal .progress span"),i.controls&&(c.controls=document.querySelector(".reveal .controls"),c.controlsLeft=A(document.querySelectorAll(".navigate-left")),c.controlsRight=A(document.querySelectorAll(".navigate-right")),c.controlsUp=A(document.querySelectorAll(".navigate-up")),c.controlsDown=A(document.querySelectorAll(".navigate-down")),c.controlsPrev=A(document.querySelectorAll(".navigate-prev")),c.controlsNext=A(document.querySelectorAll(".navigate-next")))}function S(){navigator.userAgent.match(/(iphone|ipod)/i)&&(document.documentElement.style.overflow="scroll",document.body.style.height="120%",window.addEventListener("load",_,!1),window.addEventListener("orientationchange",_,!1))}function x(){function o(){t.length&&head.js.apply(null,t),T()}var e=[],t=[];for(var n=0,r=i.dependencies.length;n<r;n++){var s=i.dependencies[n];if(!s.condition||s.condition())s.async?t.push(s.src):e.push(s.src),typeof s.callback=="function"&&head.ready(s.src.match(/([\w\d_\-]*)\.?js$|[^\\\/]*$/i)[0],s.callback)}e.length?(head.ready(o),head.js.apply(null,e)):o()}function T(){E(),C(),N(),H(),Y(),rt(),setTimeout(function(){D("ready",{indexh:o,indexv:u,currentSlide:f})},1)}function N(){h===!1&&(i.transition="linear"),i.controls&&c.controls&&(c.controls.style.display="block"),i.progress&&c.progress&&(c.progress.style.display="block"),i.transition!=="default"&&c.wrapper.classList.add(i.transition),i.rtl&&c.wrapper.classList.add("rtl"),i.center&&c.wrapper.classList.add("center"),i.mouseWheel&&(document.addEventListener("DOMMouseScroll",dt,!1),document.addEventListener("mousewheel",dt,!1)),i.rollingLinks&&P();if(i.theme&&c.theme){var e=c.theme.getAttribute("href"),t=/[^\/]*?(?=\.css)/,n=e.match(t)[0];i.theme!==n&&(e=e.replace(t,i.theme),c.theme.setAttribute("href",e))}}function C(){window.addEventListener("hashchange",mt,!1),window.addEventListener("resize",gt,!1),i.touch&&(document.addEventListener("touchstart",ct,!1),document.addEventListener("touchmove",ht,!1),document.addEventListener("touchend",pt,!1)),i.keyboard&&document.addEventListener("keydown",lt,!1),i.progress&&c.progress&&c.progress.addEventListener("click",M(vt),!1);if(i.controls&&c.controls){var e="ontouchstart"in window?"touchstart":"click";c.controlsLeft.forEach(function(t){t.addEventListener(e,M(it),!1)}),c.controlsRight.forEach(function(t){t.addEventListener(e,M(st),!1)}),c.controlsUp.forEach(function(t){t.addEventListener(e,M(ot),!1)}),c.controlsDown.forEach(function(t){t.addEventListener(e,M(ut),!1)}),c.controlsPrev.forEach(function(t){t.addEventListener(e,M(at),!1)}),c.controlsNext.forEach(function(t){t.addEventListener(e,M(ft),!1)})}}function k(){document.removeEventListener("keydown",lt,!1),window.removeEventListener("hashchange",mt,!1),window.removeEventListener("resize",gt,!1),i.touch&&(document.removeEventListener("touchstart",ct,!1),document.removeEventListener("touchmove",ht,!1),document.removeEventListener("touchend",pt,!1)),i.progress&&c.progress&&c.progress.removeEventListener("click",M(vt),!1);if(i.controls&&c.controls){var e="ontouchstart"in window?"touchstart":"click";c.controlsLeft.forEach(function(t){t.removeEventListener(e,M(it),!1)}),c.controlsRight.forEach(function(t){t.removeEventListener(e,M(st),!1)}),c.controlsUp.forEach(function(t){t.removeEventListener(e,M(ot),!1)}),c.controlsDown.forEach(function(t){t.removeEventListener(e,M(ut),!1)}),c.controlsPrev.forEach(function(t){t.removeEventListener(e,M(at),!1)}),c.controlsNext.forEach(function(t){t.removeEventListener(e,M(ft),!1)})}}function L(e,t){for(var n in t)e[n]=t[n]}function A(e){return Array.prototype.slice.call(e)}function O(e,t){var n=e.x-t.x,r=e.y-t.y;return Math.sqrt(n*n+r*r)}function M(e){return function(t){t.preventDefault(),e.call(null,t)}}function _(){setTimeout(function(){window.scrollTo(0,1)},0)}function D(e,t){var n=document.createEventLine truncated
|
||||
Reference in new issue
Block a user