2010-11-15 16:45:40 +03:00
|
|
|
(function() {
|
2011-07-12 15:08:29 +04:00
|
|
|
|
2011-07-15 04:53:20 +04:00
|
|
|
var url = window.location,
|
2011-07-16 04:52:21 +04:00
|
|
|
body = document.body,
|
2011-07-15 04:53:20 +04:00
|
|
|
slides = document.querySelectorAll('div.slide'),
|
2010-11-15 16:45:40 +03:00
|
|
|
progress = document.querySelector('div.progress div'),
|
2011-07-16 04:52:21 +04:00
|
|
|
slideList = [];
|
2010-10-30 04:16:19 +04:00
|
|
|
|
2010-11-08 04:34:56 +03:00
|
|
|
for(var i = 0, slidesLength = slides.length; i < slidesLength; i++) {
|
2011-07-16 04:52:21 +04:00
|
|
|
slides[i].addEventListener('click', enterFull, false);
|
|
|
|
slideList[i] = slides[i].id;
|
2010-11-08 04:34:56 +03:00
|
|
|
}
|
2011-07-16 05:13:35 +04:00
|
|
|
|
2011-07-16 04:52:21 +04:00
|
|
|
function resizeFull(p) {
|
2011-07-16 05:13:35 +04:00
|
|
|
if(typeof p == 'boolean' && !p) {
|
|
|
|
var transform = 'none';
|
|
|
|
} else {
|
2011-07-12 15:08:29 +04:00
|
|
|
var sx = body.clientWidth / window.innerWidth,
|
|
|
|
sy = body.clientHeight / window.innerHeight,
|
|
|
|
transform = 'scale(' + (1/Math.max(sx, sy)) + ')';
|
|
|
|
}
|
|
|
|
body.style.MozTransform = transform;
|
|
|
|
body.style.WebkitTransform = transform;
|
|
|
|
body.style.OTransform = transform;
|
|
|
|
body.style.msTransform = transform;
|
|
|
|
body.style.transform = transform;
|
2010-11-08 04:34:56 +03:00
|
|
|
}
|
2011-07-12 15:18:02 +04:00
|
|
|
|
2010-11-08 04:34:56 +03:00
|
|
|
function turnSlide(e) {
|
2011-07-16 04:52:21 +04:00
|
|
|
var current = slideList.indexOf(url.hash.substr(1));
|
|
|
|
if(e) {
|
|
|
|
if(e.type == 'keydown') {
|
2011-07-16 14:01:16 +04:00
|
|
|
var prevent = true;
|
2011-07-16 04:52:21 +04:00
|
|
|
switch(e.which) {
|
|
|
|
case 33 : // PgUp
|
|
|
|
case 38 : // Up
|
|
|
|
case 37 : // Left
|
|
|
|
case 75 : // k
|
|
|
|
current--;
|
|
|
|
break;
|
|
|
|
case 34 : // PgDown
|
|
|
|
case 40 : // Down
|
|
|
|
case 39 : // Right
|
|
|
|
case 74 : // j
|
|
|
|
current++;
|
|
|
|
break;
|
|
|
|
case 36 : // Home
|
|
|
|
current = 0;
|
|
|
|
break;
|
|
|
|
case 35 : // End
|
|
|
|
current = slideList.length-1;
|
|
|
|
break;
|
|
|
|
case 32 : // Space
|
|
|
|
current += e.shiftKey ? -1 : 1;
|
|
|
|
break;
|
2011-07-16 14:01:16 +04:00
|
|
|
case 13 : // Enter
|
|
|
|
if(!current+1) enterFull();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
prevent = false;
|
2011-07-16 04:52:21 +04:00
|
|
|
}
|
2011-07-16 14:01:16 +04:00
|
|
|
if(prevent) e.preventDefault();
|
2011-07-16 04:52:21 +04:00
|
|
|
}
|
|
|
|
if(e.type == 'click') {
|
|
|
|
current = slideList.indexOf(e.target.parentNode.id);
|
2010-11-08 04:34:56 +03:00
|
|
|
}
|
2011-07-12 15:08:29 +04:00
|
|
|
} else {
|
2011-07-16 04:52:21 +04:00
|
|
|
current = (current+1) ? current : 0;
|
2010-11-08 02:26:01 +03:00
|
|
|
}
|
2011-07-12 15:08:29 +04:00
|
|
|
target = slideList[current];
|
2010-11-08 04:34:56 +03:00
|
|
|
if(target) url.hash = target;
|
2011-07-16 14:01:16 +04:00
|
|
|
updateProgress();
|
2010-11-08 02:26:01 +03:00
|
|
|
}
|
2010-10-30 04:16:19 +04:00
|
|
|
|
2011-07-16 04:52:21 +04:00
|
|
|
function enterFull(e) {
|
2011-07-15 04:53:20 +04:00
|
|
|
body.className = 'full';
|
2011-07-16 05:13:35 +04:00
|
|
|
resizeFull(true);
|
2011-07-16 04:52:21 +04:00
|
|
|
turnSlide(e);
|
2011-07-16 14:01:16 +04:00
|
|
|
updateProgress();
|
2011-07-16 04:52:21 +04:00
|
|
|
if(!isFull()) history.pushState(null, null, url.pathname + '?full' + url.hash);
|
2011-07-16 05:13:35 +04:00
|
|
|
window.addEventListener('resize', resizeFull, false);
|
2011-07-16 04:52:21 +04:00
|
|
|
document.addEventListener('keyup', exitFullEsc, false);
|
2011-07-12 15:08:29 +04:00
|
|
|
}
|
|
|
|
|
2011-07-16 04:52:21 +04:00
|
|
|
function exitFull() {
|
2011-07-15 04:53:20 +04:00
|
|
|
body.className = 'list';
|
2011-07-16 05:13:35 +04:00
|
|
|
resizeFull(false);
|
2011-07-16 14:01:16 +04:00
|
|
|
var hash = url.hash;
|
|
|
|
history.pushState(null, null, url.pathname.replace('?full', ''));
|
|
|
|
url.hash = hash;
|
2011-07-16 05:13:35 +04:00
|
|
|
window.removeEventListener('resize', resizeFull, false);
|
2011-07-16 04:52:21 +04:00
|
|
|
document.removeEventListener('keyup', exitFullEsc, false);
|
2011-07-12 15:08:29 +04:00
|
|
|
}
|
2011-07-16 05:13:35 +04:00
|
|
|
|
2011-07-16 04:52:21 +04:00
|
|
|
function exitFullEsc(e) {
|
2011-07-12 15:08:29 +04:00
|
|
|
if(e.which != 27) return;
|
2011-07-16 04:52:21 +04:00
|
|
|
exitFull();
|
2010-11-08 04:34:56 +03:00
|
|
|
}
|
2011-07-12 15:08:29 +04:00
|
|
|
|
2011-07-16 04:52:21 +04:00
|
|
|
function isFull() {
|
|
|
|
return url.search.substr(1) == 'full';
|
2010-11-15 16:45:40 +03:00
|
|
|
}
|
2010-10-30 04:16:19 +04:00
|
|
|
|
2011-07-16 14:01:16 +04:00
|
|
|
function updateProgress() {
|
|
|
|
if(!progress) return;
|
|
|
|
progress.style.width = (100/(slideList.length-1) * slideList.indexOf(url.hash.substr(1))).toFixed(2) + '%';
|
|
|
|
}
|
|
|
|
|
2011-07-16 04:52:21 +04:00
|
|
|
window.addEventListener('DOMContentLoaded', function() {
|
|
|
|
if(isFull()) enterFull();
|
|
|
|
}, false);
|
|
|
|
document.addEventListener('keydown', turnSlide, false);
|
2010-11-08 02:26:01 +03:00
|
|
|
|
2010-11-08 04:34:56 +03:00
|
|
|
})();
|