I am building a site on http://jeemzandcompany.vaneckoosterink-preview.com It is a joomla 2.5.7 site.
$(document).ready(function() {$("#accordion3").msAccordion({defaultid:1, vertical:true}); });
This opens the TAB 1 -> the upper one. Thats what I want! If I click on a menu item in this TAB, the page loads a new url and refresh. The function in the index.php is run again, and the TAB closes and opens again.
What I want is opening the first TAB on pageload, but after click menu item the page stays that way, just load the other content in the open TAB.
This is not alone for the 1st TAB, but also for the other 4 tabs. So there must be in my opinion a piece of code that detects which div-TAB is open and stays that way when clicking a menu item till click again on the same TAB (closes) or click antoher TAB (closes the active one and opens the clicked one)
;(function($){ $.fn.msAccordion = function(options) { options = $.extend({ currentDiv:'1', previousDiv:'', vertical: false, defaultid:0, currentcounter:0, intervalid:0, autodelay:0, event:"click", alldivs_array:new Array() }, options); $(this).addClass("accordionWrapper"); $(this).css({overflow:"hidden"}); //alert(this); var elementid = $(this).attr("id"); var allDivs = this.children(); if(options.autodelay>0) { $("#"+ elementid +" > div").bind("mouseenter", function(){ pause(); }); $("#"+ elementid +" > div").bind("mouseleave", function(){ startPlay(); }); } //set ids allDivs.each(function(current) { var iCurrent = current; var sTitleID = elementid+"_msTitle_"+(iCurrent); var sContentID = sTitleID+"_msContent_"+(iCurrent); var currentDiv = allDivs[iCurrent]; var totalChild = currentDiv.childNodes.length; var titleDiv = $(currentDiv).find("div.title"); titleDiv.attr("id", sTitleID); var contentDiv = $(currentDiv).find("div.content"); contentDiv.attr("id", sContentID); options.alldivs_array.push(sTitleID); $("#"+sTitleID).bind(options.event, function(){pause();openMe(sTitleID);}); }); //make vertical if(options.vertical) {makeVertical();}; //open default openMe(elementid+"_msTitle_"+options.defaultid); if(options.autodelay>0) {startPlay();}; //alert(allDivs.length); function openMe(id) { var sTitleID = id; var iCurrent = sTitleID.split("_")[sTitleID.split("_").length-1]; options.currentcounter = iCurrent; var sContentID = id+"_msContent_"+iCurrent; if( sContentID == options.currentDiv && $("#"+sContentID).css("display") != "none" ){ closeMe(sContentID); return; } if($("#"+sContentID).css("display")=="none") { if(options.previousDiv!="") { closeMe(options.previousDiv); }; if(options.vertical) { $("#"+sContentID).slideDown("slow"); } else { $("#"+sContentID).show("slow"); } options.currentDiv = sContentID; options.previousDiv = options.currentDiv; }; }; function closeMe(div) { if(options.vertical) { $("#"+div).slideUp("slow"); } else { $("#"+div).hide("slow"); }; }; function makeVertical() { $("#"+elementid +" > div").css({display:"block", float:"none", clear:"both"}); $("#"+elementid +" > div > div.title").css({display:"block", float:"none", clear:"both"}); $("#"+elementid +" > div > div.content").css({clear:"both"}); }; function startPlay() { options.intervalid = window.setInterval(play, options.autodelay*1000); }; function play() { var sTitleId = options.alldivs_array[options.currentcounter]; openMe(sTitleId); options.currentcounter++; if(options.currentcounter==options.alldivs_array.length) options.currentcounter = 0; }; function pause() { window.clearInterval(options.intervalid); }; } })(jQuery);