jmpressjs / jmpress.js

A jQuery plugin to build a website on the infinite canvas
http://jmpressjs.github.com/jmpress.js
1.5k stars 237 forks source link

Map one step to another step #47

Closed buddyboss closed 12 years ago

buddyboss commented 12 years ago

Is it possible to map the clicking on one step to another step? For example, if you click STEP 1, instead of zooming over to STEP 1 you are instead moved over to STEP 2 with STEP 2 selected as the "active" step.

shama commented 12 years ago

Yep, try this:

$('#jmpress').jmpress();
$('.step').click(function(e) {
    $('#jmpress').jmpress('next');
    return false;
});
sokra commented 12 years ago

There is also a data-delegate which delegates the activeness to another step (by jq-selector).

or

You use the beforeSelect event to detect clicks on steps and stop the selecting process and instead select another step. (reason parameter is "click" or so)

buddyboss commented 12 years ago

Thanks much.

"There is also a data-delegate which delegates the activeness to another step (by jq-selector)."

Do I write this inline as data-delegate="selector" ?

I'm having some trouble getting this to work.

sokra commented 12 years ago
<div class="step" id="stepA"></step>
<div class="step" id="stepB" data-delegate="#stepD"></step>
<div class="step" id="stepC"></step>
<div class="step" id="stepD"></step>

or in a template like any other property {delegate: "#stepD"}.

This modifies only the visible control flow (view) and not the internal control flow.

Camera looks at: #stepA -> #stepD -> #stepC -> #stepD -> #stepA -> ...

Hashtag: #/stepA -> #/stepB -> #/stepC -> #/stepD -> #/stepA -> ...

I don't know if it is appropiate for your usecase, I've used it for example to show the title slide again in the middle of a presentation (without copying it).

Another comment to the other option:

It is the event beforeChange and you can cancel the selection process with eventData.cancel(). Here is a example:

$("#jmpress").jmpress("beforeChange", function(el, eventData) {
  if(eventData.reason === "click" && someCodition(el)) {
    eventData.cancel();
    $("#jmpress").jmpress("select", "#someOtherStep");
  }
});
trueshot commented 12 years ago

The problem I am having with this issue is the element passed to beforeChange is already the next element instead of original element. I am trying to get the down arrow key to go to row elements: (rowA, rowB, etc.). When the right arrow is used, I want to move to rowA_colOne or rowB_colOne, etc). My code is very much like yours with the evenData.cancel, and then the select command. I use a data-right="rowA_colOne" to track which element is its right but it goes to "rowB_colOne" instead. So, is the "beforeChange" really a "beforeChangeButAfterNextElementAlreadyGrabbedAndThisElementIsIt".

Thanks. Having fun with this thing.

sokra commented 12 years ago

get the current element with this.jmpress("active")

sokra commented 12 years ago

but if you want to override the up and down keys, you should use the keybord config like in the cube example.

trueshot commented 12 years ago

Thanks. It was a little tricky, but I got it working. The tricky part was that because the last key pressed on the browser remains the same, it went into an infinite loop. Thanks for your help and I will look at the cube example again.

sokra commented 12 years ago

@trueshot any update on this?

trueshot commented 12 years ago

I got it to work fine for my purposes. I am not sure there is any general usefulness to my approach though. Thanks for the followup.

sokra commented 12 years ago

nice. I close this issue.