(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
'use strict';

var _sticky = require('./sticky');

// initialize all elements
var componentsList = document.querySelectorAll(_sticky.Status.getSelector()); // Import all components

for (var i = 0; i < componentsList.length; i++) {
	new _sticky.Status(componentsList[i]);
}
},{"./sticky":2}],2:[function(require,module,exports){
'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

/**
 * Sticky.js
 * Script to make a component sticky
 */

/**
 * Declare constants
 */
var attributeBase = 'data-rs-sticky';

var Sticky = exports.Sticky = function () {
  function Sticky(element) {
    _classCallCheck(this, Sticky);

    this.element = element;
    this.addEventHandlers();
  }

  /**
   * Declare attribute constants
   */


  _createClass(Sticky, [{
    key: 'addEventHandlers',


    /**
     * Add event handlers
     */
    value: function addEventHandlers() {
      this.makeElementSticky();
    }
  }, {
    key: 'makeElementSticky',
    value: function makeElementSticky() {
      var _this = this;

      var elementPos = this.element.offsetTop;
      window.addEventListener('scroll', function () {
        var windowScrollPos = window.scrollY;

        if (windowScrollPos > elementPos) {
          _this.element.classList.add(_this.classes.sticky);
          _this.addExtraSpacingToNextElement();
        } else {
          _this.element.classList.remove(_this.classes.sticky);
          _this.removeExtraSpacingNextElement();
        }
      });
    }
  }, {
    key: 'addExtraSpacingToNextElement',
    value: function addExtraSpacingToNextElement() {
      var stickyHeight = this.element.offsetHeight;
      var nextElement = this.next(this.element);
      nextElement.setAttribute('style', 'top: ' + stickyHeight + 'px; position: relative');
    }
  }, {
    key: 'removeExtraSpacingNextElement',
    value: function removeExtraSpacingNextElement() {
      var nextElement = this.next(this.element);
      nextElement.removeAttribute('style');
    }

    /*
     * Function to get the next elements node instead of text node
     */

  }, {
    key: 'next',
    value: function next(elem) {
      do {
        elem = elem.nextSibling;
      } while (elem && elem.nodeType !== 1);
      return elem;
    }

    /**
     * Get selector
     */

  }, {
    key: 'attributes',
    get: function get() {
      return {};
    }

    /**
     * Declare classes
     */

  }, {
    key: 'classes',
    get: function get() {
      return {
        sticky: this.element.dataset.rsSticky ? this.element.dataset.rsSticky : 'is-sticky'
      };
    }
  }], [{
    key: 'getSelector',
    value: function getSelector() {
      return '[' + attributeBase + ']';
    }
  }]);

  return Sticky;
}();
},{}]},{},[1]);
