Created
June 22, 2017 08:23
-
-
Save Deviad/b0dc20744584b5214e980e5148e22729 to your computer and use it in GitHub Desktop.
Script for opening tabs from Divi Menu
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
<script> | |
var tab = null; | |
var menuSelector = null; | |
jQuery(function ($) { | |
console.log('test'); | |
//howtos tab | |
function changeMenuSelector() { | |
if ($( document ).width() > 967) { | |
menuSelector = 'top-menu-nav'; | |
} else { | |
menuSelector = 'et_mobile_nav_menu'; | |
} | |
} | |
changeMenuSelector(); | |
$( window ).resize(function() { | |
changeMenuSelector(); | |
}); | |
$('#'+menuSelector+' a[href*="howtos"]').on('click', function(event){ | |
var e = event; | |
var $ = jQuery; | |
setTimeout(function () { | |
e.preventDefault(); | |
console.log('pluto'); | |
window.localStorage.setItem('tab', 'et_pb_tab_0'); | |
if(window.location.pathname.indexOf('blog-posts') === -1) | |
{ | |
window.location.href='http://www.davidepugliese.com/blog-posts/'; | |
} else { | |
tab = localStorage.getItem('tab'); | |
$("li."+tab+">a")[0].click(); | |
window.localStorage.removeItem('tab'); | |
} | |
},1000);}); | |
$('#'+menuSelector +' a[href*="projects"]').on('click', function(e){ | |
e.preventDefault(); | |
console.log('pluto'); | |
localStorage.setItem('tab', 'et_pb_tab_1'); | |
if(window.location.pathname.indexOf('blog-posts') === -1) | |
{ | |
window.location.href='http://www.davidepugliese.com/blog-posts/'; | |
} else { | |
tab = localStorage.getItem('tab'); | |
$("li."+tab+">a")[0].click(); | |
localStorage.removeItem('tab'); | |
} | |
}); | |
$('#'+menuSelector +' a[href*="reviews"]').on('click', function(e){ | |
e.preventDefault(); | |
console.log('pluto'); | |
localStorage.setItem('tab', 'et_pb_tab_2'); | |
if(window.location.pathname.indexOf('blog-posts') === -1) | |
{ | |
window.location.href='http://www.davidepugliese.com/blog-posts/'; | |
} else { | |
tab = localStorage.getItem('tab'); | |
$("li."+tab+">a")[0].click(); | |
localStorage.removeItem('tab'); | |
} | |
}); | |
$('#'+menuSelector +' a[href*="elearning"]').on('click', function(e){ | |
e.preventDefault(); | |
console.log('pluto'); | |
localStorage.setItem('tab', 'et_pb_tab_3'); | |
if(window.location.pathname.indexOf('blog-posts') === -1) | |
{ | |
window.location.href='http://www.davidepugliese.com/blog-posts/'; | |
} else { | |
tab = localStorage.getItem('tab'); | |
$("li."+tab+">a")[0].click(); | |
localStorage.removeItem('tab'); | |
} | |
}); | |
$('#'+menuSelector +' a[href*="others"]').on('click', function(e){ | |
e.preventDefault(); | |
console.log('pluto'); | |
localStorage.setItem('tab', 'et_pb_tab_4'); | |
if(window.location.pathname.indexOf('blog-posts') === -1) | |
{ | |
window.location.href='http://www.davidepugliese.com/blog-posts/'; | |
} else { | |
tab = localStorage.getItem('tab'); | |
$("li."+tab+">a")[0].click(); | |
localStorage.removeItem('tab'); | |
} | |
}); | |
if (!!localStorage.getItem('tab')) { | |
tab = localStorage.getItem('tab'); | |
console.log(tab); | |
setTimeout(function(){$("li."+tab+">a")[0].click();}, 1) | |
$("html, body").animate({ scrollTop: $('.et_pb_module.et_pb_tabs.et_pb_tabs_0').offset().top }, | |
1000); | |
localStorage.removeItem('tab'); | |
} | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment