Skip to content

Instantly share code, notes, and snippets.

@anasnakawa
Created June 14, 2018 12:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anasnakawa/0ab01dca8d5e0b5805a0feb7be28d130 to your computer and use it in GitHub Desktop.
Save anasnakawa/0ab01dca8d5e0b5805a0feb7be28d130 to your computer and use it in GitHub Desktop.
snippet when it will be added to the page, it will rotate tabs every few seconds
<script type="text/javascript">
(function() {
'use strict';
/**
* configurations
*/
var tabsClass = 'my-rotating-tabs'; // <- put the css class of the tabs you want to control
var secondsToRotate = 5; // <- every how many second should the tabs rotate?
/**
* hook method to be executed as soon as shortpoint
* is available in the page
*/
function initHook() {
// exit on edit mode
if( window.shortPointInserter ) {
return;
}
setTimeout( rotateTabs, 500);
};
/**
* locals
*/
var currentIndex = 0;
/**
* pause one or more tickers on the page
*/
function rotateTabs() {
var $ = shortpoint.$;
$( '.' + tabsClass ).each(function() {
var $tabTitles = $(this).find( '.shortpoint-tab-title' );
var totalTabs = $tabTitles.length;
setInterval(function() {
currentIndex = ( currentIndex + 1 ) % totalTabs;
var $a = $tabTitles.eq( currentIndex );
var $tab = $( $a.attr('href') );
$a.tab('show');
$tab.addClass('shortpoint-in').addClass('shortpoint-fade');
}, secondsToRotate * 1000)
})
}
// shortpoint not yet available in the page
// wait for shortpoint ready dom event
document.addEventListener( 'shortpoint-render-above-fold', initHook );
})();
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment