|
|
@ -21,10 +21,6 @@ $.fn.tab = function(parameters) { |
|
|
|
? $(window) |
|
|
|
: $(this), |
|
|
|
|
|
|
|
settings = ( $.isPlainObject(parameters) ) |
|
|
|
? $.extend(true, {}, $.fn.tab.settings, parameters) |
|
|
|
: $.extend({}, $.fn.tab.settings), |
|
|
|
|
|
|
|
moduleSelector = $allModules.selector || '', |
|
|
|
time = new Date().getTime(), |
|
|
|
performance = [], |
|
|
@ -33,7 +29,7 @@ $.fn.tab = function(parameters) { |
|
|
|
methodInvoked = (typeof query == 'string'), |
|
|
|
queryArguments = [].slice.call(arguments, 1), |
|
|
|
|
|
|
|
module, |
|
|
|
initializedHistory = false, |
|
|
|
returnedValue |
|
|
|
; |
|
|
|
|
|
|
@ -41,56 +37,86 @@ $.fn.tab = function(parameters) { |
|
|
|
.each(function() { |
|
|
|
var |
|
|
|
|
|
|
|
className = settings.className, |
|
|
|
metadata = settings.metadata, |
|
|
|
selector = settings.selector, |
|
|
|
error = settings.error, |
|
|
|
|
|
|
|
eventNamespace = '.' + settings.namespace, |
|
|
|
moduleNamespace = 'module-' + settings.namespace, |
|
|
|
settings = ( $.isPlainObject(parameters) ) |
|
|
|
? $.extend(true, {}, $.fn.tab.settings, parameters) |
|
|
|
: $.extend({}, $.fn.tab.settings), |
|
|
|
|
|
|
|
$module = $(this), |
|
|
|
className = settings.className, |
|
|
|
metadata = settings.metadata, |
|
|
|
selector = settings.selector, |
|
|
|
error = settings.error, |
|
|
|
|
|
|
|
cache = {}, |
|
|
|
firstLoad = true, |
|
|
|
recursionDepth = 0, |
|
|
|
eventNamespace = '.' + settings.namespace, |
|
|
|
moduleNamespace = 'module-' + settings.namespace, |
|
|
|
|
|
|
|
$module = $(this), |
|
|
|
$context, |
|
|
|
$tabs, |
|
|
|
|
|
|
|
cache = {}, |
|
|
|
firstLoad = true, |
|
|
|
recursionDepth = 0, |
|
|
|
element = this, |
|
|
|
instance = $module.data(moduleNamespace), |
|
|
|
|
|
|
|
activeTabPath, |
|
|
|
parameterArray, |
|
|
|
historyEvent, |
|
|
|
module, |
|
|
|
|
|
|
|
historyEvent |
|
|
|
|
|
|
|
element = this, |
|
|
|
instance = $module.data(moduleNamespace) |
|
|
|
; |
|
|
|
|
|
|
|
module = { |
|
|
|
|
|
|
|
initialize: function() { |
|
|
|
module.debug('Initializing tab menu item', $module); |
|
|
|
|
|
|
|
module.fix.callbacks(); |
|
|
|
|
|
|
|
module.determineTabs(); |
|
|
|
module.debug('Determining tabs', settings.context, $tabs); |
|
|
|
|
|
|
|
|
|
|
|
module.debug('Determining tabs', settings.context, $tabs); |
|
|
|
// set up automatic routing
|
|
|
|
if(settings.auto) { |
|
|
|
module.set.auto(); |
|
|
|
} |
|
|
|
module.bind.events(); |
|
|
|
|
|
|
|
// attach events if navigation wasn't set to window
|
|
|
|
if( !$.isWindow( element ) ) { |
|
|
|
module.debug('Attaching tab activation events to element', $module); |
|
|
|
$module |
|
|
|
.on('click' + eventNamespace, module.event.click) |
|
|
|
; |
|
|
|
if(settings.history && !initializedHistory) { |
|
|
|
module.initializeHistory(); |
|
|
|
initializedHistory = true; |
|
|
|
} |
|
|
|
|
|
|
|
module.instantiate(); |
|
|
|
}, |
|
|
|
|
|
|
|
instantiate: function () { |
|
|
|
module.verbose('Storing instance of module', module); |
|
|
|
instance = module; |
|
|
|
$module |
|
|
|
.data(moduleNamespace, module) |
|
|
|
; |
|
|
|
}, |
|
|
|
|
|
|
|
destroy: function() { |
|
|
|
module.debug('Destroying tabs', $module); |
|
|
|
$module |
|
|
|
.removeData(moduleNamespace) |
|
|
|
.off(eventNamespace) |
|
|
|
; |
|
|
|
}, |
|
|
|
|
|
|
|
bind: { |
|
|
|
events: function() { |
|
|
|
// if using $.tab dont add events
|
|
|
|
if( !$.isWindow( element ) ) { |
|
|
|
module.debug('Attaching tab activation events to element', $module); |
|
|
|
$module |
|
|
|
.on('click' + eventNamespace, module.event.click) |
|
|
|
; |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
determineTabs: function() { |
|
|
|
var |
|
|
|
$reference |
|
|
@ -100,7 +126,7 @@ $.fn.tab = function(parameters) { |
|
|
|
if(settings.context === 'parent') { |
|
|
|
if($module.closest(selector.ui).length > 0) { |
|
|
|
$reference = $module.closest(selector.ui); |
|
|
|
module.verbose('Using closest UI element for determining parent', $reference); |
|
|
|
module.verbose('Using closest UI element as parent', $reference); |
|
|
|
} |
|
|
|
else { |
|
|
|
$reference = $module; |
|
|
@ -115,7 +141,6 @@ $.fn.tab = function(parameters) { |
|
|
|
else { |
|
|
|
$context = $('body'); |
|
|
|
} |
|
|
|
|
|
|
|
// find tabs
|
|
|
|
if(settings.childrenOnly) { |
|
|
|
$tabs = $context.children(selector.tabs); |
|
|
@ -146,49 +171,31 @@ $.fn.tab = function(parameters) { |
|
|
|
}, |
|
|
|
|
|
|
|
initializeHistory: function() { |
|
|
|
if(settings.history) { |
|
|
|
module.debug('Initializing page state'); |
|
|
|
if( $.address === undefined ) { |
|
|
|
module.error(error.state); |
|
|
|
return false; |
|
|
|
} |
|
|
|
else { |
|
|
|
if(settings.historyType == 'state') { |
|
|
|
module.debug('Using HTML5 to manage state'); |
|
|
|
if(settings.path !== false) { |
|
|
|
$.address |
|
|
|
.history(true) |
|
|
|
.state(settings.path) |
|
|
|
; |
|
|
|
} |
|
|
|
else { |
|
|
|
module.error(error.path); |
|
|
|
return false; |
|
|
|
} |
|
|
|
module.debug('Initializing page state'); |
|
|
|
if( $.address === undefined ) { |
|
|
|
module.error(error.state); |
|
|
|
return false; |
|
|
|
} |
|
|
|
else { |
|
|
|
if(settings.historyType == 'state') { |
|
|
|
module.debug('Using HTML5 to manage state'); |
|
|
|
if(settings.path !== false) { |
|
|
|
$.address |
|
|
|
.history(true) |
|
|
|
.state(settings.path) |
|
|
|
; |
|
|
|
} |
|
|
|
else { |
|
|
|
module.error(error.path); |
|
|
|
return false; |
|
|
|
} |
|
|
|
$.address |
|
|
|
.bind('change', module.event.history.change) |
|
|
|
; |
|
|
|
} |
|
|
|
$.address |
|
|
|
.bind('change', module.event.history.change) |
|
|
|
; |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
instantiate: function () { |
|
|
|
module.verbose('Storing instance of module', module); |
|
|
|
instance = module; |
|
|
|
$module |
|
|
|
.data(moduleNamespace, module) |
|
|
|
; |
|
|
|
}, |
|
|
|
|
|
|
|
destroy: function() { |
|
|
|
module.debug('Destroying tabs', $module); |
|
|
|
$module |
|
|
|
.removeData(moduleNamespace) |
|
|
|
.off(eventNamespace) |
|
|
|
; |
|
|
|
}, |
|
|
|
|
|
|
|
event: { |
|
|
|
click: function(event) { |
|
|
|
var |
|
|
@ -296,13 +303,10 @@ $.fn.tab = function(parameters) { |
|
|
|
|
|
|
|
changeTab: function(tabPath) { |
|
|
|
var |
|
|
|
tabPath = (typeof tabPath == 'string') |
|
|
|
? tabPath.toLowerCase() |
|
|
|
: tabPath, |
|
|
|
pushStateAvailable = (window.history && window.history.pushState), |
|
|
|
shouldIgnoreLoad = (pushStateAvailable && settings.ignoreFirstLoad && firstLoad), |
|
|
|
remoteContent = (settings.auto || $.isPlainObject(settings.apiSettings) ), |
|
|
|
// only get default path if not remote content
|
|
|
|
// only add default path if not remote content
|
|
|
|
pathArray = (remoteContent && !shouldIgnoreLoad) |
|
|
|
? module.utilities.pathToArray(tabPath) |
|
|
|
: module.get.defaultPathArray(tabPath) |
|
|
@ -632,6 +636,9 @@ $.fn.tab = function(parameters) { |
|
|
|
if(pathName === undefined) { |
|
|
|
pathName = activeTabPath; |
|
|
|
} |
|
|
|
if(typeof pathName == 'string') { |
|
|
|
pathName = pathName.toLowerCase(); |
|
|
|
} |
|
|
|
return typeof pathName == 'string' |
|
|
|
? pathName.split('/') |
|
|
|
: [pathName] |
|
|
@ -814,9 +821,6 @@ $.fn.tab = function(parameters) { |
|
|
|
} |
|
|
|
}) |
|
|
|
; |
|
|
|
if(module && !methodInvoked) { |
|
|
|
module.initializeHistory(); |
|
|
|
} |
|
|
|
return (returnedValue !== undefined) |
|
|
|
? returnedValue |
|
|
|
: this |
|
|
|