docbrown/app/assets/javascripts/initializers/initializeTouchDevice.js
Ben Halpern dd20e70f12
Simplify article show page reactions (#2827)
* Simplify article show page reactions

* Clean up styling and adjust zen mode logic

* Remove unused variables

* Update app/views/articles/_actions.html.erb

Co-Authored-By: Nick Taylor <nick@iamdeveloper.com>

* Small style mods

* Slight padding change

* Finalize new show page button design
2019-05-15 10:32:36 -04:00

47 lines
1.8 KiB
JavaScript

function initializeTouchDevice() {
var isTouchDevice = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini|DEV-Native-ios/i.test(navigator.userAgent);
setTimeout(function(){
removeShowingMenu();
if (isTouchDevice) {
document.getElementById("navigation-butt").onclick = function(e){
document.getElementById("navbar-menu-wrapper").classList.toggle('showing');
}
} else {
document.getElementById("navbar-menu-wrapper").classList.add('desktop')
document.getElementById("navigation-butt").onfocus = function(e){
document.getElementById("navbar-menu-wrapper").classList.add('showing');
}
document.getElementById("last-nav-link").onblur = function(e) {
setTimeout(function(){
console.log(document.activeElement)
if (document.activeElement != document.getElementById("second-last-nav-link")) {
document.getElementById("navbar-menu-wrapper").classList.remove('showing');
}
}, 10)
}
document.getElementById("navigation-butt").onblur = function(e){
setTimeout(function(){
console.log(document.activeElement)
if (document.activeElement != document.getElementById("first-nav-link")) {
document.getElementById("navbar-menu-wrapper").classList.remove('showing');
}
}, 10)
}
}
document.getElementById("menubg").onclick = function(e) {
document.getElementById("navbar-menu-wrapper").classList.remove('showing');
}
},10)
}
function removeShowingMenu() {
document.getElementById("navbar-menu-wrapper").classList.remove('showing')
setTimeout(function(){
document.getElementById("navbar-menu-wrapper").classList.remove('showing')
},5)
setTimeout(function(){
document.getElementById("navbar-menu-wrapper").classList.remove('showing')
},150)
}