From 0e7c128adba0999a922e76846566d51c5cc4c91c Mon Sep 17 00:00:00 2001 From: jlukic Date: Fri, 11 Oct 2013 00:41:39 -0400 Subject: [PATCH] updates dropdown.js to use latest invoke Former-commit-id: 45cc09fc6c2123b160dba1c684d46f9521cf07dc Former-commit-id: 068d2fc8c8ab26265c41d54bb4c27ec75c270cb8 --- src/modules/dropdown.js | 79 +++++++++++++++++++++++++++-------------- 1 file changed, 53 insertions(+), 26 deletions(-) diff --git a/src/modules/dropdown.js b/src/modules/dropdown.js index b28a21ee0..3668a4bfa 100755 --- a/src/modules/dropdown.js +++ b/src/modules/dropdown.js @@ -15,19 +15,7 @@ $.fn.dropdown = function(parameters) { $allModules = $(this), $document = $(document), - settings = ( $.isPlainObject(parameters) ) - ? $.extend(true, {}, $.fn.dropdown.settings, parameters) - : $.fn.dropdown.settings, - - className = settings.className, - metadata = settings.metadata, - namespace = settings.namespace, - selector = settings.selector, - error = settings.error, - - eventNamespace = '.' + namespace, - dropdownNamespace = 'module-' + namespace, - dropdownSelector = $allModules.selector || '', + moduleSelector = $allModules.selector || '', time = new Date().getTime(), performance = [], @@ -41,17 +29,30 @@ $.fn.dropdown = function(parameters) { $allModules .each(function() { var - $module = $(this), - $item = $module.find(selector.item), - $text = $module.find(selector.text), - $input = $module.find(selector.input), + settings = ( $.isPlainObject(parameters) ) + ? $.extend(true, {}, $.fn.dropdown.settings, parameters) + : $.fn.dropdown.settings, + + className = settings.className, + metadata = settings.metadata, + namespace = settings.namespace, + selector = settings.selector, + error = settings.error, - $menu = $module.children(selector.menu), + eventNamespace = '.' + namespace, + dropdownNamespace = 'module-' + namespace, + isTouchDevice = ('ontouchstart' in document.documentElement), - isTouchDevice = ('ontouchstart' in document.documentElement), + $module = $(this), + $item = $module.find(selector.item), + $text = $module.find(selector.text), + $input = $module.find(selector.input), - element = this, - instance = $module.data(dropdownNamespace), + $menu = $module.children(selector.menu), + + + element = this, + instance = $module.data(dropdownNamespace), module ; @@ -595,8 +596,8 @@ $.fn.dropdown = function(parameters) { totalTime += data['Execution Time']; }); title += ' ' + totalTime + 'ms'; - if(dropdownSelector) { - title += ' \'' + dropdownSelector + '\''; + if(moduleSelector) { + title += ' \'' + moduleSelector + '\''; } if( (console.group !== undefined || console.table !== undefined) && performance.length > 0) { console.groupCollapsed(title); @@ -616,7 +617,8 @@ $.fn.dropdown = function(parameters) { invoke: function(query, passedArguments, context) { var maxDepth, - found + found, + response ; passedArguments = passedArguments || queryArguments; context = element || context; @@ -624,21 +626,46 @@ $.fn.dropdown = function(parameters) { query = query.split(/[\. ]/); maxDepth = query.length - 1; $.each(query, function(depth, value) { + var camelCaseValue = (depth != maxDepth) + ? value + query[depth + 1].charAt(0).toUpperCase() + query[depth + 1].slice(1) + : query + ; if( $.isPlainObject( instance[value] ) && (depth != maxDepth) ) { instance = instance[value]; } + else if( $.isPlainObject( instance[camelCaseValue] ) && (depth != maxDepth) ) { + instance = instance[camelCaseValue]; + } else if( instance[value] !== undefined ) { found = instance[value]; + return false; + } + else if( instance[camelCaseValue] !== undefined ) { + found = instance[camelCaseValue]; + return false; } else { module.error(error.method); + return false; } }); } if ( $.isFunction( found ) ) { - return found.apply(context, passedArguments); + response = found.apply(context, passedArguments); + } + else if(found !== undefined) { + response = found; + } + if($.isArray(invokedResponse)) { + invokedResponse.push(response); + } + else if(typeof invokedResponse == 'string') { + invokedResponse = [invokedResponse, response]; + } + else if(response !== undefined) { + invokedResponse = response; } - return found || false; + return found; } };