提交 dcaa8716 编写于 作者: S Sam Stephenson

Update to Prototype 1.4.0_rc3. Closes #1893, #2505, #2550, #2748, #2783.

git-svn-id: http://svn-commit.rubyonrails.org/rails/branches/stable@3079 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
上级 9796a587
*SVN*
* Update to Prototype 1.4.0_rc3. Closes #1893, #2505, #2550, #2748, #2783. [Sam Stephenson]
* Updated docs for in_place_editor, fixes a couple bugs and offers extended support for external controls [Justin Palmer]
* Rename Version constant to VERSION. #2802 [Marcel Molina Jr.]
......
/* Prototype JavaScript framework, version 1.4.0_rc2
/* Prototype JavaScript framework, version 1.4.0_rc3
* (c) 2005 Sam Stephenson <sam@conio.net>
*
* THIS FILE IS AUTOMATICALLY GENERATED. When sending patches, please diff
......@@ -11,7 +11,8 @@
/*--------------------------------------------------------------------------*/
var Prototype = {
Version: '1.4.0_rc2',
Version: '1.4.0_rc3',
ScriptFragment: '(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)',
emptyFunction: function() {},
K: function(x) {return x}
......@@ -143,6 +144,22 @@ Object.extend(String.prototype, {
return this.replace(/<\/?[^>]+>/gi, '');
},
stripScripts: function() {
return this.replace(new RegExp(Prototype.ScriptFragment, 'img'), '');
},
extractScripts: function() {
var matchAll = new RegExp(Prototype.ScriptFragment, 'img');
var matchOne = new RegExp(Prototype.ScriptFragment, 'im');
return (this.match(matchAll) || []).map(function(scriptTag) {
return (scriptTag.match(matchOne) || ['', ''])[1];
});
},
evalScripts: function() {
return this.extractScripts().map(eval);
},
escapeHTML: function() {
var div = document.createElement('div');
var text = document.createTextNode(this);
......@@ -214,8 +231,8 @@ var Enumerable = {
all: function(iterator) {
var result = true;
this.each(function(value, index) {
if (!(result &= (iterator || Prototype.K)(value, index)))
throw $break;
result = result && !!(iterator || Prototype.K)(value, index);
if (!result) throw $break;
});
return result;
},
......@@ -223,7 +240,7 @@ var Enumerable = {
any: function(iterator) {
var result = true;
this.each(function(value, index) {
if (result &= (iterator || Prototype.K)(value, index))
if (result = !!(iterator || Prototype.K)(value, index))
throw $break;
});
return result;
......@@ -425,7 +442,7 @@ Object.extend(Array.prototype, {
indexOf: function(object) {
for (var i = 0; i < this.length; i++)
if (this[i] == object) return i;
return false;
return -1;
},
reverse: function() {
......@@ -486,9 +503,9 @@ function $H(object) {
Object.extend(hash, Hash);
return hash;
}
var Range = Class.create();
Object.extend(Range.prototype, Enumerable);
Object.extend(Range.prototype, {
ObjectRange = Class.create();
Object.extend(ObjectRange.prototype, Enumerable);
Object.extend(ObjectRange.prototype, {
initialize: function(start, end, exclusive) {
this.start = start;
this.end = end;
......@@ -513,7 +530,7 @@ Object.extend(Range.prototype, {
});
var $R = function(start, end, exclusive) {
return new Range(start, end, exclusive);
return new ObjectRange(start, end, exclusive);
}
var Ajax = {
......@@ -549,8 +566,7 @@ Ajax.Responders = {
if (responder[callback] && typeof responder[callback] == 'function') {
try {
responder[callback].apply(responder, [request, transport, json]);
} catch (e) {
}
} catch (e) {}
}
});
}
......@@ -626,8 +642,7 @@ Ajax.Request.prototype = Object.extend(new Ajax.Base(), {
this.transport.send(this.options.method == 'post' ? body : null);
} catch (e) {
(this.options.onException || Prototype.emptyFunction)(this, e);
Ajax.Responders.dispatch('onException', this, e);
this.dispatchException(e);
}
},
......@@ -661,12 +676,23 @@ Ajax.Request.prototype = Object.extend(new Ajax.Base(), {
this.respondToReadyState(this.transport.readyState);
},
header: function(name) {
try {
return this.transport.getResponseHeader(name);
} catch (e) {}
},
evalJSON: function() {
try {
var json = this.transport.getResponseHeader('X-JSON'), object;
object = eval(json);
return object;
return eval(this.header('X-JSON'));
} catch (e) {}
},
evalResponse: function() {
try {
return eval(this.transport.responseText);
} catch (e) {
this.dispatchException(e);
}
},
......@@ -674,22 +700,38 @@ Ajax.Request.prototype = Object.extend(new Ajax.Base(), {
var event = Ajax.Request.Events[readyState];
var transport = this.transport, json = this.evalJSON();
if (event == 'Complete')
(this.options['on' + this.transport.status]
|| this.options['on' + (this.responseIsSuccess() ? 'Success' : 'Failure')]
|| Prototype.emptyFunction)(transport, json);
if (event == 'Complete') {
try {
(this.options['on' + this.transport.status]
|| this.options['on' + (this.responseIsSuccess() ? 'Success' : 'Failure')]
|| Prototype.emptyFunction)(transport, json);
} catch (e) {
this.dispatchException(e);
}
if (this.header('Content-type') == 'text/javascript')
this.evalResponse();
}
(this.options['on' + event] || Prototype.emptyFunction)(transport, json);
Ajax.Responders.dispatch('on' + event, this, transport, json);
try {
(this.options['on' + event] || Prototype.emptyFunction)(transport, json);
Ajax.Responders.dispatch('on' + event, this, transport, json);
} catch (e) {
this.dispatchException(e);
}
/* Avoid memory leak in MSIE: clean up the oncomplete event handler */
if (event == 'Complete')
this.transport.onreadystatechange = Prototype.emptyFunction;
},
dispatchException: function(exception) {
(this.options.onException || Prototype.emptyFunction)(this, exception);
Ajax.Responders.dispatch('onException', this, exception);
}
});
Ajax.Updater = Class.create();
Ajax.Updater.ScriptFragment = '(?:<script.*?>)((\n|.)*?)(?:<\/script>)';
Object.extend(Object.extend(Ajax.Updater.prototype, Ajax.Request.prototype), {
initialize: function(container, url, options) {
......@@ -714,16 +756,16 @@ Object.extend(Object.extend(Ajax.Updater.prototype, Ajax.Request.prototype), {
updateContent: function() {
var receiver = this.responseIsSuccess() ?
this.containers.success : this.containers.failure;
var response = this.transport.responseText;
var match = new RegExp(Ajax.Updater.ScriptFragment, 'img');
var response = this.transport.responseText.replace(match, '');
var scripts = this.transport.responseText.match(match);
if (!this.options.evalScripts)
response = response.stripScripts();
if (receiver) {
if (this.options.insertion) {
new this.options.insertion(receiver, response);
} else {
receiver.innerHTML = response;
Element.update(receiver, response);
}
}
......@@ -731,14 +773,6 @@ Object.extend(Object.extend(Ajax.Updater.prototype, Ajax.Request.prototype), {
if (this.onComplete)
setTimeout(this.onComplete.bind(this), 10);
}
if (this.options.evalScripts && scripts) {
match = new RegExp(Ajax.Updater.ScriptFragment, 'im');
setTimeout((function() {
for (var i = 0; i < scripts.length; i++)
eval(scripts[i].match(match)[1]);
}).bind(this), 10);
}
}
});
......@@ -830,6 +864,11 @@ Object.extend(Element, {
element.parentNode.removeChild(element);
},
update: function(element, html) {
$(element).innerHTML = html.stripScripts();
setTimeout(function() {html.evalScripts()}, 10);
},
getHeight: function(element) {
element = $(element);
return element.offsetHeight;
......@@ -969,7 +1008,7 @@ Abstract.Insertion = function(adjacency) {
Abstract.Insertion.prototype = {
initialize: function(element, content) {
this.element = $(element);
this.content = content;
this.content = content.stripScripts();
if (this.adjacency && this.element.insertAdjacentHTML) {
try {
......@@ -986,6 +1025,8 @@ Abstract.Insertion.prototype = {
if (this.initializeRange) this.initializeRange();
this.insertContent([this.range.createContextualFragment(this.content)]);
}
setTimeout(function() {content.evalScripts()}, 10);
},
contentFromAnonymousTable: function() {
......@@ -1079,7 +1120,7 @@ Element.ClassNames.prototype = {
if (!this.include(classNameToRemove)) return;
this.set(this.select(function(className) {
return className != classNameToRemove;
}));
}).join(' '));
},
toString: function() {
......@@ -1109,8 +1150,10 @@ var Field = {
},
activate: function(element) {
$(element).focus();
$(element).select();
element = $(element);
element.focus();
if (element.select)
element.select();
}
}
......@@ -1178,16 +1221,15 @@ var Form = {
}
},
findFirstElement: function(form) {
return Form.getElements(form).find(function(element) {
return element.type != 'hidden' && !element.disabled &&
['input', 'select', 'textarea'].include(element.tagName.toLowerCase());
});
},
focusFirstElement: function(form) {
form = $(form);
var elements = Form.getElements(form);
for (var i = 0; i < elements.length; i++) {
var element = elements[i];
if (element.type != 'hidden' && !element.disabled) {
Field.activate(element);
break;
}
}
Field.activate(Form.findFirstElement(form));
},
reset: function(form) {
......@@ -1349,24 +1391,14 @@ Abstract.EventObserver.prototype = {
switch (element.type.toLowerCase()) {
case 'checkbox':
case 'radio':
element.target = this;
element.prev_onclick = element.onclick || Prototype.emptyFunction;
element.onclick = function() {
this.prev_onclick();
this.target.onElementEvent();
}
Event.observe(element, 'click', this.onElementEvent.bind(this));
break;
case 'password':
case 'text':
case 'textarea':
case 'select-one':
case 'select-multiple':
element.target = this;
element.prev_onchange = element.onchange || Prototype.emptyFunction;
element.onchange = function() {
this.prev_onchange();
this.target.onElementEvent();
}
Event.observe(element, 'change', this.onElementEvent.bind(this));
break;
}
}
......
*SVN*
* Update to Prototype 1.4.0_rc3. Closes #1893, #2505, #2550, #2748, #2783. [Sam Stephenson]
* Rename Version constant to VERSION. #2802 [Marcel Molina Jr.]
* Update to latest script.aculo.us version (as of [3031])
......
/* Prototype JavaScript framework, version 1.4.0_rc2
/* Prototype JavaScript framework, version 1.4.0_rc3
* (c) 2005 Sam Stephenson <sam@conio.net>
*
* THIS FILE IS AUTOMATICALLY GENERATED. When sending patches, please diff
......@@ -11,7 +11,8 @@
/*--------------------------------------------------------------------------*/
var Prototype = {
Version: '1.4.0_rc2',
Version: '1.4.0_rc3',
ScriptFragment: '(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)',
emptyFunction: function() {},
K: function(x) {return x}
......@@ -143,6 +144,22 @@ Object.extend(String.prototype, {
return this.replace(/<\/?[^>]+>/gi, '');
},
stripScripts: function() {
return this.replace(new RegExp(Prototype.ScriptFragment, 'img'), '');
},
extractScripts: function() {
var matchAll = new RegExp(Prototype.ScriptFragment, 'img');
var matchOne = new RegExp(Prototype.ScriptFragment, 'im');
return (this.match(matchAll) || []).map(function(scriptTag) {
return (scriptTag.match(matchOne) || ['', ''])[1];
});
},
evalScripts: function() {
return this.extractScripts().map(eval);
},
escapeHTML: function() {
var div = document.createElement('div');
var text = document.createTextNode(this);
......@@ -214,8 +231,8 @@ var Enumerable = {
all: function(iterator) {
var result = true;
this.each(function(value, index) {
if (!(result &= (iterator || Prototype.K)(value, index)))
throw $break;
result = result && !!(iterator || Prototype.K)(value, index);
if (!result) throw $break;
});
return result;
},
......@@ -223,7 +240,7 @@ var Enumerable = {
any: function(iterator) {
var result = true;
this.each(function(value, index) {
if (result &= (iterator || Prototype.K)(value, index))
if (result = !!(iterator || Prototype.K)(value, index))
throw $break;
});
return result;
......@@ -425,7 +442,7 @@ Object.extend(Array.prototype, {
indexOf: function(object) {
for (var i = 0; i < this.length; i++)
if (this[i] == object) return i;
return false;
return -1;
},
reverse: function() {
......@@ -486,9 +503,9 @@ function $H(object) {
Object.extend(hash, Hash);
return hash;
}
var Range = Class.create();
Object.extend(Range.prototype, Enumerable);
Object.extend(Range.prototype, {
ObjectRange = Class.create();
Object.extend(ObjectRange.prototype, Enumerable);
Object.extend(ObjectRange.prototype, {
initialize: function(start, end, exclusive) {
this.start = start;
this.end = end;
......@@ -513,7 +530,7 @@ Object.extend(Range.prototype, {
});
var $R = function(start, end, exclusive) {
return new Range(start, end, exclusive);
return new ObjectRange(start, end, exclusive);
}
var Ajax = {
......@@ -549,8 +566,7 @@ Ajax.Responders = {
if (responder[callback] && typeof responder[callback] == 'function') {
try {
responder[callback].apply(responder, [request, transport, json]);
} catch (e) {
}
} catch (e) {}
}
});
}
......@@ -626,8 +642,7 @@ Ajax.Request.prototype = Object.extend(new Ajax.Base(), {
this.transport.send(this.options.method == 'post' ? body : null);
} catch (e) {
(this.options.onException || Prototype.emptyFunction)(this, e);
Ajax.Responders.dispatch('onException', this, e);
this.dispatchException(e);
}
},
......@@ -661,12 +676,23 @@ Ajax.Request.prototype = Object.extend(new Ajax.Base(), {
this.respondToReadyState(this.transport.readyState);
},
header: function(name) {
try {
return this.transport.getResponseHeader(name);
} catch (e) {}
},
evalJSON: function() {
try {
var json = this.transport.getResponseHeader('X-JSON'), object;
object = eval(json);
return object;
return eval(this.header('X-JSON'));
} catch (e) {}
},
evalResponse: function() {
try {
return eval(this.transport.responseText);
} catch (e) {
this.dispatchException(e);
}
},
......@@ -674,22 +700,38 @@ Ajax.Request.prototype = Object.extend(new Ajax.Base(), {
var event = Ajax.Request.Events[readyState];
var transport = this.transport, json = this.evalJSON();
if (event == 'Complete')
(this.options['on' + this.transport.status]
|| this.options['on' + (this.responseIsSuccess() ? 'Success' : 'Failure')]
|| Prototype.emptyFunction)(transport, json);
if (event == 'Complete') {
try {
(this.options['on' + this.transport.status]
|| this.options['on' + (this.responseIsSuccess() ? 'Success' : 'Failure')]
|| Prototype.emptyFunction)(transport, json);
} catch (e) {
this.dispatchException(e);
}
if (this.header('Content-type') == 'text/javascript')
this.evalResponse();
}
(this.options['on' + event] || Prototype.emptyFunction)(transport, json);
Ajax.Responders.dispatch('on' + event, this, transport, json);
try {
(this.options['on' + event] || Prototype.emptyFunction)(transport, json);
Ajax.Responders.dispatch('on' + event, this, transport, json);
} catch (e) {
this.dispatchException(e);
}
/* Avoid memory leak in MSIE: clean up the oncomplete event handler */
if (event == 'Complete')
this.transport.onreadystatechange = Prototype.emptyFunction;
},
dispatchException: function(exception) {
(this.options.onException || Prototype.emptyFunction)(this, exception);
Ajax.Responders.dispatch('onException', this, exception);
}
});
Ajax.Updater = Class.create();
Ajax.Updater.ScriptFragment = '(?:<script.*?>)((\n|.)*?)(?:<\/script>)';
Object.extend(Object.extend(Ajax.Updater.prototype, Ajax.Request.prototype), {
initialize: function(container, url, options) {
......@@ -714,16 +756,16 @@ Object.extend(Object.extend(Ajax.Updater.prototype, Ajax.Request.prototype), {
updateContent: function() {
var receiver = this.responseIsSuccess() ?
this.containers.success : this.containers.failure;
var response = this.transport.responseText;
var match = new RegExp(Ajax.Updater.ScriptFragment, 'img');
var response = this.transport.responseText.replace(match, '');
var scripts = this.transport.responseText.match(match);
if (!this.options.evalScripts)
response = response.stripScripts();
if (receiver) {
if (this.options.insertion) {
new this.options.insertion(receiver, response);
} else {
receiver.innerHTML = response;
Element.update(receiver, response);
}
}
......@@ -731,14 +773,6 @@ Object.extend(Object.extend(Ajax.Updater.prototype, Ajax.Request.prototype), {
if (this.onComplete)
setTimeout(this.onComplete.bind(this), 10);
}
if (this.options.evalScripts && scripts) {
match = new RegExp(Ajax.Updater.ScriptFragment, 'im');
setTimeout((function() {
for (var i = 0; i < scripts.length; i++)
eval(scripts[i].match(match)[1]);
}).bind(this), 10);
}
}
});
......@@ -830,6 +864,11 @@ Object.extend(Element, {
element.parentNode.removeChild(element);
},
update: function(element, html) {
$(element).innerHTML = html.stripScripts();
setTimeout(function() {html.evalScripts()}, 10);
},
getHeight: function(element) {
element = $(element);
return element.offsetHeight;
......@@ -969,7 +1008,7 @@ Abstract.Insertion = function(adjacency) {
Abstract.Insertion.prototype = {
initialize: function(element, content) {
this.element = $(element);
this.content = content;
this.content = content.stripScripts();
if (this.adjacency && this.element.insertAdjacentHTML) {
try {
......@@ -986,6 +1025,8 @@ Abstract.Insertion.prototype = {
if (this.initializeRange) this.initializeRange();
this.insertContent([this.range.createContextualFragment(this.content)]);
}
setTimeout(function() {content.evalScripts()}, 10);
},
contentFromAnonymousTable: function() {
......@@ -1079,7 +1120,7 @@ Element.ClassNames.prototype = {
if (!this.include(classNameToRemove)) return;
this.set(this.select(function(className) {
return className != classNameToRemove;
}));
}).join(' '));
},
toString: function() {
......@@ -1109,8 +1150,10 @@ var Field = {
},
activate: function(element) {
$(element).focus();
$(element).select();
element = $(element);
element.focus();
if (element.select)
element.select();
}
}
......@@ -1178,16 +1221,15 @@ var Form = {
}
},
findFirstElement: function(form) {
return Form.getElements(form).find(function(element) {
return element.type != 'hidden' && !element.disabled &&
['input', 'select', 'textarea'].include(element.tagName.toLowerCase());
});
},
focusFirstElement: function(form) {
form = $(form);
var elements = Form.getElements(form);
for (var i = 0; i < elements.length; i++) {
var element = elements[i];
if (element.type != 'hidden' && !element.disabled) {
Field.activate(element);
break;
}
}
Field.activate(Form.findFirstElement(form));
},
reset: function(form) {
......@@ -1349,24 +1391,14 @@ Abstract.EventObserver.prototype = {
switch (element.type.toLowerCase()) {
case 'checkbox':
case 'radio':
element.target = this;
element.prev_onclick = element.onclick || Prototype.emptyFunction;
element.onclick = function() {
this.prev_onclick();
this.target.onElementEvent();
}
Event.observe(element, 'click', this.onElementEvent.bind(this));
break;
case 'password':
case 'text':
case 'textarea':
case 'select-one':
case 'select-multiple':
element.target = this;
element.prev_onchange = element.onchange || Prototype.emptyFunction;
element.onchange = function() {
this.prev_onchange();
this.target.onElementEvent();
}
Event.observe(element, 'change', this.onElementEvent.bind(this));
break;
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册