diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-07-01 07:25:44 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-07-01 07:25:44 +0000 |
commit | cadcd9e7144394ecc9df01961191d20e5e219a37 (patch) | |
tree | 6014e509c117efbb6cb20e806388e73f7d34f8c6 /actionpack/lib/action_view/helpers/javascripts | |
parent | 24a8cb1e5600d95a51323982e4d7508eb22c8b1f (diff) | |
download | rails-cadcd9e7144394ecc9df01961191d20e5e219a37.tar.gz rails-cadcd9e7144394ecc9df01961191d20e5e219a37.tar.bz2 rails-cadcd9e7144394ecc9df01961191d20e5e219a37.zip |
Fix IE 30-sec timeout bug, make auto_complete_for even more delicious #1572 [Thomas Fuchs]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1579 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib/action_view/helpers/javascripts')
4 files changed, 67 insertions, 34 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; diff --git a/actionpack/lib/action_view/helpers/javascripts/dragdrop.js b/actionpack/lib/action_view/helpers/javascripts/dragdrop.js index 6086b44ee0..78f82bcd23 100644 --- a/actionpack/lib/action_view/helpers/javascripts/dragdrop.js +++ b/actionpack/lib/action_view/helpers/javascripts/dragdrop.js @@ -221,9 +221,9 @@ Draggables = { addObserver: function(observer) { this.observers.push(observer); }, - notify: function(eventName) { // 'onStart', 'onEnd' + notify: function(eventName, draggable) { // 'onStart', 'onEnd' for(var i = 0; i < this.observers.length; i++) - this.observers[i][eventName](); + this.observers[i][eventName](draggable); } } @@ -243,7 +243,8 @@ Draggable.prototype = { endeffect: function(element) { new Effect.Opacity(element, {duration:0.2, from:0.7, to:1.0}); }, - zindex: 1000 + zindex: 1000, + revert: false }.extend(arguments[1] || {}); this.element = $(element); @@ -278,8 +279,8 @@ Draggable.prototype = { this.active = true; var style = this.element.style; - this.originalY = this.element.offsetTop - this.currentTop(); - this.originalTop; - this.originalX = this.element.offsetLeft - this.currentLeft(); - this.originalLeft; + this.originalY = this.element.offsetTop - this.currentTop() - this.originalTop; + this.originalX = this.element.offsetLeft - this.currentLeft() - this.originalLeft; this.offsetY = event.clientY - this.originalY - this.originalTop; this.offsetX = event.clientX - this.originalX - this.originalLeft; @@ -292,9 +293,12 @@ Draggable.prototype = { this.dragging = false; Droppables.fire(event, this.element); - Draggables.notify('onEnd'); + Draggables.notify('onEnd', this); - if(this.options.revert && this.options.reverteffect) { + var revert = this.options.revert; + if(revert && typeof revert == 'function') revert = revert(this.element); + + if(revert && this.options.reverteffect) { this.options.reverteffect(this.element, this.currentTop()-this.originalTop, this.currentLeft()-this.originalLeft); @@ -330,7 +334,7 @@ Draggable.prototype = { this.dragging = true; if(style.position=="") style.position = "relative"; style.zIndex = this.options.zindex; - Draggables.notify('onStart'); + Draggables.notify('onStart', this); if(this.options.starteffect) this.options.starteffect(this.element); } diff --git a/actionpack/lib/action_view/helpers/javascripts/effects.js b/actionpack/lib/action_view/helpers/javascripts/effects.js index 9a26c5d712..756c95cfeb 100644 --- a/actionpack/lib/action_view/helpers/javascripts/effects.js +++ b/actionpack/lib/action_view/helpers/javascripts/effects.js @@ -307,25 +307,33 @@ Effect.Puff = function(element) { } Effect.BlindUp = function(element) { + $(element)._overflow = $(element).style.overflow || 'visible'; $(element).style.overflow = 'hidden'; new Effect.Scale(element, 0, { scaleContent: false, scaleX: false, afterFinish: function(effect) - { Element.hide(effect.element) } + { + Element.hide(effect.element); + effect.element.style.overflow = effect.element._overflow; + } }.extend(arguments[1] || {}) ); } Effect.BlindDown = function(element) { $(element).style.height = '0px'; + $(element)._overflow = $(element).style.overflow || 'visible'; $(element).style.overflow = 'hidden'; Element.show(element); new Effect.Scale(element, 100, { scaleContent: false, scaleX: false, scaleMode: 'contents', - scaleFrom: 0 + scaleFrom: 0, + afterFinish: function(effect) { + effect.element.style.overflow = effect.element._overflow; + } }.extend(arguments[1] || {}) ); } @@ -375,6 +383,7 @@ Effect.Shake = function(element) { } Effect.SlideDown = function(element) { + $(element)._overflow = $(element).style.overflow || 'visible'; $(element).style.height = '0px'; $(element).style.overflow = 'hidden'; $(element).firstChild.style.position = 'relative'; @@ -386,12 +395,15 @@ Effect.SlideDown = function(element) { scaleFrom: 0, afterUpdate: function(effect) { effect.element.firstChild.style.bottom = - (effect.originalHeight - effect.element.clientHeight) + 'px'; } + (effect.originalHeight - effect.element.clientHeight) + 'px'; }, + afterFinish: function(effect) + { effect.element.style.overflow = effect.element._overflow; } }.extend(arguments[1] || {}) ); } Effect.SlideUp = function(element) { + $(element)._overflow = $(element).style.overflow || 'visible'; $(element).style.overflow = 'hidden'; $(element).firstChild.style.position = 'relative'; Element.show(element); @@ -402,7 +414,10 @@ Effect.SlideUp = function(element) { { effect.element.firstChild.style.bottom = (effect.originalHeight - effect.element.clientHeight) + 'px'; }, afterFinish: function(effect) - { Element.hide(effect.element); } + { + Element.hide(effect.element); + effect.element.style.overflow = effect.element._overflow; + } }.extend(arguments[1] || {}) ); } diff --git a/actionpack/lib/action_view/helpers/javascripts/prototype.js b/actionpack/lib/action_view/helpers/javascripts/prototype.js index a76d3e62b6..9225f13125 100644 --- a/actionpack/lib/action_view/helpers/javascripts/prototype.js +++ b/actionpack/lib/action_view/helpers/javascripts/prototype.js @@ -221,11 +221,12 @@ Ajax.Request.prototype = (new Ajax.Base()).extend({ }, setRequestHeaders: function() { - var requestHeaders = ['X-Requested-With', 'XMLHttpRequest', + var requestHeaders = [ + 'X-Requested-With', 'XMLHttpRequest', 'X-Prototype-Version', Prototype.Version]; if (this.options.method == 'post') - requestHeaders.push('Connection', 'close', + requestHeaders.push(//'Connection', 'close', 'Content-type', 'application/x-www-form-urlencoded'); if (this.options.requestHeaders) @@ -987,8 +988,10 @@ var Position = { clone: function(source, target) { source = $(source); target = $(target); - target.style.top = source.style.top; - target.style.left = source.style.left; + target.style.position = 'absolute'; + var offsets = this.cumulativeOffset(source); + target.style.top = offsets[1] + 'px'; + target.style.left = offsets[0] + 'px'; target.style.width = source.offsetWidth + 'px'; target.style.height = source.offsetHeight + 'px'; } |