Reputation: 35213
I'm using the AJAX control toolkits autocomplete in a really old project of mine. I have some problem with the mouseover highlighting.
In the example that works, the generated <li>
tags gets a mouseover event which changes their background color using inline css. Works well. However, when i change the markup from:
<li>
Hello world
</li>
to
<li>
<div>Hello</div>
<div>world</div>
</li>
The <li>
element will only change background color when i hover a part of them which is not covered by one of the divs.
Since I can't modify the generated (and minified) javasacript, I'm looking for a quick and dirty fix.
I have tried to change the z-index of the elements, without success. I've also tried to find the event of the li and add it to the div. But I can't find a way to copy events that is not added by jquery to another element.
Any ideas here are much appreciated.
Below if the reverted minified javascript if its to any help:
_highlightItem: function(item) {
/// <summary>
/// Highlights the specified item
/// </summary>
/// <param name="item" type="Sys.UI.DomElement" DomElement="true" mayBeNull="false" />
/// <returns />
var children = this._completionListElement.childNodes;
// Unselect any previously highlighted item
for (var i = 0; i < children.length; i++) {
var child = children[i];
if (child._highlighted) {
if (this._completionListItemCssClass) {
Sys.UI.DomElement.removeCssClass(child, this._highlightedItemCssClass);
Sys.UI.DomElement.addCssClass(child, this._completionListItemCssClass);
} else {
if (Sys.Browser.agent === Sys.Browser.Safari) {
child.style.backgroundColor = 'white';
child.style.color = 'black';
} else {
child.style.backgroundColor = this._textBackground;
child.style.color = this._textColor;
}
}
this.raiseItemOut(new AjaxControlToolkit.AutoCompleteItemEventArgs(child, child.firstChild.nodeValue, child._value));
}
}
// Highlight the new item
if(this._highlightedItemCssClass) {
Sys.UI.DomElement.removeCssClass(item, this._completionListItemCssClass);
Sys.UI.DomElement.addCssClass(item, this._highlightedItemCssClass);
} else {
if (Sys.Browser.agent === Sys.Browser.Safari) {
item.style.backgroundColor = 'lemonchiffon';
} else {
item.style.backgroundColor = 'highlight';
item.style.color = 'highlighttext';
}
}
item._highlighted = true;
this.raiseItemOver(new AjaxControlToolkit.AutoCompleteItemEventArgs(item, item.firstChild.nodeValue, item._value));
},
Upvotes: 2
Views: 587
Reputation: 1601
Why not use CSS to add the needed highlights?
li > div:hover {
/* Highlight Rule Here */
}
Upvotes: 4