From 278d4c6693b429dd9bdcdec78ddcc12c10ad011f Mon Sep 17 00:00:00 2001 From: Patrick Cook Date: Mon, 17 Sep 2012 16:32:19 -0700 Subject: [PATCH 1/5] Fixed border around drop-down and added break-word to prevent horizontal scrolling --- jquery/css/jquery.combobox/style.css | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/jquery/css/jquery.combobox/style.css b/jquery/css/jquery.combobox/style.css index 7f66aa8..895bd1b 100644 --- a/jquery/css/jquery.combobox/style.css +++ b/jquery/css/jquery.combobox/style.css @@ -61,17 +61,18 @@ z-index: 1000; max-height: 200px; overflow: auto; + border: 1px solid #CCC; } .combobox_selector ul { padding: 0; margin: 0; list-style: none; - border:1px solid #CCC; } .combobox_selector li { padding: 2px 5px; + word-wrap: break-word; } .combobox_selector li:hover, From d53d4261ad6edaa77ec9b7a64cfecc8cd8d6a25e Mon Sep 17 00:00:00 2001 From: Patrick Cook Date: Wed, 26 Sep 2012 14:19:51 -0700 Subject: [PATCH 2/5] Added destroy method and memory leak fixes --- jquery/js/jquery.combobox.js | 50 ++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 16 deletions(-) diff --git a/jquery/js/jquery.combobox.js b/jquery/js/jquery.combobox.js index 8aaec45..fd501fb 100644 --- a/jquery/js/jquery.combobox.js +++ b/jquery/js/jquery.combobox.js @@ -10,21 +10,29 @@ * Date: 2012-01-15 */ (function () { + var COMBOBOX_DATA_KEY = 'jQueryCombobox'; + var EVENT_NAMESPACE = '.jQueryCombobox'; jQuery.fn.combobox = function (selectOptions) { + var el, combobox; + + // Destroy comboboxes + if(selectOptions === 'destroy') { + return this.each(function () { + el = jQuery(this); + combobox = el.data(COMBOBOX_DATA_KEY); + combobox.destroy(); + el.removeData(COMBOBOX_DATA_KEY) + }); + } return this.each(function () { - var newCombobox = new Combobox(this, selectOptions); - jQuery.combobox.instances.push(newCombobox); + combobox = new Combobox(this, selectOptions); + jQuery(this).data(COMBOBOX_DATA_KEY, combobox); }); }; - jQuery.combobox = { - instances : [] - }; - - var Combobox = function (textInputElement, selectOptions) { this.textInputElement = jQuery(textInputElement); this.textInputElement.wrap( @@ -35,16 +43,16 @@ this.setSelectOptions(selectOptions); var inputHeight = this.textInputElement.outerHeight(); var buttonLeftPosition = this.textInputElement.outerWidth() + 0; - var showSelectorButton = jQuery( + this.showSelectorButton = jQuery( '
' ); - this.textInputElement.css('margin', '0 '+showSelectorButton.outerWidth()+'px 0 0'); - showSelectorButton.insertAfter(this.textInputElement); + this.textInputElement.css('margin', '0 '+this.showSelectorButton.outerWidth()+'px 0 0'); + this.showSelectorButton.insertAfter(this.textInputElement); var thisSelector = this.selector; var thisCombobox = this; - showSelectorButton.click(function (e) { + this.showSelectorButton.bind('click' + EVENT_NAMESPACE, function (e) { jQuery('html').trigger('click'); thisSelector.buildSelectOptionList(); thisSelector.show(); @@ -63,7 +71,7 @@ bindKeypress : function () { var thisCombobox = this; - this.textInputElement.keyup(function (event) { + this.textInputElement.bind('keyup' + EVENT_NAMESPACE, function (event) { if (event.keyCode == Combobox.keys.TAB || event.keyCode == Combobox.keys.SHIFT) { @@ -98,6 +106,12 @@ focus : function () { this.textInputElement.trigger('focus'); + }, + + destroy : function() { + this.textInputElement.unbind(EVENT_NAMESPACE); + this.showSelectorButton.unbind(EVENT_NAMESPACE); + this.selector.destroy(); } }; @@ -198,15 +212,15 @@ { return false; } - jQuery('html').keydown(this.keypressHandler); + jQuery('html').bind('keydown' + EVENT_NAMESPACE,this.keypressHandler); this.selectorElement.slideDown('fast'); - jQuery('html').click(this.htmlClickHandler); + jQuery('html').bind('click' + EVENT_NAMESPACE, this.htmlClickHandler); return true; }, hide : function () { - jQuery('html').unbind('keydown', this.keypressHandler); - jQuery('html').unbind('click', this.htmlClickHandler); + jQuery('html').unbind('keydown' + EVENT_NAMESPACE, this.keypressHandler); + jQuery('html').unbind('click' + EVENT_NAMESPACE, this.htmlClickHandler); this.selectorElement.unbind('click'); this.unselect(); this.selectorElement.hide(); @@ -245,6 +259,10 @@ } else { return this.combobox.textInputElement.val(); } + }, + + destroy : function() { + jQuery('html').unbind(EVENT_NAMESPACE); } }; From 9f1369d66d80ec04d916f94411e695810917b813 Mon Sep 17 00:00:00 2001 From: Patrick Cook Date: Wed, 26 Sep 2012 14:23:44 -0700 Subject: [PATCH 3/5] Updated documentation with destroy method --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 9f3acbd..5facf45 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,8 @@ How to Use it 'Oranges', 'Bananas' ]); + + jQuery('#combobox1').combobox('destroy'); }); From 1dc0af7fb182693699d5affb8a6f1620123ac291 Mon Sep 17 00:00:00 2001 From: Patrick Cook Date: Wed, 26 Sep 2012 14:25:43 -0700 Subject: [PATCH 4/5] Fixed spacing in readme file --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5facf45..d381880 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ How to Use it 'Bananas' ]); - jQuery('#combobox1').combobox('destroy'); + jQuery('#combobox1').combobox('destroy'); }); From 530df32fbacc07b7238f575c9217b9df9fd6246b Mon Sep 17 00:00:00 2001 From: Patrick Cook Date: Thu, 27 Sep 2012 13:12:19 -0700 Subject: [PATCH 5/5] Revert "Fixed border around drop-down and added break-word to prevent horizontal" This reverts commit 278d4c6693b429dd9bdcdec78ddcc12c10ad011f. --- jquery/css/jquery.combobox/style.css | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/jquery/css/jquery.combobox/style.css b/jquery/css/jquery.combobox/style.css index 895bd1b..7f66aa8 100644 --- a/jquery/css/jquery.combobox/style.css +++ b/jquery/css/jquery.combobox/style.css @@ -61,18 +61,17 @@ z-index: 1000; max-height: 200px; overflow: auto; - border: 1px solid #CCC; } .combobox_selector ul { padding: 0; margin: 0; list-style: none; + border:1px solid #CCC; } .combobox_selector li { padding: 2px 5px; - word-wrap: break-word; } .combobox_selector li:hover,