title: jQuery scroll is working on pages it should not work on because of turbolinks
body: <pre><code>var paginationscript = function() {
    if($('#infinite-scrolling').size() &gt; 0) {
      $('.pagination').hide();
      $('#load_more_photos').show();
      $('#load_more_photos').on('click', function() {
        var url = $('.pagination .next_page a').attr('href');
        $.getScript(url);
        $('#load_more_photos').hide();   
        $(window).on('scroll', function() {
          var url = $('.pagination .next_page a').attr('href')
          if($(window).scrollTop() &gt; $(document).height() - $(window).height() - 60 &amp;&amp; $.active == 0) {
          $.getScript(url);
          }
        });
      }); 
    }
  };
  </code></pre>
  
  <p>So this creates an instagram-like setup where we first hide <code>'.pagination'</code> which is used if the user does not have js enabled, showing a <code>button</code>.  They click that button and get the next page of photos. Then from there we use <code>scroll</code> to add the next pages. This all works fine. </p>
  
  <p>The problem that with turbolinks enabled, it works on completely different parts of the app despite the fact that those pages <strong>do not</strong> contain the element <code>'#infinite-scrolling'</code>. Those pages <strong>do have</strong> <code>$('.pagination .next_page a').attr('href')</code> and that seems to be enough for turbolinks to enable the <code>scroll</code> function on those pages!</p>
  
  <p>I tried to wrap the <code>scroll</code> function in <code>if(window.location.pathname == "/photos")</code> but that still did not help. </p>
  
  <p><strong>Edit</strong>: I added a script to the other pages <code>$(window).off('scroll')</code> and that does stop the scroll from working on those pages, however I would be interested in a better way to go about it.</p>