Created
June 16, 2009 21:15
-
-
Save PHLAK/130902 to your computer and use it in GitHub Desktop.
Simple AJAX serverd tabs with caching
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
<h1>My Account</h1> | |
<div id="account-tabs" class="clearfix"> | |
<ul> | |
<li id="account-dashboard" class="tabli"><a href="/account/dashboard">Account Dashboard</a></li> | |
<li id="order-history" class="tabli"><a href="/account/order-history">Order History</a></li> | |
<li id="address-book" class="tabli"><a href="/account/address-book">Address Book</a></li> | |
</ul> | |
</div> | |
<div id="account-box"></div> | |
<script type="text/javascript"><!-- | |
$(document).ready(function(){ | |
function createTabs($tabLiClass, $targetContentDivID, $initialTabID){ | |
$("."+$tabLiClass+" a").click(function(){ | |
if($(this).data("loaded") != true){ | |
//make req | |
var $myEl = this; | |
$("#"+$targetContentDivID).html('<b>Loading content...</b><br /><br /><img src="/images/loadingAnimation.gif" />'); | |
$.ajax({ | |
url: $(this).attr("href"), | |
success: function(contents){ | |
$($myEl).data("tabcontents", contents); | |
$("#"+$targetContentDivID).html($($myEl).data("tabcontents")); | |
} | |
}); | |
$(this).data("loaded", true); | |
} else { | |
$("#"+$targetContentDivID).html($(this).data("tabcontents")); | |
} | |
$("."+$tabLiClass).removeClass('active'); | |
$(this).parent().addClass('active'); | |
return false; | |
}); | |
$("#"+$initialTabID+" a").click(); | |
} | |
createTabs("tabli", "account-box","account-dashboard"); | |
}); | |
--></script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment