2015-08-14 09:51:05 +03:00
|
|
|
(function() {
|
2013-12-12 01:16:55 +04:00
|
|
|
var url = window.location,
|
|
|
|
body = document.body,
|
|
|
|
slides = document.querySelectorAll('div.slide'),
|
|
|
|
progress = document.querySelector('div.progress div'),
|
|
|
|
slideList = [],
|
2015-08-14 09:51:05 +03:00
|
|
|
l = slides.length,
|
|
|
|
i;
|
2013-12-12 01:16:55 +04:00
|
|
|
if (typeof keysalive === 'undefined') {
|
|
|
|
keysalive = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < l; i++) {
|
|
|
|
var cb = document.createElement('button');
|
|
|
|
cb.className = 'cb';
|
|
|
|
cb.innerHTML = 'x';
|
|
|
|
slides[i].appendChild(cb);
|
|
|
|
slideList.push({
|
|
|
|
id: slides[i].id,
|
|
|
|
hasInnerNavigation: null !== slides[i].querySelector('.inner')
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Encode code blocks */
|
|
|
|
function encode() {
|
|
|
|
var codes = document.querySelectorAll('code');
|
|
|
|
var all = codes.length;
|
2015-08-14 09:51:05 +03:00
|
|
|
while (all--) {
|
2013-12-12 01:16:55 +04:00
|
|
|
var tc = codes[all].innerHTML;
|
2015-08-14 09:51:05 +03:00
|
|
|
if (tc.indexOf('<') !== -1) {
|
|
|
|
tc = tc.replace(/</g, '<');
|
|
|
|
tc = tc.replace(/>/g, '>');
|
|
|
|
codes[all].innerHTML = tc;
|
2013-12-12 01:16:55 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
encode();
|
2015-08-14 09:51:05 +03:00
|
|
|
|
2013-12-12 01:16:55 +04:00
|
|
|
var demos = document.querySelectorAll('[contenteditable]'),
|
2015-08-14 09:51:05 +03:00
|
|
|
alldemos = demos.length;
|
2013-12-12 01:16:55 +04:00
|
|
|
|
|
|
|
function dokeys(ev) {
|
|
|
|
keysalive = true;
|
|
|
|
}
|
2015-08-14 09:51:05 +03:00
|
|
|
|
2013-12-12 01:16:55 +04:00
|
|
|
function stopkeys(ev) {
|
|
|
|
keysalive = false;
|
|
|
|
}
|
|
|
|
while (alldemos--) {
|
|
|
|
demos[alldemos].addEventListener('focus', stopkeys, false);
|
|
|
|
demos[alldemos].addEventListener('blur', dokeys, false);
|
|
|
|
}
|
2015-08-14 09:51:05 +03:00
|
|
|
|
2013-12-12 01:16:55 +04:00
|
|
|
function getTransform() {
|
|
|
|
var denominator = Math.max(
|
|
|
|
body.clientWidth / window.innerWidth,
|
|
|
|
body.clientHeight / window.innerHeight
|
|
|
|
);
|
|
|
|
|
|
|
|
return 'scale(' + (1 / denominator) + ')';
|
|
|
|
}
|
|
|
|
|
|
|
|
function applyTransform(transform) {
|
|
|
|
body.style.WebkitTransform = transform;
|
|
|
|
body.style.MozTransform = transform;
|
|
|
|
body.style.msTransform = transform;
|
|
|
|
body.style.OTransform = transform;
|
|
|
|
body.style.transform = transform;
|
|
|
|
}
|
|
|
|
|
|
|
|
function enterSlideMode() {
|
|
|
|
body.className = 'full';
|
|
|
|
applyTransform(getTransform());
|
|
|
|
}
|
|
|
|
|
|
|
|
function enterListMode() {
|
|
|
|
body.className = 'list';
|
|
|
|
applyTransform('none');
|
|
|
|
}
|
|
|
|
|
|
|
|
function getCurrentSlideNumber() {
|
|
|
|
var i, l = slideList.length,
|
|
|
|
currentSlideId = url.hash.substr(1);
|
|
|
|
|
|
|
|
for (i = 0; i < l; ++i) {
|
|
|
|
if (currentSlideId === slideList[i].id) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
function scrollToSlide(slideNumber) {
|
2015-08-14 09:51:05 +03:00
|
|
|
if (-1 === slideNumber) {
|
|
|
|
return;
|
|
|
|
}
|
2013-12-12 01:16:55 +04:00
|
|
|
var currentSlide = document.getElementById(slideList[slideNumber].id);
|
|
|
|
if (null !== currentSlide) {
|
|
|
|
window.scrollTo(0, currentSlide.offsetTop);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function isListMode() {
|
2015-09-29 03:01:13 +03:00
|
|
|
// Should use `URLSearchParams` but modern browser support is poor.
|
|
|
|
return url.search.indexOf('?full') !== -1 || url.search.indexOf('&full') !== -1;
|
2013-12-12 01:16:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function normalizeSlideNumber(slideNumber) {
|
|
|
|
if (0 > slideNumber) {
|
|
|
|
return slideList.length - 1;
|
|
|
|
} else if (slideList.length <= slideNumber) {
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
return slideNumber;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function updateProgress(slideNumber) {
|
2015-08-14 09:51:05 +03:00
|
|
|
if (null === progress) {
|
|
|
|
return;
|
|
|
|
}
|
2013-12-12 01:16:55 +04:00
|
|
|
progress.style.width = (100 / (slideList.length - 1) * normalizeSlideNumber(slideNumber)).toFixed(2) + '%';
|
|
|
|
}
|
|
|
|
|
|
|
|
function getSlideHash(slideNumber) {
|
|
|
|
return '#' + slideList[normalizeSlideNumber(slideNumber)].id;
|
|
|
|
}
|
|
|
|
|
|
|
|
function goToSlide(slideNumber) {
|
|
|
|
var currentSlide = document.getElementById(slideList[slideNumber].id);
|
|
|
|
if (currentSlide.classList.contains('inactive')) {
|
|
|
|
goToSlide(slides[slideNumber + 1] ? slideNumber + 1 : 0);
|
|
|
|
} else {
|
|
|
|
url.hash = getSlideHash(slideNumber);
|
|
|
|
lognotes(slideNumber);
|
|
|
|
if (!isListMode()) {
|
|
|
|
updateProgress(slideNumber);
|
|
|
|
GIFrefresh(slideNumber);
|
|
|
|
playVideoIfAutoplay(slideNumber);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function GIFrefresh(slideNumber) {
|
|
|
|
if (slides[slideNumber]) {
|
|
|
|
var img = slides[slideNumber].querySelector('img');
|
|
|
|
if (img && img.src.indexOf('gif') !== -1) {
|
|
|
|
img.src = img.src;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-08-14 09:51:05 +03:00
|
|
|
|
2013-12-12 01:16:55 +04:00
|
|
|
function playVideoIfAutoplay(slideNumber) {
|
|
|
|
if (slides[slideNumber] &&
|
2015-08-14 09:51:05 +03:00
|
|
|
slides[slideNumber].className.indexOf('autoplay') !== -1) {
|
2013-12-12 01:16:55 +04:00
|
|
|
var video = slides[slideNumber].querySelector('video');
|
|
|
|
if (video) {
|
|
|
|
video.play();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function getContainingSlideId(el) {
|
|
|
|
var node = el;
|
|
|
|
while ('BODY' !== node.nodeName && 'HTML' !== node.nodeName) {
|
|
|
|
if (node.classList.contains('slide')) {
|
|
|
|
return node.id;
|
|
|
|
} else {
|
|
|
|
node = node.parentNode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
function dispatchSingleSlideMode(e) {
|
|
|
|
var slideId = getContainingSlideId(e.target);
|
|
|
|
|
|
|
|
if ('' !== slideId && isListMode()) {
|
|
|
|
e.preventDefault();
|
|
|
|
|
2015-08-14 09:51:05 +03:00
|
|
|
if (e.target.tagName === 'BUTTON' && e.target.className === 'cb') {
|
2013-12-12 01:16:55 +04:00
|
|
|
toggleSlide(e.target.parentNode);
|
|
|
|
} else {
|
|
|
|
// NOTE: we should update hash to get things work properly
|
|
|
|
url.hash = '#' + slideId;
|
|
|
|
history.replaceState(null, null, url.pathname + '?full#' + slideId);
|
|
|
|
enterSlideMode();
|
|
|
|
|
|
|
|
updateProgress(getCurrentSlideNumber());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function toggleSlide(elm) {
|
|
|
|
if (elm.classList.contains('inactive')) {
|
|
|
|
elm.classList.remove('inactive');
|
|
|
|
} else {
|
|
|
|
elm.classList.add('inactive');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Increases inner navigation by adding 'active' class to next inactive inner navigation item
|
|
|
|
function increaseInnerNavigation(slideNumber) {
|
|
|
|
// Shortcut for slides without inner navigation
|
2015-08-14 09:51:05 +03:00
|
|
|
if (true !== slideList[slideNumber].hasInnerNavigation) {
|
|
|
|
return -1;
|
|
|
|
}
|
2013-12-12 01:16:55 +04:00
|
|
|
|
|
|
|
var activeNodes = document.querySelectorAll(getSlideHash(slideNumber) + ' .active'),
|
|
|
|
// NOTE: we assume there is no other elements in inner navigation
|
|
|
|
node = activeNodes[activeNodes.length - 1].nextElementSibling;
|
|
|
|
|
|
|
|
if (null !== node) {
|
|
|
|
node.classList.add('active');
|
|
|
|
return activeNodes.length + 1;
|
|
|
|
} else {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function lognotes(slideNumber) {
|
|
|
|
if (window.console && slideList[slideNumber]) {
|
2015-08-14 09:51:05 +03:00
|
|
|
var notes = document.querySelector('#' + slideList[slideNumber].id + ' .notes');
|
2013-12-12 01:16:55 +04:00
|
|
|
if (notes) {
|
2015-08-14 09:51:05 +03:00
|
|
|
console.info(notes.innerHTML.replace(/\n\s+/g, '\n'));
|
2013-12-12 01:16:55 +04:00
|
|
|
}
|
2015-08-14 09:51:05 +03:00
|
|
|
if (slideList[slideNumber + 1]) {
|
|
|
|
var next = document.querySelector('#' + slideList[slideNumber + 1].id + ' header');
|
2013-12-12 01:16:55 +04:00
|
|
|
if (next) {
|
2015-08-14 09:51:05 +03:00
|
|
|
next = next.innerHTML.replace(/^\s+|<[^>]+>/g, '');
|
2013-12-12 01:16:55 +04:00
|
|
|
console.info('NEXT: ' + next);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Event handlers
|
|
|
|
|
2015-08-14 09:51:05 +03:00
|
|
|
window.addEventListener('DOMContentLoaded', function() {
|
2013-12-12 01:16:55 +04:00
|
|
|
if (!isListMode()) {
|
|
|
|
// "?full" is present without slide hash, so we should display first slide
|
|
|
|
if (-1 === getCurrentSlideNumber()) {
|
|
|
|
history.replaceState(null, null, url.pathname + '?full' + getSlideHash(0));
|
|
|
|
}
|
|
|
|
enterSlideMode();
|
|
|
|
updateProgress(getCurrentSlideNumber());
|
|
|
|
}
|
|
|
|
}, false);
|
|
|
|
|
2015-08-14 09:51:05 +03:00
|
|
|
window.addEventListener('popstate', function(e) {
|
2013-12-12 01:16:55 +04:00
|
|
|
if (isListMode()) {
|
|
|
|
enterListMode();
|
|
|
|
scrollToSlide(getCurrentSlideNumber());
|
|
|
|
} else {
|
|
|
|
enterSlideMode();
|
|
|
|
}
|
|
|
|
}, false);
|
|
|
|
|
2015-08-14 09:51:05 +03:00
|
|
|
window.addEventListener('resize', function(e) {
|
2013-12-12 01:16:55 +04:00
|
|
|
if (!isListMode()) {
|
|
|
|
applyTransform(getTransform());
|
|
|
|
}
|
|
|
|
}, false);
|
|
|
|
|
2015-08-14 09:51:05 +03:00
|
|
|
document.addEventListener('keydown', function(e) {
|
|
|
|
if (!keysalive) {
|
|
|
|
return;
|
|
|
|
}
|
2013-12-12 01:16:55 +04:00
|
|
|
// Shortcut for alt, shift and meta keys
|
2015-08-14 09:51:05 +03:00
|
|
|
if (e.altKey || e.ctrlKey || e.metaKey) {
|
|
|
|
return;
|
|
|
|
}
|
2013-12-12 01:16:55 +04:00
|
|
|
|
|
|
|
var currentSlideNumber = getCurrentSlideNumber();
|
|
|
|
switch (e.which) {
|
|
|
|
case 116: // F5
|
|
|
|
case 13: // Enter
|
|
|
|
if (isListMode() && -1 !== currentSlideNumber) {
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
history.pushState(null, null, url.pathname + '?full' + getSlideHash(currentSlideNumber));
|
|
|
|
enterSlideMode();
|
|
|
|
|
|
|
|
updateProgress(currentSlideNumber);
|
|
|
|
}
|
2015-08-14 09:51:05 +03:00
|
|
|
break;
|
2013-12-12 01:16:55 +04:00
|
|
|
|
|
|
|
case 27: // Esc
|
|
|
|
if (!isListMode()) {
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
history.pushState(null, null, url.pathname + getSlideHash(currentSlideNumber));
|
|
|
|
enterListMode();
|
|
|
|
scrollToSlide(currentSlideNumber);
|
|
|
|
}
|
2015-08-14 09:51:05 +03:00
|
|
|
break;
|
2013-12-12 01:16:55 +04:00
|
|
|
|
|
|
|
case 33: // PgUp
|
|
|
|
case 38: // Up
|
|
|
|
case 37: // Left
|
|
|
|
case 72: // h
|
|
|
|
case 75: // k
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
currentSlideNumber--;
|
|
|
|
goToSlide(currentSlideNumber);
|
2015-08-14 09:51:05 +03:00
|
|
|
break;
|
2013-12-12 01:16:55 +04:00
|
|
|
|
|
|
|
case 34: // PgDown
|
|
|
|
case 40: // Down
|
|
|
|
case 39: // Right
|
|
|
|
case 76: // l
|
|
|
|
case 74: // j
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
// Only go to next slide if current slide have no inner
|
|
|
|
// navigation or inner navigation is fully shown
|
|
|
|
// NOTE: But first of all check if there is no current slide
|
2015-08-14 09:51:05 +03:00
|
|
|
if (-1 === currentSlideNumber ||
|
2013-12-12 01:16:55 +04:00
|
|
|
!slideList[currentSlideNumber].hasInnerNavigation ||
|
|
|
|
-1 === increaseInnerNavigation(currentSlideNumber)
|
|
|
|
) {
|
|
|
|
currentSlideNumber++;
|
|
|
|
goToSlide(currentSlideNumber);
|
|
|
|
}
|
2015-08-14 09:51:05 +03:00
|
|
|
break;
|
2013-12-12 01:16:55 +04:00
|
|
|
|
|
|
|
case 36: // Home
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
currentSlideNumber = 0;
|
|
|
|
goToSlide(currentSlideNumber);
|
2015-08-14 09:51:05 +03:00
|
|
|
break;
|
2013-12-12 01:16:55 +04:00
|
|
|
|
|
|
|
case 35: // End
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
currentSlideNumber = slideList.length - 1;
|
|
|
|
goToSlide(currentSlideNumber);
|
2015-08-14 09:51:05 +03:00
|
|
|
break;
|
2013-12-12 01:16:55 +04:00
|
|
|
|
|
|
|
case 9: // Tab = +1; Shift + Tab = -1
|
|
|
|
case 32: // Space = +1; Shift + Space = -1
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
currentSlideNumber += e.shiftKey ? -1 : 1;
|
|
|
|
goToSlide(currentSlideNumber);
|
2015-08-14 09:51:05 +03:00
|
|
|
break;
|
2013-12-12 01:16:55 +04:00
|
|
|
case 78:
|
|
|
|
slides[currentSlideNumber].classList.toggle('peek');
|
2015-08-14 09:51:05 +03:00
|
|
|
break;
|
2013-12-12 01:16:55 +04:00
|
|
|
default:
|
|
|
|
// Behave as usual
|
|
|
|
}
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
document.addEventListener('click', dispatchSingleSlideMode, false);
|
|
|
|
document.addEventListener('touchend', dispatchSingleSlideMode, false);
|
|
|
|
|
2015-08-14 09:51:05 +03:00
|
|
|
document.addEventListener('touchstart', function(e) {
|
2013-12-12 01:16:55 +04:00
|
|
|
if (!isListMode()) {
|
|
|
|
var currentSlideNumber = getCurrentSlideNumber(),
|
|
|
|
x = e.touches[0].pageX;
|
|
|
|
if (x > window.innerWidth / 2) {
|
|
|
|
currentSlideNumber++;
|
|
|
|
} else {
|
|
|
|
currentSlideNumber--;
|
|
|
|
}
|
|
|
|
|
|
|
|
goToSlide(currentSlideNumber);
|
|
|
|
}
|
|
|
|
}, false);
|
|
|
|
|
2015-08-14 09:51:05 +03:00
|
|
|
document.addEventListener('touchmove', function(e) {
|
2013-12-12 01:16:55 +04:00
|
|
|
if (!isListMode()) {
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
}());
|
|
|
|
|
|
|
|
function goFullScreen() {
|
|
|
|
document.fullscreenEnabled = document.fullscreenEnabled ||
|
2015-08-14 09:51:05 +03:00
|
|
|
document.mozFullScreenEnabled ||
|
|
|
|
document.documentElement.webkitRequestFullScreen;
|
|
|
|
|
|
|
|
function requestFullscreen(element) {
|
|
|
|
if (element.requestFullscreen) {
|
2013-12-12 01:16:55 +04:00
|
|
|
element.requestFullscreen();
|
2015-08-14 09:51:05 +03:00
|
|
|
} else if (element.mozRequestFullScreen) {
|
2013-12-12 01:16:55 +04:00
|
|
|
element.mozRequestFullScreen();
|
2015-08-14 09:51:05 +03:00
|
|
|
} else if (element.webkitRequestFullScreen) {
|
|
|
|
element.webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT);
|
2013-12-12 01:16:55 +04:00
|
|
|
}
|
|
|
|
}
|
2015-08-14 09:51:05 +03:00
|
|
|
if (document.fullscreenEnabled) {
|
|
|
|
requestFullscreen(document.documentElement);
|
2013-12-12 01:16:55 +04:00
|
|
|
}
|
2015-08-13 05:31:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
var lang = 'en-US';
|
|
|
|
try {
|
|
|
|
lang = new URL(window.location).searchParams.get('lang');
|
|
|
|
} catch (ex) {
|
2015-08-14 09:51:05 +03:00
|
|
|
// searchParams isn't supported in all browsers
|
2015-08-13 05:31:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Pre-selects the correct current language on the dropdown menu
|
|
|
|
document.getElementById('langMenuId').value = lang;
|
|
|
|
|
2015-08-14 09:51:05 +03:00
|
|
|
function changeLanguage() {
|
2015-08-13 05:31:31 +03:00
|
|
|
var langObj = document.getElementById('langMenuId');
|
|
|
|
document.documentElement.lang = langObj.value;
|
|
|
|
|
|
|
|
// Update the language code in the URL bar
|
|
|
|
try {
|
|
|
|
var url = new URL(window.location);
|
|
|
|
url.searchParams.set('lang', langObj.value);
|
|
|
|
history.replaceState({}, document.title, url);
|
|
|
|
} catch (ex) {
|
|
|
|
// This might not be supported in all browsers
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
changeLanguage();
|