Fix lazy tab loading

This commit is contained in:
Eelco Dolstra
2013-09-21 19:25:01 +02:00
parent 9602499c1c
commit 24c757845d
2 changed files with 18 additions and 15 deletions

View File

@ -71,3 +71,20 @@ $(document).ready(function() {
});
})
});
var tabsLoaded = {};
var makeLazyTab = function(tabName, uri) {
$('.nav-tabs').bind('show', function(e) {
var pattern = /#.+/gi;
var id = e.target.toString().match(pattern)[0];
if (id == '#' + tabName && !tabsLoaded[id]) {
tabsLoaded[id] = 1;
$('#' + tabName).load(uri, function(response, status, xhr) {
if (status == "error") {
$('#' + tabName).html("<div class='alert alert-error'>Error loading tab: " + xhr.status + " " + xhr.statusText + "</div>");
}
});
}
});
}