[Proto-Scripty] Re: Odd behaviour with chained calls.
2009/2/16 kangax kan...@gmail.com: On Feb 16, 11:10 am, Richard Quadling rquadl...@googlemail.com wrote: Hi. I want to set an error message for 20 seconds ... $('sessionError').update(o_E.responseText).show().hide.delay(20); The message is displayed correctly. But not hidden again after 20 seconds or so. Instead, I'm getting an error ... element.style is undefined. If I ... $('sessionError').update('An error').show().hide(20); at the command prompt in FB, then no problems. It seems delay is not working as I would expect. If I ... $('sessionError').update('An error').show().hide.delay(20); at the command prompt I get a number which I assume is the id of the timer so I can cancel it. Example online (requires a javascript console). Go tohttp://www.prototypejs.organd enter the following code into your javascript console. $('header').update('Prototype is quite good!').show().hide.delay(2) You will see the timer ID (4 in my case) and then the error message (after a little while). $('header').update('Prototype is quite good!').show().hide.delay(2) 4 $(element).style is undefined [Break on this error] $(element).style.display = 'none'; prototype.js (line 1349) The problem is that `hide` is not being called in a context of an element (but rather in a context of what `delay` specifies, which is a `hide` function itself). You can work around it by binding `hide` to `el` - in other words, making sure `hide` is to be called in a context of `el`: var el = $('header'); el.update('Prototype is quite good!').show(); el.hide.bind(el).delay(2); Even better, you can take advantage of `delay` being able to `curry` arguments of a reciever function: var el = $('header'); el.update('Prototype is quite good!').show(); Element.hide.delay(2, el); You can of course shorten it up further to something like: Element.hide.delay(2, $('header').update('Prototype is quite good!').show()); but I wouldn't, as it becomes rather cryptic : ) -- kangax Ah. I keep thinking ... Element.hide(el); is the same as el.hide(); That's where I've gone wrong. I think. -- - Richard Quadling Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498r=213474731 Standing on the shoulders of some very clever giants! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Odd behaviour with chained calls.
Richard Quadling wrote: Hi. I want to set an error message for 20 seconds ... $('sessionError').update(o_E.responseText).show().hide.delay(20); The message is displayed correctly. But not hidden again after 20 seconds or so. It's because you lose the scope of the $('sessionError') Element when you get the hide-method. You're back in the calling scope, which doesn't seem to be an Element, so that's why there's no style-property. This works: $('sessionError').update(o_E.responseText).show() .hide.bind($('sessionError')).delay(20); But the chaining doesn't really make sense any more. I think it could best be solved like this: $('sessionError').update(o_E.responseText).show(); (function () { $('sessionError').hide (); }).delay (20: Have fun Daniel -- Daniel Rubin dru...@dimedis.de dimedis GmbH www.dimedis.de Dillenburger Strasse 83 0221/921260-44 (-59,Fax) 51105 Koeln Software Entwicklung HRB Köln 51787Geschäftsführer: Dipl.-Ing. W. Halling --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~--- begin:vcard fn:Daniel Rubin n:Rubin;Daniel org:dimedis GmbH;Software Entwicklung adr;quoted-printable:;;Dillenburger Strasse 83;K=C3=B6ln;;51105;Deutschland email;internet:dru...@dimedis.de tel;work:0221 / 921260-44 tel;fax:0221 / 921260-59 x-mozilla-html:FALSE url:http://www.dimedis.de/ version:2.1 end:vcard
[Proto-Scripty] Re: Odd behaviour with chained calls.
2009/2/16 Daniel Rubin dru...@dimedis.de: Richard Quadling wrote: Hi. I want to set an error message for 20 seconds ... $('sessionError').update(o_E.responseText).show().hide.delay(20); The message is displayed correctly. But not hidden again after 20 seconds or so. It's because you lose the scope of the $('sessionError') Element when you get the hide-method. You're back in the calling scope, which doesn't seem to be an Element, so that's why there's no style-property. This works: $('sessionError').update(o_E.responseText).show() .hide.bind($('sessionError')).delay(20); But the chaining doesn't really make sense any more. I think it could best be solved like this: $('sessionError').update(o_E.responseText).show(); (function () { $('sessionError').hide (); }).delay (20: Have fun Daniel -- Daniel Rubin dru...@dimedis.de dimedis GmbH www.dimedis.de Dillenburger Strasse 83 0221/921260-44 (-59,Fax) 51105 Koeln Software Entwicklung HRB Köln 51787Geschäftsführer: Dipl.-Ing. W. Halling I'm getting it. Slowly. Very very slowly. Thank you. -- - Richard Quadling Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498r=213474731 Standing on the shoulders of some very clever giants! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---
[Proto-Scripty] Re: Odd behaviour with chained calls.
On Feb 16, 11:10 am, Richard Quadling rquadl...@googlemail.com wrote: Hi. I want to set an error message for 20 seconds ... $('sessionError').update(o_E.responseText).show().hide.delay(20); The message is displayed correctly. But not hidden again after 20 seconds or so. Instead, I'm getting an error ... element.style is undefined. If I ... $('sessionError').update('An error').show().hide(20); at the command prompt in FB, then no problems. It seems delay is not working as I would expect. If I ... $('sessionError').update('An error').show().hide.delay(20); at the command prompt I get a number which I assume is the id of the timer so I can cancel it. Example online (requires a javascript console). Go tohttp://www.prototypejs.organd enter the following code into your javascript console. $('header').update('Prototype is quite good!').show().hide.delay(2) You will see the timer ID (4 in my case) and then the error message (after a little while). $('header').update('Prototype is quite good!').show().hide.delay(2) 4 $(element).style is undefined [Break on this error] $(element).style.display = 'none'; prototype.js (line 1349) The problem is that `hide` is not being called in a context of an element (but rather in a context of what `delay` specifies, which is a `hide` function itself). You can work around it by binding `hide` to `el` - in other words, making sure `hide` is to be called in a context of `el`: var el = $('header'); el.update('Prototype is quite good!').show(); el.hide.bind(el).delay(2); Even better, you can take advantage of `delay` being able to `curry` arguments of a reciever function: var el = $('header'); el.update('Prototype is quite good!').show(); Element.hide.delay(2, el); You can of course shorten it up further to something like: Element.hide.delay(2, $('header').update('Prototype is quite good!').show()); but I wouldn't, as it becomes rather cryptic : ) -- kangax --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Prototype script.aculo.us group. To post to this group, send email to prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~--~~~~--~~--~--~---