Skip to content

Instantly share code, notes, and snippets.

@neduma
Created May 10, 2012 19:03
Show Gist options
  • Save neduma/2655153 to your computer and use it in GitHub Desktop.
Save neduma/2655153 to your computer and use it in GitHub Desktop.
chosen lib patch to support ie7 event.targets
index e5049b0..b9c5a8f 100644
--- a/chosen/chosen.proto.js
+++ b/chosen/chosen.proto.js
@@ -1,6 +1,6 @@
// Chosen, a Select Box Enhancer for jQuery and Protoype
// by Patrick Filler for Harvest, http://getharvest.com
-//
+//
// Version 0.9.8
// Full source at https://github.com/harvesthq/chosen
// Copyright (c) 2011 Harvest http://getharvest.com
@@ -408,6 +408,7 @@ Copyright (c) 2011 by Harvest
Chosen.prototype.container_mousedown = function(evt) {
var target_closelink;
if (!this.is_disabled) {
+ evt.target = evt != null && evt.target ? $(evt.target) : null;
target_closelink = evt != null ? evt.target.hasClassName("search-choice-close") : false;
if (evt && evt.type === "mousedown" && !this.results_showing) evt.stop();
if (!this.pending_destroy_click && !target_closelink) {
@@ -462,6 +463,7 @@ Copyright (c) 2011 by Harvest
};
Chosen.prototype.test_active_click = function(evt) {
+ evt.target = evt != null && evt.target ? $(evt.target) : null;
if (evt.target.up('#' + this.container_id)) {
return this.active_field = true;
} else {
@@ -601,6 +603,7 @@ Copyright (c) 2011 by Harvest
Chosen.prototype.search_results_mouseup = function(evt) {
var target;
+ evt.target = evt != null && evt.target ? $(evt.target) : null;
target = evt.target.hasClassName("active-result") ? evt.target : evt.target.up(".active-result");
if (target) {
this.result_highlight = target;
@@ -610,11 +613,13 @@ Copyright (c) 2011 by Harvest
Chosen.prototype.search_results_mouseover = function(evt) {
var target;
+ evt.target = evt != null && evt.target ? $(evt.target) : null;
target = evt.target.hasClassName("active-result") ? evt.target : evt.target.up(".active-result");
if (target) return this.result_do_highlight(target);
};
Chosen.prototype.search_results_mouseout = function(evt) {
+ evt.target = evt != null && evt.target ? $(evt.target) : null;
if (evt.target.hasClassName('active-result') || evt.target.up('.active-result')) {
return this.result_clear_highlight();
}
@@ -622,6 +627,7 @@ Copyright (c) 2011 by Harvest
Chosen.prototype.choices_click = function(evt) {
evt.preventDefault();
+ evt.target = evt != null && evt.target ? $(evt.target) : null;
if (this.active_field && !(evt.target.hasClassName('search-choice') || evt.target.up('.search-choice')) && !this.results_showing) {
return this.results_show();
}
@neduma
Copy link
Author

neduma commented May 10, 2012

More from http://prototypejs.org/api/event/element

Note that prior to version 1.5.1, if the browser does not support native DOM extensions (see this page for further details), the element returned by Event.element might very well not be extended. If you intend to use methods from Element.Methods on it, you need to wrap the call in the $() function like so:

Event.observe(document.body, 'click', function(event) {
  var element = $(Event.element(event));
  /* ...  */
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment