From 24c757845d7cefb6769c12a56be035f1b267f7d9 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Sat, 21 Sep 2013 19:25:01 +0200 Subject: [PATCH] Fix lazy tab loading --- src/root/common.tt | 16 +--------------- src/root/static/js/common.js | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 15 deletions(-) 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 %]
Loading...
[% 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("
Error loading tab: " + xhr.status + " " + xhr.statusText + "
"); + } + }); + } + }); +}