# Dialog プラグイン

テスト環境 ( バージョン番号 ) :[2.0.2](https://github.com/apache/cordova-plugin-dialogs/releases/tag/2.0.2)

このプラグインの詳細は、 [こちらの原文 ( GitHub )](https://github.com/apache/cordova-plugin-dialogs) をご確認ください。

このプラグインは、グローバルな `navigator.notification` オブジェクトを介して、いくつかのネイティブ ダイアログ UI エレメントへのアクセスを提供します。 このオブジェクトは、グローバルスコープ ( `navigator` ) に属していますが、使用できるのは、`deviceready` イベントの発火後になります。

```javascript
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
    console.log(navigator.notification);
}
```

## プラグイン ID

```javascript
cordova-plugin-dialogs
```

## プラグインの追加方法

このプラグインを使用する場合には、Monaca クラウド IDE の \[ Cordova プラグインの管理 ] 上で、`Notification` プラグインを[有効](/products_guide/monaca_ide/dependencies/cordova_plugin.md#cordova-puraguin-noinpto)にします。

## メソッド

* `navigator.notification.alert`
* `navigator.notification.confirm`
* `navigator.notification.prompt`
* `navigator.notification.beep`

## navigator.notification.alert

アラートまたはダイアログを、カスタマイズして表示します。多くの場合、Cordova では、ネイティブ側のダイアログを使用していますが、プラットフォームによっては、ブラウザー側の `alert` 関数を使用しており、 カスタマイズが制限されている場合があります。

```javascript
navigator.notification.alert(message, alertCallback, [title], [buttonName])
```

* **message**: ダイアログのメッセージ *(String)*
* **alertCallback**: アラートダイアログを閉じたときに呼ぶコールバッ&#x30AF;*(Function)*
* **title**: ダイアログのタイトル ( *String* 、任意、デフォルトでは`Alert` )
* **buttonName**: ボタンの名前 ( *String* 、任意、デフォルトでは `OK` )

### 例

```javascript
function alertDismissed() {
    // do something
}

navigator.notification.alert(
    'You are the winner!',  // message
    alertDismissed,         // callback
    'Game Over',            // title
    'Done'                  // buttonName
);
```

### 対象プラットフォーム

* Android
* iOS

## navigator.notification.confirm

確認用ダイアログを表示します ( カスタマイズ可 )。

```javascript
navigator.notification.confirm(message, confirmCallback, [title], [buttonLabels])
```

* **message**: ダイアログのメッセージ *(String)*
* **confirmCallback**: 押されたボタンのインデックス ( 1、2、3 )に応じて、または、ボタンを押さずにダイアログを閉じたときに ( 0)、呼ばれるコールバック *(Function)*
* **title**: ダイアログのタイトル ( *String* 、任意、デフォルトでは`Confirm` )
* **buttonLabels**: ボタンの名前の配列 ( *Array* 、任意、デフォルトでは\[`OK,Cancel`])

### confirmCallback

`confirmCallback` は、ユーザーが確認ダイアログボックスのいずれかのボタンを押すと実行されます。このコールバックは、引数として、`buttonIndex` ( 押されたボタンのインデックス、*Number* ) を取ります。インデックスは、1 から始まり、値は、`1`、`2`、`3`、・・・ となります ( 1 オリジンインデックス方式 )。

### 例

```javascript
function onConfirm(buttonIndex) {
    alert('You selected button ' + buttonIndex);
}

navigator.notification.confirm(
    'You are the winner!', // message
     onConfirm,            // callback to invoke with index of button pressed
    'Game Over',           // title
    ['Restart','Exit']     // buttonLabels
);
```

### 対象プラットフォーム

* Android
* iOS

### Android 特有の動作

* Android は、最大3つのボタンをサポートしていますが、それ以上は無視されます。

## navigator.notification.prompt

ネイティブのダイアログを表示します ( ブラウザー標準の `prompt` 関数よりも、カスタマイズが容易 )。

```javascript
navigator.notification.prompt(message, promptCallback, [title], [buttonLabels], [defaultText])
```

* **message**: ダイアログのメッセージ *(String)*
* **promptCallback**: 押されたボタンのインデックス ( 1、2、3 )に応じて、または、ボタンを押さずにダイアログを閉じたときに ( 0)、呼ばれるコールバック *(Function)*
* **title**: ダイアログのタイトル ( *String* 、任意、デフォルトでは`Prompt` )
* **buttonLabels**: ボタンの名前の配列 ( *Array* 、任意、デフォルトでは\[`OK,Cancel`] )
* **defaultText**: テキストボックスのデフォルトの入力値 (`String`、任意、デフォルトでは空の文字列 )

### promptCallback

prompt ダイアログ上に表示されたボタンを押したときに、`promptCallback` が実行されます。次のプロパティを格納した `results` オブジェクトが、このコールバックに渡されます。

* **buttonIndex**:

  押されるボタンのインデックスです。インデックスには、1オリジンインデックス方式

  を使用しており、値は、`1`、`2`、`3`、・・・　となります。 *(Number)*
* **input1**: prompt ダイアログに入力されたテキスト *(String)*

### 例

```javascript
function onPrompt(results) {
    alert("You selected button number " + results.buttonIndex + " and entered " + results.input1);
}

navigator.notification.prompt(
    'Please enter your name',  // message
    onPrompt,                  // callback to invoke
    'Registration',            // title
    ['Ok','Exit'],             // buttonLabels
    'Jane Doe'                 // defaultText
);
```

### 対象プラットフォーム

* Android
* iOS

### Android 特有の動作

* Android では、最大 3個のボタンを使用できます。それ以上のボタンは無視します。
* Android 3.0 以上の場合、Holoテーマを使用している端末では、ボタンの表示が逆順になります。

## navigator.notification.beep

ビープ ( beep ) 音を鳴らします。

```javascript
navigator.notification.beep(times);
```

* **times**: ビープ音のリピート回数 *(Number)*

### 例

```javascript
// Beep twice!
navigator.notification.beep(2);
```

### 対象プラットフォーム

* Android
* iOS

### Android 特有の動作

* Android では、デフォルトの **着信音** を鳴らします \[ **設定/音と通知 ( または、ディスプレイ )** 画面で設定 ]。

関連項目:

* [サードパーティー製プラグイン](/reference/third_party_phonegap.md)
* [基本プラグイン](/reference/core-cordova-plugins.md)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ja.docs.monaca.io/reference/core-cordova-plugins/cordova_10.0/dialogs.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
