refactor js, more natural order of startup methods

This commit is contained in:
Hakim El Hattab committed 2013-08-15 08:54:17 -04:00
1 parent ac3f021a14
commit ead85fd475
2 files changed
+103 -103

No files matched your search

+101 -101
View File
@@ -209,6 +209,94 @@ var Reveal = (function(){
} }
/**
* Loads the dependencies of reveal.js. Dependencies are
* defined via the configuration option 'dependencies'
* and will be loaded prior to starting/binding reveal.js.
* Some dependencies may have an 'async' flag, if so they
* will load after reveal.js has been started up.
*/
function load() {
var scripts = [],
scriptsAsync = [];
for( var i = 0, len = config.dependencies.length; i < len; i++ ) {
var s = config.dependencies[i];
// Load if there's no condition or the condition is truthy
if( !s.condition || s.condition() ) {
if( s.async ) {
scriptsAsync.push( s.src );
}
else {
scripts.push( s.src );
}
// Extension may contain callback functions
if( typeof s.callback === 'function' ) {
head.ready( s.src.match( /([\w\d_\-]*)\.?js$|[^\\\/]*$/i )[0], s.callback );
}
}
}
// Called once synchronous scripts finish loading
function proceed() {
if( scriptsAsync.length ) {
// Load asynchronous scripts
head.js.apply( null, scriptsAsync );
}
start();
}
if( scripts.length ) {
head.ready( proceed );
// Load synchronous scripts
head.js.apply( null, scripts );
}
else {
proceed();
}
}
/**
* Starts up reveal.js by binding input events and navigating
* to the current URL deeplink if there is one.
*/
function start() {
// Make sure we've got all the DOM elements we need
setupDOM();
// Decorate the slide DOM elements with state classes (past/future)
setupSlides();
// Updates the presentation to match the current configuration values
configure();
// Read the initial hash
readURL();
// Notify listeners that the presentation is ready but use a 1ms
// timeout to ensure it's not fired synchronously after #initialize()
setTimeout( function() {
// Enable transitions now that we're loaded
dom.slides.classList.remove( 'no-transition' );
loaded = true;
dispatchEvent( 'ready', {
'indexh': indexh,
'indexv': indexv,
'currentSlide': currentSlide
} );
}, 1 );
}
/** /**
* Iterates through and decorates slides DOM elements with * Iterates through and decorates slides DOM elements with
* appropriate classes. * appropriate classes.
@@ -383,107 +471,6 @@ var Reveal = (function(){
} }
/**
* Hides the address bar if we're on a mobile device.
*/
function hideAddressBar() {
if( /iphone|ipod|android/gi.test( navigator.userAgent ) && !/crios/gi.test( navigator.userAgent ) ) {
// Events that should trigger the address bar to hide
window.addEventListener( 'load', removeAddressBar, false );
window.addEventListener( 'orientationchange', removeAddressBar, false );
}
}
/**
* Loads the dependencies of reveal.js. Dependencies are
* defined via the configuration option 'dependencies'
* and will be loaded prior to starting/binding reveal.js.
* Some dependencies may have an 'async' flag, if so they
* will load after reveal.js has been started up.
*/
function load() {
var scripts = [],
scriptsAsync = [];
for( var i = 0, len = config.dependencies.length; i < len; i++ ) {
var s = config.dependencies[i];
// Load if there's no condition or the condition is truthy
if( !s.condition || s.condition() ) {
if( s.async ) {
scriptsAsync.push( s.src );
}
else {
scripts.push( s.src );
}
// Extension may contain callback functions
if( typeof s.callback === 'function' ) {
head.ready( s.src.match( /([\w\d_\-]*)\.?js$|[^\\\/]*$/i )[0], s.callback );
}
}
}
// Called once synchronous scripts finish loading
function proceed() {
if( scriptsAsync.length ) {
// Load asynchronous scripts
head.js.apply( null, scriptsAsync );
}
start();
}
if( scripts.length ) {
head.ready( proceed );
// Load synchronous scripts
head.js.apply( null, scripts );
}
else {
proceed();
}
}
/**
* Starts up reveal.js by binding input events and navigating
* to the current URL deeplink if there is one.
*/
function start() {
// Make sure we've got all the DOM elements we need
setupDOM();
// Decorate the slide DOM elements with state classes (past/future)
setupSlides();
// Updates the presentation to match the current configuration values
configure();
// Read the initial hash
readURL();
// Notify listeners that the presentation is ready but use a 1ms
// timeout to ensure it's not fired synchronously after #initialize()
setTimeout( function() {
// Enable transitions now that we're loaded
dom.slides.classList.remove( 'no-transition' );
loaded = true;
dispatchEvent( 'ready', {
'indexh': indexh,
'indexv': indexv,
'currentSlide': currentSlide
} );
}, 1 );
}
/** /**
* Applies the configuration settings from the config * Applies the configuration settings from the config
* object. May be called multiple times. * object. May be called multiple times.
@@ -744,6 +731,19 @@ var Reveal = (function(){
} }
/**
* Hides the address bar if we're on a mobile device.
*/
function hideAddressBar() {
if( /iphone|ipod|android/gi.test( navigator.userAgent ) && !/crios/gi.test( navigator.userAgent ) ) {
// Events that should trigger the address bar to hide
window.addEventListener( 'load', removeAddressBar, false );
window.addEventListener( 'orientationchange', removeAddressBar, false );
}
}
/** /**
* Causes the address bar to hide on mobile devices, * Causes the address bar to hide on mobile devices,
* more vertical space ftw. * more vertical space ftw.
+2 -2
View File
@@ -1,8 +1,8 @@
/*! /*!
* reveal.js 2.5.0 (2013-08-15, 08:50) * reveal.js 2.5.0 (2013-08-15, 08:53)
* http://lab.hakim.se/reveal-js * http://lab.hakim.se/reveal-js
* MIT licensed * MIT licensed
* *
* Copyright (C) 2013 Hakim El Hattab, http://hakim.se * Copyright (C) 2013 Hakim El Hattab, http://hakim.se
*/ */
var Reveal=function(){"use strict";function e(e){return t(),Rt||Ct?(window.addEventListener("load",x,!1),f(zt,e),i(),s(),void 0):(document.body.setAttribute("class","no-transforms"),void 0)}function t(){Ct="WebkitPerspective"in document.body.style||"MozPerspective"in document.body.style||"msPerspective"in document.body.style||"OPerspective"in document.body.style||"perspective"in document.body.style,Rt="WebkitTransform"in document.body.style||"MozTransform"in document.body.style||"msTransform"in document.body.style||"OTransform"in document.body.style||"transform"in document.body.style,It=navigator.userAgent.match(/(iphone|ipod|android)/gi)}function n(){var e=v(document.querySelectorAll(Xt));e.forEach(function(e){var t=v(e.querySelectorAll("section"));t.forEach(function(e,t){t>0&&e.classList.add("future")})})}function r(){_t.theme=document.querySelector("#theme"),_t.wrapper=document.querySelector(".reveal"),_t.slides=document.querySelector(".reveal .slides"),_t.slides.classList.add("no-transition"),_t.background=o(_t.wrapper,"div","backgrounds",null),_t.progress=o(_t.wrapper,"div","progress","<span></span>"),_t.progressbar=_t.progress.querySelector("span"),o(_t.wrapper,"aside","controls",'<div class="navigate-left"></div><div class="navigate-right"></div><div class="navigate-up"></div><div class="navigate-down"></div>'),o(_t.wrapper,"div","state-background",null),o(_t.wrapper,"div","pause-overlay",null),zt.controls&&(_t.controls=document.querySelector(".reveal .controls"),_t.controlsLeft=v(document.querySelectorAll(".navigate-left")),_t.controlsRight=v(document.querySelectorAll(".navigate-right")),_t.controlsUp=v(document.querySelectorAll(".navigate-up")),_t.controlsDown=v(document.querySelectorAll(".navigate-down")),_t.controlsPrev=v(document.querySelectorAll(".navigate-prev")),_t.controlsNext=v(document.querySelectorAll(".navigate-next")))}function o(e,t,n,r){var o=e.querySelector("."+n);return o||(o=document.createElement(t),o.classList.add(n),null!==r&&(o.innerHTML=r),e.appendChild(o)),o}function a(){function e(e,t){var n={background:e.getAttribute("data-background"),backgroundSize:e.getAttribute("data-background-size"),backgroundImage:e.getAttribute("data-background-image"),backgroundColor:e.getAttribute("data-background-color"),backgroundRepeat:e.getAttribute("data-background-repeat"),backgroundPosition:e.getAttribute("data-background-position"),backgroundTransition:e.getAttribute("data-background-transition")},r=document.createElement("div");return r.className="slide-background",n.background&&(/^(http|file|\/\/)/gi.test(n.background)||/\.(png|jpg|jpeg|gif|bmp)$/gi.test(n.background)?r.style.backgroundImage="url("+n.background+")":r.style.background=n.background),n.backgroundSize&&(r.style.backgroundSize=n.backgroundSize),n.backgroundImage&&(r.style.backgroundImage='url("'+n.backgroundImage+'")'),n.backgroundColor&&(r.style.backgroundColor=n.backgroundColor),n.backgroundRepeat&&(r.style.backgroundRepeat=n.backgroundRepeat),n.backgroundPosition&&(r.style.backgroundPosition=n.backgroundPosition),n.backgroundTransition&&r.setAttribute("data-background-transition",n.backgroundTransition),t.appendChild(r),r}h()&&document.body.classList.add("print-pdf"),_t.background.innerHTML="",_t.background.classList.add("no-transition"),v(document.querySelectorAll(Xt)).forEach(function(t){var n;n=h()?e(t,t):e(t,_t.background),v(t.querySelectorAll("section")).forEach(function(t){h()?e(t,t):e(t,n)})})}function i(){/iphone|ipod|android/gi.test(navigator.userAgent)&&!/crios/gi.test(navigator.userAgent)&&(window.addEventListener("load",y,!1),window.addEventListener("orientationchange",y,!1))}function s(){function e(){n.length&&head.js.apply(null,n),c()}for(var t=[],n=[],r=0,o=zt.dependencies.length;o>r;r++){var a=zt.dependencies[r];(!a.condition||a.condition())&&(a.async?n.push(a.src):t.push(a.src),"function"==typeof a.callback&&head.ready(a.src.match(/([\w\d_\-]*)\.?js$|[^\\\/]*$/i)[0],a.callback))}t.length?(head.ready(e),head.js.apply(null,t)):e()}function c(){r(),n(),l(),B(),setTimeout(function(){_t.slides.classList.remove("no-transition"),Ut=!0,b("ready",{indexh:Mt,indexv:Pt,currentSlide:Nt})},1)}function l(e){if(_t.wrapper.classList.remove(zt.transition),"object"==typeof e&&f(zt,e),Ct===!1&&(zt.transition="linear"),_t.wrapper.classList.add(zt.transition),_t.wrapper.setAttribute("data-transition-speed",zt.transitionSpeed),_t.wrapper.setAttribute("data-background-transition",zt.backgroundTransition),_t.controls&&(_t.controls.style.display=zt.controls&&_t.controls?"block":"none"),_t.progress&&(_t.progress.style.display=zt.progress&&_t.progress?"block":"none"),zt.rtl?_t.wrapper.classList.add("rtl"):_t.wrapper.classList.remove("rtl"),zt.center?_t.wrapper.classList.add("center"):_t.wrapper.classList.remove("center"),zt.mouseWheel?(document.addEventListener("DOMMouseScroll",ht,!1),document.addEventListener("mousewheel",ht,!1)):(document.removeEventListener("DOMMouseScroll",ht,!1),document.removeEventListener("mousewheel",ht,!1)Line truncated var Reveal=function(){"use strict";function e(e){return t(),Rt||Ct?(window.addEventListener("load",x,!1),d(zt,e),h(),n(),void 0):(document.body.setAttribute("class","no-transforms"),void 0)}function t(){Ct="WebkitPerspective"in document.body.style||"MozPerspective"in document.body.style||"msPerspective"in document.body.style||"OPerspective"in document.body.style||"perspective"in document.body.style,Rt="WebkitTransform"in document.body.style||"MozTransform"in document.body.style||"msTransform"in document.body.style||"OTransform"in document.body.style||"transform"in document.body.style,It=navigator.userAgent.match(/(iphone|ipod|android)/gi)}function n(){function e(){n.length&&head.js.apply(null,n),r()}for(var t=[],n=[],o=0,a=zt.dependencies.length;a>o;o++){var i=zt.dependencies[o];(!i.condition||i.condition())&&(i.async?n.push(i.src):t.push(i.src),"function"==typeof i.callback&&head.ready(i.src.match(/([\w\d_\-]*)\.?js$|[^\\\/]*$/i)[0],i.callback))}t.length?(head.ready(e),head.js.apply(null,t)):e()}function r(){a(),o(),c(),B(),setTimeout(function(){_t.slides.classList.remove("no-transition"),Ut=!0,b("ready",{indexh:Mt,indexv:Pt,currentSlide:Nt})},1)}function o(){var e=f(document.querySelectorAll(Xt));e.forEach(function(e){var t=f(e.querySelectorAll("section"));t.forEach(function(e,t){t>0&&e.classList.add("future")})})}function a(){_t.theme=document.querySelector("#theme"),_t.wrapper=document.querySelector(".reveal"),_t.slides=document.querySelector(".reveal .slides"),_t.slides.classList.add("no-transition"),_t.background=i(_t.wrapper,"div","backgrounds",null),_t.progress=i(_t.wrapper,"div","progress","<span></span>"),_t.progressbar=_t.progress.querySelector("span"),i(_t.wrapper,"aside","controls",'<div class="navigate-left"></div><div class="navigate-right"></div><div class="navigate-up"></div><div class="navigate-down"></div>'),i(_t.wrapper,"div","state-background",null),i(_t.wrapper,"div","pause-overlay",null),zt.controls&&(_t.controls=document.querySelector(".reveal .controls"),_t.controlsLeft=f(document.querySelectorAll(".navigate-left")),_t.controlsRight=f(document.querySelectorAll(".navigate-right")),_t.controlsUp=f(document.querySelectorAll(".navigate-up")),_t.controlsDown=f(document.querySelectorAll(".navigate-down")),_t.controlsPrev=f(document.querySelectorAll(".navigate-prev")),_t.controlsNext=f(document.querySelectorAll(".navigate-next")))}function i(e,t,n,r){var o=e.querySelector("."+n);return o||(o=document.createElement(t),o.classList.add(n),null!==r&&(o.innerHTML=r),e.appendChild(o)),o}function s(){function e(e,t){var n={background:e.getAttribute("data-background"),backgroundSize:e.getAttribute("data-background-size"),backgroundImage:e.getAttribute("data-background-image"),backgroundColor:e.getAttribute("data-background-color"),backgroundRepeat:e.getAttribute("data-background-repeat"),backgroundPosition:e.getAttribute("data-background-position"),backgroundTransition:e.getAttribute("data-background-transition")},r=document.createElement("div");return r.className="slide-background",n.background&&(/^(http|file|\/\/)/gi.test(n.background)||/\.(png|jpg|jpeg|gif|bmp)$/gi.test(n.background)?r.style.backgroundImage="url("+n.background+")":r.style.background=n.background),n.backgroundSize&&(r.style.backgroundSize=n.backgroundSize),n.backgroundImage&&(r.style.backgroundImage='url("'+n.backgroundImage+'")'),n.backgroundColor&&(r.style.backgroundColor=n.backgroundColor),n.backgroundRepeat&&(r.style.backgroundRepeat=n.backgroundRepeat),n.backgroundPosition&&(r.style.backgroundPosition=n.backgroundPosition),n.backgroundTransition&&r.setAttribute("data-background-transition",n.backgroundTransition),t.appendChild(r),r}m()&&document.body.classList.add("print-pdf"),_t.background.innerHTML="",_t.background.classList.add("no-transition"),f(document.querySelectorAll(Xt)).forEach(function(t){var n;n=m()?e(t,t):e(t,_t.background),f(t.querySelectorAll("section")).forEach(function(t){m()?e(t,t):e(t,n)})})}function c(e){if(_t.wrapper.classList.remove(zt.transition),"object"==typeof e&&d(zt,e),Ct===!1&&(zt.transition="linear"),_t.wrapper.classList.add(zt.transition),_t.wrapper.setAttribute("data-transition-speed",zt.transitionSpeed),_t.wrapper.setAttribute("data-background-transition",zt.backgroundTransition),_t.controls&&(_t.controls.style.display=zt.controls&&_t.controls?"block":"none"),_t.progress&&(_t.progress.style.display=zt.progress&&_t.progress?"block":"none"),zt.rtl?_t.wrapper.classList.add("rtl"):_t.wrapper.classList.remove("rtl"),zt.center?_t.wrapper.classList.add("center"):_t.wrapper.classList.remove("center"),zt.mouseWheel?(document.addEventListener("DOMMouseScroll",ht,!1),document.addEventListener("mousewheel",ht,!1)):(document.removeEventListener("DOMMouseScroll",ht,!1),document.removeEventListener("mousewheel",ht,!1)),zt.rollingLinks?w():L(),zt.previewLinks?E():(k(),E("[data-preview-link]")),zt.theme&&_t.theme){var t=_t.theme.getAttribute("href"),n=/[^\/]*?(?=\.css)/,r=t.match(n)[0];zt.theme!==r&&(t=t.reLine truncated