Permalink
Browse files

Script.aculo.us: autocompletion focus fix, setContentZoom fix #1546 […

…Thomas Fuchs]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1560 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent a551ba2 commit 0ffcceffac52cc4ed373eb9db27d6c776b5d96b7 @dhh dhh committed Jun 29, 2005
@@ -61,6 +61,7 @@ Ajax.Autocompleter.prototype = (new Ajax.Base()).extend({
this.observer = null;
+ Event.observe(this.element, "blur", this.onBlur.bindAsEventListener(this));
Event.observe(this.element, "keypress", this.onKeyPress.bindAsEventListener(this));
Event.observe(document, "click", this.onBlur.bindAsEventListener(this));
},
@@ -108,9 +109,15 @@ Ajax.Autocompleter.prototype = (new Ajax.Base()).extend({
}
},
+ addObservers: function(element) {
+ Event.observe(element, "mouseover", this.onHover.bindAsEventListener(this));
+ Event.observe(element, "click", this.onClick.bindAsEventListener(this));
+ },
+
onComplete: function(request) {
- if(!this.changed) {
+ if(!this.changed && this.has_focus) {
this.update.innerHTML = request.responseText;
+ Element.cleanWhitespace(this.update);
Element.cleanWhitespace(this.update.firstChild);
if(this.update.firstChild && this.update.firstChild.childNodes) {
@@ -119,8 +126,7 @@ Ajax.Autocompleter.prototype = (new Ajax.Base()).extend({
for (var i = 0; i < this.entry_count; i++) {
entry = this.get_entry(i);
entry.autocompleteIndex = i;
- Event.observe(entry, "mouseover", this.onHover.bindAsEventListener(this));
- Event.observe(entry, "click", this.onClick.bindAsEventListener(this));
+ this.addObservers(entry);
}
} else {
this.entry_count = 0;
@@ -171,26 +177,29 @@ Ajax.Autocompleter.prototype = (new Ajax.Base()).extend({
},
onHover: function(event) {
- element = Event.findElement(event, 'LI');
+ var element = Event.findElement(event, 'LI');
if(this.index != element.autocompleteIndex)
{
this.index = element.autocompleteIndex;
this.render();
}
+ Event.stop(event);
},
onClick: function(event) {
- element = Event.findElement(event, 'LI');
+ var element = Event.findElement(event, 'LI');
this.index = element.autocompleteIndex;
this.select_entry();
+ Event.stop(event);
},
onBlur: function(event) {
- element = Event.element(event);
+ var element = Event.element(event);
if(element==this.update) return;
while(element.parentNode)
{ element = element.parentNode; if(element==this.update) return; }
this.hide();
+ this.has_focus = false;
this.active = false;
},
@@ -235,13 +235,13 @@ Draggable.prototype = {
var options = {
handle: false,
starteffect: function(element) {
- new Effect2.Opacity(element, {duration:0.2, from:1.0, to:0.7});
+ new Effect.Opacity(element, {duration:0.2, from:1.0, to:0.7});
},
reverteffect: function(element, top_offset, left_offset) {
- new Effect2.MoveBy(element, -top_offset, -left_offset, {duration:0.4});
+ new Effect.MoveBy(element, -top_offset, -left_offset, {duration:0.4});
},
endeffect: function(element) {
- new Effect2.Opacity(element, {duration:0.2, from:0.7, to:1.0});
+ new Effect.Opacity(element, {duration:0.2, from:0.7, to:1.0});
},
zindex: 1000
}.extend(arguments[1] || {});
@@ -466,6 +466,4 @@ Sortable = {
return queryComponents.join("&");
}
-}
-
-/*--------------------------------------------------------------------------*/
+}
@@ -529,7 +529,7 @@ Effect.Pulsate = function(element) {
Effect.Fold = function(element) {
$(element).style.overflow = 'hidden';
- new Effect2.Scale(element, 5, {
+ new Effect.Scale(element, 5, {
scaleContent: false,
scaleTo: 100,
scaleX: false,
@@ -547,11 +547,6 @@ Effect.Fold = function(element) {
Element.setContentZoom = function(element, percent) {
var element = $(element);
-
- var sizeEm = 1.0;
- if (element.style.fontSize.indexOf("em")>0)
- sizeEm = parseFloat(element.style.fontSize);
-
- element.style.fontSize = sizeEm*(percent/100) + "em";
+ element.style.fontSize = (percent/100) + "em";
if(navigator.appVersion.indexOf('AppleWebKit')>0) window.scrollBy(0,0);
}

0 comments on commit 0ffccef

Please sign in to comment.