Browse Source

updates dropdown.js to use latest invoke

Former-commit-id: 45cc09fc6c
Former-commit-id: 068d2fc8c8
pull/258/head
jlukic 11 years ago
parent
commit
0e7c128adb
1 changed files with 53 additions and 26 deletions
  1. 79
      src/modules/dropdown.js

79
src/modules/dropdown.js

@ -15,19 +15,7 @@ $.fn.dropdown = function(parameters) {
$allModules = $(this), $allModules = $(this),
$document = $(document), $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(), time = new Date().getTime(),
performance = [], performance = [],
@ -41,17 +29,30 @@ $.fn.dropdown = function(parameters) {
$allModules $allModules
.each(function() { .each(function() {
var 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 module
; ;
@ -595,8 +596,8 @@ $.fn.dropdown = function(parameters) {
totalTime += data['Execution Time']; totalTime += data['Execution Time'];
}); });
title += ' ' + totalTime + 'ms'; title += ' ' + totalTime + 'ms';
if(dropdownSelector) {
title += ' \'' + dropdownSelector + '\'';
if(moduleSelector) {
title += ' \'' + moduleSelector + '\'';
} }
if( (console.group !== undefined || console.table !== undefined) && performance.length > 0) { if( (console.group !== undefined || console.table !== undefined) && performance.length > 0) {
console.groupCollapsed(title); console.groupCollapsed(title);
@ -616,7 +617,8 @@ $.fn.dropdown = function(parameters) {
invoke: function(query, passedArguments, context) { invoke: function(query, passedArguments, context) {
var var
maxDepth, maxDepth,
found
found,
response
; ;
passedArguments = passedArguments || queryArguments; passedArguments = passedArguments || queryArguments;
context = element || context; context = element || context;
@ -624,21 +626,46 @@ $.fn.dropdown = function(parameters) {
query = query.split(/[\. ]/); query = query.split(/[\. ]/);
maxDepth = query.length - 1; maxDepth = query.length - 1;
$.each(query, function(depth, value) { $.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) ) { if( $.isPlainObject( instance[value] ) && (depth != maxDepth) ) {
instance = instance[value]; instance = instance[value];
} }
else if( $.isPlainObject( instance[camelCaseValue] ) && (depth != maxDepth) ) {
instance = instance[camelCaseValue];
}
else if( instance[value] !== undefined ) { else if( instance[value] !== undefined ) {
found = instance[value]; found = instance[value];
return false;
}
else if( instance[camelCaseValue] !== undefined ) {
found = instance[camelCaseValue];
return false;
} }
else { else {
module.error(error.method); module.error(error.method);
return false;
} }
}); });
} }
if ( $.isFunction( found ) ) { 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;
} }
}; };

Loading…
Cancel
Save