Skip to content

Commit

Permalink
MINOR Close open TreeDropdownField panels if user clicks outside of t…
Browse files Browse the repository at this point in the history
…he field (emulate behaviour of chosen.js and most native OS dropdowns)
  • Loading branch information
chillu committed Jan 3, 2012
1 parent c0c073e commit 66a6047
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion javascript/TreeDropdownField.js
Expand Up @@ -13,7 +13,12 @@
'fieldTitle': '(choose)',
'searchFieldTitle': '(choose or search)'
};


var _clickTestFn = function(e) {
// If the click target is not a child of the current field, close the panel automatically.
if(!$(e.target).parents('.TreeDropdownField').length) jQuery('.TreeDropdownField').entwine('ss').closePanel();
};

/**
* @todo Error display
* @todo No results display for search
Expand Down Expand Up @@ -45,6 +50,9 @@
openPanel: function() {
// close all other panels
$('.TreeDropdownField').closePanel();

// Listen for clicks outside of the field to auto-close it
$('body').bind('click', _clickTestFn);

var panel = this.getPanel(), tree = this.find('.tree-holder');

Expand Down Expand Up @@ -80,6 +88,8 @@

},
closePanel: function() {
jQuery('body').unbind('click', _clickTestFn);

// swap the up arrow with a down arrow
var toggle = this.find(".treedropdownfield-toggle-panel-link");
toggle.removeClass('treedropdownfield-open-tree');
Expand Down

0 comments on commit 66a6047

Please sign in to comment.