Browse Source

Simplify logic with parent context

pull/1257/head
jlukic 10 years ago
parent
commit
d1c47dfa57
1 changed files with 25 additions and 21 deletions
  1. 46
      src/definitions/modules/tab.js

46
src/definitions/modules/tab.js

@ -51,13 +51,13 @@ $.tab = $.fn.tab = function(parameters) {
moduleNamespace = 'module-' + settings.namespace, moduleNamespace = 'module-' + settings.namespace,
$module = $(this), $module = $(this),
$tabs = $(selector.tabs),
cache = {}, cache = {},
firstLoad = true, firstLoad = true,
recursionDepth = 0, recursionDepth = 0,
$context, $context,
$tabs,
activeTabPath, activeTabPath,
parameterArray, parameterArray,
historyEvent, historyEvent,
@ -71,10 +71,8 @@ $.tab = $.fn.tab = function(parameters) {
initialize: function() { initialize: function() {
module.debug('Initializing tab menu item', $module); module.debug('Initializing tab menu item', $module);
if(settings.context) {
module.determineTabs();
module.debug('Using only tabs inside context', settings.context, $tabs);
}
module.determineTabs();
module.debug('Determining tabs', settings.context, $tabs);
// set up automatic routing // set up automatic routing
if(settings.auto) { if(settings.auto) {
@ -98,21 +96,28 @@ $.tab = $.fn.tab = function(parameters) {
var var
$reference $reference
; ;
// determine tab context
if(settings.context === 'parent') { if(settings.context === 'parent') {
if($module.closest('.' + className.ui).size() > 0) {
$reference = $module.closest('.' + className.ui);
if($module.closest(selector.ui).size() > 0) {
$reference = $module.closest(selector.ui);
module.verbose('Using closest UI element for determining parent', $reference); module.verbose('Using closest UI element for determining parent', $reference);
} }
else { else {
$reference = $module; $reference = $module;
} }
$context = $reference.parent(); $context = $reference.parent();
module.verbose('Determining parent element for creating context', $context);
module.verbose('Determined parent element for creating context', $context);
} }
else {
else if(settings.context) {
$context = $(settings.context); $context = $(settings.context);
module.verbose('Using selector for tab context', settings.context, $context); module.verbose('Using selector for tab context', settings.context, $context);
} }
else {
$context = $('body');
}
// find tabs
if(settings.childrenOnly) { if(settings.childrenOnly) {
$tabs = $context.children(selector.tabs); $tabs = $context.children(selector.tabs);
module.debug('Searching tab context children for tabs', $context, $tabs); module.debug('Searching tab context children for tabs', $context, $tabs);
@ -308,11 +313,9 @@ $.tab = $.fn.tab = function(parameters) {
$.proxy(settings.onTabLoad, $tab)(currentPath, parameterArray, historyEvent); $.proxy(settings.onTabLoad, $tab)(currentPath, parameterArray, historyEvent);
} }
} }
else {
else if(tabPath.search('/') == -1) {
// look for in page anchor // look for in page anchor
$anchor = (tabPath.search('/') == -1)
? $('#' + tabPath + ', a[name="' + tabPath + '"]')
: $('#qqq'),
$anchor = $('#' + tabPath + ', a[name="' + tabPath + '"]'),
currentPath = $anchor.closest('[data-tab]').data('tab'); currentPath = $anchor.closest('[data-tab]').data('tab');
$tab = module.get.tabElement(currentPath); $tab = module.get.tabElement(currentPath);
// if anchor exists use parent tab // if anchor exists use parent tab
@ -324,10 +327,11 @@ $.tab = $.fn.tab = function(parameters) {
module.debug('First time tab loaded calling tab init'); module.debug('First time tab loaded calling tab init');
$.proxy(settings.onTabInit, $tab)(currentPath, parameterArray, historyEvent); $.proxy(settings.onTabInit, $tab)(currentPath, parameterArray, historyEvent);
} }
return false;
} }
else {
module.error(error.missingTab, $module, currentPath);
}
}
else {
module.error(error.missingTab, $module, $context, currentPath);
return false; return false;
} }
}); });
@ -729,8 +733,8 @@ $.fn.tab.settings = {
namespace : 'tab', namespace : 'tab',
debug : false, debug : false,
verbose : false,
performance : false,
verbose : true,
performance : true,
// uses pjax style endpoints fetching content from same url with remote-content headers // uses pjax style endpoints fetching content from same url with remote-content headers
auto : false, auto : false,
@ -784,12 +788,12 @@ $.fn.tab.settings = {
className : { className : {
loading : 'loading', loading : 'loading',
active : 'active',
ui : 'ui'
active : 'active'
}, },
selector : { selector : {
tabs : '.ui.tab'
tabs : '.ui.tab',
ui : '.ui'
} }
}; };

Loading…
Cancel
Save