JavaScript Documentation / ui

This object contains methods for interacting with the user.

ui.alert(message, [title], [button1], [button2], ..., [handler])

Displays an alert that can contain text and buttons.

Parameters

Example

ui.alert('Hello world');

ui.hudSuccess([message])

Displays a HUD with a success icon. The HUD will be dismissed automatically.

Parameters

Example

ui.hudSuccess('Done');

ui.hudError([message])

Displays a HUD with an error icon. The HUD will be dismissed automatically.

Parameters

Example

ui.hudError('Failed');

ui.hudProgress([message], [progress])

Displays a HUD with a progress indicator. The HUD will not be dismissed automatically, calls hudSuccess, hudError or hudDismiss to dismiss the HUD.

Parameters

Example

ui.hudProgress();
ui.hudProgress(null, 0.2);
ui.hudProgress(null, 0.5);
ui.hudProgress(null, 0.8);
ui.hudSuccess();

ui.hudDismiss()

Dismisses the current HUD.

ui.input([title], [text], [placeholder], [keyboardType], handler)

Shows a view with a single text field, used to ask for user input.

Parameters

Example

ui.input('Search', null, 'Enter search term', value => {
    if (value) {
        ui.alert(value);
    }
});

ui.list([title], [data], [multipleSelection], handler)

Shows a list of values that can be filtered by searching, used to ask for user selection.

Parameters

Example

ui.hudProgress('Searching');
http.get('https://itunes.apple.com/search', { term: 'jack johnson', limit: 25 }, (data, error) => {
    if (error) {
        ui.hudError();
    }
    else {
        ui.hudDismiss();
        const listData = data.results.map(item => item.trackName);
        ui.list('Search Result', listData, true, selectedValues => {
            if (!selectedValues) {
                return;
            }
            const text = selectedValues.join('\n');
            if (editor.isClosed()) {
                editor.newFile(text);
            }
            else {
                editor.replaceSelection(text);
            }
        });
    }
});