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 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** - 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. - **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** - 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 `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** - Fixes `ascending` and `descending` icons were reversed in table
- **Table** - `very basic table` now works together with `padded 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) ? $(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 = [],
@ -33,7 +29,7 @@ $.fn.tab = function(parameters) {
methodInvoked = (typeof query == 'string'), methodInvoked = (typeof query == 'string'),
queryArguments = [].slice.call(arguments, 1), queryArguments = [].slice.call(arguments, 1),
module,
initializedHistory = false,
returnedValue returnedValue
; ;
@ -41,56 +37,86 @@ $.fn.tab = function(parameters) {
.each(function() { .each(function() {
var 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, $context,
$tabs, $tabs,
cache = {},
firstLoad = true,
recursionDepth = 0,
element = this,
instance = $module.data(moduleNamespace),
activeTabPath, activeTabPath,
parameterArray, parameterArray,
historyEvent,
module,
historyEvent
element = this,
instance = $module.data(moduleNamespace)
; ;
module = { module = {
initialize: function() { initialize: function() {
module.debug('Initializing tab menu item', $module); module.debug('Initializing tab menu item', $module);
module.fix.callbacks(); module.fix.callbacks();
module.determineTabs(); module.determineTabs();
module.debug('Determining tabs', settings.context, $tabs);
module.debug('Determining tabs', settings.context, $tabs);
// set up automatic routing // set up automatic routing
if(settings.auto) { if(settings.auto) {
module.set.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(); 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() { determineTabs: function() {
var var
$reference $reference
@ -100,7 +126,7 @@ $.fn.tab = function(parameters) {
if(settings.context === 'parent') { if(settings.context === 'parent') {
if($module.closest(selector.ui).length > 0) { if($module.closest(selector.ui).length > 0) {
$reference = $module.closest(selector.ui); $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 { else {
$reference = $module; $reference = $module;
@ -115,7 +141,6 @@ $.fn.tab = function(parameters) {
else { else {
$context = $('body'); $context = $('body');
} }
// find tabs // find tabs
if(settings.childrenOnly) { if(settings.childrenOnly) {
$tabs = $context.children(selector.tabs); $tabs = $context.children(selector.tabs);
@ -146,49 +171,31 @@ $.fn.tab = function(parameters) {
}, },
initializeHistory: function() { 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: { event: {
click: function(event) { click: function(event) {
var var
@ -296,13 +303,10 @@ $.fn.tab = function(parameters) {
changeTab: function(tabPath) { changeTab: function(tabPath) {
var var
tabPath = (typeof tabPath == 'string')
? tabPath.toLowerCase()
: tabPath,
pushStateAvailable = (window.history && window.history.pushState), pushStateAvailable = (window.history && window.history.pushState),
shouldIgnoreLoad = (pushStateAvailable && settings.ignoreFirstLoad && firstLoad), shouldIgnoreLoad = (pushStateAvailable && settings.ignoreFirstLoad && firstLoad),
remoteContent = (settings.auto || $.isPlainObject(settings.apiSettings) ), 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) pathArray = (remoteContent && !shouldIgnoreLoad)
? module.utilities.pathToArray(tabPath) ? module.utilities.pathToArray(tabPath)
: module.get.defaultPathArray(tabPath) : module.get.defaultPathArray(tabPath)
@ -632,6 +636,9 @@ $.fn.tab = function(parameters) {
if(pathName === undefined) { if(pathName === undefined) {
pathName = activeTabPath; pathName = activeTabPath;
} }
if(typeof pathName == 'string') {
pathName = pathName.toLowerCase();
}
return typeof pathName == 'string' return typeof pathName == 'string'
? pathName.split('/') ? pathName.split('/')
: [pathName] : [pathName]
@ -814,9 +821,6 @@ $.fn.tab = function(parameters) {
} }
}) })
; ;
if(module && !methodInvoked) {
module.initializeHistory();
}
return (returnedValue !== undefined) return (returnedValue !== undefined)
? returnedValue ? returnedValue
: this : this

Loading…
Cancel
Save