Skip to content
This repository
Browse code

Sync Prototype; closes #1539

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1558 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit a551ba2c01f5fcc1c0eff13c8ef24082e55071b9 1 parent 31e4893
Sam Stephenson sstephenson authored

Showing 1 changed file with 59 additions and 30 deletions. Show diff stats Hide diff stats

  1. +59 30 actionpack/lib/action_view/helpers/javascripts/prototype.js
89 actionpack/lib/action_view/helpers/javascripts/prototype.js
... ... @@ -1,4 +1,4 @@
1   -/* Prototype: an object-oriented Javascript library, version 1.3.0
  1 +/* Prototype JavaScript framework, version 1.3.0
2 2 * (c) 2005 Sam Stephenson <sam@conio.net>
3 3 *
4 4 * THIS FILE IS AUTOMATICALLY GENERATED. When sending patches, please diff
@@ -152,10 +152,17 @@ String.prototype.extend({
152 152 return this.replace(/<\/?[^>]+>/gi, '');
153 153 },
154 154
  155 + escapeHTML: function() {
  156 + var div = document.createElement('div');
  157 + var text = document.createTextNode(this);
  158 + div.appendChild(text);
  159 + return div.innerHTML;
  160 + },
  161 +
155 162 unescapeHTML: function() {
156   - return this.replace(/&lt;/gi,"<").replace(/&gt;/gi,">").
157   - replace(/&quot;/gi,'"').replace(/&apos;/gi,"'").
158   - replace(/&amp;/gi,"&").replace(/[\n\r]/gi,"");
  163 + var div = document.createElement('div');
  164 + div.innerHTML = this.stripTags();
  165 + return div.childNodes[0].nodeValue;
159 166 }
160 167 });
161 168
@@ -238,23 +245,24 @@ Ajax.Request.prototype = (new Ajax.Base()).extend({
238 245 var event = Ajax.Request.Events[readyState];
239 246
240 247 if (event == 'Complete' && this.transport.status != 200)
241   - (this.options['on' + this.transport.status] ||
242   - this.options.onFailure ||
243   - Prototype.emptyFunction)(this.transport);
  248 + (this.options['on' + this.transport.status]
  249 + || this.options.onFailure
  250 + || Prototype.emptyFunction)(this.transport);
244 251
245 252 (this.options['on' + event] || Prototype.emptyFunction)(this.transport);
246 253 }
247 254 });
248 255
249 256 Ajax.Updater = Class.create();
  257 +Ajax.Updater.ScriptFragmentMatch = /<script.*?>((?:\n|.)*?)<\/script>/im;
  258 +
250 259 Ajax.Updater.prototype = (new Ajax.Base()).extend({
251 260 initialize: function(container, url, options) {
252 261 this.containers = {
253 262 success: container.success ? $(container.success) : $(container),
254 263 failure: container.failure ? $(container.failure) : null
255 264 }
256   -
257   - this.script_re = /<script.*?>((?:\n|.)*?)<\/script>/im;
  265 +
258 266 this.setOptions(options);
259 267
260 268 if (this.options.asynchronous) {
@@ -272,12 +280,12 @@ Ajax.Updater.prototype = (new Ajax.Base()).extend({
272 280 var receiver =
273 281 (this.request.transport.status == 200) ?
274 282 this.containers.success : this.containers.failure;
275   -
276   - var response = this.request.transport.responseText.replace(
277   - this.script_re, '');
278   -
279   - var scripts = this.request.transport.responseText.match(
280   - this.script_re);
  283 +
  284 + var response = this.request.transport.responseText.
  285 + replace(Ajax.Updater.ScriptFragmentMatch, '');
  286 +
  287 + var scripts = this.request.transport.responseText.
  288 + match(Ajax.Updater.ScriptFragmentMatch);
281 289
282 290 if (receiver) {
283 291 if (this.options.insertion) {
@@ -288,13 +296,12 @@ Ajax.Updater.prototype = (new Ajax.Base()).extend({
288 296 }
289 297
290 298 if (this.request.transport.status == 200) {
291   - if (this.onComplete) {
  299 + if (this.onComplete)
292 300 setTimeout((function() {this.onComplete(
293 301 this.request.transport)}).bind(this), 10);
294   - }
295   - if (this.options.script && scripts) {
296   - setTimeout((function() { eval(scripts[1]) }).bind(this), 10);
297   - }
  302 +
  303 + if (this.options.evalScripts && scripts)
  304 + setTimeout((function() {eval(scripts[1])}).bind(this), 10);
298 305 }
299 306 }
300 307 });
@@ -340,11 +347,8 @@ Ajax.PeriodicalUpdater.prototype = (new Ajax.Base()).extend({
340 347 onTimerEvent: function() {
341 348 this.updater = new Ajax.Updater(this.container, this.url, this.options);
342 349 }
343   -
344 350 });
345 351
346   -/*--------------------------------------------------------------------------*/
347   -
348 352 document.getElementsByClassName = function(className) {
349 353 var children = document.getElementsByTagName('*') || document.all;
350 354 var elements = new Array();
@@ -855,31 +859,56 @@ Object.extend(Event, {
855 859 // node the event was triggered on; traverses the DOM upwards
856 860 findElement: function(event, tagName) {
857 861 var element = Event.element(event);
858   - while (element.parentNode && (!element.tagName ||
859   - (element.tagName.toUpperCase() != tagName.toUpperCase())))
  862 + while (element.parentNode && (!element.tagName ||
  863 + (element.tagName.toUpperCase() != tagName.toUpperCase())))
860 864 element = element.parentNode;
861 865 return element;
862 866 },
863 867
864   - observe: function(element, name, observer) {
  868 + observe: function(element, name, observer, useCapture) {
865 869 var element = $(element);
  870 + useCapture = useCapture || false;
  871 +
866 872 if (name == 'keypress') {
867   - if (navigator.appVersion.indexOf('AppleWebKit') > 0) {
868   - element.addEventListener('keydown', observer, false);
  873 + if (navigator.appVersion.indexOf('AppleWebKit') > 0) {
  874 + element.addEventListener('keydown', observer, useCapture);
869 875 return;
870 876 }
871 877 if (element.addEventListener) {
872   - element.addEventListener('keypress', observer, false);
  878 + element.addEventListener('keypress', observer, useCapture);
873 879 } else if (element.attachEvent) {
874 880 element.attachEvent('onkeydown', observer);
875 881 }
876 882 } else {
877 883 if (element.addEventListener) {
878   - element.addEventListener(name, observer, false);
  884 + element.addEventListener(name, observer, useCapture);
879 885 } else if (element.attachEvent) {
880 886 element.attachEvent('on' + name, observer);
881 887 }
882 888 }
  889 + },
  890 +
  891 + stopObserving: function(element, name, observer, useCapture) {
  892 + var element = $(element);
  893 + useCapture = useCapture || false;
  894 +
  895 + if (name == 'keypress') {
  896 + if (navigator.appVersion.indexOf('AppleWebKit') > 0) {
  897 + element.removeEventListener('keydown', observer, useCapture);
  898 + return;
  899 + }
  900 + if (element.removeEventListener) {
  901 + element.removeEventListener('keypress', observer, useCapture);
  902 + } else if (element.detachEvent) {
  903 + element.detachEvent('onkeydown', observer);
  904 + }
  905 + } else {
  906 + if (element.removeEventListener) {
  907 + element.removeEventListener(name, observer, useCapture);
  908 + } else if (element.detachEvent) {
  909 + element.detachEvent('on' + name, observer);
  910 + }
  911 + }
883 912 }
884 913 });
885 914

0 comments on commit a551ba2

Please sign in to comment.
Something went wrong with that request. Please try again.