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

Commit

Permalink
Merge pull request #2 from thecodeassassin/master
Browse files Browse the repository at this point in the history
New version 1.1.0
  • Loading branch information
Stephen Hoogendijk committed Jan 28, 2014
2 parents 6167d88 + bbfa673 commit a27d615
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 11 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ shown event.
Changelog
===

Version 1.1.0
------
Added feature to go to the tab specified in the URL (for example #tab1 will open the tab with ID #tab1)


Version 1.0.1
------
Added minified version of the script. Fixed small issue with gracefully degrading
Expand Down
40 changes: 30 additions & 10 deletions js/bootstrap-remote-tabs.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
var $ = jQuery;
/**
/*!
*
* Bootstrap remote data tabs plugin
* Version 1.0.1
*
* Author: Stephen Hoogendijk (TheCodeAssassin)
*
Expand All @@ -10,7 +11,20 @@ var $ = jQuery;
* @returns {{hasLoadingMask: boolean, load: Function, _executeRemoteCall: Function}}
* @constructor
*/
var hasLoadingMask = (jQuery().mask ? true : false),
bootstrapVersion2 = (jQuery().typeahead ? true : false);

// hook the event based on the version of bootstrap
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,

Expand All @@ -32,15 +46,18 @@ var RemoteTabs = function() {
tabData,
tabCallback,
url,
simulateDelay;
simulateDelay,
alwaysRefresh;

// check if the tab has a data-url property
if(tabObj.is('[data-tab-url]')) {
url = tabObj.attr('data-tab-url');
tabDiv = $(tabObj.attr('href'));
tabDiv = $( '#' + tabObj.attr('href').split('#')[1]);
tabData = tabObj.attr('data-tab-json') || [];
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
Expand All @@ -54,12 +71,17 @@ var RemoteTabs = function() {
}

tabObj.on(tabEvent, function(e) {

// change the hash of the location
window.location.hash = e.target.hash;

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

if(me.hasLoadingMask) {
tabDiv.mask('Loading...');
}
tabObj.addClass('loading');

// delay the json call if it has been given a value
if(simulateDelay) {
Expand Down Expand Up @@ -97,6 +119,7 @@ var RemoteTabs = function() {
url: url,
data: customData || [],
success: function(data) {
trigger.removeClass('loading');
if(me.hasLoadingMask) {
tabContainer.unmask();
}
Expand All @@ -111,21 +134,18 @@ var RemoteTabs = function() {
}
},
fail: function(data) {
trigger.removeClass('loading');
if(me.hasLoadingMask) {
tabContainer.unmask();
}
}
});
}
};
var hasLoadingMask = (jQuery().mask ? true : false),
bootstrapVersion2 = (jQuery().typeahead ? true : false);

// hook the event based on the version of bootstrap
var event = (bootstrapVersion2 ? 'show' : 'show.bs.tab');
obj.load(event, hasLoadingMask);
obj.load(showEvent, hasLoadingMask);

return obj;
};

var remoteTabsPluginLoaded = new RemoteTabs();
var remoteTabsPluginLoaded = new RemoteTabs();
2 changes: 1 addition & 1 deletion js/bootstrap-remote-tabs.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a27d615

Please sign in to comment.