W3C home > Mailing lists > Public > whatwg@whatwg.org > February 2011

[whatwg] Optional non-blocking mode for simple dialogs (alert, confirm, prompt).

From: Glenn Maynard <glenn@zewt.org>
Date: Sun, 27 Feb 2011 05:19:30 -0500
Message-ID: <AANLkTimo7D4YsjqE16mA+VwQhMGha=am+h77Z_SmKM1U@mail.gmail.com>
On Sun, Feb 27, 2011 at 3:57 AM, Ben Rimmington <benrimmington at me.com>wrote:

> >> For user agents that don't support the updated API:
> >>
> >>> function promptWrapper(message, default, callback) {
> >>>     var result = window.prompt(message, default, callback);
> >>>     if (callback && (typeof callback === "function")) {
> >>>         if (result !== callback) {
> >>>             callback(result);
> >>>         }
> >>>         return callback;
> >>>     }
> >>>     return result;
> >>> }
> >
> > Of course, that would be a synchronous callback rather than an async
> one...
>
> On 27 Feb 2011, at 00:08, Adam Barth wrote:
> That's true, a compatibility layer such as promptWrapper() would need to
> use window.setTimeout() for an async callback. The example code was mainly
> intended to show how "feature detection" of the non-blocking mode could be
> implemented.
>

Feature detection needs to be possible without actually calling the
function--without actually opening a prompt.  For example, if you're to run
the above prompt from a timeout, you need to know that *before* you call
prompt(), since you don't want a timeout if the async API is supported.

The pattern in new APIs like IDB and FileAPI is to have separate sync and
async interfaces, not overloaded behavior, eg:

promptAsync(message, default, callback);

Better off just leaving this crusty old API in the legacy bin, though.

-- 
Glenn Maynard
Received on Sunday, 27 February 2011 02:19:30 UTC

This archive was generated by hypermail 2.4.0 : Wednesday, 22 January 2020 16:59:31 UTC