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' title : 'Tab'
description : 'A tab is a section of content tied to a navigation menu' description : 'A tab is a section of content tied to a navigation menu'
type : 'Draft'
type : 'UI Module'
--- ---
<script src="/javascript/tab.js"></script> <script src="/javascript/tab.js"></script>
<%- @partial('header', { tabs: 'module' }) %>
<%- @partial('header', { tabs: { examples: 'Examples', usage: 'Usage', settings: 'Settings' } }) %>
<div class="main container"> <div class="main container">
@ -18,7 +18,6 @@ type : 'Draft'
<div class="peek"> <div class="peek">
<div class="ui vertical pointing secondary menu"> <div class="ui vertical pointing secondary menu">
<a class="active item">Types</a> <a class="active item">Types</a>
<a class="item">Variations</a>
</div> </div>
</div> </div>
@ -29,7 +28,7 @@ type : 'Draft'
<h4 class="ui header">Initializing tabs</h4> <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>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> <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) $allModules = $.isFunction(this)
? $(window) ? $(window)
: $(this), : $(this),
settings = ( $.isPlainObject(parameters) )
? $.extend(true, {}, $.fn.tab.settings, parameters)
: $.extend({}, $.fn.tab.settings),
moduleSelector = $allModules.selector || '', moduleSelector = $allModules.selector || '',
time = new Date().getTime(), time = new Date().getTime(),
performance = [], performance = [],
@ -25,6 +30,8 @@ $.tab = $.fn.tab = function(parameters) {
query = arguments[0], query = arguments[0],
methodInvoked = (typeof query == 'string'), methodInvoked = (typeof query == 'string'),
queryArguments = [].slice.call(arguments, 1), queryArguments = [].slice.call(arguments, 1),
module,
returnedValue returnedValue
; ;
@ -32,9 +39,6 @@ $.tab = $.fn.tab = function(parameters) {
$allModules $allModules
.each(function() { .each(function() {
var var
settings = ( $.isPlainObject(parameters) )
? $.extend(true, {}, $.fn.tab.settings, parameters)
: $.extend({}, $.fn.tab.settings),
className = settings.className, className = settings.className,
metadata = settings.metadata, metadata = settings.metadata,
@ -57,8 +61,7 @@ $.tab = $.fn.tab = function(parameters) {
historyEvent, historyEvent,
element = this, element = this,
instance = $module.data(moduleNamespace),
module
instance = $module.data(moduleNamespace)
; ;
module = { module = {
@ -86,8 +89,6 @@ $.tab = $.fn.tab = function(parameters) {
.on('click' + eventNamespace, module.event.click) .on('click' + eventNamespace, module.event.click)
; ;
} }
module.initializeHistory();
module.instantiate(); module.instantiate();
}, },
@ -142,7 +143,6 @@ $.tab = $.fn.tab = function(parameters) {
} }
} }
$.address $.address
.unbind('change')
.bind('change', module.event.history.change) .bind('change', module.event.history.change)
; ;
} }
@ -306,7 +306,9 @@ $.tab = $.fn.tab = function(parameters) {
} }
} }
else { else {
module.error(error.missingTab, tab);
if(!settings.history) {
module.error(error.missingTab, $module, currentPath);
}
return false; return false;
} }
}); });
@ -320,7 +322,7 @@ $.tab = $.fn.tab = function(parameters) {
apiSettings = { apiSettings = {
dataType : 'html', dataType : 'html',
stateContext : $tab, stateContext : $tab,
success : function(response) {
onSuccess : function(response) {
module.cache.add(fullTabPath, response); module.cache.add(fullTabPath, response);
module.content.update(tabPath, response); module.content.update(tabPath, response);
if(tabPath == activeTabPath) { if(tabPath == activeTabPath) {
@ -687,6 +689,9 @@ $.tab = $.fn.tab = function(parameters) {
} }
}) })
; ;
if(!methodInvoked) {
module.initializeHistory();
}
return (returnedValue !== undefined) return (returnedValue !== undefined)
? returnedValue ? returnedValue
: this : this
@ -745,7 +750,7 @@ $.fn.tab.settings = {
error: { error: {
api : 'You attempted to load content without API module', api : 'You attempted to load content without API module',
method : 'The method you called is not defined', 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.', noContent : 'The tab you specified is missing a content url.',
path : 'History enabled, but no path was specified', path : 'History enabled, but no path was specified',
recursion : 'Max recursive depth reached', recursion : 'Max recursive depth reached',

Loading…
Cancel
Save