use a closure to bind a function to this, Prototype function.bind doesn't work in jQuery, was causing an error when blurring a select in Safari

This commit is contained in:
Adam Kittelson 2011-07-19 13:41:29 -07:00
parent 6247674d71
commit e8ac2bb71b
2 changed files with 14 additions and 4 deletions

View file

@ -151,14 +151,22 @@
return this.mouse_on_container = false; return this.mouse_on_container = false;
}; };
Chosen.prototype.input_focus = function(evt) { Chosen.prototype.input_focus = function(evt) {
var binding;
binding = this;
if (!this.active_field) { if (!this.active_field) {
return setTimeout(this.container_click.bind(this), 50); return setTimeout((function() {
return binding.container_click();
}), 50);
} }
}; };
Chosen.prototype.input_blur = function(evt) { Chosen.prototype.input_blur = function(evt) {
var binding;
if (!this.mouse_on_container) { if (!this.mouse_on_container) {
this.active_field = false; this.active_field = false;
return setTimeout(this.blur_test.bind(this), 100); binding = this;
return setTimeout((function() {
return binding.blur_test();
}), 100);
} }
}; };
Chosen.prototype.blur_test = function(evt) { Chosen.prototype.blur_test = function(evt) {

View file

@ -129,12 +129,14 @@ class Chosen
mouse_leave: -> @mouse_on_container = false mouse_leave: -> @mouse_on_container = false
input_focus: (evt) -> input_focus: (evt) ->
setTimeout this.container_click.bind(this), 50 unless @active_field binding = this
setTimeout (-> binding.container_click()), 50 unless @active_field
input_blur: (evt) -> input_blur: (evt) ->
if not @mouse_on_container if not @mouse_on_container
@active_field = false @active_field = false
setTimeout this.blur_test.bind(this), 100 binding = this
setTimeout (-> binding.blur_test()), 100
blur_test: (evt) -> blur_test: (evt) ->
this.close_field() if not @active_field and @container.hasClass "chzn-container-active" this.close_field() if not @active_field and @container.hasClass "chzn-container-active"