diff options
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | jquery.multiple.select.js | 31 |
2 files changed, 17 insertions, 15 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 9120512..71d0c0e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ### 1.2.0 +* [enh] INPUT tags should be nameless. * [bug] Fix #48: auto hide when the single option is set to true. * [bug] Fix #65: show selectAll and hide noResults when open. * [bug] Fix #45, #64: update width option to support a percentage setting. diff --git a/jquery.multiple.select.js b/jquery.multiple.select.js index ee81828..57a4e99 100644 --- a/jquery.multiple.select.js +++ b/jquery.multiple.select.js @@ -28,7 +28,8 @@ }; function MultipleSelect($el, options) { - var name = $el.attr('name') || options.name || ''; + var that = this, + name = $el.attr('name') || options.name || ''; this.options = options; @@ -72,6 +73,20 @@ this.selectAllName = 'data-name="selectAll' + name + '"'; this.selectGroupName = 'data-name="selectGroup' + name + '"'; this.selectItemName = 'data-name="selectItem' + name + '"'; + + if (!this.options.keepOpen) { + $('body').click(function (e) { + if ($(e.target)[0] === that.$choice[0] || + $(e.target).parents('.ms-choice')[0] === that.$choice[0]) { + return; + } + if (($(e.target)[0] === that.$drop[0] || + $(e.target).parents('.ms-drop')[0] !== that.$drop[0] && e.target !== $el[0]) && + that.options.isOpen) { + that.close(); + } + }); + } } MultipleSelect.prototype = { @@ -125,20 +140,6 @@ if (this.options.isOpen) { this.open(); } - - if (!this.options.keepOpen) { - $('body').click(function (e) { - if ($(e.target)[0] === that.$choice[0] || - $(e.target).parents('.ms-choice')[0] === that.$choice[0]) { - return; - } - if (($(e.target)[0] === that.$drop[0] || - $(e.target).parents('.ms-drop')[0] !== that.$drop[0]) && - that.options.isOpen) { - that.close(); - } - }); - } }, optionToHtml: function (i, elm, group, groupDisabled) { |