add configure api method for update config after initialization

This commit is contained in:
Hakim El Hattab 2013-02-24 00:44:20 -05:00
parent a9b4eb9a05
commit f795cb0269
2 changed files with 65 additions and 46 deletions

View File

@ -335,40 +335,40 @@ var Reveal = (function(){
/** /**
* Applies the configuration settings from the config object. * Applies the configuration settings from the config object.
*/ */
function configure() { function configure( options ) {
if( supports3DTransforms === false ) { dom.wrapper.classList.remove( config.transition );
config.transition = 'linear';
}
if( config.controls && dom.controls ) { // New config options may be passed when this method
dom.controls.style.display = 'block'; // is invoked through the API after initialization
} if( typeof options === 'object' ) extend( config, options );
if( config.progress && dom.progress ) { // Force linear transition based on browser capabilities
dom.progress.style.display = 'block'; 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.controls.style.display = ( config.controls && dom.controls ) ? 'block' : 'none';
dom.wrapper.classList.add( 'rtl' ); dom.progress.style.display = ( config.progress && dom.progress ) ? 'block' : 'none';
}
if( config.center ) { dom.wrapper.classList.toggle( 'rtl', config.rtl );
dom.wrapper.classList.add( 'center' ); dom.wrapper.classList.toggle( 'center', config.center );
}
if( config.mouseWheel ) { if( config.mouseWheel ) {
document.addEventListener( 'DOMMouseScroll', onDocumentMouseScroll, false ); // FF document.addEventListener( 'DOMMouseScroll', onDocumentMouseScroll, false ); // FF
document.addEventListener( 'mousewheel', onDocumentMouseScroll, false ); document.addEventListener( 'mousewheel', onDocumentMouseScroll, false );
} }
else {
document.removeEventListener( 'DOMMouseScroll', onDocumentMouseScroll, false ); // FF
document.removeEventListener( 'mousewheel', onDocumentMouseScroll, false );
}
// 3D links // 3D links
if( config.rollingLinks ) { if( config.rollingLinks ) {
linkify(); enable3DLinks();
}
else {
disable3DLinks();
} }
// Load the theme in the config, if it's not already loaded // 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. * Wrap all links in 3D goodness.
*/ */
function linkify() { function enable3DLinks() {
if( supports3DTransforms && !( 'msPerspective' in document.body.style ) ) { 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++ ) { for( var i = 0, len = anchors.length; i < len; i++ ) {
var node = nodes[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'); var span = document.createElement('span');
span.setAttribute('data-title', node.text); span.setAttribute('data-title', anchor.text);
span.innerHTML = node.innerHTML; span.innerHTML = anchor.innerHTML;
node.classList.add( 'roll' ); anchor.classList.add( 'roll' );
node.innerHTML = ''; anchor.innerHTML = '';
node.appendChild(span); 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 * Applies JavaScript-controlled layout rules to the
* presentation. * presentation.
@ -602,14 +621,9 @@ var Reveal = (function(){
dom.slides.style.transform = transform; dom.slides.style.transform = transform;
} }
if( config.center ) {
// Select all slides, vertical and horizontal // Select all slides, vertical and horizontal
var slides = toArray( document.querySelectorAll( SLIDES_SELECTOR ) ); var slides = toArray( document.querySelectorAll( SLIDES_SELECTOR ) );
// Determine the minimum top offset for slides
var minTop = -slideHeight / 2;
for( var i = 0, len = slides.length; i < len; i++ ) { for( var i = 0, len = slides.length; i < len; i++ ) {
var slide = slides[ i ]; var slide = slides[ i ];
@ -618,15 +632,19 @@ var Reveal = (function(){
continue; continue;
} }
if( config.center ) {
// Vertical stacks are not centered since their section // Vertical stacks are not centered since their section
// children will be // children will be
if( slide.classList.contains( 'stack' ) ) { if( slide.classList.contains( 'stack' ) ) {
slide.style.top = 0; slide.style.top = 0;
} }
else { 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 { return {
initialize: initialize, initialize: initialize,
configure: configure,
// Navigation methods // Navigation methods
slide: slide, slide: slide,

4
js/reveal.min.js vendored

File diff suppressed because one or more lines are too long