Last active
January 3, 2016 22:59
-
-
Save richardvanbergen/8532058 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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