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-12 15:08:29 +04:00
|
|
|
body = document.body;
|
2011-07-15 04:53:20 +04:00
|
|
|
slides = document.querySelectorAll('div.slide'),
|
2010-11-08 04:34:56 +03:00
|
|
|
slideList = [], hashList = {},
|
2010-11-15 16:45:40 +03:00
|
|
|
progress = document.querySelector('div.progress div'),
|
2010-11-08 04:34:56 +03:00
|
|
|
fullscreen = false;
|
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++) {
|
|
|
|
var id = slides[i].id;
|
|
|
|
slideList[i] = '#' + id;
|
|
|
|
hashList['#' + id] = i;
|
2011-07-12 15:08:29 +04:00
|
|
|
slides[i].addEventListener('click', function(){
|
|
|
|
enterSingle();
|
|
|
|
turnSlide(hashList['#' + this.id]);
|
|
|
|
}, false);
|
2010-11-08 04:34:56 +03:00
|
|
|
}
|
2010-11-01 07:35:25 +03:00
|
|
|
|
2011-07-12 15:08:29 +04:00
|
|
|
function resizeBody(p) {
|
|
|
|
if(typeof p == 'boolean' && p) {
|
|
|
|
var transform = 'none';
|
|
|
|
} else {
|
|
|
|
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) {
|
|
|
|
var current = hashList[url.hash],
|
|
|
|
target;
|
2011-07-12 15:08:29 +04:00
|
|
|
if(e.type == 'keyup') { // Key-Based
|
2010-11-08 04:34:56 +03:00
|
|
|
switch(e.which) {
|
|
|
|
case 33 : // PgUp
|
|
|
|
case 38 : // Up
|
|
|
|
case 37 : // Left
|
2011-07-15 04:53:20 +04:00
|
|
|
case 72 : // h
|
|
|
|
case 75 : // k
|
2010-11-08 04:34:56 +03:00
|
|
|
current--;
|
|
|
|
break;
|
|
|
|
case 34 : // PgDown
|
|
|
|
case 40 : // Down
|
|
|
|
case 39 : // Right
|
2011-07-15 04:53:20 +04:00
|
|
|
case 76 : // l
|
|
|
|
case 74 : // j
|
2010-11-08 04:34:56 +03:00
|
|
|
current++;
|
|
|
|
break;
|
2011-04-25 04:41:47 +04:00
|
|
|
case 36 : // Home
|
|
|
|
current = 0;
|
|
|
|
break;
|
|
|
|
case 35 : // End
|
|
|
|
current = slideList.length-1;
|
|
|
|
break;
|
2010-11-08 04:34:56 +03:00
|
|
|
case 32 : // Space
|
|
|
|
current += e.shiftKey ? -1 : 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
e.preventDefault();
|
2011-07-12 15:08:29 +04:00
|
|
|
} else {
|
|
|
|
current = e || 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;
|
2010-11-15 16:45:40 +03:00
|
|
|
updateProgress();
|
2010-11-08 02:26:01 +03:00
|
|
|
}
|
2010-10-30 04:16:19 +04:00
|
|
|
|
2011-07-12 15:08:29 +04:00
|
|
|
function enterSingle() {
|
2011-07-15 04:53:20 +04:00
|
|
|
body.className = 'full';
|
2011-07-12 15:08:29 +04:00
|
|
|
resizeBody();
|
|
|
|
updateProgress();
|
|
|
|
window.addEventListener('resize', resizeBody, false);
|
|
|
|
document.addEventListener('keyup', turnSlide, false);
|
|
|
|
document.addEventListener('keyup', exitSingleEsc, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
function exitSingle() {
|
2011-07-15 04:53:20 +04:00
|
|
|
body.className = 'list';
|
2011-07-12 15:08:29 +04:00
|
|
|
resizeBody(true);
|
|
|
|
window.removeEventListener('resize', resizeBody, false);
|
|
|
|
window.removeEventListener('keyup', turnSlide, false);
|
|
|
|
document.removeEventListener('keyup', exitSingleEsc, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
function exitSingleEsc(e) {
|
|
|
|
if(e.which != 27) return;
|
|
|
|
exitSingle();
|
|
|
|
url.hash = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
function checkHash() {
|
2011-07-15 04:53:20 +04:00
|
|
|
// if(!window.location.search.length) history.pushState(null, null, window.location.href + '?list');
|
2011-07-12 15:08:29 +04:00
|
|
|
if(typeof hashList[url.hash] != 'undefined') {
|
|
|
|
enterSingle();
|
2011-05-26 13:06:36 +04:00
|
|
|
}
|
2010-11-08 04:34:56 +03:00
|
|
|
}
|
2011-07-12 15:08:29 +04:00
|
|
|
|
2010-11-15 16:45:40 +03:00
|
|
|
function updateProgress() {
|
2010-11-16 00:39:10 +03:00
|
|
|
if(!progress) return;
|
2010-11-15 16:45:40 +03:00
|
|
|
progress.style.width = (100/(slideList.length-1) * hashList[url.hash]).toFixed(2) + '%';
|
|
|
|
}
|
2010-10-30 04:16:19 +04:00
|
|
|
|
2011-07-12 15:08:29 +04:00
|
|
|
window.addEventListener('DOMContentLoaded', checkHash, false);
|
2010-11-08 02:26:01 +03:00
|
|
|
|
2010-11-08 04:34:56 +03:00
|
|
|
})();
|