Permalink
Browse files

Last-minute ajax fixes #898

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@973 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
dhh committed Mar 22, 2005
1 parent 11a5492 commit e1ce18020e1c23c148060ec2180dc0ed794be06e
@@ -45,10 +45,8 @@ def link_to_function(name, function, html_options = {})
# :url => { :action => "undo", :n => word_counter },
# :complete => "undoRequestCompleted(request)"
#
- # The complete list of callbacks that may be specified are:
+ # The callbacks that may be specified are:
#
- # <tt>:uninitialized</tt>:: Called before the remote document is
- # initialized with data.
# <tt>:loading</tt>:: Called when the remote document is being
# loaded with data by the browser.
# <tt>:loaded</tt>:: Called when the browser has finished loading
@@ -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 <sam@conio.net>
*
* 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;
}
@@ -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 <sam@conio.net>
*
* 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;
}

0 comments on commit e1ce180

Please sign in to comment.