Sha256: 1614e0227972ee2cef12e59d67dd11421e0514cd846fef88c6b7790f3eb7e9bb

Contents?: true

Size: 1.15 KB

Versions: 3

Compression:

Stored size: 1.15 KB

Contents

'use strict';

const scrolling = require('./scrolling');
const questions = require('./questions');

const scrollForm = () => {

  // TODO  index() = function () {}

  let scroller;
  let currentPosition = 0;

  const speed = 400;

  const init = () => {
    const container = questions.getContainer();
    const firstQuestion = questions.getQuestion(0);

    scroller = scrolling.createScroller(container, 0, 0)

    scrolling.scrollTo(scroller, firstQuestion, speed, () => questions.setActiveQuestion(0));
  };

  const next = () => {
    const nextPosition = currentPosition + 1;
    const newTarget = questions.getQuestion(nextPosition);

    if (newTarget) {
      scrolling.scrollTo(scroller, newTarget, speed, () => questions.setActiveQuestion(nextPosition));
      currentPosition += 1;
    }
  };

  const prev = () => {
    const prevPosition = currentPosition - 1;
    const newTarget = questions.getQuestion(prevPosition);

    if (newTarget) {
      scrolling.scrollTo(scroller, newTarget, speed, () => questions.setActiveQuestion(prevPosition));
      currentPosition -= 1;
    }
  };

  return {
    init,
    next,
    prev,
  };

};

module.exports = scrollForm();

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
dta_rapid-0.3.5 assets/js/scroll-form.js
dta_rapid-0.3.4 assets/js/scroll-form.js
dta_rapid-0.3.3 assets/js/scroll-form.js