diff --git a/src/root/common.tt b/src/root/common.tt index 79ca3bd5..42bf4224 100644 --- a/src/root/common.tt +++ b/src/root/common.tt @@ -459,21 +459,7 @@ BLOCK makeLazyTab %] <center><img src="/static/images/ajax-loader.gif" alt="Loading..." /></center> </div> <script> - $(function() { - var tabsLoaded = {}; - $('.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>"); - } - }); - } - }); - }); + $(function() { makeLazyTab("[% tabName %]", "[% uri %]"); }); </script> [% END; diff --git a/src/root/static/js/common.js b/src/root/static/js/common.js index 7477455b..bbddd470 100644 --- a/src/root/static/js/common.js +++ b/src/root/static/js/common.js @@ -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>"); + } + }); + } + }); +}