adambuczek
4/25/2016 - 1:46 PM

cycleClasses.js

(function (document, $) {

  var body = $('body');

  body.on('keypress', (e) => {

    var classNames = [
          'cursor-hand-open',
          // 'cursor-door-open',
          // 'cursor-door-closed',
          // 'cursor-sword',
          // 'cursor-dialog'
          'cursor-stairs'
        ],
        checked = [];

    e.preventDefault();

    if (!body[0].className) { return body.addClass(classNames[0]); }

    for (var i = classNames.length - 1; i >= 0; i--) {

      if (body.hasClass(classNames[i])) {
        body.removeClass(classNames[i]).addClass(classNames[(i + 1) % classNames.length]);
        break;
      }

      checked.push(classNames[i]);
    }

    return (checked.length === classNames.length) ? body.addClass(classNames[0]) : true;

  });

    body.on('click', () => {
      body.toggleClass('cursor-hand-closed');
    });

})(document, jQuery);