aboutsummaryrefslogtreecommitdiffstats
path: root/railties/html/javascripts
diff options
context:
space:
mode:
authorSam Stephenson <sam@37signals.com>2006-02-12 01:30:13 +0000
committerSam Stephenson <sam@37signals.com>2006-02-12 01:30:13 +0000
commit838ec413ebe08be71eea3dec0b061c6f609c839f (patch)
tree8df6658227aeeb613ec809d0da6539bb2d956eeb /railties/html/javascripts
parente90bbbdd837ffc83dccbd05528c4f1521e3956ee (diff)
downloadrails-838ec413ebe08be71eea3dec0b061c6f609c839f.tar.gz
rails-838ec413ebe08be71eea3dec0b061c6f609c839f.tar.bz2
rails-838ec413ebe08be71eea3dec0b061c6f609c839f.zip
Add JavaScriptGenerator#replace_element for replacing an element's "outer HTML". Closes #3246.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3579 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'railties/html/javascripts')
-rw-r--r--railties/html/javascripts/prototype.js47
1 files changed, 23 insertions, 24 deletions
diff --git a/railties/html/javascripts/prototype.js b/railties/html/javascripts/prototype.js
index 62ee54efc1..f37149127f 100644
--- a/railties/html/javascripts/prototype.js
+++ b/railties/html/javascripts/prototype.js
@@ -436,8 +436,7 @@ var Enumerable = {
var collections = [this].concat(args).map($A);
return this.map(function(value, index) {
- iterator(value = collections.pluck(index));
- return value;
+ return iterator(collections.pluck(index));
});
},
@@ -943,6 +942,19 @@ Object.extend(Element, {
setTimeout(function() {html.evalScripts()}, 10);
},
+ replace: function(element, html) {
+ element = $(element);
+ if (element.outerHTML) {
+ element.outerHTML = html.stripScripts();
+ } else {
+ var range = element.ownerDocument.createRange();
+ range.selectNodeContents(element);
+ element.parentNode.replaceChild(
+ range.createContextualFragment(html.stripScripts()), element);
+ }
+ setTimeout(function() {html.evalScripts()}, 10);
+ },
+
getHeight: function(element) {
element = $(element);
return element.offsetHeight;
@@ -1305,18 +1317,8 @@ var Field = {
$(arguments[i]).value = '';
},
- // Pass the field id or element as the first parameter and optionally a triggering delay in micro-seconds as the second.
- // The delay is useful when the focus is part of effects that won't finish instantly since they prevent the focus from
- // taking hold. Set the delay to right after the effect finishes and the focus will work.
- focus: function() {
- element = $(arguments[0]);
- delay = arguments[1];
-
- if (delay) {
- setTimeout(function() { $(element).focus(); }, delay)
- } else {
- $(element).focus();
- }
+ focus: function(element) {
+ $(element).focus();
},
present: function() {
@@ -1549,16 +1551,15 @@ Form.Observer.prototype = Object.extend(new Abstract.TimedObserver(), {
Abstract.EventObserver = function() {}
Abstract.EventObserver.prototype = {
- initialize: function() {
- this.element = $(arguments[0]);
- this.callback = arguments[1];
- this.trigger = arguments[2];
+ initialize: function(element, callback) {
+ this.element = $(element);
+ this.callback = callback;
this.lastValue = this.getValue();
if (this.element.tagName.toLowerCase() == 'form')
this.registerFormCallbacks();
else
- this.registerCallback(this.element, this.trigger);
+ this.registerCallback(this.element);
},
onElementEvent: function() {
@@ -1572,13 +1573,11 @@ Abstract.EventObserver.prototype = {
registerFormCallbacks: function() {
var elements = Form.getElements(this.element);
for (var i = 0; i < elements.length; i++)
- this.registerCallback(elements[i], this.trigger);
+ this.registerCallback(elements[i]);
},
- registerCallback: function(element, trigger) {
- if (trigger && element.type) {
- Event.observe(element, trigger, this.onElementEvent.bind(this));
- } else if (element.type) {
+ registerCallback: function(element) {
+ if (element.type) {
switch (element.type.toLowerCase()) {
case 'checkbox':
case 'radio':