From 56a9d35cb7762e0d3b80f4561038dde0d7130bc9 Mon Sep 17 00:00:00 2001 From: Stephen Date: Thu, 30 Jan 2014 06:51:36 +1000 Subject: [PATCH 1/4] Update bootstrap-remote-tabs.js Changed location of tabContainer.html(data) so that content exists prior to callbackFn for better binding. Added in tabParent as the parent of all tab panels to enable a an empty request on change (lines 130-132). Both the tabParent value needs to exist and on each container the class remove-rd so that the remove action is intentional, especially given this is undesirable in the case where the tab doesn't need to be refreshed. The point of that was to solve the issue of binding events to hidden tab content. --- js/bootstrap-remote-tabs.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/js/bootstrap-remote-tabs.js b/js/bootstrap-remote-tabs.js index 1765318..13148ab 100644 --- a/js/bootstrap-remote-tabs.js +++ b/js/bootstrap-remote-tabs.js @@ -44,6 +44,7 @@ var RemoteTabs = function() { var tabObj = $(tab), tabDiv, tabData, + tabParent, tabCallback, url, simulateDelay, @@ -54,6 +55,7 @@ var RemoteTabs = function() { url = tabObj.attr('data-tab-url'); tabDiv = $( '#' + tabObj.attr('href').split('#')[1]); tabData = tabObj.attr('data-tab-json') || []; + tabParent = tabObj.attr('data-parent') || null; tabCallback = tabObj.attr('data-tab-callback') || null; simulateDelay = tabObj.attr('data-tab-delay') || null; alwaysRefresh = (tabObj.is('[data-tab-always-refresh]') @@ -87,10 +89,10 @@ var RemoteTabs = function() { if(simulateDelay) { clearTimeout(window.timer); window.timer=setTimeout(function(){ - me._executeRemoteCall(url, tabData, tabCallback, tabObj, tabDiv); + me._executeRemoteCall(url, tabData, tabCallback, tabObj, tabDiv, tabParent); }, simulateDelay); } else { - me._executeRemoteCall(url, tabData, tabCallback, tabObj, tabDiv); + me._executeRemoteCall(url, tabData, tabCallback, tabObj, tabDiv, tabParent); } @@ -111,7 +113,7 @@ var RemoteTabs = function() { * @param tabContainer * @private */ - _executeRemoteCall: function(url, customData, callbackFn, trigger, tabContainer) { + _executeRemoteCall: function(url, customData, callbackFn, trigger, tabContainer, tabParent) { var me = this; @@ -124,13 +126,19 @@ var RemoteTabs = function() { tabContainer.unmask(); } if (data) { + + if (tabParent != null) { + $(tabParent + ' > .remove-rd').empty(); + } + + tabContainer.html(data); + if(typeof window[callbackFn] == 'function') { window[callbackFn].call(null, data, trigger, tabContainer, customData); } if(!trigger.hasClass("loaded")) { trigger.addClass("loaded"); } - tabContainer.html(data); } }, fail: function(data) { From e5a8ae98fe2e9ae18fbcd2307540db91ab4d9646 Mon Sep 17 00:00:00 2001 From: Stephen Date: Thu, 30 Jan 2014 06:58:40 +1000 Subject: [PATCH 2/4] Update bootstrap-remote-tabs.min.js updating after non compressed version changes --- js/bootstrap-remote-tabs.min.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/bootstrap-remote-tabs.min.js b/js/bootstrap-remote-tabs.min.js index 2331052..60c1678 100644 --- a/js/bootstrap-remote-tabs.min.js +++ b/js/bootstrap-remote-tabs.min.js @@ -11,4 +11,4 @@ var $=jQuery; * @returns {{hasLoadingMask: boolean, load: Function, _executeRemoteCall: Function}} * @constructor */ -var hasLoadingMask=(jQuery().mask?true:false),bootstrapVersion2=(jQuery().typeahead?true:false);var showEvent=(bootstrapVersion2?"show":"show.bs.tab");$(function(){var a=document.location.hash;if(a){$(".nav-tabs a[href*="+a+"]").tab(showEvent)}});var RemoteTabs=function(){var a={hasLoadingMask:false,load:function(b,d){var c=this;c.hasLoadingMask=!!d;$("[data-toggle=tab]").each(function(i,h){var e=$(h),l,o,j,f,m,g;if(e.is("[data-tab-url]")){f=e.attr("data-tab-url");l=$("#"+e.attr("href").split("#")[1]);o=e.attr("data-tab-json")||[];j=e.attr("data-tab-callback")||null;m=e.attr("data-tab-delay")||null;g=(e.is("[data-tab-always-refresh]")&&e.attr("data-tab-always-refresh")=="true")||null;if(o.length>0){try{o=$.parseJSON(o)}catch(n){console.log("Invalid json passed to data-tab-json");console.log(n)}}e.on(b,function(k){window.location.hash=k.target.hash;if((!e.hasClass("loaded")||g)&&!e.hasClass("loading")){if(c.hasLoadingMask){l.mask("Loading...")}e.addClass("loading");if(m){clearTimeout(window.timer);window.timer=setTimeout(function(){c._executeRemoteCall(f,o,j,e,l)},m)}else{c._executeRemoteCall(f,o,j,e,l)}}})}})},_executeRemoteCall:function(e,g,c,d,b){var f=this;$.ajax({url:e,data:g||[],success:function(h){d.removeClass("loading");if(f.hasLoadingMask){b.unmask()}if(h){if(typeof window[c]=="function"){window[c].call(null,h,d,b,g)}if(!d.hasClass("loaded")){d.addClass("loaded")}b.html(h)}},fail:function(h){d.removeClass("loading");if(f.hasLoadingMask){b.unmask()}}})}};a.load(showEvent,hasLoadingMask);return a};var remoteTabsPluginLoaded=new RemoteTabs(); \ No newline at end of file +var hasLoadingMask=(jQuery().mask?true:false),bootstrapVersion2=(jQuery().typeahead?true:false);var showEvent=(bootstrapVersion2?'show':'show.bs.tab');$(function(){var hash=document.location.hash;if(hash){$('.nav-tabs a[href*='+hash+']').tab(showEvent)}});var RemoteTabs=function(){var obj={hasLoadingMask:false,load:function(tabEvent,hasLoadingMask){var me=this;me.hasLoadingMask=!!hasLoadingMask;$('[data-toggle=tab]').each(function(k,tab){var tabObj=$(tab),tabDiv,tabData,tabParent,tabCallback,url,simulateDelay,alwaysRefresh;if(tabObj.is('[data-tab-url]')){url=tabObj.attr('data-tab-url');tabDiv=$('#'+tabObj.attr('href').split('#')[1]);tabData=tabObj.attr('data-tab-json')||[];tabParent=tabObj.attr('data-parent')||null;tabCallback=tabObj.attr('data-tab-callback')||null;simulateDelay=tabObj.attr('data-tab-delay')||null;alwaysRefresh=(tabObj.is('[data-tab-always-refresh]')&&tabObj.attr('data-tab-always-refresh')=='true')||null;if(tabData.length>0){try{tabData=$.parseJSON(tabData)}catch(exc){console.log('Invalid json passed to data-tab-json');console.log(exc)}}tabObj.on(tabEvent,function(e){window.location.hash=e.target.hash;if((!tabObj.hasClass("loaded")||alwaysRefresh)&&!tabObj.hasClass('loading')){if(me.hasLoadingMask){tabDiv.mask('Loading...')}tabObj.addClass('loading');if(simulateDelay){clearTimeout(window.timer);window.timer=setTimeout(function(){me._executeRemoteCall(url,tabData,tabCallback,tabObj,tabDiv,tabParent)},simulateDelay)}else{me._executeRemoteCall(url,tabData,tabCallback,tabObj,tabDiv,tabParent)}}})}})},_executeRemoteCall:function(url,customData,callbackFn,trigger,tabContainer,tabParent){var me=this;$.ajax({url:url,data:customData||[],success:function(data){trigger.removeClass('loading');if(me.hasLoadingMask){tabContainer.unmask()}if(data){if(tabParent!=null){$(tabParent+' > .remove-rd').empty()}tabContainer.html(data);if(typeof window[callbackFn]=='function'){window[callbackFn].call(null,data,trigger,tabContainer,customData)}if(!trigger.hasClass("loaded")){trigger.addClass("loaded")}}},fail:function(data){trigger.removeClass('loading');if(me.hasLoadingMask){tabContainer.unmask()}}})}};obj.load(showEvent,hasLoadingMask);return obj};var remoteTabsPluginLoaded=new RemoteTabs(); From bf68b4aae9819925a6357a1ed936c943732a76fd Mon Sep 17 00:00:00 2001 From: Stephen Date: Thu, 30 Jan 2014 06:59:43 +1000 Subject: [PATCH 3/4] Update bootstrap-remote-tabs.min.js updated version number as per readme file --- js/bootstrap-remote-tabs.min.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/bootstrap-remote-tabs.min.js b/js/bootstrap-remote-tabs.min.js index 60c1678..198ded2 100644 --- a/js/bootstrap-remote-tabs.min.js +++ b/js/bootstrap-remote-tabs.min.js @@ -2,7 +2,7 @@ var $=jQuery; /* * * Bootstrap remote data tabs plugin - * Version 1.0.1 + * Version 1.1.0 * * Author: Stephen Hoogendijk (TheCodeAssassin) * From 8cc069d3ccc7a4ec72a8f5e6b6e7d41018c6b8c0 Mon Sep 17 00:00:00 2001 From: Stephen Date: Thu, 30 Jan 2014 07:00:01 +1000 Subject: [PATCH 4/4] Update bootstrap-remote-tabs.js updated version number as per readme file --- js/bootstrap-remote-tabs.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/bootstrap-remote-tabs.js b/js/bootstrap-remote-tabs.js index 13148ab..7d5c73a 100644 --- a/js/bootstrap-remote-tabs.js +++ b/js/bootstrap-remote-tabs.js @@ -2,7 +2,7 @@ var $ = jQuery; /*! * * Bootstrap remote data tabs plugin - * Version 1.0.1 + * Version 1.1.0 * * Author: Stephen Hoogendijk (TheCodeAssassin) *