Bidirectional Utils.cycle() for Framer
August 20, 2017 ยท View on GitHub
Framer's Utils.cycle() extension that allows you to browse arrays in both directions (instead of returning only next item).
How To Use (Try the live demo)
or
- Copy the
Utilscycle.coffeefile to your prototype'smodulesfolder. - Call
Utilscycle = require "Utilscycle"in your Framer prototype. - Now your Utils.cycle() can iterate in both directions.
- To return
nextitem, call yourcycler()with no ortrueas an argument - To return
previousitem, call yourcycler()withfalseas an argument
Utilscycle = require "Utilscycle"
alphabet = ["a", "b", "c", "d", "e", "f", "g", "h"]
cycler = Utils.cycle(alphabet)
# cycler(none or true) => next
# cycler(false) => previous
print cycler() # Outputs "a" (next)
print cycler() # Outputs "b" (next)
print cycler(true) # Outputs "c" (next)
print cycler(false) # Outputs "b" (previous)
print cycler(false) # Outputs "a" (previous)
If you don't want to load this silly thing from another file, you can copy its code from Utilscycle.coffee