Hi all! How can I do a Ajax.Replacer instead of Ajax.Updater? I created Ajax.Replacer but I would like to include it or don''t use it if your library has some code to do this Thanks! -- Mis Cosas http://blogs.sistes.net/Garito/
The easiest is probably clear the containers contents in the onSuccess handler. This gets called just before the container gets updated. Nick On 6/1/06, Garito <garito-faBWk5Y7ALWsTnJN9+BGXg@public.gmane.org> wrote:> Hi all! > How can I do a Ajax.Replacer instead of Ajax.Updater? > > I created Ajax.Replacer but I would like to include it or don''t use it > if your library has some code to do this > > Thanks! > > -- > Mis Cosas > http://blogs.sistes.net/Garito/ > > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >
Hi!
In my opinion prototype.js is a good library. With it I learn more
javascript than in my whole life but I need to create another class to
work like I prefer
I would like to have a Ajax class that replace instead of update a container
Why?
I love something like this:
<div id=''List1'' class=''List''>
<div id=''Element1''
class=''Element''>
Element1
<a href="javascript: Ajax.Replacer(''Element1'',
''http://myserver/Edit/Element1'',
options)">Edit</a>
</div>
<div id=''Element2''
class=''Element''>
Element2
<a href="javascript: Ajax.Replacer(''Element2'',
''http://myserver/Edit/Element2'',
options)">Edit</a>
</div>
<div id=''Element3''
class=''Element''>
Element3
<a href="javascript: Ajax.Replacer(''Element3'',
''http://myserver/Edit/Element3'',
options)">Edit</a>
</div>
</div>
I would like to maintain the right structure :
List1
Element1
Element2
Element3
But I would like to change the Element1 div complete because I don''t
know what the server give to me
For these I create Ajax.Replacer a class that replace the container
gived complete
Now I don''t want that Sam or Thomas or anyone include these class at
prototype library (I only hope so) but I would like to know if I create
the class correctly or there are another better way to write it
Thanks!
PD: I have Ajax.Adder too to add content to a web (not update its
content). If you think you need it search Ajax.Replacer at my weblog
(http://blogs.sistes.net/Garito)
Ajax.Replacer
Ajax.Replacer = Class.create();
Object.extend(Object.extend(Ajax.Replacer.prototype,
Ajax.Request.prototype), {
initialize: function(container, url, options) {
this.containers = {
success: container.success ? $(container.success) : $(container),
failure: container.failure ? $(container.failure) :
(container.success ? null : $(container))
}
this.transport = Ajax.getTransport();
this.setOptions(options);
var onComplete = this.options.onComplete || Prototype.emptyFunction;
this.options.onComplete = (function(transport, object) {
this.replaceContent();
onComplete(transport, object);
}).bind(this);
this.request(url);
},
replaceContent: function() {
var receiver = this.responseIsSuccess() ?
this.containers.success : this.containers.failure;
var response = this.transport.responseText;
if (!this.options.evalScripts)
response = response.stripScripts();
if (receiver) {
if (this.options.insertion) {
new this.options.insertion(receiver, response);
} else {
var parent = receiver.parentNode
div =
parent.appendChild(document.createElement(''div''))
Element.update(div, response)
for(i = 0; div.childNodes.length; i++)
{
if(div.childNodes[i].nodeName != ''#text''
&&
div.childNodes[i].nodeName != ''META'') { break; }
}
parent.replaceChild(div.childNodes[i], receiver)
parent.removeChild(div)
setTimeout(function() {response.evalScripts()}, 10)
}
}
if (this.responseIsSuccess()) {
if (this.onComplete)
setTimeout(this.onComplete.bind(this), 10);
}
}
});
--
Mis Cosas
http://blogs.sistes.net/Garito/
Garito wrote:> I would like to have a Ajax class that replace instead of update a > containerYour class has way too much copy and paste from prototype. The Ajax.Updater takes an Insertion object as an option. There is not a replacement insertion object but you could easily wrap Element.replace. Or you should be able to use it directly. Element.replace is not a constructor function but you can just pretend it is one. It shouldn''t hurt that "this" will be defined as an empty object while calling Element.replace since it is a class method anyway and does not use "this". new Ajax.Updater(''my_element'', ''my_url'', { insertion: Element.replace }); Eric
Eric Anderson escribió:> Garito wrote: >> I would like to have a Ajax class that replace instead of update a >> container > > Your class has way too much copy and paste from prototype. The > Ajax.Updater takes an Insertion object as an option. There is not a > replacement insertion object but you could easily wrap Element.replace. > > Or you should be able to use it directly. Element.replace is not a > constructor function but you can just pretend it is one. It shouldn''t > hurt that "this" will be defined as an empty object while calling > Element.replace since it is a class method anyway and does not use > "this". > > new Ajax.Updater(''my_element'', ''my_url'', { > insertion: Element.replace > }); > > Eric > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffsCopy paste is your friend I don''t know if I understand you so much (my english is so poor) Some code, perhaps? have these code any utility for you? Thanks! -- Mis Cosas http://blogs.sistes.net/Garito/