add configure api method for update config after initialization

This commit is contained in:
Hakim El Hattab committed 2013-02-24 00:44:20 -05:00
1 parent a9b4eb9a05
commit f795cb0269
2 files changed
+65 -46

No files matched your search

+63 -44
View File
@@ -335,40 +335,40 @@ var Reveal = (function(){
/**
* Applies the configuration settings from the config object.
*/
function configure() {
function configure( options ) {
if( supports3DTransforms === false ) {
config.transition = 'linear';
}
dom.wrapper.classList.remove( config.transition );
if( config.controls && dom.controls ) {
dom.controls.style.display = 'block';
}
// New config options may be passed when this method
// is invoked through the API after initialization
if( typeof options === 'object' ) extend( config, options );
if( config.progress && dom.progress ) {
dom.progress.style.display = 'block';
}
// Force linear transition based on browser capabilities
if( supports3DTransforms === false ) config.transition = 'linear';
if( config.transition !== 'default' ) {
dom.wrapper.classList.add( config.transition );
}
dom.wrapper.classList.add( config.transition );
if( config.rtl ) {
dom.wrapper.classList.add( 'rtl' );
}
dom.controls.style.display = ( config.controls && dom.controls ) ? 'block' : 'none';
dom.progress.style.display = ( config.progress && dom.progress ) ? 'block' : 'none';
if( config.center ) {
dom.wrapper.classList.add( 'center' );
}
dom.wrapper.classList.toggle( 'rtl', config.rtl );
dom.wrapper.classList.toggle( 'center', config.center );
if( config.mouseWheel ) {
document.addEventListener( 'DOMMouseScroll', onDocumentMouseScroll, false ); // FF
document.addEventListener( 'mousewheel', onDocumentMouseScroll, false );
}
else {
document.removeEventListener( 'DOMMouseScroll', onDocumentMouseScroll, false ); // FF
document.removeEventListener( 'mousewheel', onDocumentMouseScroll, false );
}
// 3D links
if( config.rollingLinks ) {
linkify();
enable3DLinks();
}
else {
disable3DLinks();
}
// Load the theme in the config, if it's not already loaded
@@ -524,28 +524,47 @@ var Reveal = (function(){
/**
* Wrap all links in 3D goodness.
*/
function linkify() {
function enable3DLinks() {
if( supports3DTransforms && !( 'msPerspective' in document.body.style ) ) {
var nodes = document.querySelectorAll( SLIDES_SELECTOR + ' a:not(.image)' );
var anchors = document.querySelectorAll( SLIDES_SELECTOR + ' a:not(.image)' );
for( var i = 0, len = nodes.length; i < len; i++ ) {
var node = nodes[i];
for( var i = 0, len = anchors.length; i < len; i++ ) {
var anchor = anchors[i];
if( node.textContent && !node.querySelector( '*' ) && ( !node.className || !node.classList.contains( node, 'roll' ) ) ) {
if( anchor.textContent && !anchor.querySelector( '*' ) && ( !anchor.className || !anchor.classList.contains( anchor, 'roll' ) ) ) {
var span = document.createElement('span');
span.setAttribute('data-title', node.text);
span.innerHTML = node.innerHTML;
span.setAttribute('data-title', anchor.text);
span.innerHTML = anchor.innerHTML;
node.classList.add( 'roll' );
node.innerHTML = '';
node.appendChild(span);
anchor.classList.add( 'roll' );
anchor.innerHTML = '';
anchor.appendChild(span);
}
}
}
}
/**
* Unwrap all 3D links.
*/
function disable3DLinks() {
var anchors = document.querySelectorAll( SLIDES_SELECTOR + ' a.roll' );
for( var i = 0, len = anchors.length; i < len; i++ ) {
var anchor = anchors[i];
var span = anchor.querySelector( 'span' );
if( span ) {
anchor.classList.remove( 'roll' );
anchor.innerHTML = span.innerHTML;
}
}
}
/**
* Applies JavaScript-controlled layout rules to the
* presentation.
@@ -602,31 +621,30 @@ var Reveal = (function(){
dom.slides.style.transform = transform;
}
if( config.center ) {
// Select all slides, vertical and horizontal
var slides = toArray( document.querySelectorAll( SLIDES_SELECTOR ) );
// Select all slides, vertical and horizontal
var slides = toArray( document.querySelectorAll( SLIDES_SELECTOR ) );
for( var i = 0, len = slides.length; i < len; i++ ) {
var slide = slides[ i ];
// Determine the minimum top offset for slides
var minTop = -slideHeight / 2;
for( var i = 0, len = slides.length; i < len; i++ ) {
var slide = slides[ i ];
// Don't bother updating invisible slides
if( slide.style.display === 'none' ) {
continue;
}
// Don't bother updating invisible slides
if( slide.style.display === 'none' ) {
continue;
}
if( config.center ) {
// Vertical stacks are not centered since their section
// children will be
if( slide.classList.contains( 'stack' ) ) {
slide.style.top = 0;
}
else {
slide.style.top = Math.max( - ( slide.offsetHeight / 2 ) - 20, minTop ) + 'px';
slide.style.top = Math.max( - ( slide.offsetHeight / 2 ) - 20, -slideHeight / 2 ) + 'px';
}
}
else {
slide.style.top = '';
}
}
@@ -1812,6 +1830,7 @@ var Reveal = (function(){
return {
initialize: initialize,
configure: configure,
// Navigation methods
slide: slide,
+2 -2
View File
@@ -1,8 +1,8 @@
/*!
* reveal.js 2.3 (2013-02-13, 18:00)
* reveal.js 2.3 (2013-02-24, 00:42)
* http://lab.hakim.se/reveal-js
* MIT licensed
*
* Copyright (C) 2013 Hakim El Hattab, http://hakim.se
*/
var Reveal=function(){"use strict";function E(e){if(!d&&!p){document.body.setAttribute("class","no-transforms");return}window.addEventListener("load",H,!1),A(i,e),x(),T()}function S(){h.theme=document.querySelector("#theme"),h.wrapper=document.querySelector(".reveal"),h.slides=document.querySelector(".reveal .slides");if(!h.wrapper.querySelector(".progress")&&i.progress){var e=document.createElement("div");e.classList.add("progress"),e.innerHTML="<span></span>",h.wrapper.appendChild(e)}if(!h.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>',h.wrapper.appendChild(t)}if(!h.wrapper.querySelector(".state-background")){var n=document.createElement("div");n.classList.add("state-background"),h.wrapper.appendChild(n)}if(!h.wrapper.querySelector(".pause-overlay")){var r=document.createElement("div");r.classList.add("pause-overlay"),h.wrapper.appendChild(r)}h.progress=document.querySelector(".reveal .progress"),h.progressbar=document.querySelector(".reveal .progress span"),i.controls&&(h.controls=document.querySelector(".reveal .controls"),h.controlsLeft=O(document.querySelectorAll(".navigate-left")),h.controlsRight=O(document.querySelectorAll(".navigate-right")),h.controlsUp=O(document.querySelectorAll(".navigate-up")),h.controlsDown=O(document.querySelectorAll(".navigate-down")),h.controlsPrev=O(document.querySelectorAll(".navigate-prev")),h.controlsNext=O(document.querySelectorAll(".navigate-next")))}function x(){/iphone|ipod|android/gi.test(navigator.userAgent)&&!/crios/gi.test(navigator.userAgent)&&(window.addEventListener("load",_,!1),window.addEventListener("orientationchange",_,!1))}function T(){function o(){t.length&&head.js.apply(null,t),N()}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 N(){S(),k(),C(),H(),Y(),rt(),setTimeout(function(){D("ready",{indexh:o,indexv:u,currentSlide:f})},1)}function C(){p===!1&&(i.transition="linear"),i.controls&&h.controls&&(h.controls.style.display="block"),i.progress&&h.progress&&(h.progress.style.display="block"),i.transition!=="default"&&h.wrapper.classList.add(i.transition),i.rtl&&h.wrapper.classList.add("rtl"),i.center&&h.wrapper.classList.add("center"),i.mouseWheel&&(document.addEventListener("DOMMouseScroll",vt,!1),document.addEventListener("mousewheel",vt,!1)),i.rollingLinks&&P();if(i.theme&&h.theme){var e=h.theme.getAttribute("href"),t=/[^\/]*?(?=\.css)/,n=e.match(t)[0];i.theme!==n&&(e=e.replace(t,i.theme),h.theme.setAttribute("href",e))}}function k(){window.addEventListener("hashchange",xt,!1),window.addEventListener("resize",Tt,!1),i.touch&&(document.addEventListener("touchstart",ht,!1),document.addEventListener("touchmove",pt,!1),document.addEventListener("touchend",dt,!1)),i.keyboard&&document.addEventListener("keydown",ct,!1),i.progress&&h.progress&&h.progress.addEventListener("click",mt,!1);if(i.controls&&h.controls){var e="ontouchstart"in window?"touchstart":"click";h.controlsLeft.forEach(function(t){t.addEventListener(e,gt,!1)}),h.controlsRight.forEach(function(t){t.addEventListener(e,yt,!1)}),h.controlsUp.forEach(function(t){t.addEventListener(e,bt,!1)}),h.controlsDown.forEach(function(t){t.addEventListener(e,wt,!1)}),h.controlsPrev.forEach(function(t){t.addEventListener(e,Et,!1)}),h.controlsNext.forEach(function(t){t.addEventListener(e,St,!1)})}}function L(){document.removeEventListener("keydown",ct,!1),window.removeEventListener("hashchange",xt,!1),window.removeEventListener("resize",Tt,!1),i.touch&&(document.removeEventListener("touchstart",ht,!1),document.removeEventListener("touchmove",pt,!1),document.removeEventListener("touchend",dt,!1)),i.progress&&h.progress&&h.progress.removeEventListener("click",mt,!1);if(i.controls&&h.controls){var e="ontouchstart"in window&&window.ontouchstart!=null?"touchstart":"click";h.controlsLeft.forEach(function(t){t.removeEventListener(e,gt,!1)}),h.controlsRight.forEach(function(t){t.removeEventListener(e,yt,!1)}),h.controlsUp.forEach(function(t){t.removeEventListener(e,bt,!1)}),h.controlsDown.forEach(function(t){t.removeEventListener(e,wt,!1)}),h.controlsPrev.forEach(function(t){t.removeEventListener(e,Et,!1)}),h.controlsNext.forEach(function(t){t.removeEventListener(e,St,!1)})}}function A(e,t){for(var n in t)e[n]=t[n]}function O(e){return Array.prototype.slice.call(e)}function M(e,t){var n=e.x-t.x,r=e.y-t.y;return Math.sqrt(n*n+r*r)}function _(){window.orientation===0?(document.documentElement.style.overflow="scroll",document.body.style.height="120%"):(document.documentElement.style.overflow="",document.body.style.height="100%"),setTimeout(function(){wiLine truncated
var Reveal=function(){"use strict";function E(e){if(!d&&!p){document.body.setAttribute("class","no-transforms");return}window.addEventListener("load",B,!1),A(i,e),x(),T()}function S(){h.theme=document.querySelector("#theme"),h.wrapper=document.querySelector(".reveal"),h.slides=document.querySelector(".reveal .slides");if(!h.wrapper.querySelector(".progress")&&i.progress){var e=document.createElement("div");e.classList.add("progress"),e.innerHTML="<span></span>",h.wrapper.appendChild(e)}if(!h.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>',h.wrapper.appendChild(t)}if(!h.wrapper.querySelector(".state-background")){var n=document.createElement("div");n.classList.add("state-background"),h.wrapper.appendChild(n)}if(!h.wrapper.querySelector(".pause-overlay")){var r=document.createElement("div");r.classList.add("pause-overlay"),h.wrapper.appendChild(r)}h.progress=document.querySelector(".reveal .progress"),h.progressbar=document.querySelector(".reveal .progress span"),i.controls&&(h.controls=document.querySelector(".reveal .controls"),h.controlsLeft=O(document.querySelectorAll(".navigate-left")),h.controlsRight=O(document.querySelectorAll(".navigate-right")),h.controlsUp=O(document.querySelectorAll(".navigate-up")),h.controlsDown=O(document.querySelectorAll(".navigate-down")),h.controlsPrev=O(document.querySelectorAll(".navigate-prev")),h.controlsNext=O(document.querySelectorAll(".navigate-next")))}function x(){/iphone|ipod|android/gi.test(navigator.userAgent)&&!/crios/gi.test(navigator.userAgent)&&(window.addEventListener("load",_,!1),window.addEventListener("orientationchange",_,!1))}function T(){function o(){t.length&&head.js.apply(null,t),N()}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 N(){S(),k(),C(),B(),Z(),it(),setTimeout(function(){D("ready",{indexh:o,indexv:u,currentSlide:f})},1)}function C(e){h.wrapper.classList.remove(i.transition),typeof e=="object"&&A(i,e),p===!1&&(i.transition="linear"),h.wrapper.classList.add(i.transition),h.controls.style.display=i.controls&&h.controls?"block":"none",h.progress.style.display=i.progress&&h.progress?"block":"none",h.wrapper.classList.toggle("rtl",i.rtl),h.wrapper.classList.toggle("center",i.center),i.mouseWheel?(document.addEventListener("DOMMouseScroll",mt,!1),document.addEventListener("mousewheel",mt,!1)):(document.removeEventListener("DOMMouseScroll",mt,!1),document.removeEventListener("mousewheel",mt,!1)),i.rollingLinks?P():H();if(i.theme&&h.theme){var t=h.theme.getAttribute("href"),n=/[^\/]*?(?=\.css)/,r=t.match(n)[0];i.theme!==r&&(t=t.replace(n,i.theme),h.theme.setAttribute("href",t))}}function k(){window.addEventListener("hashchange",Tt,!1),window.addEventListener("resize",Nt,!1),i.touch&&(document.addEventListener("touchstart",pt,!1),document.addEventListener("touchmove",dt,!1),document.addEventListener("touchend",vt,!1)),i.keyboard&&document.addEventListener("keydown",ht,!1),i.progress&&h.progress&&h.progress.addEventListener("click",gt,!1);if(i.controls&&h.controls){var e="ontouchstart"in window&&window.ontouchstart!=null?"touchstart":"click";h.controlsLeft.forEach(function(t){t.addEventListener(e,yt,!1)}),h.controlsRight.forEach(function(t){t.addEventListener(e,bt,!1)}),h.controlsUp.forEach(function(t){t.addEventListener(e,wt,!1)}),h.controlsDown.forEach(function(t){t.addEventListener(e,Et,!1)}),h.controlsPrev.forEach(function(t){t.addEventListener(e,St,!1)}),h.controlsNext.forEach(function(t){t.addEventListener(e,xt,!1)})}}function L(){document.removeEventListener("keydown",ht,!1),window.removeEventListener("hashchange",Tt,!1),window.removeEventListener("resize",Nt,!1),i.touch&&(document.removeEventListener("touchstart",pt,!1),document.removeEventListener("touchmove",dt,!1),document.removeEventListener("touchend",vt,!1)),i.progress&&h.progress&&h.progress.removeEventListener("click",gt,!1);if(i.controls&&h.controls){var e="ontouchstart"in window&&window.ontouchstart!=null?"touchstart":"click";h.controlsLeft.forEach(function(t){t.removeEventListener(e,yt,!1)}),h.controlsRight.forEach(function(t){t.removeEventListener(e,bt,!1)}),h.controlsUp.forEach(function(t){t.removeEventListener(e,wt,!1)}),h.controlsDown.forEach(function(t){t.removeEventListener(e,Et,!1)}),h.controlsPrev.forEach(function(t){t.removeEventListener(e,St,!1)}),h.controlsNext.forEach(function(t){t.removeEventListener(e,xt,!1)})}}function A(e,t){for(var n in t)e[n]=t[n]}function O(e){return Array.prototype.slice.call(e)}function M(e,t){var n=e.x-t.x,r=e.y-t.y;return Math.sqrt(n*n+r*r)}function _(){window.orientation===0?Line truncated