"goto now accepts more types of parameters: numbers, id strings and DOM elements"
This commit is contained in:
@@ -41,6 +41,10 @@ VERSION HISTORY
|
|||||||
- `past` class is added to already visited steps (when the step is left)
|
- `past` class is added to already visited steps (when the step is left)
|
||||||
* and good news, `goto()` API method is back! it seems that `goto` **was** a future reserved word but isn't anymore,
|
* and good news, `goto()` API method is back! it seems that `goto` **was** a future reserved word but isn't anymore,
|
||||||
so we can use this short and pretty name instead of camelCassy `stepTo` - and yes, that means API changed again...
|
so we can use this short and pretty name instead of camelCassy `stepTo` - and yes, that means API changed again...
|
||||||
|
* additionally `goto()` method now supports new types of parameters:
|
||||||
|
- you can give it a number of step you want to go to: `impress().goto(7)`
|
||||||
|
- or its id: `impress().goto("the-best-slide-ever")`
|
||||||
|
- of course DOM element is still acceptable: `impress().goto( document.getElementById("overview") )`
|
||||||
|
|
||||||
### 0.4.1 ([browse](http://github.com/bartaz/impress.js/tree/0.4.1), [zip](http://github.com/bartaz/impress.js/zipball/0.4.1), [tar](http://github.com/bartaz/impress.js/tarball/0.4.1))
|
### 0.4.1 ([browse](http://github.com/bartaz/impress.js/tree/0.4.1), [zip](http://github.com/bartaz/impress.js/zipball/0.4.1), [tar](http://github.com/bartaz/impress.js/tarball/0.4.1))
|
||||||
|
|
||||||
|
|||||||
@@ -339,8 +339,9 @@ if ("ontouchstart" in document.documentElement) {
|
|||||||
|
|
||||||
`api.init()` - initializes the presentation,
|
`api.init()` - initializes the presentation,
|
||||||
`api.next()` - moves to next step of the presentation,
|
`api.next()` - moves to next step of the presentation,
|
||||||
`api.prev()` - moves to previous step of the presentation
|
`api.prev()` - moves to previous step of the presentation,
|
||||||
`api.goto( stepElement ) - moves the presentation to given step element (the DOM element of the step).
|
`api.goto( idx | id | element )` - moves the presentation to the step given by its index number,
|
||||||
|
id or the DOM element.
|
||||||
|
|
||||||
You can also simply call `impress()` again to get the API, so `impress().next()` is also allowed.
|
You can also simply call `impress()` again to get the API, so `impress().next()` is also allowed.
|
||||||
Don't worry, it wont initialize the presentation again.
|
Don't worry, it wont initialize the presentation again.
|
||||||
|
|||||||
@@ -356,10 +356,18 @@
|
|||||||
triggerEvent(root, "impress-init", { api: roots[ "impress-root-" + rootId ] });
|
triggerEvent(root, "impress-init", { api: roots[ "impress-root-" + rootId ] });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var getStep = function ( step ) {
|
||||||
|
if (typeof step === "number") {
|
||||||
|
step = step < 0 ? steps[ steps.length + step] : steps[ step ];
|
||||||
|
} else if (typeof step === "string") {
|
||||||
|
step = byId(step);
|
||||||
|
}
|
||||||
|
return (step && step.id && stepsData["impress-" + step.id]) ? step : null;
|
||||||
|
};
|
||||||
|
|
||||||
var goto = function ( el, force ) {
|
var goto = function ( el, force ) {
|
||||||
if ( !initialized ||
|
|
||||||
!(el && el.id && stepsData["impress-" + el.id]) || // element is not a step
|
if ( !initialized || !(el = getStep(el)) || (el === activeStep && !force) ) {
|
||||||
(el === activeStep && !force) ) {
|
|
||||||
// selected element is not defined as step or is already active
|
// selected element is not defined as step or is already active
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user