Browse Source

Fix issues with tab module scoping caused by m initializeHistory. Fixes some minor jslint

flex-list
jlukic 10 years ago
parent
commit
98de07d98c
2 changed files with 82 additions and 76 deletions
  1. 2
      RELEASE-NOTES.md
  2. 156
      src/definitions/modules/tab.js

2
RELEASE-NOTES.md

@ -259,7 +259,9 @@
- **Sticky** - Fix issue with sticky content scroll css transition causing element to scroll too slowly when cannot fit on screen.
- **Sticky** - Fix issues when `pushing: true` with sticky content having incorrect bottom spacing, when container has bottom padding
- **Sticky** - Fixed issue with sticky content animating width on display in some cases.
- **Tab** - multiple tab groups initialized together with `context: 'parent'` will now each use their own parent
- **Tab** - Tab name is no longer case sensitive
- **Tab** - Tabs now use the standard component design pattern internally
- **Table** - Fixes `sorted` column are not correctly centered with `center aligned` due to margin on sort icon
- **Table** - Fixes `ascending` and `descending` icons were reversed in table
- **Table** - `very basic table` now works together with `padded table`

156
src/definitions/modules/tab.js

@ -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

Loading…
Cancel
Save