diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-03-26 15:35:06 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-03-26 15:35:06 +0000 |
commit | 8e76a5920e2daaf0ea44b5b6195b75788c5de44c (patch) | |
tree | 93968aaf8aa37fe2894639988c4cc71841c44dbf /actionpack/lib | |
parent | e79801d7f254572e195a0048fc912571b51aa23d (diff) | |
download | rails-8e76a5920e2daaf0ea44b5b6195b75788c5de44c.tar.gz rails-8e76a5920e2daaf0ea44b5b6195b75788c5de44c.tar.bz2 rails-8e76a5920e2daaf0ea44b5b6195b75788c5de44c.zip |
Added other DOM manipulation positions than just replace
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1006 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_view/helpers/javascript_helper.rb | 5 | ||||
-rw-r--r-- | actionpack/lib/action_view/helpers/javascripts/prototype.js | 67 |
2 files changed, 68 insertions, 4 deletions
diff --git a/actionpack/lib/action_view/helpers/javascript_helper.rb b/actionpack/lib/action_view/helpers/javascript_helper.rb index 513074cddd..1d70073069 100644 --- a/actionpack/lib/action_view/helpers/javascript_helper.rb +++ b/actionpack/lib/action_view/helpers/javascript_helper.rb @@ -158,8 +158,9 @@ module ActionView js_options = build_callbacks(options) js_options['asynchronous'] = options[:type] != :synchronous - js_options['method'] = options[:method] if options[:method] - js_options['effect'] = ("\'"+options[:effect].to_s+"\'") if options[:effect] + js_options['method'] = options[:method] if options[:method] + js_options['position'] = options[:position] ? "'#{options[:position].to_s}'" : "'replace'" + js_options['effect'] = ("\'"+options[:effect].to_s+"\'") if options[:effect] if options[:form] js_options['parameters'] = 'Form.serialize(this)' diff --git a/actionpack/lib/action_view/helpers/javascripts/prototype.js b/actionpack/lib/action_view/helpers/javascripts/prototype.js index d634c5c6b5..60dbd5d419 100644 --- a/actionpack/lib/action_view/helpers/javascripts/prototype.js +++ b/actionpack/lib/action_view/helpers/javascripts/prototype.js @@ -135,7 +135,8 @@ Ajax.Base.prototype = { this.options = { method: 'post', asynchronous: true, - parameters: '' + parameters: '', + position: 'replace' }.extend(options || {}); } } @@ -204,9 +205,17 @@ Ajax.Updater.prototype = (new Ajax.Base()).extend({ updateContent: function() { this.container.innerHTML = this.request.transport.responseText; + + if (this.options.position.toLowerCase() == 'replace') { + this.container.innerHTML = this.request.transport.responseText; + } else { + Insert[this.options.position.toLowerCase()]( this.container, this.request.transport.responseText ); + } + switch(this.options.effect) { case 'highlight': new YellowFader(this.container); break; } + if (this.onComplete) this.onComplete(this.request); } }); @@ -382,4 +391,58 @@ YellowFader.prototype = { highlight: function(element, current) { element.style.backgroundColor = "#ffff" + current.toColorPart(); } -}
\ No newline at end of file +} + +/*--------------------------------------------------------------------------*/ + +Insert = { + before_begin: function(dom, html) { + dom = $(dom); + if (dom.insertAdjacentHTML) { + dom.insertAdjacentHTML('BeforeBegin', html); + } else { + var r = dom.ownerDocument.createRange(); + r.setStartBefore(dom); + var df = r.createContextualFragment(html); + dom.parentNode.insertBefore(df, dom); + } + }, + + after_begin: function(dom, html) { + dom = $(dom); + if (dom.insertAdjacentHTML) { + dom.insertAdjacentHTML('AfterBegin', html); + } else { + var r = dom.ownerDocument.createRange(); + r.selectNodeContents(dom); + r.collapse(true); + var df = r.createContextualFragment( html ); + dom.insertBefore(df, dom.firstChild ); + } + }, + + before_end: function(dom, html) { + dom = $(dom); + if (dom.insertAdjacentHTML) { + dom.insertAdjacentHTML('BeforeEnd', html); + } else { + var r = dom.ownerDocument.createRange(); + r.selectNodeContents(dom); + r.collapse(dom); + var df = r.createContextualFragment(html); + dom.appendChild(df); + } + }, + + after_end: function(dom, html) { + dom = $(dom); + if (dom.insertAdjacentHTML) { + dom.insertAdjacentHTML('BeforeBegin', html); + } else { + var r = dom.ownerDocument.createRange(); + r.setStartAfter(dom); + var df = r.createContextualFragment( html ); + dom.parentNode.insertBefore(df, dom.nextSibling); + } + } +};
\ No newline at end of file |