Skip to content

Instantly share code, notes, and snippets.

@Solomko2
Created October 9, 2015 22:32
Show Gist options
  • Select an option

  • Save Solomko2/48d24b84d39fe5b26d35 to your computer and use it in GitHub Desktop.

Select an option

Save Solomko2/48d24b84d39fe5b26d35 to your computer and use it in GitHub Desktop.
$(document).ready(function() {
// Загрузка из localStorage сохранённого пункта меню и открытие его
var storage = localStorage.getItem('item');
if (storage && storage !== "#") {
$('.nav-tabs a[href="' + storage + '"]').tab('show');
}
// Функция клика на произвольный пункт меню
$('ul.nav').on('click', 'li:not(.active, .dropdown, .disabled, .divider)', function() {
var itemId = $(this).find('a').attr('href');
localStorage.setItem('item', itemId);
});
var list = $('ul.nav').find('li');
var length = list.length - 1;
// Функция клика на кнопку Next
$('.next').click(function() {
list.each(function(i) {
if($(this).hasClass('active') && !$(this).hasClass('dropdown')) {
if (i != length) {
$(this).removeClass('active');
searchValidItem(i);
return false;
} else {
$(this).removeClass('active');
searchValidItem(-1);
return false;
}
}
});
});
});
// Функция для определения следующего подходящего пункта в меню
var searchValidItem = function(index) {
var list = $('ul.nav').find('li');
var nextIndex = index+1;
var nextItem = list.eq(nextIndex);
if (!nextItem.hasClass("disabled") && !nextItem.hasClass("dropdown") && !nextItem.hasClass("divider")) {
nextItem.find("a").tab('show');
localStorage.setItem('item', nextItem.find('a').attr('href'));
} else {
searchValidItem(nextIndex);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment