Skip to content

Commit 8fc7a02

Browse files
committed
More blur/focus improvements.
1 parent 5ec87ba commit 8fc7a02

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

karma.conf.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ module.exports = function(config) {
6464
config.set({
6565
frameworks: ['mocha', 'chai'],
6666
files: [
67+
'dist/css/selectize.default.css',
6768
'bower_components/jquery/jquery.js',
6869
'bower_components/microplugin/src/microplugin.js',
6970
'bower_components/sifter/sifter.js',
@@ -77,7 +78,7 @@ module.exports = function(config) {
7778
'test/*.js'
7879
],
7980
preprocessors: {
80-
'src/**/*.js': ['coverage']
81+
'src/*.js': ['coverage']
8182
},
8283
coverageReporter: {
8384
type: process.env.TRAVIS_CI && process.env.TARGET === 'phantomjs' ? 'lcov' : 'text-summary',

src/selectize.js

+13-12
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,7 @@ $.extend(Selectize.prototype, {
161161
self.$dropdown_content = $dropdown_content;
162162

163163
$dropdown.on('mouseenter', '[data-selectable]', function() { return self.onOptionHover.apply(self, arguments); });
164-
$dropdown.on('mousedown', '[data-selectable]', function() { return self.onOptionSelect.apply(self, arguments); });
165-
$dropdown.on('click', '[data-selectable]', function() { return self.onOptionSelect.apply(self, arguments); });
164+
$dropdown.on('mousedown click', '[data-selectable]', function() { return self.onOptionSelect.apply(self, arguments); });
166165
watchChildEvent($control, 'mousedown', '*:not(input)', function() { return self.onItemSelect.apply(self, arguments); });
167166
autoGrow($control_input);
168167

@@ -202,7 +201,7 @@ $.extend(Selectize.prototype, {
202201
}
203202
// blur on click outside
204203
if (!self.$control.has(e.target).length && e.target !== self.$control[0]) {
205-
self.blur();
204+
self.blur(e.target);
206205
}
207206
}
208207
});
@@ -590,17 +589,17 @@ $.extend(Selectize.prototype, {
590589
* Triggered on <input> blur.
591590
*
592591
* @param {object} e
592+
* @param {Element} dest
593593
*/
594-
onBlur: function(e) {
594+
onBlur: function(e, dest) {
595595
var self = this;
596-
var wasFocused = self.isFocused;
596+
if (!self.isFocused) return;
597+
self.isFocused = false;
597598

598599
if (self.ignoreFocus) {
599-
self.isFocused = false;
600600
return;
601601
} else if (!self.ignoreBlur && document.activeElement === self.$dropdown_content[0]) {
602602
// necessary to prevent IE closing the dropdown when the scrollbar is clicked
603-
self.isFocused = false;
604603
self.ignoreBlur = true;
605604
self.onFocus(e);
606605
return;
@@ -615,14 +614,13 @@ $.extend(Selectize.prototype, {
615614
self.refreshState();
616615

617616
// IE11 bug: element still marked as active
618-
document.body.focus();
617+
(dest || document.body).focus();
619618

620619
self.ignoreFocus = false;
621-
if (wasFocused) self.trigger('blur');
620+
self.trigger('blur');
622621
};
623622

624623
self.ignoreFocus = true;
625-
self.isFocused = false;
626624
if (self.settings.create && self.settings.createOnBlur) {
627625
self.createItem(null, false, deactivate);
628626
} else {
@@ -915,9 +913,12 @@ $.extend(Selectize.prototype, {
915913

916914
/**
917915
* Forces the control out of focus.
916+
*
917+
* @param {Element} dest
918918
*/
919-
blur: function() {
920-
this.$control_input.blur();
919+
blur: function(dest) {
920+
this.$control_input[0].blur();
921+
this.onBlur(null, dest);
921922
},
922923

923924
/**

0 commit comments

Comments
 (0)