Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make the browser history work as it should #25

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions digitalpaper/static/digitalpaper/js/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,18 @@ var libePage = function(pageNumber, pageId, pageChannel, pageMaps) {
windowSource: libeConfig.modelmapping[k],
loader: 1,
functionCallOnClose: function() {
if(window.history) {
if (window.history.state == 'popup') {
// pop the 'popup' state
window.history.back();
}
}
jQuery('body').css({'overflow': 'auto'});
},
functionCallOnOpen: function() {
if(window.history && window.history.pushState) {
window.history.pushState('popup', '');
}
jQuery('body').css({'overflow': 'hidden'});
}
});
Expand Down
26 changes: 26 additions & 0 deletions digitalpaper/static/digitalpaper/js/reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,26 @@ var libeReader = function() {
jQuery(document).unbind('keydown', keyboardCallback);
}

function bindHistory() {
if (window.history) {
jQuery(window).bind('popstate', function(e) {
if (e.originalEvent.state == 'zoom') {
quitZoom();
} else {
// close the window in case we hit the back button
$.fn.closeDOMWindow();
}
});
}
jQuery(window).bind('hashchange', function(e) {
e.preventDefault();
p = _parseHashtoGetParams(location.hash);
if (_displayedPage != p[1]) {
showPage(p[1]);
}
});
}

function zoom(event) {
var offset = jQuery(this).offset();
if (!offset) {
Expand All @@ -47,6 +67,11 @@ var libeReader = function() {
x = x + previousElement.width();
}
zoomAtCoordinates(x, y);

if(window.history && window.history.pushState) {
window.history.pushState('zoom', '');
}

return false;
}

Expand Down Expand Up @@ -812,6 +837,7 @@ var libeReader = function() {
jQuery('#bookSwitcher').append(a);
a.bind('click', showSelectedPage);
}
bindHistory();
}

return {
Expand Down
3 changes: 1 addition & 2 deletions digitalpaper/templates/digitalpaper/base.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{% load i18n reader_tags %}
<!doctype html>
{% load i18n reader_tags %}<!doctype html>
<html>
<head>
<meta charset="utf-8" />
Expand Down