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

@ -459,21 +459,7 @@ BLOCK makeLazyTab %]
<center><img src="/static/images/ajax-loader.gif" alt="Loading..." /></center> <center><img src="/static/images/ajax-loader.gif" alt="Loading..." /></center>
</div> </div>
<script> <script>
$(function() { $(function() { makeLazyTab("[% tabName %]", "[% uri %]"); });
var tabsLoaded = {};
$('.nav-tabs').bind('show', function(e) {
var pattern = /#.+/gi;
var id = e.target.toString().match(pattern)[0];
if (id == "#[% tabName %]" &amp;&amp; !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>");
}
});
}
});
});
</script> </script>
[% END; [% END;

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>");
}
});
}
});
}