From 98de07d98c379c5fd160e0ff0cbf6bf555113f7e Mon Sep 17 00:00:00 2001 From: jlukic Date: Tue, 23 Jun 2015 16:29:49 -0400 Subject: [PATCH] Fix issues with tab module scoping caused by m initializeHistory. Fixes some minor jslint --- RELEASE-NOTES.md | 2 + src/definitions/modules/tab.js | 156 +++++++++++++++++---------------- 2 files changed, 82 insertions(+), 76 deletions(-) diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index cfc0d7a15..f70049c7c 100644 --- a/RELEASE-NOTES.md +++ b/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` diff --git a/src/definitions/modules/tab.js b/src/definitions/modules/tab.js index be0ad8d50..9debd5a21 100644 --- a/src/definitions/modules/tab.js +++ b/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