Browse Source

Fixes tab history to work correctly when multiple tab elements must use same history event. Adds tab documentation back into docs

pull/954/head
jlukic 10 years ago
parent
commit
fd9e766c37
2 changed files with 19 additions and 15 deletions
  1. 7
      server/documents/modules/tab.html.eco
  2. 27
      src/definitions/modules/tab.js

7
server/documents/modules/tab.html.eco

@ -4,12 +4,12 @@ css : 'tab'
title : 'Tab'
description : 'A tab is a section of content tied to a navigation menu'
type : 'Draft'
type : 'UI Module'
---
<script src="/javascript/tab.js"></script>
<%- @partial('header', { tabs: 'module' }) %>
<%- @partial('header', { tabs: { examples: 'Examples', usage: 'Usage', settings: 'Settings' } }) %>
<div class="main container">
@ -18,7 +18,6 @@ type : 'Draft'
<div class="peek">
<div class="ui vertical pointing secondary menu">
<a class="active item">Types</a>
<a class="item">Variations</a>
</div>
</div>
@ -29,7 +28,7 @@ type : 'Draft'
<h4 class="ui header">Initializing tabs</h4>
<p>Tabs are usually used in concert with an element that activates the tab. Tabs are initialized on the activating item instead of the tab.</p>
<p>If there are no menus that activate tab elements on the page, tabs can be initialized globally by using <code>$.tab()</code></p>
<p>If there are no menus that activate tab elements on the page, tabs can be initialized globally by using <code>$.tab()</code> and activated programmatically using <code>$.tab('change tab', path);</code></p>
<p>Tabs are connected to their activators with a metadata attribute <code>data-tab</code>. This should be added to both the activating element and the tab itself.</p>

27
src/definitions/modules/tab.js

@ -18,6 +18,11 @@ $.tab = $.fn.tab = function(parameters) {
$allModules = $.isFunction(this)
? $(window)
: $(this),
settings = ( $.isPlainObject(parameters) )
? $.extend(true, {}, $.fn.tab.settings, parameters)
: $.extend({}, $.fn.tab.settings),
moduleSelector = $allModules.selector || '',
time = new Date().getTime(),
performance = [],
@ -25,6 +30,8 @@ $.tab = $.fn.tab = function(parameters) {
query = arguments[0],
methodInvoked = (typeof query == 'string'),
queryArguments = [].slice.call(arguments, 1),
module,
returnedValue
;
@ -32,9 +39,6 @@ $.tab = $.fn.tab = function(parameters) {
$allModules
.each(function() {
var
settings = ( $.isPlainObject(parameters) )
? $.extend(true, {}, $.fn.tab.settings, parameters)
: $.extend({}, $.fn.tab.settings),
className = settings.className,
metadata = settings.metadata,
@ -57,8 +61,7 @@ $.tab = $.fn.tab = function(parameters) {
historyEvent,
element = this,
instance = $module.data(moduleNamespace),
module
instance = $module.data(moduleNamespace)
;
module = {
@ -86,8 +89,6 @@ $.tab = $.fn.tab = function(parameters) {
.on('click' + eventNamespace, module.event.click)
;
}
module.initializeHistory();
module.instantiate();
},
@ -142,7 +143,6 @@ $.tab = $.fn.tab = function(parameters) {
}
}
$.address
.unbind('change')
.bind('change', module.event.history.change)
;
}
@ -306,7 +306,9 @@ $.tab = $.fn.tab = function(parameters) {
}
}
else {
module.error(error.missingTab, tab);
if(!settings.history) {
module.error(error.missingTab, $module, currentPath);
}
return false;
}
});
@ -320,7 +322,7 @@ $.tab = $.fn.tab = function(parameters) {
apiSettings = {
dataType : 'html',
stateContext : $tab,
success : function(response) {
onSuccess : function(response) {
module.cache.add(fullTabPath, response);
module.content.update(tabPath, response);
if(tabPath == activeTabPath) {
@ -687,6 +689,9 @@ $.tab = $.fn.tab = function(parameters) {
}
})
;
if(!methodInvoked) {
module.initializeHistory();
}
return (returnedValue !== undefined)
? returnedValue
: this
@ -745,7 +750,7 @@ $.fn.tab.settings = {
error: {
api : 'You attempted to load content without API module',
method : 'The method you called is not defined',
missingTab : 'Tab cannot be found',
missingTab : 'Activated tab cannot be found for this context.',
noContent : 'The tab you specified is missing a content url.',
path : 'History enabled, but no path was specified',
recursion : 'Max recursive depth reached',

Loading…
Cancel
Save