From: Michael Ang Date: Sat, 2 Oct 2010 00:05:02 +0000 (+0000) Subject: Refactor nav bar hide/show X-Git-Url: http://git.rot13.org/?p=bookreader.git;a=commitdiff_plain;h=d71a231828fe68a3f2b8de067b5b4b64ce916e6e Refactor nav bar hide/show --- diff --git a/BookReader/BookReader.js b/BookReader/BookReader.js index e7f4103..9c430dc 100644 --- a/BookReader/BookReader.js +++ b/BookReader/BookReader.js @@ -157,13 +157,23 @@ BookReader.prototype.init = function() { $("#BookReader").empty(); this.initToolbar(this.mode, this.ui); // Build inside of toolbar div + $("#BookReader").append("
"); $("#BRcontainer").append("
"); + + this.initNavbar(); + this.bindNavigationHandlers(); + + // Autohide nav after showing for awhile + var self = this; + $(window).bind('load', function() { + setTimeout(function() { self.hideNavigation(); }, 3000); + }); $("#BRcontainer").bind('scroll', this, function(e) { e.data.loadLeafs(); }); - + this.setupKeyListeners(); this.startLocationPolling(); @@ -235,6 +245,8 @@ BookReader.prototype.init = function() { // Enact other parts of initial params this.updateFromParams(params); + + //XXXmang window.setTimeout(self.hideNavigation, 3000); } BookReader.prototype.setupKeyListeners = function() { @@ -3526,6 +3538,73 @@ BookReader.prototype.updateToolbarZoom = function(reduce) { $('#BRzoom').text(value); } +// bindNavigationHandlers +//______________________________________________________________________________ +// Bind navigation handlers +BookReader.prototype.bindNavigationHandlers = function() { + $('#BookReader').die('mousemove.navigation').live('mousemove.navigation', + { 'br': this }, + this.navigationMousemoveHandler + ); +} + +// unbindNavigationHandlers +//______________________________________________________________________________ +// Unbind navigation handlers +BookReader.prototype.unbindNavigationHandlers = function() { + $('#BookReader').die('mousemove.navigation'); +} + +// navigationMousemoveHandler +//______________________________________________________________________________ +// Handle mousemove related to navigation. Bind at #BookReader level to allow autohide. +BookReader.prototype.navigationMousemoveHandler = function(event) { + // $$$ possibly not great to be calling this for every mousemove + var navkey = $(document).height() - 75; + if ((event.pageY < 76) || (event.pageY > navkey)) { + // inside or near navigation elements + event.data['br'].hideNavigation(); + } else { + event.data['br'].showNavigation(); + } +} + +// navigationIsVisible +//______________________________________________________________________________ +// Returns true if the navigation elements are currently visible +BookReader.prototype.navigationIsVisible = function() { + // $$$ doesn't account for transitioning states, nav must be fully visible to return true + var toolpos = $('#BRtoolbar').offset(); + var tooltop = toolpos.top; + if (tooltop == 0) { + return true; + } + return false; +} + +// hideNavigation +//______________________________________________________________________________ +// Hide navigation elements, if visible +BookReader.prototype.hideNavigation = function() { + // Check if navigation is showing + if (this.navigationIsVisible()) { + // $$$ don't hardcode height + $('#BRtoolbar').animate({top:-60}); + $('#BRnav').animate({bottom:-60}); + } +} + +// showNavigation +//______________________________________________________________________________ +// Show navigation elements +BookReader.prototype.showNavigation = function() { + // Check if navigation is hidden + if (!this.navigationIsVisible()) { + $('#BRtoolbar').animate({top:0}); + $('#BRnav').animate({bottom:0}); + } +} + // firstDisplayableIndex //______________________________________________________________________________ // Returns the index of the first visible page, dependent on the mode. diff --git a/BookReaderIA/inc/BookReader.inc b/BookReaderIA/inc/BookReader.inc index a0638fd..3547aaf 100644 --- a/BookReaderIA/inc/BookReader.inc +++ b/BookReaderIA/inc/BookReader.inc @@ -215,61 +215,11 @@ class BookReader - -
-
-

- -

-
-
- Search results -
-
- - -
- - -
- -