Skip to content

Commit b86479c

Browse files
authored
feat(tab): callback to support tab change cancel
This PR adds a new callback "onBeforeChange" before changing a tab, so you can cancel the tab change if needed.
1 parent b51d0d1 commit b86479c

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/definitions/modules/tab.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,10 @@ $.fn.tab = function(parameters) {
379379
module.verbose('Tab parameters found', nextPathArray);
380380
}
381381
}
382+
if (settings.onBeforeChange.call(element, currentPath) === false) {
383+
module.debug('onBeforeChange returned false, cancelling tab change', $tab);
384+
return false;
385+
}
382386
if(isLastTab && remoteContent) {
383387
if(!shouldIgnoreLoad) {
384388
module.activate.navigation(currentPath);
@@ -415,6 +419,10 @@ $.fn.tab = function(parameters) {
415419
// if anchor exists use parent tab
416420
if($anchor && $anchor.length > 0 && currentPath) {
417421
module.debug('Anchor link used, opening parent tab', $tab, $anchor);
422+
if (settings.onBeforeChange.call(element, currentPath) === false) {
423+
module.debug('onBeforeChange returned false, cancelling tab change', $tab);
424+
return false;
425+
}
418426
if( !$tab.hasClass(className.active) ) {
419427
setTimeout(function() {
420428
module.scrollTo($anchor);
@@ -968,6 +976,7 @@ $.fn.tab.settings = {
968976
onLoad : function(tabPath, parameterArray, historyEvent) {}, // called on every load
969977
onVisible : function(tabPath, parameterArray, historyEvent) {}, // called every time tab visible
970978
onRequest : function(tabPath, parameterArray, historyEvent) {}, // called ever time a tab beings loading remote content
979+
onBeforeChange: function(tabPath) {}, // called before a tab is about to be changed. Returning false will cancel the tab change
971980

972981
templates : {
973982
determineTitle: function(tabArray) {} // returns page title for path

0 commit comments

Comments
 (0)