Skip to content

Commit

Permalink
"goto now accepts duration parameter"
Browse files Browse the repository at this point in the history
  • Loading branch information
bartaz committed Mar 14, 2012
1 parent 9d99c03 commit b0c5644
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ VERSION HISTORY
- 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") )`
* and if it's not enough, `goto()` also accepts second parameter to define the transition duration in ms, for example
`impress().goto("make-it-quick", 300)` or `impress().goto("now", 0)`


### 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))

Expand Down
5 changes: 3 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,9 @@ <h1>impress.js<sup>*</sup></h1>
`api.init()` - initializes the presentation,
`api.next()` - moves to next step of the presentation,
`api.prev()` - moves to previous step of the presentation,
`api.goto( idx | id | element )` - moves the presentation to the step given by its index number,
id or the DOM element.
`api.goto( idx | id | element, [duration] )` - moves the presentation to the step given by its index number
id or the DOM element; second parameter can be used to define duration of the transition in ms,
but it's optional - if not provided default transition duration for the presentation will be used.
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.
Expand Down
27 changes: 15 additions & 12 deletions js/impress.js
Original file line number Diff line number Diff line change
Expand Up @@ -365,10 +365,10 @@
return (step && step.id && stepsData["impress-" + step.id]) ? step : null;
};

var goto = function ( el, force ) {
var goto = function ( el, duration ) {

if ( !initialized || !(el = getStep(el)) || (el === activeStep && !force) ) {
// selected element is not defined as step or is already active
if ( !initialized || !(el = getStep(el)) ) {
// presentation not initialized or given element is not a step
return false;
}

Expand Down Expand Up @@ -409,12 +409,10 @@
// check if the transition is zooming in or not
var zoomin = target.scale >= currentState.scale;

// if presentation starts (nothing is active yet)
// don't animate (set duration to 0)
var duration = (activeStep) ? config.transitionDuration : 0,
delay = (config.transitionDuration / 2);
duration = toNumber(duration, config.transitionDuration);
var delay = (duration / 2);

if (force) {
if (el === activeStep) {
windowScale = computeWindowScale(config);
}

Expand Down Expand Up @@ -486,23 +484,28 @@
root.addEventListener("impress-init", function(){
// HASH CHANGE

var lastHash = "";

// `#/step-id` is used instead of `#step-id` to prevent default browser
// scrolling to element in hash
//
// and it has to be set after animation finishes, because in Chrome it
// causes transtion being laggy
// BUG: http://code.google.com/p/chromium/issues/detail?id=62820
root.addEventListener("impress-step-enter", function (event) {
window.location.hash = "#/" + event.target.id;
window.location.hash = lastHash = "#/" + event.target.id;
}, false);

window.addEventListener("hashchange", function () {
goto( getElementFromUrl() );
// don't go twice to same element
if (window.location.hash !== lastHash) {
goto( getElementFromUrl() );
}
}, false);

// START
// by selecting step defined in url or first step of the presentation
goto(getElementFromUrl() || steps[0]);
goto(getElementFromUrl() || steps[0], 0);
}, false);

body.classList.add("impress-disabled");
Expand Down Expand Up @@ -633,7 +636,7 @@
// rescale presentation when window is resized
window.addEventListener("resize", throttle(function () {
// force going to active step again, to trigger rescaling
api.goto( document.querySelector(".active"), true );
api.goto( document.querySelector(".active"), 500 );
}, 250), false);

}, false);
Expand Down

0 comments on commit b0c5644

Please sign in to comment.