Difference between revisions of "Team:Aachen/Template:Team:Aachen/JS/Tour"
Line 57: | Line 57: | ||
else if (i == selectedParentIndex - 1 && selectedChildIndex > 0){ | else if (i == selectedParentIndex - 1 && selectedChildIndex > 0){ | ||
currentSelected.addClass('itemParentSelected'+selectedParentIndex); | currentSelected.addClass('itemParentSelected'+selectedParentIndex); | ||
− | currentSelected.children('.tourItemLabel').first().addClass(' | + | currentSelected.children('.tourItemLabel').first().addClass('tourItemLabelParentSelected'+selectedParentIndex); |
for (var k = 0; k < children.length; k++){ | for (var k = 0; k < children.length; k++){ | ||
if (k < selectedChildIndex){ | if (k < selectedChildIndex){ | ||
Line 66: | Line 66: | ||
else { | else { | ||
children.eq(k).addClass('itemSelected' +selectedParentIndex); | children.eq(k).addClass('itemSelected' +selectedParentIndex); | ||
− | children.eq(k).children('.tourItemLabel').first().addClass(' | + | children.eq(k).children('.tourItemLabel').first().addClass('tourItemLabelParentSelected'+selectedParentIndex); |
} | } | ||
} | } |
Latest revision as of 00:01, 16 September 2015
function isInt(n) {
return (n + "").match(/^\d+$/); //matches input against integer numbers and returns number
}
function GetParentIndexForTour() {
//return 0; //disabled for now ;) var url = window.location.pathname; var tourIndex = url.toLowerCase().indexOf('tour'); //save index of the word "tour" in the site url into a variable, returns -1 if "tour" not in url
if (tourIndex > 0) { //check to make sure tour was found in the url
if (isInt(url.charAt(tourIndex + 4))) { //checks if the first char after the word tour are integer and return the value if it is integer return url.charAt(tourIndex + 4); } } return 0;
}
function GetChildIndexForTour() {
var url = window.location.pathname; var tourIndex = url.toLowerCase().indexOf('tour'); if (tourIndex > 0) { if (isInt(url.charAt(tourIndex + 5))) { //cecks second char after the word "tour" for int and returns the value return url.charAt(tourIndex + 5); } } return 0;
}
function IsTourSite() { //checks if the site has a parentindex which marks it as a tour site
return GetParentIndexForTour() > 0;
}
function enableMenuDropdown() {
$('#btnMenu, .menuPopup, #btnMenu2').hover( function () { $('.menuPopup').show(); }, function () { $('.menuPopup').hide(); } );
}
function HandleSelectedTourItems(parents, children, selectedParentIndex, selectedChildIndex) {
for (var i = 0; i < parents.length; i++) { var currentSelected = parents.eq(i); if (i < selectedParentIndex) {
$('.tourBorderLeft').addClass('itemselected'+selectedParentIndex);
if (i == selectedParentIndex - 1 && selectedChildIndex == 0) { currentSelected.addClass('itemLastSelected'+selectedParentIndex); currentSelected.children('.tourItemLabel').first().addClass('tourItemLabelLastSelected'+selectedParentIndex);
for (var k = 0; k < children.length; k++){ children.eq(k).addClass('expanded' +selectedParentIndex); children.eq(k).children('.tourItemLabel').first().addClass('tourItemLabelExpanded'+selectedParentIndex); }
}
else if (i == selectedParentIndex - 1 && selectedChildIndex > 0){ currentSelected.addClass('itemParentSelected'+selectedParentIndex);
currentSelected.children('.tourItemLabel').first().addClass('tourItemLabelParentSelected'+selectedParentIndex);
for (var k = 0; k < children.length; k++){ if (k < selectedChildIndex){ if (k == selectedChildIndex - 1) { children.eq(k).addClass('itemLastSelected' +selectedParentIndex); children.eq(k).children('.tourItemLabel').first().addClass('tourItemLabelLastSelected'+selectedParentIndex); } else { children.eq(k).addClass('itemSelected' +selectedParentIndex); children.eq(k).children('.tourItemLabel').first().addClass('tourItemLabelParentSelected'+selectedParentIndex); } } else { children.eq(k).addClass('expanded' +selectedParentIndex); children.eq(k).children('.tourItemLabel').first().addClass('tourItemLabelExpanded'+selectedParentIndex); } } } else {
currentSelected.addClass('itemSelected'+selectedParentIndex); currentSelected.children('.tourItemLabel').first().addClass('tourItemLabelSelected'+selectedParentIndex); } } else { currentSelected.removeClass('itemLastSelected'); currentSelected.removeClass('itemSelected'); currentSelected.removeClass('tourItemLabelSelected'); } }
if (selectedParentIndex == 6) { $('.tourBorderRight').addClass('itemselected'+selectedParentIndex); } }
function ToggleTourMenu() {
var parentIndex = GetParentIndexForTour(); var childIndex = GetChildIndexForTour();
// show Tour on tour sites
if (IsTourSite() == true){ $('.tourBoundingBox').show();
$('body').css("overflow-x","hidden")
}
// Show subcategories
var expandBoxes = $('.tourBoundingBoxInner').children('.expandedTour');
for (var i = 0; i < expandBoxes.length; i++) {
if (i == parentIndex - 1) { expandBoxes.eq(i).show();
if (expandBoxes.eq(i).find('.childTourItem').length > 0 ) { //moves content box down if row of subcategories is visible $('.tour').css('padding-bottom', '150px'); }
} else { expandBoxes.eq(i).hide(); } }
// Handle selected items var parents = $('.tourBoundingBoxInner').children('.parentTourItem');
var expandedChildren = 2*parentIndex
var currentChildren = $(".tourBoundingBoxInner .expandedTour:nth-child(" + expandedChildren +")").find('.childTourItem'); HandleSelectedTourItems(parents, currentChildren, parentIndex, childIndex);
}
$(document).ready(function () {
enableMenuDropdown(); ToggleTourMenu();
});