Browse files

Sync Prototype; closes #1539

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1558 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 31e4893 commit a551ba2c01f5fcc1c0eff13c8ef24082e55071b9 @sstephenson sstephenson committed Jun 29, 2005
Showing with 59 additions and 30 deletions.
  1. +59 −30 actionpack/lib/action_view/helpers/javascripts/prototype.js
View
89 actionpack/lib/action_view/helpers/javascripts/prototype.js
@@ -1,4 +1,4 @@
-/* Prototype: an object-oriented Javascript library, version 1.3.0
+/* Prototype JavaScript framework, version 1.3.0
* (c) 2005 Sam Stephenson <sam@conio.net>
*
* THIS FILE IS AUTOMATICALLY GENERATED. When sending patches, please diff
@@ -152,10 +152,17 @@ String.prototype.extend({
return this.replace(/<\/?[^>]+>/gi, '');
},
+ escapeHTML: function() {
+ var div = document.createElement('div');
+ var text = document.createTextNode(this);
+ div.appendChild(text);
+ return div.innerHTML;
+ },
+
unescapeHTML: function() {
- return this.replace(/&lt;/gi,"<").replace(/&gt;/gi,">").
- replace(/&quot;/gi,'"').replace(/&apos;/gi,"'").
- replace(/&amp;/gi,"&").replace(/[\n\r]/gi,"");
+ var div = document.createElement('div');
+ div.innerHTML = this.stripTags();
+ return div.childNodes[0].nodeValue;
}
});
@@ -238,23 +245,24 @@ Ajax.Request.prototype = (new Ajax.Base()).extend({
var event = Ajax.Request.Events[readyState];
if (event == 'Complete' && this.transport.status != 200)
- (this.options['on' + this.transport.status] ||
- this.options.onFailure ||
- Prototype.emptyFunction)(this.transport);
+ (this.options['on' + this.transport.status]
+ || this.options.onFailure
+ || Prototype.emptyFunction)(this.transport);
(this.options['on' + event] || Prototype.emptyFunction)(this.transport);
}
});
Ajax.Updater = Class.create();
+Ajax.Updater.ScriptFragmentMatch = /<script.*?>((?:\n|.)*?)<\/script>/im;
+
Ajax.Updater.prototype = (new Ajax.Base()).extend({
initialize: function(container, url, options) {
this.containers = {
success: container.success ? $(container.success) : $(container),
failure: container.failure ? $(container.failure) : null
}
-
- this.script_re = /<script.*?>((?:\n|.)*?)<\/script>/im;
+
this.setOptions(options);
if (this.options.asynchronous) {
@@ -272,12 +280,12 @@ Ajax.Updater.prototype = (new Ajax.Base()).extend({
var receiver =
(this.request.transport.status == 200) ?
this.containers.success : this.containers.failure;
-
- var response = this.request.transport.responseText.replace(
- this.script_re, '');
-
- var scripts = this.request.transport.responseText.match(
- this.script_re);
+
+ var response = this.request.transport.responseText.
+ replace(Ajax.Updater.ScriptFragmentMatch, '');
+
+ var scripts = this.request.transport.responseText.
+ match(Ajax.Updater.ScriptFragmentMatch);
if (receiver) {
if (this.options.insertion) {
@@ -288,13 +296,12 @@ Ajax.Updater.prototype = (new Ajax.Base()).extend({
}
if (this.request.transport.status == 200) {
- if (this.onComplete) {
+ if (this.onComplete)
setTimeout((function() {this.onComplete(
this.request.transport)}).bind(this), 10);
- }
- if (this.options.script && scripts) {
- setTimeout((function() { eval(scripts[1]) }).bind(this), 10);
- }
+
+ if (this.options.evalScripts && scripts)
+ setTimeout((function() {eval(scripts[1])}).bind(this), 10);
}
}
});
@@ -340,11 +347,8 @@ Ajax.PeriodicalUpdater.prototype = (new Ajax.Base()).extend({
onTimerEvent: function() {
this.updater = new Ajax.Updater(this.container, this.url, this.options);
}
-
});
-/*--------------------------------------------------------------------------*/
-
document.getElementsByClassName = function(className) {
var children = document.getElementsByTagName('*') || document.all;
var elements = new Array();
@@ -855,31 +859,56 @@ Object.extend(Event, {
// node the event was triggered on; traverses the DOM upwards
findElement: function(event, tagName) {
var element = Event.element(event);
- while (element.parentNode && (!element.tagName ||
- (element.tagName.toUpperCase() != tagName.toUpperCase())))
+ while (element.parentNode && (!element.tagName ||
+ (element.tagName.toUpperCase() != tagName.toUpperCase())))
element = element.parentNode;
return element;
},
- observe: function(element, name, observer) {
+ observe: function(element, name, observer, useCapture) {
var element = $(element);
+ useCapture = useCapture || false;
+
if (name == 'keypress') {
- if (navigator.appVersion.indexOf('AppleWebKit') > 0) {
- element.addEventListener('keydown', observer, false);
+ if (navigator.appVersion.indexOf('AppleWebKit') > 0) {
+ element.addEventListener('keydown', observer, useCapture);
return;
}
if (element.addEventListener) {
- element.addEventListener('keypress', observer, false);
+ element.addEventListener('keypress', observer, useCapture);
} else if (element.attachEvent) {
element.attachEvent('onkeydown', observer);
}
} else {
if (element.addEventListener) {
- element.addEventListener(name, observer, false);
+ element.addEventListener(name, observer, useCapture);
} else if (element.attachEvent) {
element.attachEvent('on' + name, observer);
}
}
+ },
+
+ stopObserving: function(element, name, observer, useCapture) {
+ var element = $(element);
+ useCapture = useCapture || false;
+
+ if (name == 'keypress') {
+ if (navigator.appVersion.indexOf('AppleWebKit') > 0) {
+ element.removeEventListener('keydown', observer, useCapture);
+ return;
+ }
+ if (element.removeEventListener) {
+ element.removeEventListener('keypress', observer, useCapture);
+ } else if (element.detachEvent) {
+ element.detachEvent('onkeydown', observer);
+ }
+ } else {
+ if (element.removeEventListener) {
+ element.removeEventListener(name, observer, useCapture);
+ } else if (element.detachEvent) {
+ element.detachEvent('on' + name, observer);
+ }
+ }
}
});

0 comments on commit a551ba2

Please sign in to comment.