Thomas 'PointedEars' Lahn <> writes:
> Lasse Reichstein Nielsen wrote:
> It would have been better (and more simple) to give the controls a name
> (instead of an ID) and to make them part of a form. Because that would
> have allowed the developer to use both backwards-compatible and standards
> compliant references to access the element objects that represent the
> controls in the DOM.
That would be a workaround. There is no form because there is no
relevant action attribute to give the form, i.e., the form isn't
really a form, it's just a programming hack to allow another way
to address elements.
> However, even if the markup would be kept as is, certainly it would have
> been better to test if gEBI returned a viable reference before using its
> return value in a property access. Such reference worms are the direct
> result of the ill-advised preconception that what works in one UA also
> must work in another.
In this case it's te result of deliberatly not writing for non-W3C-DOM
compliant browsers. Should fallback for such browsers be deemed
necessary, obviously it should be added.
> <URL:http://pointedears.de/scripts/test/whatami#inference>
No inference here, just assumptions (of requirements being satisfied).
>
>> setTimeout: The conversion is triggered by a "keypress" event.
>
> Yes, it is.
>
>> This is a cancellable event that happens before the default
>> behavior (e.g., inserting the pressed letter).
>
> So one should better had made use of the `keyup' event, instead of
> attempting to produce an unreliable delay through an equally unreliable
> proprietary host-defined feature.
I can see that the keyup event happens after the character is added to
the textarea in my browser. However, since we are mentioning standards,
there is no specification of key events in the DOM2 Events specification,
so that could be a conincidence.
Personally, I would prefer writing the entire text and the pressing a
key to convert it, but the OP asked for continuous conversion.
Another approach would be using setInterval to convert repeatedly with
a small interval. This would be just as non-standard, obviously.
>> The timeout waits for the default behavior to have happened,
>
> Not at all. Instead, because it is too small for the minimum time frame
> known to be assigned to the process from the scheduler, a one millisecond
> timeout will either not cause a delay at all, or delay for an undefined
> non-zero number of milliseconds, at least the size of the scheduled time
> frame, depending on the implementation and the OS.
I assume here that the script is being executed single-threaded, so at
least the timer event won't trigger until after the current event is
finished.
> In that time, if there was a timing issue (which I doubt), it may as
> well be that the default behavior did not happen due to some other
> factors we cannot know of.
It is true that if any other execution comes between the key event and
the timer event, the content of the textarea could have changed. I can
live with that. In fact, it would be desireable that the conversion
happens after any change to the input textarea.
Yet another approach is to have each keypress/keyup schedule a
conversion 500ms later, and having new key events in the meantime
cancel the timer and create a new. Especially if conversion is
time consuming.
The possibilities are endless, but there is no completely standard
compliant way of having continous updates when neither timers
nor key events are standardized.
/L
--
Lasse Reichstein Nielsen -
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'