aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view/helpers/javascripts/prototype.js
diff options
context:
space:
mode:
authorThomas Fuchs <thomas@fesch.at>2006-04-01 19:47:31 +0000
committerThomas Fuchs <thomas@fesch.at>2006-04-01 19:47:31 +0000
commitbb2276098a5a21c35e5ee72b3097bd9d7caa919f (patch)
tree2836ff94d390e690cee155b35c42bb9f55a5571e /actionpack/lib/action_view/helpers/javascripts/prototype.js
parent217f67bf847c3f80e9e13698fd42dcf3b3782fa9 (diff)
downloadrails-bb2276098a5a21c35e5ee72b3097bd9d7caa919f.tar.gz
rails-bb2276098a5a21c35e5ee72b3097bd9d7caa919f.tar.bz2
rails-bb2276098a5a21c35e5ee72b3097bd9d7caa919f.zip
Applied Prototype $() performance patches (#4465, #4477) and updated script.aculo.us [Sam Stephenson, Thomas Fuchs]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4122 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib/action_view/helpers/javascripts/prototype.js')
-rw-r--r--actionpack/lib/action_view/helpers/javascripts/prototype.js37
1 files changed, 35 insertions, 2 deletions
diff --git a/actionpack/lib/action_view/helpers/javascripts/prototype.js b/actionpack/lib/action_view/helpers/javascripts/prototype.js
index 2d4ba34c18..56817066b6 100644
--- a/actionpack/lib/action_view/helpers/javascripts/prototype.js
+++ b/actionpack/lib/action_view/helpers/javascripts/prototype.js
@@ -900,13 +900,14 @@ if (!window.Element)
Element.extend = function(element) {
if (!element) return;
+ if (_nativeExtensions) return element;
if (!element._extended && element.tagName && element != window) {
- var methods = Element.Methods;
+ var methods = Element.Methods, cache = Element.extend.cache;
for (property in methods) {
var value = methods[property];
if (typeof value == 'function')
- element[property] = value.bind(null, element);
+ element[property] = cache.findOrStore(value);
}
}
@@ -914,6 +915,14 @@ Element.extend = function(element) {
return element;
}
+Element.extend.cache = {
+ findOrStore: function(value) {
+ return this[value] = this[value] || function() {
+ return value.apply(null, [this].concat($A(arguments)));
+ }
+ }
+}
+
Element.Methods = {
visible: function(element) {
return $(element).style.display != 'none';
@@ -1105,6 +1114,30 @@ Element.Methods = {
Object.extend(Element, Element.Methods);
+var _nativeExtensions = false;
+
+if(!HTMLElement && /Konqueror|Safari|KHTML/.test(navigator.userAgent)) {
+ var HTMLElement = {}
+ HTMLElement.prototype = document.createElement('div').__proto__;
+}
+
+Element.addMethods = function(methods) {
+ Object.extend(Element.Methods, methods || {});
+
+ if(typeof HTMLElement != 'undefined') {
+ var methods = Element.Methods, cache = Element.extend.cache;
+ for (property in methods) {
+ var value = methods[property];
+ if (typeof value == 'function') {
+ HTMLElement.prototype[property] = cache.findOrStore(value);
+ }
+ }
+ _nativeExtensions = true;
+ }
+}
+
+Element.addMethods();
+
var Toggle = new Object();
Toggle.display = Element.toggle;