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=ZEND002498&r=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 -~----------~----~----~----~------~----~------~--~---