"navigation handlers are now added when impress is initialized"
This commit is contained in:
@@ -168,10 +168,20 @@
|
||||
transitionDuration: 1000
|
||||
};
|
||||
|
||||
var empty = function () { return false; };
|
||||
|
||||
var impress = window.impress = function ( rootId ) {
|
||||
|
||||
// if impress.js is not supported by the browser return a dummy API
|
||||
// it may not be a perfect solution but we return early and avoid
|
||||
// running code that may use features not implemented in the browser
|
||||
if (!impressSupported) {
|
||||
return null;
|
||||
return {
|
||||
init: empty,
|
||||
stepTo: empty,
|
||||
prev: empty,
|
||||
next: empty
|
||||
};
|
||||
}
|
||||
|
||||
rootId = rootId || "impress";
|
||||
@@ -191,9 +201,9 @@
|
||||
|
||||
// step events
|
||||
|
||||
var triggerEvent = function (el, eventName) {
|
||||
var triggerEvent = function (el, eventName, detail) {
|
||||
var event = document.createEvent("CustomEvent");
|
||||
event.initCustomEvent(eventName, true, true, {});
|
||||
event.initCustomEvent(eventName, true, true, detail);
|
||||
el.dispatchEvent(event);
|
||||
};
|
||||
|
||||
@@ -342,7 +352,7 @@
|
||||
|
||||
initialized = true;
|
||||
|
||||
triggerEvent(root, "impressInit");
|
||||
triggerEvent(root, "impressInit", { api: roots[ "impress-root-" + rootId ] });
|
||||
};
|
||||
|
||||
var stepTo = function ( el, force ) {
|
||||
@@ -502,13 +512,6 @@
|
||||
(function ( document, window ) {
|
||||
'use strict';
|
||||
|
||||
var impress = window.impress;
|
||||
|
||||
// if impress is not supported don't add any handlers
|
||||
if (!impress.supported) {
|
||||
return;
|
||||
}
|
||||
|
||||
// throttling function calls, by Remy Sharp
|
||||
// http://remysharp.com/2010/07/21/throttling-function-calls/
|
||||
var throttle = function (fn, delay) {
|
||||
@@ -522,6 +525,9 @@
|
||||
};
|
||||
};
|
||||
|
||||
document.addEventListener("impressInit", function (event) {
|
||||
var api = event.detail.api;
|
||||
|
||||
// keyboard navigation handlers
|
||||
|
||||
// prevent default keydown action when one of supported key is pressed
|
||||
@@ -538,14 +544,14 @@
|
||||
case 33: // pg up
|
||||
case 37: // left
|
||||
case 38: // up
|
||||
impress().prev();
|
||||
api.prev();
|
||||
break;
|
||||
case 9: // tab
|
||||
case 32: // space
|
||||
case 34: // pg down
|
||||
case 39: // right
|
||||
case 40: // down
|
||||
impress().next();
|
||||
api.next();
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -572,7 +578,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
if ( impress().stepTo(target) ) {
|
||||
if ( api.stepTo(target) ) {
|
||||
event.stopImmediatePropagation();
|
||||
event.preventDefault();
|
||||
}
|
||||
@@ -587,7 +593,7 @@
|
||||
target = target.parentNode;
|
||||
}
|
||||
|
||||
if ( impress().stepTo(target) ) {
|
||||
if ( api.stepTo(target) ) {
|
||||
event.preventDefault();
|
||||
}
|
||||
}, false);
|
||||
@@ -600,9 +606,9 @@
|
||||
result = null;
|
||||
|
||||
if ( x < width ) {
|
||||
result = impress().prev();
|
||||
result = api.prev();
|
||||
} else if ( x > window.innerWidth - width ) {
|
||||
result = impress().next();
|
||||
result = api.next();
|
||||
}
|
||||
|
||||
if (result) {
|
||||
@@ -614,7 +620,10 @@
|
||||
// rescale presentation when window is resized
|
||||
window.addEventListener("resize", throttle(function () {
|
||||
// force going to active step again, to trigger rescaling
|
||||
impress().stepTo( document.querySelector(".active"), true );
|
||||
api.stepTo( document.querySelector(".active"), true );
|
||||
}, 250), false);
|
||||
|
||||
}, false);
|
||||
|
||||
})(document, window);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user