Skip to content
This repository was archived by the owner on Oct 28, 2020. It is now read-only.

Commit a27d615

Browse files
author
Stephen Hoogendijk
committed
Merge pull request #2 from thecodeassassin/master
New version 1.1.0
2 parents 6167d88 + bbfa673 commit a27d615

File tree

3 files changed

+36
-11
lines changed

3 files changed

+36
-11
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ shown event.
5252
Changelog
5353
===
5454

55+
Version 1.1.0
56+
------
57+
Added feature to go to the tab specified in the URL (for example #tab1 will open the tab with ID #tab1)
58+
59+
5560
Version 1.0.1
5661
------
5762
Added minified version of the script. Fixed small issue with gracefully degrading

js/bootstrap-remote-tabs.js

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
var $ = jQuery;
2-
/**
2+
/*!
33
*
44
* Bootstrap remote data tabs plugin
5+
* Version 1.0.1
56
*
67
* Author: Stephen Hoogendijk (TheCodeAssassin)
78
*
@@ -10,7 +11,20 @@ var $ = jQuery;
1011
* @returns {{hasLoadingMask: boolean, load: Function, _executeRemoteCall: Function}}
1112
* @constructor
1213
*/
14+
var hasLoadingMask = (jQuery().mask ? true : false),
15+
bootstrapVersion2 = (jQuery().typeahead ? true : false);
16+
17+
// hook the event based on the version of bootstrap
18+
var showEvent = (bootstrapVersion2 ? 'show' : 'show.bs.tab');
19+
20+
$(function() {
21+
var hash = document.location.hash;
22+
if (hash) {
23+
$('.nav-tabs a[href*='+hash+']').tab(showEvent);
24+
}
25+
});
1326
var RemoteTabs = function() {
27+
1428
var obj = {
1529
hasLoadingMask: false,
1630

@@ -32,15 +46,18 @@ var RemoteTabs = function() {
3246
tabData,
3347
tabCallback,
3448
url,
35-
simulateDelay;
49+
simulateDelay,
50+
alwaysRefresh;
3651

3752
// check if the tab has a data-url property
3853
if(tabObj.is('[data-tab-url]')) {
3954
url = tabObj.attr('data-tab-url');
40-
tabDiv = $(tabObj.attr('href'));
55+
tabDiv = $( '#' + tabObj.attr('href').split('#')[1]);
4156
tabData = tabObj.attr('data-tab-json') || [];
4257
tabCallback = tabObj.attr('data-tab-callback') || null;
4358
simulateDelay = tabObj.attr('data-tab-delay') || null;
59+
alwaysRefresh = (tabObj.is('[data-tab-always-refresh]')
60+
&& tabObj.attr('data-tab-always-refresh') == 'true') || null;
4461

4562
if(tabData.length > 0) {
4663
try
@@ -54,12 +71,17 @@ var RemoteTabs = function() {
5471
}
5572

5673
tabObj.on(tabEvent, function(e) {
74+
75+
// change the hash of the location
76+
window.location.hash = e.target.hash;
5777

58-
if (!tabObj.hasClass("loaded") || tabObj.is('[data-tab-always-refresh]')) {
78+
if ((!tabObj.hasClass("loaded") || alwaysRefresh) &&
79+
!tabObj.hasClass('loading')) {
5980

6081
if(me.hasLoadingMask) {
6182
tabDiv.mask('Loading...');
6283
}
84+
tabObj.addClass('loading');
6385

6486
// delay the json call if it has been given a value
6587
if(simulateDelay) {
@@ -97,6 +119,7 @@ var RemoteTabs = function() {
97119
url: url,
98120
data: customData || [],
99121
success: function(data) {
122+
trigger.removeClass('loading');
100123
if(me.hasLoadingMask) {
101124
tabContainer.unmask();
102125
}
@@ -111,21 +134,18 @@ var RemoteTabs = function() {
111134
}
112135
},
113136
fail: function(data) {
137+
trigger.removeClass('loading');
114138
if(me.hasLoadingMask) {
115139
tabContainer.unmask();
116140
}
117141
}
118142
});
119143
}
120144
};
121-
var hasLoadingMask = (jQuery().mask ? true : false),
122-
bootstrapVersion2 = (jQuery().typeahead ? true : false);
123145

124-
// hook the event based on the version of bootstrap
125-
var event = (bootstrapVersion2 ? 'show' : 'show.bs.tab');
126-
obj.load(event, hasLoadingMask);
146+
obj.load(showEvent, hasLoadingMask);
127147

128148
return obj;
129149
};
130150

131-
var remoteTabsPluginLoaded = new RemoteTabs();
151+
var remoteTabsPluginLoaded = new RemoteTabs();

js/bootstrap-remote-tabs.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)