From e1ce18020e1c23c148060ec2180dc0ed794be06e Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Tue, 22 Mar 2005 12:13:36 +0000 Subject: Last-minute ajax fixes #898 git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@973 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- .../action_view/helpers/javascripts/prototype.js | 33 ++++++++++++++-------- 1 file changed, 21 insertions(+), 12 deletions(-) (limited to 'actionpack/lib/action_view/helpers/javascripts') diff --git a/actionpack/lib/action_view/helpers/javascripts/prototype.js b/actionpack/lib/action_view/helpers/javascripts/prototype.js index 9790d3b689..b998985235 100644 --- a/actionpack/lib/action_view/helpers/javascripts/prototype.js +++ b/actionpack/lib/action_view/helpers/javascripts/prototype.js @@ -1,13 +1,12 @@ -/* Prototype: an object-oriented Javascript library, version 1.0.0 +/* Prototype: an object-oriented Javascript library, version 1.0.1 * (c) 2005 Sam Stephenson * * Prototype is freely distributable under the terms of an MIT-style license. * For details, see http://prototype.conio.net/ */ - Prototype = { - Version : '1.0.0' + Version: '1.0.1' } Class = { @@ -59,9 +58,8 @@ Try = { Toggle = { display: function() { - elements = $.apply(this, arguments); for (var i = 0; i < elements.length; i++) { - element = elements[i]; + var element = $(elements[i]); element.style.display = (element.style.display == 'none' ? '' : 'none'); } @@ -73,7 +71,7 @@ Toggle = { function $() { var elements = new Array(); - for (i = 0; i < arguments.length; i++) { + for (var i = 0; i < arguments.length; i++) { var element = arguments[i]; if (typeof element == 'string') element = document.getElementById(element); @@ -145,23 +143,32 @@ Ajax.Request.prototype = (new Ajax.Base()).extend({ this.transport.open(this.options.method, url, true); - if (this.options.asynchronous) + if (this.options.asynchronous) { this.transport.onreadystatechange = this.onStateChange.bind(this); - + setTimeout((function() {this.respondToReadyState(1)}).bind(this), 10); + } + if (this.options.method == 'post') { this.transport.setRequestHeader('Connection', 'close'); this.transport.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); } - this.transport.send(this.options.method == 'post' ? this.options.parameters + '&_=' : null); + this.transport.send(this.options.method == 'post' ? + this.options.parameters + '&_=' : null); } catch (e) { } }, onStateChange: function() { - var event = Ajax.Request.Events[this.transport.readyState]; + var readyState = this.transport.readyState; + if (readyState != 1) + this.respondToReadyState(this.transport.readyState); + }, + + respondToReadyState: function(readyState) { + var event = Ajax.Request.Events[readyState]; (this.options['on' + event] || Ajax.emptyFunction)(this.transport); } }); @@ -189,9 +196,11 @@ Ajax.Updater.prototype = (new Ajax.Base()).extend({ } }); +/*--------------------------------------------------------------------------*/ + Field = { clear: function() { - for (i = 0; i < arguments.length; i++) + for (var i = 0; i < arguments.length; i++) $(arguments[i]).value = ''; }, @@ -200,7 +209,7 @@ Field = { }, present: function() { - for (i = 0; i < arguments.length; i++) + for (var i = 0; i < arguments.length; i++) if ($(arguments[i]).value == '') return false; return true; } -- cgit v1.2.3