1

I have a javascript method which accepts the transition name as a parameter and passes it to jquery.mobile for changing page:

$.mobile.changePage(renderedPage, { transition: transition, reverse: reverse });

Now I need to check if the transition name passed to my method is a valid transition. (this is because invalid transition name will cause a break in .changePage() method)

I browsed the source code of jquery.mobile but could not find a collection that contains all transition names or transition handlers.

Anybody has a trick to do this?

Mo Valipour
  • 13,286
  • 12
  • 61
  • 87

1 Answers1

1

In jquery mobile, there are only six transitions available. you could just make sure that the given transition is in the array of available transitions. http://jquerymobile.com/demos/1.0a4.1/docs/pages/docs-transitions.html

var transitionArr = ["slide","slideup","slidedown","pop","fade","flip"];
$.mobile.changePage(renderedPage, {
  transition: $.inArray(transition,transitionArr) == -1 ? transition : "slide",
  reverse:reverse
});

However, i was unable to find an array or object in the core that directly referenced these transitions in a way that we could use to dynamically build this array.

Kevin B
  • 94,570
  • 16
  • 163
  • 180
  • +1 for $.inArray, but why are you looking up "reverse" in the transitionArr? that's just a boolean. – Mo Valipour Aug 31 '11 at 08:13
  • another issue in your code: $.inArray() returns index of element in array, so the criteria is met when the transition does not exist in the array (i.e. $.inArray() returns -1). – Mo Valipour Aug 31 '11 at 08:26
  • sry about the reverse check, i don't do any development in jquery mobile and assumed wrong. fixed. As far as the $.inArray returning -1, -1 is a false-y value, so if it comes up as -1 it will default to "slide". If you want a more exact check you can use !== -1 – Kevin B Aug 31 '11 at 13:42
  • 1
    This is wrong, any number value in js is assumed "true" unless it is equal to "0". see here: http://jsfiddle.net/Tasba/ – Mo Valipour Sep 01 '11 at 08:33
  • sorry, you are correct of course. I'm not sure where i got that from. – Kevin B Sep 01 '11 at 13:51