From b4dcde6baf6fdaecb375826f4126202ab08988ab Mon Sep 17 00:00:00 2001 From: jlukic Date: Sat, 28 Sep 2013 09:13:52 -0400 Subject: [PATCH] preserves variable name styles for dropdown --- src/modules/dropdown.js | 263 ++++++++++++++++++++-------------------- 1 file changed, 131 insertions(+), 132 deletions(-) diff --git a/src/modules/dropdown.js b/src/modules/dropdown.js index 7ce62a256..c31938e68 100755 --- a/src/modules/dropdown.js +++ b/src/modules/dropdown.js @@ -13,10 +13,10 @@ $.fn.dropdown = function(parameters) { var - $allDropdowns = $(this), - $document = $(document), + $allModules = $(this), + $document = $(document), - settings = ( $.isPlainObject(parameters) ) + settings = ( $.isPlainObject(parameters) ) ? $.extend(true, {}, $.fn.dropdown.settings, parameters) : $.fn.dropdown.settings, @@ -28,7 +28,7 @@ $.fn.dropdown = function(parameters) { eventNamespace = '.' + namespace, dropdownNamespace = 'module-' + namespace, - dropdownSelector = $allDropdowns.selector || '', + dropdownSelector = $allModules.selector || '', time = new Date().getTime(), performance = [], @@ -39,72 +39,72 @@ $.fn.dropdown = function(parameters) { invokedResponse ; - $allDropdowns + $allModules .each(function() { var - $dropdown = $(this), - $item = $dropdown.find(selector.item), - $text = $dropdown.find(selector.text), - $input = $dropdown.find(selector.input), + $module = $(this), + $item = $module.find(selector.item), + $text = $module.find(selector.text), + $input = $module.find(selector.input), - $menu = $dropdown.children(selector.menu), + $menu = $module.children(selector.menu), isTouchDevice = ('ontouchstart' in document.documentElement), element = this, - instance = $dropdown.data(dropdownNamespace), - dropdown + instance = $module.data(dropdownNamespace), + module ; - dropdown = { + module = { initialize: function() { - dropdown.debug('Initializing dropdown', settings); + module.debug('Initializing dropdown', settings); if(isTouchDevice) { - $dropdown - .on('touchstart' + eventNamespace, dropdown.event.test.toggle) + $module + .on('touchstart' + eventNamespace, module.event.test.toggle) ; } else if(settings.on == 'click') { - $dropdown - .on('click' + eventNamespace, dropdown.event.test.toggle) + $module + .on('click' + eventNamespace, module.event.test.toggle) ; } else if(settings.on == 'hover') { - $dropdown - .on('mouseenter' + eventNamespace, dropdown.delay.show) - .on('mouseleave' + eventNamespace, dropdown.delay.hide) + $module + .on('mouseenter' + eventNamespace, module.delay.show) + .on('mouseleave' + eventNamespace, module.delay.hide) ; } else { - $dropdown - .on(settings.on + eventNamespace, dropdown.toggle) + $module + .on(settings.on + eventNamespace, module.toggle) ; } if(settings.action == 'form') { - dropdown.set.selected(); + module.set.selected(); } $item - .on('mouseenter' + eventNamespace, dropdown.event.item.mouseenter) - .on('mouseleave' + eventNamespace, dropdown.event.item.mouseleave) - .on(dropdown.get.selectEvent() + eventNamespace, dropdown.event.item.click) + .on('mouseenter' + eventNamespace, module.event.item.mouseenter) + .on('mouseleave' + eventNamespace, module.event.item.mouseleave) + .on(module.get.selectEvent() + eventNamespace, module.event.item.click) ; - dropdown.instantiate(); + module.instantiate(); }, instantiate: function() { - dropdown.verbose('Storing instance of dropdown', dropdown); - $dropdown - .data(dropdownNamespace, dropdown) + module.verbose('Storing instance of dropdown', module); + $module + .data(dropdownNamespace, module) ; }, destroy: function() { - dropdown.verbose('Destroying previous dropdown for', $dropdown); + module.verbose('Destroying previous dropdown for', $module); $item .off(eventNamespace) ; - $dropdown + $module .off(eventNamespace) .removeData(dropdownNamespace) ; @@ -118,11 +118,11 @@ $.fn.dropdown = function(parameters) { test: { toggle: function(event) { - dropdown.determine.intent(event, dropdown.toggle); + module.determine.intent(event, module.toggle); event.stopImmediatePropagation(); }, hide: function(event) { - dropdown.determine.intent(event, dropdown.hide); + module.determine.intent(event, module.hide); event.stopPropagation(); } }, @@ -135,11 +135,11 @@ $.fn.dropdown = function(parameters) { $otherMenus = $(this).siblings(selector.item).children(selector.menu) ; if( $currentMenu.size() > 0 ) { - clearTimeout(dropdown.itemTimer); - dropdown.itemTimer = setTimeout(function() { - dropdown.animate.hide(false, $otherMenus); - dropdown.verbose('Showing sub-menu', $currentMenu); - dropdown.animate.show(false, $currentMenu); + clearTimeout(module.itemTimer); + module.itemTimer = setTimeout(function() { + module.animate.hide(false, $otherMenus); + module.verbose('Showing sub-menu', $currentMenu); + module.animate.show(false, $currentMenu); }, settings.delay.show * 2); } }, @@ -149,10 +149,10 @@ $.fn.dropdown = function(parameters) { $currentMenu = $(this).find(selector.menu) ; if($currentMenu.size() > 0) { - clearTimeout(dropdown.itemTimer); - dropdown.itemTimer = setTimeout(function() { - dropdown.verbose('Hiding sub-menu', $currentMenu); - dropdown.animate.hide(false, $currentMenu); + clearTimeout(module.itemTimer); + module.itemTimer = setTimeout(function() { + module.verbose('Hiding sub-menu', $currentMenu); + module.animate.hide(false, $currentMenu); }, settings.delay.hide); } }, @@ -164,14 +164,14 @@ $.fn.dropdown = function(parameters) { value = $choice.data(metadata.value) || text ; if( $choice.find(selector.menu).size() === 0 ) { - dropdown.verbose('Adding active state to selected item'); + module.verbose('Adding active state to selected item'); $item .removeClass(className.active) ; $choice .addClass(className.active) ; - dropdown.determine.selectAction(text, value); + module.determine.selectAction(text, value); $.proxy(settings.onChange, element)(value, text); event.stopPropagation(); } @@ -187,46 +187,46 @@ $.fn.dropdown = function(parameters) { determine: { selectAction: function(text, value) { - dropdown.verbose('Determining action', settings.action); - if( $.isFunction( dropdown[settings.action] ) ) { - dropdown.verbose('Triggering preset action', settings.action); - dropdown[ settings.action ](text, value); + module.verbose('Determining action', settings.action); + if( $.isFunction( module[settings.action] ) ) { + module.verbose('Triggering preset action', settings.action); + module[ settings.action ](text, value); } else if( $.isFunction(settings.action) ) { - dropdown.verbose('Triggering user action', settings.action); + module.verbose('Triggering user action', settings.action); settings.action(text, value); } else { - dropdown.error(error.action); + module.error(error.action); } }, intent: function(event, callback) { - dropdown.debug('Determining whether event occurred in dropdown', event.target); + module.debug('Determining whether event occurred in dropdown', event.target); callback = callback || function(){}; if( $(event.target).closest($menu).size() === 0 ) { - dropdown.verbose('Triggering event', callback); + module.verbose('Triggering event', callback); callback(); } else { - dropdown.verbose('Event occurred in dropdown, canceling callback'); + module.verbose('Event occurred in dropdown, canceling callback'); } } }, bind: { intent: function() { - dropdown.verbose('Binding hide intent event to document'); + module.verbose('Binding hide intent event to document'); $document - .on(dropdown.get.selectEvent(), dropdown.event.test.hide) + .on(module.get.selectEvent(), module.event.test.hide) ; } }, unbind: { intent: function() { - dropdown.verbose('Removing hide intent event from document'); + module.verbose('Removing hide intent event from document'); $document - .off(dropdown.get.selectEvent()) + .off(module.get.selectEvent()) ; } }, @@ -234,14 +234,14 @@ $.fn.dropdown = function(parameters) { nothing: function() {}, changeText: function(text, value) { - dropdown.set.text(text); - dropdown.hide(); + module.set.text(text); + module.hide(); }, updateForm: function(text, value) { - dropdown.set.text(text); - dropdown.set.value(value); - dropdown.hide(); + module.set.text(text); + module.set.value(value); + module.hide(); }, get: { @@ -275,27 +275,27 @@ $.fn.dropdown = function(parameters) { set: { text: function(text) { - dropdown.debug('Changing text', text, $text); + module.debug('Changing text', text, $text); $text.removeClass(className.placeholder); $text.text(text); }, value: function(value) { - dropdown.debug('Adding selected value to hidden input', value, $input); + module.debug('Adding selected value to hidden input', value, $input); $input.val(value); }, active: function() { - $dropdown.addClass(className.active); + $module.addClass(className.active); }, visible: function() { - $dropdown.addClass(className.visible); + $module.addClass(className.visible); }, selected: function(value) { var - $selectedItem = dropdown.get.item(value), + $selectedItem = module.get.item(value), selectedText ; if($selectedItem) { - dropdown.debug('Setting selected menu item to', $selectedItem); + module.debug('Setting selected menu item to', $selectedItem); selectedText = $selectedItem.data(metadata.text) || $selectedItem.text(); $item .removeClass(className.active) @@ -303,17 +303,17 @@ $.fn.dropdown = function(parameters) { $selectedItem .addClass(className.active) ; - dropdown.set.text(selectedText); + module.set.text(selectedText); } } }, remove: { active: function() { - $dropdown.removeClass(className.active); + $module.removeClass(className.active); }, visible: function() { - $dropdown.removeClass(className.visible); + $module.removeClass(className.visible); } }, @@ -337,7 +337,7 @@ $.fn.dropdown = function(parameters) { return (isTouchDevice || settings.on == 'click'); }, show: function() { - return !$dropdown.hasClass(className.disabled); + return !$module.hasClass(className.disabled); } }, @@ -347,8 +347,8 @@ $.fn.dropdown = function(parameters) { $currentMenu = $subMenu || $menu ; callback = callback || function(){}; - if( dropdown.is.hidden($currentMenu) ) { - dropdown.verbose('Doing menu show animation', $currentMenu); + if( module.is.hidden($currentMenu) ) { + module.verbose('Doing menu show animation', $currentMenu); if(settings.transition == 'none') { callback(); } @@ -370,10 +370,10 @@ $.fn.dropdown = function(parameters) { .delay(50) .animate({ opacity : 1 - }, settings.duration, 'easeOutQuad', dropdown.event.resetStyle) + }, settings.duration, 'easeOutQuad', module.event.resetStyle) .end() .slideDown(100, 'easeOutQuad', function() { - $.proxy(dropdown.event.resetStyle, this)(); + $.proxy(module.event.resetStyle, this)(); callback(); }) ; @@ -383,13 +383,13 @@ $.fn.dropdown = function(parameters) { .hide() .clearQueue() .fadeIn(settings.duration, function() { - $.proxy(dropdown.event.resetStyle, this)(); + $.proxy(module.event.resetStyle, this)(); callback(); }) ; } else { - dropdown.error(error.transition); + module.error(error.transition); } } }, @@ -398,8 +398,8 @@ $.fn.dropdown = function(parameters) { $currentMenu = $subMenu || $menu ; callback = callback || function(){}; - if(dropdown.is.visible($currentMenu) ) { - dropdown.verbose('Doing menu hide animation', $currentMenu); + if(module.is.visible($currentMenu) ) { + module.verbose('Doing menu hide animation', $currentMenu); if($.fn.transition !== undefined) { $currentMenu.transition({ animation : settings.transition + ' out', @@ -420,11 +420,11 @@ $.fn.dropdown = function(parameters) { .css('opacity', 1) .animate({ opacity : 0 - }, 100, 'easeOutQuad', dropdown.event.resetStyle) + }, 100, 'easeOutQuad', module.event.resetStyle) .end() .delay(50) .slideUp(100, 'easeOutQuad', function() { - $.proxy(dropdown.event.resetStyle, this)(); + $.proxy(module.event.resetStyle, this)(); callback(); }) ; @@ -434,72 +434,72 @@ $.fn.dropdown = function(parameters) { .show() .clearQueue() .fadeOut(150, function() { - $.proxy(dropdown.event.resetStyle, this)(); + $.proxy(module.event.resetStyle, this)(); callback(); }) ; } else { - dropdown.error(error.transition); + module.error(error.transition); } } } }, show: function() { - dropdown.debug('Checking if dropdown can show'); - if( dropdown.is.hidden() ) { - dropdown.hideOthers(); - dropdown.set.active(); - dropdown.animate.show(dropdown.set.visible); - if( dropdown.can.click() ) { - dropdown.bind.intent(); + module.debug('Checking if dropdown can show'); + if( module.is.hidden() ) { + module.hideOthers(); + module.set.active(); + module.animate.show(module.set.visible); + if( module.can.click() ) { + module.bind.intent(); } $.proxy(settings.onShow, element)(); } }, hide: function() { - if( dropdown.is.visible() ) { - dropdown.debug('Hiding dropdown'); - if( dropdown.can.click() ) { - dropdown.unbind.intent(); + if( module.is.visible() ) { + module.debug('Hiding dropdown'); + if( module.can.click() ) { + module.unbind.intent(); } - dropdown.remove.active(); - dropdown.animate.hide(dropdown.remove.visible); + module.remove.active(); + module.animate.hide(module.remove.visible); $.proxy(settings.onHide, element)(); } }, delay: { show: function() { - dropdown.verbose('Delaying show event to ensure user intent'); - clearTimeout(dropdown.timer); - dropdown.timer = setTimeout(dropdown.show, settings.delay.show); + module.verbose('Delaying show event to ensure user intent'); + clearTimeout(module.timer); + module.timer = setTimeout(module.show, settings.delay.show); }, hide: function() { - dropdown.verbose('Delaying hide event to ensure user intent'); - clearTimeout(dropdown.timer); - dropdown.timer = setTimeout(dropdown.hide, settings.delay.hide); + module.verbose('Delaying hide event to ensure user intent'); + clearTimeout(module.timer); + module.timer = setTimeout(module.hide, settings.delay.hide); } }, hideOthers: function() { - dropdown.verbose('Finding other dropdowns to hide'); - $allDropdowns - .not($dropdown) + module.verbose('Finding other dropdowns to hide'); + $allModules + .not($module) .has(selector.menu + ':visible') .dropdown('hide') ; }, toggle: function() { - dropdown.verbose('Toggling menu visibility'); - if( dropdown.is.hidden() ) { - dropdown.show(); + module.verbose('Toggling menu visibility'); + if( module.is.hidden() ) { + module.show(); } else { - dropdown.hide(); + module.hide(); } }, @@ -519,41 +519,41 @@ $.fn.dropdown = function(parameters) { internal: function(name, value) { if(value !== undefined) { if( $.isPlainObject(name) ) { - $.extend(true, dropdown, name); + $.extend(true, module, name); } else { - dropdown[name] = value; + module[name] = value; } } else { - return dropdown[name]; + return module[name]; } }, debug: function() { if(settings.debug) { if(settings.performance) { - dropdown.performance.log(arguments); + module.performance.log(arguments); } else { - dropdown.debug = Function.prototype.bind.call(console.info, console, settings.name + ':'); - dropdown.debug.apply(console, arguments); + module.debug = Function.prototype.bind.call(console.info, console, settings.name + ':'); + module.debug.apply(console, arguments); } } }, verbose: function() { if(settings.verbose && settings.debug) { if(settings.performance) { - dropdown.performance.log(arguments); + module.performance.log(arguments); } else { - dropdown.verbose = Function.prototype.bind.call(console.info, console, settings.name + ':'); - dropdown.verbose.apply(console, arguments); + module.verbose = Function.prototype.bind.call(console.info, console, settings.name + ':'); + module.verbose.apply(console, arguments); } } }, error: function() { - dropdown.error = Function.prototype.bind.call(console.error, console, settings.name + ':'); - dropdown.error.apply(console, arguments); + module.error = Function.prototype.bind.call(console.error, console, settings.name + ':'); + module.error.apply(console, arguments); }, performance: { log: function(message) { @@ -574,8 +574,8 @@ $.fn.dropdown = function(parameters) { 'Execution Time' : executionTime }); } - clearTimeout(dropdown.performance.timer); - dropdown.performance.timer = setTimeout(dropdown.performance.display, 100); + clearTimeout(module.performance.timer); + module.performance.timer = setTimeout(module.performance.display, 100); }, display: function() { var @@ -583,7 +583,7 @@ $.fn.dropdown = function(parameters) { totalTime = 0 ; time = false; - clearTimeout(dropdown.performance.timer); + clearTimeout(module.performance.timer); $.each(performance, function(index, data) { totalTime += data['Execution Time']; }); @@ -591,7 +591,6 @@ $.fn.dropdown = function(parameters) { if(dropdownSelector) { title += ' \'' + dropdownSelector + '\''; } - title += ' ' + '(' + $allDropdowns.size() + ')'; if( (console.group !== undefined || console.table !== undefined) && performance.length > 0) { console.groupCollapsed(title); if(console.table) { @@ -625,7 +624,7 @@ $.fn.dropdown = function(parameters) { found = instance[value]; } else { - dropdown.error(error.method); + module.error(error.method); } }); } @@ -638,15 +637,15 @@ $.fn.dropdown = function(parameters) { if(methodInvoked) { if(instance === undefined) { - dropdown.initialize(); + module.initialize(); } - invokedResponse = dropdown.invoke(query); + invokedResponse = module.invoke(query); } else { if(instance !== undefined) { - dropdown.destroy(); + module.destroy(); } - dropdown.initialize(); + module.initialize(); } }) ;