MINOR Close open TreeDropdownField panels if user clicks outside of the field (emulate behaviour of chosen.js and most native OS dropdowns)

This commit is contained in:
Ingo Schommer 2012-01-03 14:42:56 +01:00
parent c0c073e03f
commit 66a60476ac

View File

@ -14,6 +14,11 @@
'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
@ -46,6 +51,9 @@
// 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');
// set the panel to the bottom of the field. Takes into account the
@ -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');