(function() {
  "use strict";
  App.FoundationExtras = {
    initialize: function() {
      $(document).foundation();
    }
  };
}).call(this);

(function() {
  "use strict";
  App.FoundationExtras = {
    initialize: function() {
      $(document).foundation();
    },
    destroy: function() {
      if ($(".sticky").length > 0) {
        $(".sticky").foundation("_destroy");
      }
    }
  };

  $(document).on("turbolinks:before-visit", App.FoundationExtras.destroy);
}).call(this);

Destroy Sticky elements before leaving the page
Destroy Sticky elements before leaving the page

When Foundation initializes a page that has any sticky element, it
loads a window scroll listener into window object to handle the sticky
element positioning when scrolling. This works great until user moves
to a page without sticky elements and the window listeners remain
attached to the window object on this new page too when there is no
need to run the scrollListener and there is no sticky elements so the
window scroll listener cannot find the sticky object on that page a lot
of errors are thrown when user scrolls.

With this approach we are destroying sticky elements before leaving
the page which also remove the Sticky scrollListener from the window
object.

I do not know how to write a test to demonstrate this fix, but at least
there is some steps to reproduce this behavior:

0. Undo this commit
1. Go to any proposal page
2. Click on any link (with Turbolinks enabled)
3. Scroll the page
4. Check the console log. Yo will find as error occurrences as pixels you scrolled.
