Javascript 在squarespace上无限滚动获取类别筛选器

Javascript 在squarespace上无限滚动获取类别筛选器,javascript,squarespace,jsontemplate,Javascript,Squarespace,Jsontemplate,我使用这段代码在squarespace上无限加载一个页面。我的问题是重新加载没有捕获我在url中设置的过滤。它似乎无法“查看”我的集合中的变量,甚至无法“查看”url或categoryFilter。我尝试使用.var指令,但延迟加载的项无法看到之前定义的范围。我的点子快用完了,请帮帮我 编辑:我找到了答案,但又得到了一个问题 我能够使用window.location.href而不是window.location.pathname最终以这种方式获取参数。但这在IE11中不起作用,所以现在我必须搜索

我使用这段代码在squarespace上无限加载一个页面。我的问题是重新加载没有捕获我在url中设置的过滤。它似乎无法“查看”我的集合中的变量,甚至无法“查看”url或categoryFilter。我尝试使用.var指令,但延迟加载的项无法看到之前定义的范围。我的点子快用完了,请帮帮我

编辑:我找到了答案,但又得到了一个问题

我能够使用window.location.href而不是window.location.pathname最终以这种方式获取参数。但这在IE11中不起作用,所以现在我必须搜索它

 <script>

 function infiniteScroll(parent, post) {

     // Set some variables. We'll use all these later.
     var postIndex = 1,
         execute = true,
         stuffBottom = Y.one(parent).get('clientHeight') + Y.one(parent).getY(),
         urlQuery = window.location.pathname,
         postNumber = Static.SQUARESPACE_CONTEXT.collection.itemCount,
         presentNumber = Y.all(post).size();

     Y.on('scroll', function() {

         if (presentNumber >= postNumber && execute === true) {
             Y.one(parent).append('<h1>There are no more posts.</h1>')
             execute = false;
         } else {

             // A few more variables.
             var spaceHeight = document.documentElement.clientHeight + window.scrollY,
             next = false;

             /*
                 This if statement measures if the distance from
                 the top of the page to the bottom of the content
                 is less than the scrollY position. If it is,
                 it's sets next to true.
             */
             if (stuffBottom < spaceHeight && execute === true) {
                 next = true;
             }

             if (next === true) {

                 /*
                     Immediately set execute back to false.
                     This prevents the scroll listener from
                     firing too often.
                 */
                 execute = false;

                 // Increment the post index.
                 postIndex++;

                 // Make the Ajax request.
                 Y.io(urlQuery + '?page=' + postIndex, {
                     on: {
                         success: function (x, o) {
                             try {
                                 d = Y.DOM.create(o.responseText);
                             } catch (e) {
                                 console.log("JSON Parse failed!");
                                 return;
                             }

                             // Append the contents of the next page to this page.
                             Y.one(parent).append(Y.Selector.query(parent, d, true).innerHTML);

                             // Reset some variables.
                             stuffBottom = Y.one(parent).get('clientHeight') + Y.one(parent).getY();
                             presentNumber = Y.all(post).size();
                             execute = true;

                         }
                     }
                 });
             }
         }
     });
 }

 // Call the function on domready.
 Y.use('node', function() {
     Y.on('domready', function() {
         infiniteScroll('#content','.lazy-post');
     });
 });


 </script>

功能无限滚动(父级、后级){
//设置一些变量。我们稍后将使用所有这些变量。
var postIndex=1,
执行=真,
stuffBottom=Y.one(父级).get('clientHeight')+Y.one(父级).getY(),
urlQuery=window.location.pathname,
postNumber=Static.SQUARESPACE\u CONTEXT.collection.itemCount,
presentNumber=Y.all(post.size();
Y.on('滚动',函数(){
if(presentNumber>=postNumber&&execute==true){
Y.one(父).append('没有更多的帖子')
执行=错误;
}否则{
//还有几个变量。
var spaceHeight=document.documentElement.clientHeight+window.scrollY,
下一个=假;
/*
此if语句测量从
从页面顶部到内容底部
小于滚动位置。如果是,
这几乎是真的。
*/
if(stuffBottom
我能够让这个脚本按我想要的方式工作

我想我可以用:

Static.SQUARESPACE_CONTEXT.collection.itemCount
要使用jsont获得类似{collection.categoryFilter},请执行以下操作:

Static.SQUARESPACE_CONTEXT.collection.categoryFilter
或者这个:

Static.SQUARESPACE_CONTEXT.categoryFilter
它不起作用,所以我改了

urlQuery = window.location.pathname

这给了我所需要的参数

我遇到的IE11问题是该脚本使用

window.scrollY
我把它改成了ie11兼容的

Window.pageYOffset
我们走得很好

Window.pageYOffset