Skip to content

Instantly share code, notes, and snippets.

@richardvanbergen
Last active January 3, 2016 22:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save richardvanbergen/8532058 to your computer and use it in GitHub Desktop.
Save richardvanbergen/8532058 to your computer and use it in GitHub Desktop.
// earlier in the document
// cache DOM object lookups
$.app.elems = {
body: $('body'),
appContainer: $('#app-page'),
pages: $('.page'),
nav: $('#nav'),
focusInputs: $(
'select,' +
'input[type=text],' +
'input[type=password],' +
'input[type=file],' +
'input[type=search],' +
'input[type=url],' +
'input[type=number],' +
'input[type=color],' +
'input[type=range],' +
'input[type=date]'
)
};
/// [...]
// give this one it's own scope
(function() {
// input focus detection
var previousState = {
tabMenuVisible: null
};
$.app.elems.body.on('vclick', function(e) {
// show the nav if it needs to be visible
if (previousState.tabMenuVisible) {
$.app.elems.nav.slideDown();
}
// reset the view state
previousState.tabMenuVisible = null;
});
$.app.elems.focusInputs.on('vclick', function(e) {
e.stopPropagation();
// store the current state if it hasn't already been set
if (previousState.tabMenuVisible === null) {
previousState.tabMenuVisible = ($.app.elems.nav.css('display') === 'block')
}
// hide the nav if visible
if (previousState.tabMenuVisible) {
$.app.elems.nav.slideUp();
}
// focus the element
$.app.scroller.scrollTo(this, 1000, true, true);
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment