Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
Add v2.8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
YannickRe committed Dec 26, 2018
1 parent e0ca2a0 commit f13eb30
Show file tree
Hide file tree
Showing 79 changed files with 12,713 additions and 867 deletions.
12 changes: 8 additions & 4 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ var config = require('./core/server/config'),
'core/*.js',
'core/server/*.js',
'core/server/**/*.js',
'!core/server/public/**/*.js'
'!core/server/public/**/*.js',
'!core/server/lib/members/static/auth/**/*.js'
]
},
test: {
Expand Down Expand Up @@ -342,7 +343,8 @@ var config = require('./core/server/config'),
npmInstall: true
},
projects: {
'core/client': 'init'
'core/client': 'init',
'core/server/lib/members/static/auth': 'init'
}
},

Expand All @@ -351,12 +353,14 @@ var config = require('./core/server/config'),
},

prod: {
'core/client': 'shell:ember:prod'
'core/client': 'shell:ember:prod',
'core/server/lib/members/static/auth': 'shell:preact:prod'
},

watch: {
projects: {
'core/client': ['shell:ember:watch', '--live-reload-base-url="' + urlService.utils.getSubdir() + '/ghost/"']
'core/client': ['shell:ember:watch', '--live-reload-base-url="' + urlService.utils.getSubdir() + '/ghost/"'],
'core/server/lib/members/static/auth': ['shell:preact:dev']
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion content/themes/casper/assets/built/infinitescroll.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion content/themes/casper/assets/built/infinitescroll.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

153 changes: 65 additions & 88 deletions content/themes/casper/assets/js/infinitescroll.js
Original file line number Diff line number Diff line change
@@ -1,115 +1,92 @@
/* global maxPages */

// Code snippet inspired by https://github.com/douglasrodrigues5/ghost-blog-infinite-scroll
$(function ($) {
var currentPage = 1;
var pathname = window.location.pathname;
var $document = $(document);
var $result = $('.post-feed');
/**
* Infinite Scroll
*/

(function(window, document) {
// next link element
var nextElement = document.querySelector('link[rel=next]');
if (!nextElement) return;

// post feed element
var feedElement = document.querySelector('.post-feed');
if (!feedElement) return;

var buffer = 300;

var ticking = false;
var isLoading = false;
var loading = false;

var lastScrollY = window.scrollY;
var lastWindowHeight = window.innerHeight;
var lastDocumentHeight = $document.height();

function onScroll() {
lastScrollY = window.scrollY;
requestTick();
}
var lastDocumentHeight = document.documentElement.scrollHeight;

function onResize() {
lastWindowHeight = window.innerHeight;
lastDocumentHeight = $document.height();
requestTick();
}

function requestTick() {
if (!ticking) {
requestAnimationFrame(infiniteScroll);
function onPageLoad() {
if (this.status === 404) {
window.removeEventListener('scroll', onScroll);
window.removeEventListener('resize', onResize);
return;
}
ticking = true;
}

function sanitizePathname(path) {
var paginationRegex = /(?:page\/)(\d)(?:\/)$/i;

// remove hash params from path
path = path.replace(/#(.*)$/g, '').replace('////g', '/');

// remove pagination from the path and replace the current pages
// with the actual requested page. E. g. `/page/3/` indicates that
// the user actually requested page 3, so we should request page 4
// next, unless it's the last page already.
if (path.match(paginationRegex)) {
currentPage = parseInt(path.match(paginationRegex)[1]);
// append contents
var postElements = this.response.querySelectorAll('.post-card');
postElements.forEach(function (item) {
feedElement.appendChild(item);
});

path = path.replace(paginationRegex, '');
// set next link
var resNextElement = this.response.querySelector('link[rel=next]');
if (resNextElement) {
nextElement.href = resNextElement.href;
} else {
window.removeEventListener('scroll', onScroll);
window.removeEventListener('resize', onResize);
}

return path;
// sync status
lastDocumentHeight = document.documentElement.scrollHeight;
ticking = false;
loading = false;
}

function infiniteScroll() {
// sanitize the pathname from possible pagination or hash params
pathname = sanitizePathname(pathname);

function onUpdate() {
// return if already loading
if (isLoading) {
return;
}
if (loading) return;

// return if not scroll to the bottom
if (lastScrollY + lastWindowHeight <= lastDocumentHeight - buffer) {
ticking = false;
return;
}

/**
* maxPages is defined in default.hbs and is the value
* of the amount of pagination pages.
* If we reached the last page or are past it,
* we return and disable the listeners.
*/
if (currentPage >= maxPages) {
window.removeEventListener('scroll', onScroll, {passive: true});
window.removeEventListener('resize', onResize);
return;
}
loading = true;

isLoading = true;

// next page
currentPage += 1;

// Load more
var nextPage = pathname + 'page/' + currentPage + '/';

$.get(nextPage, function (content) {
var parse = document.createRange().createContextualFragment(content);
var posts = parse.querySelectorAll('.post');
if (posts.length) {
[].forEach.call(posts, function (post) {
$result[0].appendChild(post);
});
}
}).fail(function (xhr) {
// 404 indicates we've run out of pages
if (xhr.status === 404) {
window.removeEventListener('scroll', onScroll, {passive: true});
window.removeEventListener('resize', onResize);
}
}).always(function () {
lastDocumentHeight = $document.height();
isLoading = false;
ticking = false;
});
var xhr = new window.XMLHttpRequest();
xhr.responseType = 'document';

xhr.addEventListener('load', onPageLoad);

xhr.open('GET', nextElement.href);
xhr.send(null);
}

function requestTick() {
ticking || window.requestAnimationFrame(onUpdate);
ticking = true;
}

function onScroll() {
lastScrollY = window.scrollY;
requestTick();
}

function onResize() {
lastWindowHeight = window.innerHeight;
lastDocumentHeight = document.documentElement.scrollHeight;
requestTick();
}

window.addEventListener('scroll', onScroll, {passive: true});
window.addEventListener('scroll', onScroll, { passive: true });
window.addEventListener('resize', onResize);

infiniteScroll();
});
requestTick();
})(window, document);
6 changes: 0 additions & 6 deletions content/themes/casper/default.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,6 @@
<script type="text/javascript" src="{{asset "built/jquery.fitvids.js"}}"></script>

{{#if pagination.pages}}
<script>
// maxPages is a global variable that is needed to determine
// if we need to load more pages for the infinitescroll, or if
// we reached the last page already.
var maxPages = parseInt('{{pagination.pages}}');
</script>
<script src="{{asset "built/infinitescroll.js"}}"></script>
{{/if}}

Expand Down
2 changes: 1 addition & 1 deletion content/themes/casper/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "casper",
"description": "The default personal blogging theme for Ghost. Beautiful, minimal and responsive.",
"demo": "https://demo.ghost.io",
"version": "2.7.0",
"version": "2.7.1",
"engines": {
"ghost": ">=2.0.0"
},
Expand Down
Loading

0 comments on commit f13eb30

Please sign in to comment.