Skip to content

Commit

Permalink
Merge pull request #832 from tf/no-animate-deep-link
Browse files Browse the repository at this point in the history
Use page from URL hash es landing page
  • Loading branch information
tf authored Aug 21, 2017
2 parents 8890953 + c977a10 commit ffc8da5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
5 changes: 4 additions & 1 deletion app/assets/javascripts/pageflow/history.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@ pageflow.History = function(slideshow, adapter) {
slideshow.goToByPermaId(adapter.hash());
});

this.getLandingPagePermaId = function() {
return adapter.hash() || pageParameter();
};

this.start = function() {
slideshow.goToByPermaId(adapter.hash() || pageParameter());
adapter.replaceState(null, '', slideshow.currentPage().attr('id'));
};

Expand Down
27 changes: 19 additions & 8 deletions app/assets/javascripts/pageflow/slideshow.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ pageflow.Slideshow = function($el, configurations) {

this.goToByPermaId = function(permaId, options) {
if (permaId) {
return this.goTo($el.find('#' + permaId), options);
return this.goTo(getPageByPermaId(permaId), options);
}
};

Expand Down Expand Up @@ -129,7 +129,7 @@ pageflow.Slideshow = function($el, configurations) {
return this.goTo(pages.first());
};

this.update = function() {
this.update = function(options) {
pages = $el.find('section.page');

pages.each(function(index) {
Expand All @@ -141,7 +141,7 @@ pageflow.Slideshow = function($el, configurations) {
});
});

ensureCurrentPage();
ensureCurrentPage(options);
};

this.currentPage = function() {
Expand All @@ -152,8 +152,8 @@ pageflow.Slideshow = function($el, configurations) {
return currentPage.page('getConfiguration');
};

function ensureCurrentPage() {
var newCurrentPage = findNewCurrentPage();
function ensureCurrentPage(options) {
var newCurrentPage = findNewCurrentPage(options);

if (newCurrentPage) {
currentPage = newCurrentPage;
Expand All @@ -164,15 +164,23 @@ pageflow.Slideshow = function($el, configurations) {
}
}

function findNewCurrentPage() {
function findNewCurrentPage(options) {
if (!currentPage.length) {
return that.scrollNavigator.getLandingPage(pages);
var permaId = options && options.landingPagePermaId;

return permaId ?
getPageByPermaId(permaId) :
that.scrollNavigator.getLandingPage(pages);
}
else if (!currentPage.parent().length) {
return nearestPage(currentPageIndex);
}
}

function getPageByPermaId(permaId) {
return $el.find('#' + permaId);
}

this.on = function() {
$el.on.apply($el, arguments);
};
Expand Down Expand Up @@ -241,7 +249,10 @@ pageflow.Slideshow.setup = function(options) {
options.beforeFirstUpdate();
}

pageflow.slides.update();
pageflow.slides.update({
landingPagePermaId: pageflow.history.getLandingPagePermaId()
});

pageflow.history.start();

return pageflow.slides;
Expand Down

0 comments on commit ffc8da5

Please sign in to comment.