Browse Source

Adds onVisible and onRequest callbacks, adds new 2.0 callback names onFirstLoad and onLoad, adds deprecation warnings for previous callbacks #1612

pull/2347/head
jlukic 9 years ago
parent
commit
1ae05d698b
1 changed files with 79 additions and 49 deletions
  1. 128
      src/definitions/modules/tab.js

128
src/definitions/modules/tab.js

@ -251,6 +251,23 @@ $.fn.tab = function(parameters) {
}; };
} }
}, },
loading: function(tabPath) {
var
$tab = module.get.tabElement(tabPath),
isLoading = $tab.hasClass(className.loading)
;
if(!isLoading) {
module.verbose('Setting loading state for', $tab);
$tab
.addClass(className.loading)
.siblings($tabs)
.removeClass(className.active + ' ' + className.loading)
;
if($tab.length > 0) {
settings.onTabRequest.call($tab[0], tabPath);
}
}
},
state: function(state) { state: function(state) {
$.address.value(state); $.address.value(state);
} }
@ -286,7 +303,6 @@ $.fn.tab = function(parameters) {
; ;
module.verbose('Looking for tab', tab); module.verbose('Looking for tab', tab);
if(isTab) { if(isTab) {
module.verbose('Tab was found', tab); module.verbose('Tab was found', tab);
// scope up // scope up
activeTabPath = currentPath; activeTabPath = currentPath;
@ -306,15 +322,15 @@ $.fn.tab = function(parameters) {
if(isLastTab && remoteContent) { if(isLastTab && remoteContent) {
if(!shouldIgnoreLoad) { if(!shouldIgnoreLoad) {
module.activate.navigation(currentPath); module.activate.navigation(currentPath);
module.content.fetch(currentPath, tabPath);
module.fetch.content(currentPath, tabPath);
} }
else { else {
module.debug('Ignoring remote content on first tab load', currentPath); module.debug('Ignoring remote content on first tab load', currentPath);
firstLoad = false; firstLoad = false;
module.cache.add(tabPath, $tab.html()); module.cache.add(tabPath, $tab.html());
module.activate.all(currentPath); module.activate.all(currentPath);
settings.onTabInit.call($tab, currentPath, parameterArray, historyEvent);
settings.onTabLoad.call($tab, currentPath, parameterArray, historyEvent);
settings.onTabInit.call($tab[0], currentPath, parameterArray, historyEvent);
settings.onTabLoad.call($tab[0], currentPath, parameterArray, historyEvent);
} }
return false; return false;
} }
@ -324,10 +340,11 @@ $.fn.tab = function(parameters) {
if( !module.cache.read(currentPath) ) { if( !module.cache.read(currentPath) ) {
module.cache.add(currentPath, true); module.cache.add(currentPath, true);
module.debug('First time tab loaded calling tab init'); module.debug('First time tab loaded calling tab init');
settings.onTabInit.call($tab, currentPath, parameterArray, historyEvent);
settings.onTabInit.call($tab[0], currentPath, parameterArray, historyEvent);
} }
settings.onTabLoad.call($tab, currentPath, parameterArray, historyEvent);
settings.onTabLoad.call($tab[0], currentPath, parameterArray, historyEvent);
} }
} }
else if(tabPath.search('/') == -1 && tabPath !== '') { else if(tabPath.search('/') == -1 && tabPath !== '') {
// look for in page anchor // look for in page anchor
@ -341,8 +358,9 @@ $.fn.tab = function(parameters) {
if( !module.cache.read(currentPath) ) { if( !module.cache.read(currentPath) ) {
module.cache.add(currentPath, true); module.cache.add(currentPath, true);
module.debug('First time tab loaded calling tab init'); module.debug('First time tab loaded calling tab init');
settings.onTabInit.call($tab, currentPath, parameterArray, historyEvent);
settings.onTabInit.call($tab[0], currentPath, parameterArray, historyEvent);
} }
return false; return false;
} }
} }
@ -353,9 +371,30 @@ $.fn.tab = function(parameters) {
}); });
}, },
content: {
update: {
content: function(tabPath, html, evaluateScripts) {
var
$tab = module.get.tabElement(tabPath),
tab = $tab[0]
;
evaluateScripts = (evaluateScripts !== undefined)
? evaluateScripts
: settings.evaluateScripts
;
if(evaluateScripts) {
module.debug('Updating HTML and evaluating inline scripts', tabPath, html);
$tab.html(html);
}
else {
module.debug('Updating HTML', tabPath, html);
tab.innerHTML = html;
}
}
},
fetch: {
fetch: function(tabPath, fullTabPath) {
content: function(tabPath, fullTabPath) {
var var
$tab = module.get.tabElement(tabPath), $tab = module.get.tabElement(tabPath),
apiSettings = { apiSettings = {
@ -363,7 +402,7 @@ $.fn.tab = function(parameters) {
on : 'now', on : 'now',
onSuccess : function(response) { onSuccess : function(response) {
module.cache.add(fullTabPath, response); module.cache.add(fullTabPath, response);
module.content.update(tabPath, response);
module.update.content(tabPath, response);
if(tabPath == activeTabPath) { if(tabPath == activeTabPath) {
module.debug('Content loaded', tabPath); module.debug('Content loaded', tabPath);
module.activate.tab(tabPath); module.activate.tab(tabPath);
@ -371,8 +410,8 @@ $.fn.tab = function(parameters) {
else { else {
module.debug('Content loaded in background', tabPath); module.debug('Content loaded in background', tabPath);
} }
settings.onTabInit.call($tab, tabPath, parameterArray, historyEvent);
settings.onTabLoad.call($tab, tabPath, parameterArray, historyEvent);
settings.onTabInit.call($tab[0], tabPath, parameterArray, historyEvent);
settings.onTabLoad.call($tab[0], tabPath, parameterArray, historyEvent);
}, },
urlData: { urlData: {
tab: fullTabPath tab: fullTabPath
@ -388,21 +427,20 @@ $.fn.tab = function(parameters) {
cachedContent = module.cache.read(fullTabPath); cachedContent = module.cache.read(fullTabPath);
module.activate.tab(tabPath);
if(settings.cache && cachedContent) { if(settings.cache && cachedContent) {
module.activate.tab(tabPath);
module.debug('Adding cached content', fullTabPath); module.debug('Adding cached content', fullTabPath);
if(settings.evaluateScripts == 'once') { if(settings.evaluateScripts == 'once') {
module.content.update(tabPath, cachedContent, false);
module.update.content(tabPath, cachedContent, false);
} }
else { else {
module.content.update(tabPath, cachedContent);
module.update.content(tabPath, cachedContent);
} }
settings.onTabLoad.call($tab, tabPath, parameterArray, historyEvent);
settings.onTabLoad.call($tab[0], tabPath, parameterArray, historyEvent);
} }
else if(existingRequest) { else if(existingRequest) {
module.set.loading(tabPath);
module.debug('Content is already loading', fullTabPath); module.debug('Content is already loading', fullTabPath);
$tab.addClass(className.loading);
} }
else if($.api !== undefined) { else if($.api !== undefined) {
requestSettings = $.extend(true, { requestSettings = $.extend(true, {
@ -416,25 +454,6 @@ $.fn.tab = function(parameters) {
else { else {
module.error(error.api); module.error(error.api);
} }
},
update: function(tabPath, html, evaluateScripts) {
var
$tab = module.get.tabElement(tabPath),
tab = $tab[0]
;
evaluateScripts = (evaluateScripts !== undefined)
? evaluateScripts
: settings.evaluateScripts
;
if(evaluateScripts) {
module.debug('Updating HTML and evaluating inline scripts', tabPath, html);
$tab.html(html);
}
else {
module.debug('Updating HTML', tabPath, html);
tab.innerHTML = html;
}
} }
}, },
@ -445,25 +464,34 @@ $.fn.tab = function(parameters) {
}, },
tab: function(tabPath) { tab: function(tabPath) {
var var
$tab = module.get.tabElement(tabPath)
$tab = module.get.tabElement(tabPath),
isActive = $tab.hasClass(className.active)
; ;
module.verbose('Showing tab content for', $tab); module.verbose('Showing tab content for', $tab);
$tab
.addClass(className.active)
.siblings($tabs)
.removeClass(className.active + ' ' + className.loading)
;
if(!isActive) {
$tab
.addClass(className.active)
.siblings($tabs)
.removeClass(className.active + ' ' + className.loading)
;
if($tab.length > 0) {
settings.onTabVisible.call($tab[0], tabPath);
}
}
}, },
navigation: function(tabPath) { navigation: function(tabPath) {
var var
$navigation = module.get.navElement(tabPath)
$navigation = module.get.navElement(tabPath),
isActive = $navigation.hasClass(className.active)
; ;
module.verbose('Activating tab navigation for', $navigation, tabPath); module.verbose('Activating tab navigation for', $navigation, tabPath);
$navigation
.addClass(className.active)
.siblings($allModules)
.removeClass(className.active + ' ' + className.loading)
;
if(!isActive) {
$navigation
.addClass(className.active)
.siblings($allModules)
.removeClass(className.active + ' ' + className.loading)
;
}
} }
}, },
@ -789,6 +817,8 @@ $.fn.tab.settings = {
onTabInit : function(tabPath, parameterArray, historyEvent) {}, // called first time loaded onTabInit : function(tabPath, parameterArray, historyEvent) {}, // called first time loaded
onTabLoad : function(tabPath, parameterArray, historyEvent) {}, // called on every load onTabLoad : function(tabPath, parameterArray, historyEvent) {}, // called on every load
onTabVisible : function(tabPath, parameterArray, historyEvent) {}, // called every time tab visible
onTabRequest : function(tabPath, parameterArray, historyEvent) {}, // called ever time a tab beings loading remote content
templates : { templates : {
determineTitle: function(tabArray) {} // returns page title for path determineTitle: function(tabArray) {} // returns page title for path

Loading…
Cancel
Save