Skip to content

Instantly share code, notes, and snippets.

@jackmakesthings
Created July 22, 2015 17:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jackmakesthings/99d4d71bc7ff5ebd86fd to your computer and use it in GitHub Desktop.
Save jackmakesthings/99d4d71bc7ff5ebd86fd to your computer and use it in GitHub Desktop.
slideshow pseudo-code, to make sure i'm thinking about this correctly
class Slideshow {
constructor($, Utils) {
let utils = new Utils(),
orientationChange = utils.testFeature('onorientationchange'),
isActive = false,
isChanging = false,
alwaysShowControls = false, // this would be updated via however we're checking for devices - true on touch devices
totalSlides = 0,
currentSlide = 0;
let constants = {}; // can't think of any we need yet, maybe some px dimensions for the arrows or something
let selectors = {
slideshow: '.slideshow',
slide: '.slide',
slideImage: '.slide img',
controls: '.slideshow-controls',
prevButton: '.previous',
nextButton: '.next'
};
let objects = {
slideshow: $(selectors.slideshow)
}
let createSlideshow = function(slideshow) { // where slideshow = the wrapper for one particular set of slides
//
let gotoSlide = function(slideIndex) {
// if isChanging = true:
// do something here (return? throttle?) to avoid multiple transitions colliding with each other, like if someone's rapidly clicking the 'next' button over and over
// isChanging = true
// check currentSlide, find that slide object
// fade out the current slide -- should the fadeout get its own function? it's probably just a class toggle.
// fade in the new slide (the slide at slideIndex) -- same note as above
// currentSlide = slideIndex
// isChanging = false
};
let resizeHandler = function() {
// this may not actually be necessary, if we're smart with our css
// but if it is, assume this will be bound to window resizing
};
let nextHandler = function() {
// check currentSlide
// if currentSlide is the last slide, don't do anything (turns out they don't want the carousel to loop)
// otherwise, gotoSlide(currentSlide + 1)
};
let prevHandler = function() {
// check currentSlide
// if currentSlide is the first slide, don't do anything
// otherwise, gotoSlide(currentSlide - 1)
};
let showControls = function() {
//
// add a class and any other necessary attributes to make the arrows visible/usable
};
let hideControls = function() {
//
// like showControls, but in reverse
};
let bindEventListeners = function() {
// bind showControls() to mouseover on slideshow
// also bind it to wherever we're checking/updating our orientationChange check, so touch devices always get arrows
// bind hideControls() to mouseout on slideshow
// bind nextHandler() to click (and touch) on .controls.find(.next) -- bonus points if we include a keypress binding
// bind prevHandler() to .controls.find(previous)
// bind initSlideshow() to the appropriate load/ready event
};
}
this.createSlideshows = function() {
// createSlideshow for each wrapper object -- i'm modeling this after the Podcast class, should I be?
}
}
name() {
return "Slideshow";
}
init() {
this.createSlideshow();
}
}
export default Slideshow;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment