[Prototype-core] Re: $ function
I agree with jdalton - performance hit. I agree also that you shouldn't use the same values for name's and id's. $() is made for one purpose - to find elements with given id. It should be VERY fast in every case as it's a base function of Prototype. IMO, if found' element's id isn't the same as given, maybe function should even return null: [...] if (typeof element == 'string') { var id=element; element = document.getElementById(element); // not found if (element === null || !element.id || element.id!=id) { return null; } } return Element.extend(element); [...] On Jun 17, 11:36 am, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Wait for your solution, however this performance hit only occur in the ie and opera and you select the input without an id attribute, maybe 1%'s probability. Will $$(*).detect take a very long time? long than 2 seconds? Is that posibble? Thanks --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype: Core group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~--~~~~--~~--~--~---
[Prototype-core] Re: $ function
element = $$('*[id=' + id + ']').first(); should be the same with my element=$$(*).detect(function(node){return node.id==id}) is there some performance difference between these two code? Thanks On Jun 17, 9:14 pm, Adam McCrea [EMAIL PROTECTED] wrote: While I agree that it is bad practice to use names and id's which conflict, unfortunately we're not always scripting markup that we have control over. I do think this should be handled in prototype, and the ticket is here: http://dev.rubyonrails.org/ticket/6328 I recently reopened this ticket since it had been closed as a browser bug. Prototype smooths over so many browser inconsistencies that I don't quite understand that rationale. Hopefully it will be reconsidered since I added a patch with a test. The performance hit should only occur in an edge case in IE and Opera, so I don't see that as an issue. Even then, dollar-dollar is pretty fast these days, so I doubt it would be noticeable. If you have some suggestions regarding the patch, please add your comments to the ticket. - Adam On 6/17/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: I do not think so, what about this case: script src=prototype.js/script input type=text value=ie bug name=test / input type=text value=this value should be returned id=test / script alert($(test).value) /script If use your $ in ie and opera it will return null, but it should return the element which has the id test element, so I use $$ and detect the first matched element. My purpose is let the $ function has the same result on all the browsers. No matter ie opera or firefox or safari On Jun 17, 8:00 pm, DK [EMAIL PROTECTED] wrote: I agree with jdalton - performance hit. I agree also that you shouldn't use the same values for name's and id's. $() is made for one purpose - to find elements with given id. It should be VERY fast in every case as it's a base function of Prototype. IMO, if found' element's id isn't the same as given, maybe function should even return null: [...] if (typeof element == 'string') { var id=element; element = document.getElementById(element); // not found if (element === null || !element.id || element.id!=id) { return null; } } return Element.extend(element); [...] On Jun 17, 11:36 am, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Wait for your solution, however this performance hit only occur in the ie and opera and you select the input without an id attribute, maybe 1%'s probability. Will $$(*).detect take a very long time? long than 2 seconds? Is that posibble? Thanks- Hide quoted text - - Show quoted text -- Hide quoted text - - Show quoted text - --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype: Core group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~--~~~~--~~--~--~---
[Prototype-core] Re: $ function
I support the reopening of this ticket. It is truly an edge case which, IMO, should be handled. The proposed solution is quite nice, also. The only solution that could be faster than this is to temporary delete the name of the found element and repeat the $() call, after which the name would be restored. Unfortunately it isn't possible. On 6/17/07, Adam McCrea [EMAIL PROTECTED] wrote: While I agree that it is bad practice to use names and id's which conflict, unfortunately we're not always scripting markup that we have control over. I do think this should be handled in prototype, and the ticket is here: http://dev.rubyonrails.org/ticket/6328 I recently reopened this ticket since it had been closed as a browser bug. Prototype smooths over so many browser inconsistencies that I don't quite understand that rationale. Hopefully it will be reconsidered since I added a patch with a test. The performance hit should only occur in an edge case in IE and Opera, so I don't see that as an issue. Even then, dollar-dollar is pretty fast these days, so I doubt it would be noticeable. If you have some suggestions regarding the patch, please add your comments to the ticket. - Adam On 6/17/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: I do not think so, what about this case: script src=prototype.js/script input type=text value=ie bug name=test / input type=text value=this value should be returned id=test / script alert($(test).value) /script If use your $ in ie and opera it will return null, but it should return the element which has the id test element, so I use $$ and detect the first matched element. My purpose is let the $ function has the same result on all the browsers. No matter ie opera or firefox or safari On Jun 17, 8:00 pm, DK [EMAIL PROTECTED] wrote: I agree with jdalton - performance hit. I agree also that you shouldn't use the same values for name's and id's. $() is made for one purpose - to find elements with given id. It should be VERY fast in every case as it's a base function of Prototype. IMO, if found' element's id isn't the same as given, maybe function should even return null: [...] if (typeof element == 'string') { var id=element; element = document.getElementById(element); // not found if (element === null || !element.id || element.id!=id) { return null; } } return Element.extend(element); [...] On Jun 17, 11:36 am, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Wait for your solution, however this performance hit only occur in the ie and opera and you select the input without an id attribute, maybe 1%'s probability. Will $$(*).detect take a very long time? long than 2 seconds? Is that posibble? Thanks- Hide quoted text - - Show quoted text - --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype: Core group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~--~~~~--~~--~--~---
[Prototype-core] Re: $ function
On 6/17/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: is there some performance difference between these two code? Thanks Using the CSS selector instead of Enumerable enables the use of XPath. But since IE doesn't support XPath and the hack above is for IE and Opera, I'd dare to say that there is no much difference in execution time. One more thing: $$('*[id=' + id + ']') Am I right when saying that this will fail if the ID was dynamically set (in other words, it was not an attribute in HTML source)? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype: Core group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~--~~~~--~~--~--~---
[Prototype-core] Re: $ function
What about this code: if(!element.id || element.id!=id) { var tmp=[]; var t=document.getElementById(id); while(t!=null t.id!=id) { tmp.push([t,t.name]); t.name+=_tmp_; t=document.getElementById(id); } element=t; tmp.each(function(node){ node[0].name=node[1]; }); } However the ie protect its input element and do not let setAttribute change its name attribute, only way to change it is to change outerHTML which is very ugly, so I believe $$(*).detect is the best way. On Jun 17, 9:34 pm, Mislav Marohnić [EMAIL PROTECTED] wrote: On 6/17/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: is there some performance difference between these two code? Thanks Using the CSS selector instead of Enumerable enables the use of XPath. But since IE doesn't support XPath and the hack above is for IE and Opera, I'd dare to say that there is no much difference in execution time. One more thing: $$('*[id=' + id + ']') Am I right when saying that this will fail if the ID was dynamically set (in other words, it was not an attribute in HTML source)? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype: Core group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~--~~~~--~~--~--~---
[Prototype-core] Re: $ function
I rewrite it like this, I know this is very ugly someone can improve it? if(!element.id || element.id!=id) { var tmp=[];var y=100; var t=document.getElementById(id); while(t!=null t.id!=id) { var e=t.outerHTML; y++; t.outerHTML=hr id='+y+'; tmp.push([document.getElementById(y),e]); t=document.getElementById(id); } element=t; tmp.each(function(node){ node[0].outerHTML=node[1]; }); } However, it works, with the good performance which I believe. Thanks for reply On Jun 17, 11:11 pm, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: What about this code: if(!element.id || element.id!=id) { var tmp=[]; var t=document.getElementById(id); while(t!=null t.id!=id) { tmp.push([t,t.name]); t.name+=_tmp_; t=document.getElementById(id); } element=t; tmp.each(function(node){ node[0].name=node[1]; }); } However the ie protect its input element and do not let setAttribute change its name attribute, only way to change it is to change outerHTML which is very ugly, so I believe $$(*).detect is the best way. On Jun 17, 9:34 pm, Mislav Marohnić [EMAIL PROTECTED] wrote: On 6/17/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: is there some performance difference between these two code? Thanks Using the CSS selector instead of Enumerable enables the use of XPath. But since IE doesn't support XPath and the hack above is for IE and Opera, I'd dare to say that there is no much difference in execution time. One more thing: $$('*[id=' + id + ']') Am I right when saying that this will fail if the ID was dynamically set (in other words, it was not an attribute in HTML source)?- Hide quoted text - - Show quoted text - --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype: Core group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~--~~~~--~~--~--~---
[Prototype-core] Re: $ function
On Jun 17, 8:34 am, Mislav Marohnić [EMAIL PROTECTED] wrote: Am I right when saying that this will fail if the ID was dynamically set (in other words, it was not an attribute in HTML source)? Adam's test is correct -- even dynamically-set ID attributes will still be picked up by readAttribute in IE. As for the difference between $('*').detect and $('*[id=foo]'): the second is much faster in IE. The first must past each element on the page through Element.extend. The second will extend only the matched element. I suggest using Element.down, since it always returns one node: return $(document.body).down('*[id=foo]'); Cheers, Andrew --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype: Core group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~--~~~~--~~--~--~---
[Prototype-core] Re: $ function
On 6/17/07, Andrew Dupont [EMAIL PROTECTED] wrote: return $(document.body).down('*[id=foo]'); Nice. But there is an alternative that Tobie suggested: not fixing the issue. if (!element.id || element.id != id) throw Some helpful error message The error would help people learn about this issue and change their sources to avoid it. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype: Core group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~--~~~~--~~--~--~---
[Prototype-core] Re: Event.element() oddity
so far, the score at apple vs. microsoft is: 5 : one gadzillion ;) Am 17.06.2007 um 02:22 schrieb Gareth Evans: with about 5 security vunerabilities and all the fun that comes with safari ! Gareth On 6/17/07, DK [EMAIL PROTECTED] wrote: Hmm, maybe it's a little OT but I thought maybe sb doesn't already know, and would like to know :-) Apple Safari 3 public beta http://www.apple.com/safari/ Apple Safari will work on Windows too. On Jun 16, 3:57 pm, Thomas Fuchs [EMAIL PROTECTED] wrote: Note that IIRC the onload event for images is not supported (or rather, broken) on Safari 2. I've done an image loader thing the works cross-browser, but it's pretty much geared towards a specific use, so i really don't want to share this ATM (unless i clean it up first...). Best, Thomas Am 14.06.2007 um 18:17 schrieb jdalton: I created the ticket. It can be found here: http://dev.rubyonrails.org/ticket/8652 --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype: Core group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~--~~~~--~~--~--~---
[Prototype-core] Re: $ function
Oh, if only we all had the luxury to change our sources. ;-) On 6/17/07, Mislav Marohnić [EMAIL PROTECTED] wrote: On 6/17/07, Andrew Dupont [EMAIL PROTECTED] wrote: return $(document.body).down('*[id=foo]'); Nice. But there is an alternative that Tobie suggested: not fixing the issue. if (!element.id || element.id != id) throw Some helpful error message The error would help people learn about this issue and change their sources to avoid it. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype: Core group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~--~~~~--~~--~--~---
[Prototype-core] Re: $ function
I really like the throw error solution, that is great, I want to modify this function because I face even a getElementById bug in the firefox2.0,look at the code: script src=prototype.js/script input type=text value=this should be returned name=test id=www / input type=text value=this should not be returned ff2.0 bug not appeared in ff3.0 a5 name=test id=www / script alert($(www).value) window.setTimeout(function(){alert($(www).value)},1000) /script The code alert($(www).value) in the loading procession has changed the ff2.0's getElementById's behaveor, and with ff3.0 alpha5 this bug won't appeared, so maybe when you face the getELementById's misbehaving the best solution is to use $$(*[id=...]), or just throw a error message and change your html code. For my code: if(!element.id || element.id!=id) { var tmp=[];var y=100; var t=document.getElementById(id); while(t!=null t.id!=id) { var e=t.outerHTML; y++; t.outerHTML=hr id='+y+'; tmp.push([document.getElementById(y),e]); t=document.getElementById(id); } element=t; tmp.each(function(node){ node[0].outerHTML=node[1]; }); } I have some questions, 1.In ie the only way to change a input element's attribute name is to change outerHTML? 2.when I change the one reference element's outerHTML, that reference becomes invalid, I need to get it again, that is why I add var y and y+ +. 3.Is there a regular expression to get out the name attribute from these two strings 'input type=button value=aaa lll name=lll /' and'input type=button value=aaa lll name=lll l /' one name with one without, and the method to modify it. Thanks For the performacnce I think if you just use getELementById and change the bug input's name it would be the fastest, even fast than $$ (*[id='']). On Jun 18, 4:31 am, Adam McCrea [EMAIL PROTECTED] wrote: Oh, if only we all had the luxury to change our sources. ;-) On 6/17/07, Mislav Marohnić [EMAIL PROTECTED] wrote: On 6/17/07, Andrew Dupont [EMAIL PROTECTED] wrote: return $(document.body).down('*[id=foo]'); Nice. But there is an alternative that Tobie suggested: not fixing the issue. if (!element.id || element.id != id) throw Some helpful error message The error would help people learn about this issue and change their sources to avoid it.- Hide quoted text - - Show quoted text - --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype: Core group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~--~~~~--~~--~--~---