aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view/helpers/javascripts/controls.js
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/lib/action_view/helpers/javascripts/controls.js')
-rw-r--r--actionpack/lib/action_view/helpers/javascripts/controls.js47
1 files changed, 29 insertions, 18 deletions
diff --git a/actionpack/lib/action_view/helpers/javascripts/controls.js b/actionpack/lib/action_view/helpers/javascripts/controls.js
index 90a5f1132b..f4be26b289 100644
--- a/actionpack/lib/action_view/helpers/javascripts/controls.js
+++ b/actionpack/lib/action_view/helpers/javascripts/controls.js
@@ -56,6 +56,21 @@ Ajax.Autocompleter.prototype = (new Ajax.Base()).extend({
this.options.min_chars = this.options.min_chars || 1;
this.options.method = 'post';
+ this.options.onShow = this.options.onShow ||
+ function(element, update){
+ if(!update.style.position || update.style.position=='absolute') {
+ update.style.position = 'absolute';
+ var offsets = Position.cumulativeOffset(element);
+ update.style.left = offsets[0] + 'px';
+ update.style.top = (offsets[1] + element.offsetHeight) + 'px';
+ update.style.width = element.offsetWidth + 'px';
+ }
+ new Effect.Appear(update,{duration:0.3});
+ };
+ this.options.onHide = this.options.onHide ||
+ function(element, update){ new Effect.Fade(update,{duration:0.3}) };
+
+
if(this.options.indicator)
this.indicator = $(this.options.indicator);
@@ -63,28 +78,28 @@ Ajax.Autocompleter.prototype = (new Ajax.Base()).extend({
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));
},
show: function() {
- Element.show(this.update);
- if(!this.iefix && (navigator.appVersion.indexOf('MSIE')>0)) {
- new Insertion.Before(this.update,
- '<iframe id="' + this.update.id + '_iefix" style="display:none;" src="javascript:false;" frameborder="0" scrolling="no"></iframe>');
+ if(this.update.style.display=='none') this.options.onShow(this.element, this.update);
+ if(!this.iefix && (navigator.appVersion.indexOf('MSIE')>0) && this.update.style.position=='absolute') {
+ new Insertion.After(this.update,
+ '<iframe id="' + this.update.id + '_iefix" '+
+ 'style="display:none;filter:progid:DXImageTransform.Microsoft.Alpha(apacity=0);" ' +
+ 'src="javascript:;" frameborder="0" scrolling="no"></iframe>');
this.iefix = $(this.update.id+'_iefix');
- this.iefix.style.position = 'absolute';
- this.iefix.style.zIndex = 1;
- this.update.style.zIndex = 2;
}
if(this.iefix) {
Position.clone(this.update, this.iefix);
+ this.iefix.style.zIndex = 1;
+ this.update.style.zIndex = 2;
Element.show(this.iefix);
}
},
hide: function() {
+ if(this.update.style.display=='') this.options.onHide(this.element, this.update);
if(this.iefix) Element.hide(this.iefix);
- Element.hide(this.update);
},
startIndicator: function() {
@@ -194,21 +209,18 @@ Ajax.Autocompleter.prototype = (new Ajax.Base()).extend({
},
onBlur: function(event) {
- var element = Event.element(event);
- if(element==this.update) return;
- while(element.parentNode)
- { element = element.parentNode; if(element==this.update) return; }
- this.hide();
+ // needed to make click events working
+ setTimeout(this.hide.bind(this), 250);
this.has_focus = false;
- this.active = false;
+ this.active = false;
},
render: function() {
if(this.entry_count > 0) {
for (var i = 0; i < this.entry_count; i++)
this.index==i ?
- Element.Class.add(this.get_entry(i),"selected") :
- Element.Class.remove(this.get_entry(i),"selected");
+ Element.addClassName(this.get_entry(i),"selected") :
+ Element.removeClassName(this.get_entry(i),"selected");
if(this.has_focus) {
if(this.get_current_entry().scrollIntoView)
@@ -239,7 +251,6 @@ Ajax.Autocompleter.prototype = (new Ajax.Base()).extend({
},
select_entry: function() {
- this.hide();
this.active = false;
value = Element.collectTextNodesIgnoreClass(this.get_current_entry(), 'informal').unescapeHTML();
this.element.value = value;