Hello, I have a treeview, that works with scriptaculous in order to load the nodes dynamically. I also have in the main part of the page, a table with the list of elements. The lists of elements can be drag-dropped on the treeview in order to move them around (they are also draggable on other parts of the page) I need though, to refresh the treeview to reflect changes when a folder was moved (the branches changes) so i call the server to get a fragment of HTML (I know it could have been a fragment of XML, processed on client side but in my use case, it''s a rendered HTML piece) This sent piece contains javascript as well, in order to make the dynamic node still working. When the dom is reloaded, the drag/drop features reloads Droppable.dropselements. The new treeview html fragment IS the treeview that would be displayed on the page if the user would hit F5 after the drag. Everything work fine, except that the droppable areas of the freshly updated treeview are not enabled anymore. They do work on other droppable parts. here''s the code that reload the treeview: *var* CPSPortletRefresher = Class.create(); CPSPortletRefresher.prototype = { initialize: *function*() { }, refreshPortletCompleted: *function*(originalRequest) { *// getting new positions from the server* result = originalRequest.responseText; *if* (result!='''') { $(this.last_portlet_id).innerHTML = result; *var* newdiv = document.createElement("div"); newdiv.innerHTML = result; newdiv.id = this.last_portlet_id; olddiv = $(this.last_portlet_id); parent = olddiv.parentNode; olddiv.parentNode.replaceChild(newdiv, olddiv); } }, refreshPortlet: *function*(portlet_id) { *var* params = ''portlet_id='' + portlet_id; url = ''viewPortlet''; *var* refreshPortletCompletedBn = this.refreshPortletCompleted.bind(this); *var* options = {parameters: params, onComplete: refreshPortletCompletedBn}; this.last_portlet_id = portlet_id; *var* sender = *new* Ajax.Request(url, options); }, } *var* portlet_refresher = *new* CPSPortletRefresher(); So two question: 1/ is the innerHTML reliable for this kind of job ? 2/ Do I miss something ? :) Thanks ! Tarek -- Tarek Ziadé | Association AfPy | www.afpy.org Site personnel | http://programmation-python.org _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
On 2/23/06, Tarek Ziadé <ziade.tarek-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> When the dom is reloaded, the drag/drop features reloads Droppable.drops > elements.I think this statement is the heart of your problem. There''s nothing active about scriptaculous (where you''re getting the Draggables/Droppables from) that would check for a DOM "reload" (I''m not sure what that is? any change, perhaps?); I''m not even sure that kind of information is available to JavaScript. I don''t know much about scriptaculous, so don''t take this as the final answer, but the magic that makes Draggables/Droppables work are the events that are attached to each element that you make Draggable/Droppable. When you use .innerHTML on those elements'' parent, you''re effectively destroying the existing elements (and their event associations) and creating what might look like identical elements, but they''re not; they don''t have the events unless you programatically re-initialize the Draggables/Droppables.> refreshPortletCompleted: function(originalRequest) { > // getting new positions from the server > result = originalRequest.responseText; > > if (result!='''') { > $(this.last_portlet_id).innerHTML = result; > var newdiv = document.createElement("div"); > newdiv.innerHTML = result; > newdiv.id = this.last_portlet_id; > olddiv = $(this.last_portlet_id); > parent = olddiv.parentNode; > olddiv.parentNode.replaceChild(newdiv, olddiv); > } > },Isn''t most of this code redundant? You only need to use innerHTML on the existing div, or create a new div and replace the old one. Either one achieves the same DOM structure in the end. You also never use ''parent'' anywhere. Todd
You may try to use Ajax.Updater with the evalScripts option enabled. In the HTML code sent by the server, you''ll have to include <script> tag with make your new div dropable. You can also try something like Behaviour, and reapply rules once updated. Regards, Nicolas On 2/23/06, Todd Ross <rails-spinoffs-25kFIyuv2iRiLUuM0BA3LQ@public.gmane.org> wrote:> > On 2/23/06, Tarek Ziadé <ziade.tarek-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > When the dom is reloaded, the drag/drop features reloads > Droppable.drops > > elements. > > I think this statement is the heart of your problem. There''s nothing > active about scriptaculous (where you''re getting the > Draggables/Droppables from) that would check for a DOM "reload" (I''m > not sure what that is? any change, perhaps?); I''m not even sure that > kind of information is available to JavaScript. > > I don''t know much about scriptaculous, so don''t take this as the final > answer, but the magic that makes Draggables/Droppables work are the > events that are attached to each element that you make > Draggable/Droppable. When you use .innerHTML on those elements'' > parent, you''re effectively destroying the existing elements (and their > event associations) and creating what might look like identical > elements, but they''re not; they don''t have the events unless you > programatically re-initialize the Draggables/Droppables. > > > refreshPortletCompleted: function(originalRequest) { > > // getting new positions from the server > > result = originalRequest.responseText; > > > > if (result!='''') { > > $(this.last_portlet_id).innerHTML = result; > > var newdiv = document.createElement("div"); > > newdiv.innerHTML = result; > > newdiv.id = this.last_portlet_id; > > olddiv = $(this.last_portlet_id); > > parent = olddiv.parentNode; > > olddiv.parentNode.replaceChild(newdiv, olddiv); > > } > > }, > > Isn''t most of this code redundant? You only need to use innerHTML on > the existing div, or create a new div and replace the old one. Either > one achieves the same DOM structure in the end. You also never use > ''parent'' anywhere. > > Todd > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >_______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
Todd is exactly right. What''s also important to realize about this, is that when your DOM elements are destroyed by the update to innerHTML, any event handlers that were tied to them (onclick, etc..), are in danger of staying around in memory (especially if the handlers are closures which hold references to the DOM elements, called a circular reference). These memory leaks can be very detrimental to your application if they go unchecked. Think of the control you''re updating (the treeview) as a miniature page. Every time it''s refreshed (via innerHTML), you need to re-setup all of it''s client behaviors (which is what you''re seeing now). But you also should take care to clean up all of it''s resources before each update. You can do this by adding a dispose() method on your objects that detaches DOM event handlers, unregisters draggables and droppable... etc (basically any memory that the DOM elements which will be refreshed have a hold of needs to be released), and making sure dispose() gets called before the refresh happens. -----Original Message----- From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Todd Ross Sent: Thursday, February 23, 2006 5:49 AM To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: Re: [Rails-spinoffs] reloading fragments of pages On 2/23/06, Tarek Ziadé <ziade.tarek-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> When the dom is reloaded, the drag/drop features reloads Droppable.drops > elements.I think this statement is the heart of your problem. There''s nothing active about scriptaculous (where you''re getting the Draggables/Droppables from) that would check for a DOM "reload" (I''m not sure what that is? any change, perhaps?); I''m not even sure that kind of information is available to JavaScript. I don''t know much about scriptaculous, so don''t take this as the final answer, but the magic that makes Draggables/Droppables work are the events that are attached to each element that you make Draggable/Droppable. When you use .innerHTML on those elements'' parent, you''re effectively destroying the existing elements (and their event associations) and creating what might look like identical elements, but they''re not; they don''t have the events unless you programatically re-initialize the Draggables/Droppables.> refreshPortletCompleted: function(originalRequest) { > // getting new positions from the server > result = originalRequest.responseText; > > if (result!='''') { > $(this.last_portlet_id).innerHTML = result; > var newdiv = document.createElement("div"); > newdiv.innerHTML = result; > newdiv.id = this.last_portlet_id; > olddiv = $(this.last_portlet_id); > parent = olddiv.parentNode; > olddiv.parentNode.replaceChild(newdiv, olddiv); > } > },Isn''t most of this code redundant? You only need to use innerHTML on the existing div, or create a new div and replace the old one. Either one achieves the same DOM structure in the end. You also never use ''parent'' anywhere. Todd _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs The information transmitted in this electronic mail is intended only for the person or entity to which it is addressed and may contain confidential, proprietary, and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from all computers.
Ryan, Not related to this post, but you bring up a good point here. The dispose() method that you are talking about, is this something available in prototype or do we need to write it? Is it similar to unloadCache()? Doesn''t prototype do the cleanups on every subsequent load? Please let me know. Thank you, Mandy.
On 2/23/06, Todd Ross <rails-spinoffs-25kFIyuv2iRiLUuM0BA3LQ@public.gmane.org> wrote:> > On 2/23/06, Tarek Ziadé <ziade.tarek-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > When the dom is reloaded, the drag/drop features reloads > Droppable.drops > > elements. > > I think this statement is the heart of your problem. There''s nothing > active about scriptaculous (where you''re getting the > Draggables/Droppables from) that would check for a DOM "reload" (I''m > not sure what that is? any change, perhaps?); I''m not even sure that > kind of information is available to JavaScript. > > I don''t know much about scriptaculous, so don''t take this as the final > answer, but the magic that makes Draggables/Droppables work are the > events that are attached to each element that you make > Draggable/Droppable. When you use .innerHTML on those elements'' > parent, you''re effectively destroying the existing elements (and their > event associations) and creating what might look like identical > elements, but they''re not; they don''t have the events unless you > programatically re-initialize the Draggables/Droppables.yes that''s what i am doind indeed, i should''ve been clearer: after the fragment is reloaded, i relaunch the initialisation of drag/drop stuff> refreshPortletCompleted: function(originalRequest) { > > // getting new positions from the server > > result = originalRequest.responseText; > > > > if (result!='''') { > > $(this.last_portlet_id).innerHTML = result; > > var newdiv = document.createElement("div"); > > newdiv.innerHTML = result; > > newdiv.id = this.last_portlet_id; > > olddiv = $(this.last_portlet_id); > > parent = olddiv.parentNode; > > olddiv.parentNode.replaceChild(newdiv, olddiv); > > } > > }, > > Isn''t most of this code redundant? You only need to use innerHTML on > the existing div, or create a new div and replace the old one. Either > one achieves the same DOM structure in the end.this is part of my problem: if i do a direct innerHTML of the code, the javascript that''s inside of this fragment is not "effective" creating a new node solves this issue. You also never use> ''parent'' anywhere.oups right thx Todd> _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >-- Tarek Ziadé | Association AfPy | www.afpy.org Site personnel | http://programmation-python.org _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
No it''s something you would have to write. Protoype''s unloadCache() happens on page unload... we''re talking here about a single control being updated (not the whole page). So in a long-running AJAX application, the page itself may never get refreshed, there prototype would never call unloadCache(). This cleanup stuff really needs to be at an atomic per control level to support designing a scalable AJAX application. I''ve even gone as far as to create a garbage collector to handle this cleanup on a background process. -----Original Message----- From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Maninder, Singh Sent: Thursday, February 23, 2006 9:25 AM To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: RE: [Rails-spinoffs] reloading fragments of pages Ryan, Not related to this post, but you bring up a good point here. The dispose() method that you are talking about, is this something available in prototype or do we need to write it? Is it similar to unloadCache()? Doesn''t prototype do the cleanups on every subsequent load? Please let me know. Thank you, Mandy. _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs The information transmitted in this electronic mail is intended only for the person or entity to which it is addressed and may contain confidential, proprietary, and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from all computers.
On 2/23/06, Nicolas <scalpmail-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > You may try to use Ajax.Updater with the evalScripts option enabled.thanks i am going to try that In the HTML code sent by the server, you''ll have to include <script> tag> with make your new div dropable. > You can also try something like Behaviour, and reapply rules once updated. > > > Regards, > Nicolas > > > On 2/23/06, Todd Ross <rails-spinoffs-25kFIyuv2iRiLUuM0BA3LQ@public.gmane.org> wrote: > > > > On 2/23/06, Tarek Ziadé <ziade.tarek-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > wrote: > > > When the dom is reloaded, the drag/drop features reloads > > Droppable.drops > > > elements. > > > > I think this statement is the heart of your problem. There''s nothing > > active about scriptaculous (where you''re getting the > > Draggables/Droppables from) that would check for a DOM "reload" (I''m > > not sure what that is? any change, perhaps?); I''m not even sure that > > kind of information is available to JavaScript. > > > > I don''t know much about scriptaculous, so don''t take this as the final > > answer, but the magic that makes Draggables/Droppables work are the > > events that are attached to each element that you make > > Draggable/Droppable. When you use .innerHTML on those elements'' > > parent, you''re effectively destroying the existing elements (and their > > event associations) and creating what might look like identical > > elements, but they''re not; they don''t have the events unless you > > programatically re-initialize the Draggables/Droppables. > > > > > refreshPortletCompleted: function(originalRequest) { > > > // getting new positions from the server > > > result = originalRequest.responseText; > > > > > > if (result!='''') { > > > $(this.last_portlet_id).innerHTML = result; > > > var newdiv = document.createElement ("div"); > > > newdiv.innerHTML = result; > > > newdiv.id = this.last_portlet_id; > > > olddiv = $(this.last_portlet_id); > > > parent = olddiv.parentNode; > > > olddiv.parentNode.replaceChild (newdiv, olddiv); > > > } > > > }, > > > > Isn''t most of this code redundant? You only need to use innerHTML on > > the existing div, or create a new div and replace the old one. Either > > one achieves the same DOM structure in the end. You also never use > > ''parent'' anywhere. > > > > Todd > > _______________________________________________ > > Rails-spinoffs mailing list > > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs > > > > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs > > >-- Tarek Ziadé | Association AfPy | www.afpy.org Site personnel | http://programmation-python.org _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
Thanks once again Ryan. Are you planning to share your code? :)
On 2/23/06, Ryan Gahl <Ryan.Gahl-nlycWCgr5/vuufBYgWm87A@public.gmane.org> wrote:> > Todd is exactly right. What''s also important to realize about this, is > that when your DOM elements are destroyed by the update to innerHTML, any > event handlers that were tied to them (onclick, etc..), are in danger of > staying around in memory (especially if the handlers are closures which hold > references to the DOM elements, called a circular reference). These memory > leaks can be very detrimental to your application if they go unchecked. > > Think of the control you''re updating (the treeview) as a miniature page. > Every time it''s refreshed (via innerHTML), you need to re-setup all of it''s > client behaviors (which is what you''re seeing now). But you also should take > care to clean up all of it''s resources before each update. You can do this > by adding a dispose() method on your objects that detaches DOM event > handlers, unregisters draggables and droppable... etc (basically any memory > that the DOM elements which will be refreshed have a hold of needs to be > released), and making sure dispose() gets called before the refresh happens.yes, i had this problem earlier; i have set a hookEvents/unHookEvents that is is charge of cleaning up things when the fragment is reloaded, but the dispose() thing is better thx, i''ll do that Tarek _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
Perhaps. Very busy right now. :-) Time will tell. -----Original Message----- From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Maninder, Singh Sent: Thursday, February 23, 2006 9:32 AM To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: RE: [Rails-spinoffs] reloading fragments of pages Thanks once again Ryan. Are you planning to share your code? :) _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs The information transmitted in this electronic mail is intended only for the person or entity to which it is addressed and may contain confidential, proprietary, and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from all computers.
i would like to detect classnames of input_(ANYTHING) is this possible with getElementsByClassName? also, is tthere a way to get elements by attribute? or would that be too heavy on the load time?
Louis Walch wrote:> i would like to detect classnames of input_(ANYTHING) is this possible > with getElementsByClassName?Looking at the source code you could do getELementsByClassName("input_.+");, although it''s undocumented behaviour so it might mysteriously break after a prototype upgrade one day. I know the current method (of using a regexp) is one of the slowest ways of doing it.> > also, is tthere a way to get elements by attribute? or would that be too > heavy on the load time?That shouldn''t be too intensive. See prototype.js''s defnition for getElementsByClassName and hack your own. What attribute would this be useful for? Getting all text inputs? I would just getElementsByTagName and do a quick loop. -Rob> _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
thanks rob, i will give input_.+ a shot. i use a custom attrib named fldtype for some input items and am hoping to assign different actions to each input based on that.> > > Louis Walch wrote: >> i would like to detect classnames of input_(ANYTHING) is this possible >> with getElementsByClassName? > > Looking at the source code you could do > getELementsByClassName("input_.+");, although it''s undocumented > behaviour so it might mysteriously break after a prototype upgrade one > day. I know the current method (of using a regexp) is one of the slowest > ways of doing it. > >> >> also, is tthere a way to get elements by attribute? or would that be too >> heavy on the load time? > > That shouldn''t be too intensive. See prototype.js''s defnition for > getElementsByClassName and hack your own. What attribute would this be > useful for? Getting all text inputs? I would just getElementsByTagName > and do a quick loop. > > -Rob > >> _______________________________________________ >> Rails-spinoffs mailing list >> Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >
Louis, In this senario, I usually add a class to the set of elements I'm interested in getting back to later on by doing a Element.addClassName() and then doing a getElementsByClassName() later on. You can remove the 'dummy' class later if you need to: Element.removeClassName() Hope this helps. Regards, Cam On 2/23/06, Louis Walch <dev@louiswalch.com> wrote:> thanks rob, i will give input_.+ a shot. > > i use a custom attrib named fldtype for some input items and am hoping to > assign different actions to each input based on that. > > > > > > > > > > Louis Walch wrote: > >> i would like to detect classnames of input_(ANYTHING) is this possible > >> with getElementsByClassName? > > > > Looking at the source code you could do > > getELementsByClassName("input_.+");, although it's undocumented > > behaviour so it might mysteriously break after a prototype upgrade one > > day. I know the current method (of using a regexp) is one of the slowest > > ways of doing it. > > > >> > >> also, is tthere a way to get elements by attribute? or would that be too > >> heavy on the load time? > > > > That shouldn't be too intensive. See prototype.js's defnition for > > getElementsByClassName and hack your own. What attribute would this be > > useful for? Getting all text inputs? I would just getElementsByTagName > > and do a quick loop. > > > > -Rob > > > >> _______________________________________________ > >> Rails-spinoffs mailing list > >> Rails-spinoffs@lists.rubyonrails.org > >> http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs > > _______________________________________________ > > Rails-spinoffs mailing list > > Rails-spinoffs@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs > > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >-- Cam McVey cam.mcvey@gmail.com _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
i made a function which was a near duplicate of getElementsByClassName and saved it as getInputsByAttribute and saved it in an external js file. but now i am getting "getInputsByAttribute can not be found" is there something i need to do to make it part of prototype?> > > Louis Walch wrote: >> i would like to detect classnames of input_(ANYTHING) is this possible >> with getElementsByClassName? > > Looking at the source code you could do > getELementsByClassName("input_.+");, although it''s undocumented > behaviour so it might mysteriously break after a prototype upgrade one > day. I know the current method (of using a regexp) is one of the slowest > ways of doing it. > >> >> also, is tthere a way to get elements by attribute? or would that be too >> heavy on the load time? > > That shouldn''t be too intensive. See prototype.js''s defnition for > getElementsByClassName and hack your own. What attribute would this be > useful for? Getting all text inputs? I would just getElementsByTagName > and do a quick loop. > > -Rob > >> _______________________________________________ >> Rails-spinoffs mailing list >> Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >
On 2/23/06, Louis Walch <dev-bTJQVtzvk6sqDJ6do+/SaQ@public.gmane.org> wrote:> i made a function which was a near duplicate of getElementsByClassName and > saved it as getInputsByAttribute and saved it in an external js file. > > but now i am getting "getInputsByAttribute can not be found" is there > something i need to do to make it part of prototype?1) Are you including your /separate/ JavaScript file into the page that you''re trying to use it from? 2) What element (or object) are you attempting to call getInputsByAttribute on? 3) How did you declare the function (or method)? Show us the code. A live site is generally preferrable. Todd
the file is being included, it is in the top of my common.js i am getting the error before it does anything. could it be that my common.js is not written in the OO style of js? here is the code; document.getInputsByAttribute = function(attrib,val){ //Add-on to Prototype var children = document.getElementsByTagName(''INPUT''); var elements = new Array(); for (var i = 0; i < children.length; i++) { if (children[i].getAttribute(attrib) == val){ elements.push(children[i]); } } return elements; }> On 2/23/06, Louis Walch <dev-bTJQVtzvk6sqDJ6do+/SaQ@public.gmane.org> wrote: >> i made a function which was a near duplicate of getElementsByClassName >> and >> saved it as getInputsByAttribute and saved it in an external js file. >> >> but now i am getting "getInputsByAttribute can not be found" is there >> something i need to do to make it part of prototype? > > 1) Are you including your /separate/ JavaScript file into the page > that you''re trying to use it from? > > 2) What element (or object) are you attempting to call > getInputsByAttribute on? > > 3) How did you declare the function (or method)? > > Show us the code. A live site is generally preferrable. > > Todd > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >
On 2/23/06, Louis Walch <dev-bTJQVtzvk6sqDJ6do+/SaQ@public.gmane.org> wrote:> the file is being included, it is in the top of my common.js > > i am getting the error before it does anything. could it be that my > common.js is not written in the OO style of js? > > here is the code;And ... how are you calling it? Todd
whoops, sorry <script language="javascript"> function displayPreviewIcon(){ inputs = getInputsByAttribute(''fldtype'',''filelocation''); for(i=0; i < inputs.length; i++){ //Testing inputs[i].style.backgroundColor = ''#ff00ff''; } } </script> which is called onLoad> On 2/23/06, Louis Walch <dev-bTJQVtzvk6sqDJ6do+/SaQ@public.gmane.org> wrote: >> the file is being included, it is in the top of my common.js >> >> i am getting the error before it does anything. could it be that my >> common.js is not written in the OO style of js? >> >> here is the code; > > And ... how are you calling it? > > Todd > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >
On 2/23/06, Louis Walch <dev-bTJQVtzvk6sqDJ6do+/SaQ@public.gmane.org> wrote:> whoops, sorry > > <script language="javascript"> > function displayPreviewIcon(){ > inputs = getInputsByAttribute(''fldtype'',''filelocation''); > for(i=0; i < inputs.length; i++){ > //Testing > inputs[i].style.backgroundColor = ''#ff00ff''; > } > } > </script> > > which is called onLoadWhen you call a function, that function is executed (by default) in the global context. In client-side development, the global context is the ''window'' object, not the ''document'' object. Either redefine your function as window.getInputsByAttribute (or, don''t use an object qualifier at all; it''ll default to ''window'') or call it as document.getInputsByAttribute, which is where you''re defining it. When you access ''document'', it''s really giving you ''window.document'', so your function is really ''window.document.getInputsByAttribute''. There''s an extra layer you''re not accounting for. Todd
duh, ok. sorry and thanks for the help!> On 2/23/06, Louis Walch <dev-bTJQVtzvk6sqDJ6do+/SaQ@public.gmane.org> wrote: >> whoops, sorry >> >> <script language="javascript"> >> function displayPreviewIcon(){ >> inputs = getInputsByAttribute(''fldtype'',''filelocation''); >> for(i=0; i < inputs.length; i++){ >> //Testing >> inputs[i].style.backgroundColor = ''#ff00ff''; >> } >> } >> </script> >> >> which is called onLoad > > When you call a function, that function is executed (by default) in > the global context. In client-side development, the global context is > the ''window'' object, not the ''document'' object. Either redefine your > function as window.getInputsByAttribute (or, don''t use an object > qualifier at all; it''ll default to ''window'') or call it as > document.getInputsByAttribute, which is where you''re defining it. > > When you access ''document'', it''s really giving you ''window.document'', > so your function is really ''window.document.getInputsByAttribute''. > There''s an extra layer you''re not accounting for. > > Todd > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >
i think it would be a good idea to map a shortcut to getElementsByClassName like the much loved $(). i think $c() seems applicable.
You can use the new $$ with ''.'' example $$(''.className'') returns an array of all elements with the class name ''className'' On 2/23/06, Louis Walch <dev-bTJQVtzvk6sqDJ6do+/SaQ@public.gmane.org> wrote:> > i think it would be a good idea to map a shortcut to > getElementsByClassName like the much loved $(). i think $c() seems > applicable. > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >-- Yehuda Katz Web Developer (ph) 718.877.1325 (fax) 718.686.4288 _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
Awesome, I guess I missed that one. Thanks. _____ From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Yehuda Katz Sent: Thursday, February 23, 2006 8:36 PM To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: Re: [Rails-spinoffs] suggestion $c() You can use the new $$ with ''.'' example $$(''.className'') returns an array of all elements with the class name ''className'' On 2/23/06, Louis Walch < dev-bTJQVtzvk6sqDJ6do+/SaQ@public.gmane.org <mailto:dev-bTJQVtzvk6sqDJ6do+/SaQ@public.gmane.org> > wrote: i think it would be a good idea to map a shortcut to getElementsByClassName like the much loved $(). i think $c() seems applicable. _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs -- Yehuda Katz Web Developer (ph) 718.877.1325 (fax) 718.686.4288 _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
It only works in the svn version of Prototype. The current stable version does not have it. On 2/23/06, louis d walch <dev-bTJQVtzvk6sqDJ6do+/SaQ@public.gmane.org> wrote:> > Awesome, I guess I missed that one. Thanks. > > > > > ------------------------------ > > *From:* rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto: > rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] *On Behalf Of *Yehuda Katz > *Sent:* Thursday, February 23, 2006 8:36 PM > *To:* rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > *Subject:* Re: [Rails-spinoffs] suggestion $c() > > > > You can use the new $$ with ''.'' > > example $$(''.className'') returns an array of all elements with the class > name ''className'' > > On 2/23/06, *Louis Walch* < dev-bTJQVtzvk6sqDJ6do+/SaQ@public.gmane.org> wrote: > > i think it would be a good idea to map a shortcut to > getElementsByClassName like the much loved $(). i think $c() seems > applicable. > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs > > > > > -- > Yehuda Katz > Web Developer > (ph) 718.877.1325 > (fax) 718.686.4288 > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs > > >-- Yehuda Katz Web Developer (ph) 718.877.1325 (fax) 718.686.4288 _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs