Skip to content

Commit 841cf26

Browse files
committed
Putting infinite-scroll into a modular pattern
1 parent e51cc41 commit 841cf26

File tree

9 files changed

+485
-454
lines changed

9 files changed

+485
-454
lines changed

wp-content/themes/makeblog/js/footer-scripts/_underscore-min.js

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

wp-content/themes/makeblog/js/footer-scripts/infinite-scroll.js

Lines changed: 0 additions & 88 deletions
This file was deleted.

wp-content/themes/makeblog/js/footer-scripts/infinite-scroll.pkgd.min.js

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

wp-content/themes/makeblog/js/footer-scripts/min/misc.js

Lines changed: 103 additions & 83 deletions
Large diffs are not rendered by default.

wp-content/themes/makeblog/js/footer-scripts/min/misc.min.js

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
var make = make || {},
2+
_ = _,
3+
$ = jQuery || $;
4+
5+
console.log(this);
6+
7+
make.iScroller = (function(make, _, $, window) {
8+
var def = function($cont, $template) {
9+
this.$cont = $cont;
10+
this.$template = $template;
11+
12+
this.loadFuncResponse = {};
13+
14+
this.options = {
15+
// get the first post
16+
path: '/wp-json/wp/v2/posts?per_page=1&page={{#}}',
17+
18+
// set response type for json
19+
responseType: 'text',
20+
// responses on infinite scroll trigger
21+
status: '.scroll-status',
22+
// use history.pushState() or history.replaceState()
23+
history: 'push',
24+
scrollThresold: 600,
25+
debug: true
26+
};
27+
28+
init.call(this);
29+
};
30+
31+
var setup = function() {
32+
this.$cont.infiniteScroll(this.options);
33+
this.instanceData = this.$cont.data('infiniteScroll');
34+
35+
this.templateMarkup = this.$template.html();
36+
};
37+
38+
var init = function() {
39+
setup.call(this);
40+
this.bind();
41+
};
42+
43+
def.prototype = {
44+
bind: function() {
45+
this.$cont.on('load.infiniteScroll', _.bind(this.loadFunc, this));
46+
this.$cont.on('append.infiniteScroll', _.bind(this.appendFunc, this));
47+
this.$cont.on('history.infiniteScroll', _.bind(this.historyFunc, this));
48+
this.$cont.on('last.infiniteScroll', _.bind(this.lastFunc, this));
49+
},
50+
51+
loadFunc: function( event, response, path ) {
52+
this.loadFuncResponse = {
53+
//data: JSON.parse(response),
54+
storyTemplate: _.template( $('#story-item-template').html() ),
55+
compiled: storyTemplate( JSON.parse(response) ),
56+
};
57+
return compiled;
58+
59+
this.$cont.infiniteScroll( 'appendItems', this.loadFuncResponse.$items );
60+
// load the infinite scroll ad
61+
make.gpt.loadDyn();
62+
63+
// testing stuff
64+
console.log( 'Loaded: ' + path,
65+
'Current page: ' + infScrollData.pageIndex,
66+
infScrollData.loadCount + ' pages loaded'
67+
);
68+
},
69+
70+
appendFunc: function( event, response, path, items ) {
71+
console.log( 'Loaded: ' + path );
72+
},
73+
74+
historyFunc: function() {
75+
ga( 'set', 'page', window.location.pathname );
76+
ga( 'send', 'pageview' );
77+
},
78+
79+
lastFunc: function( event, response, path ) {
80+
// do stuff after last item is loaded
81+
}
82+
};
83+
84+
return def;
85+
}).call(this, make, _, $, window);
86+
87+
make._instances = {}; // i want a place to store instances of modules
88+
make._instances.iScroll = new make.iScroller($('.js-infinite-scroll-container'), $('#story-item-template')); // create a new instance of the module

wp-content/themes/makeblog/single.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
$main_post_id = get_the_ID(); ?>
1717

1818
<div class="mz-story-infinite-view">
19-
<div class="wrapper">
19+
<div class="js-infinite-scroll-container">
2020
<div class="ad-unit first-ad">
2121
<?php print $make->ads->ad_leaderboard; ?>
2222
</div>

wp-content/themes/makeblog/version-2/css/style.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)