Thu, 04 Jun 2015 14:50:33 +0200
Genesis of lecture sources for Droidcon Berlin 2015 in Postbahnhof.
1 <!---
2 Licensed to the Apache Software Foundation (ASF) under one
3 or more contributor license agreements. See the NOTICE file
4 distributed with this work for additional information
5 regarding copyright ownership. The ASF licenses this file
6 to you under the Apache License, Version 2.0 (the
7 "License"); you may not use this file except in compliance
8 with the License. You may obtain a copy of the License at
10 http://www.apache.org/licenses/LICENSE-2.0
12 Unless required by applicable law or agreed to in writing,
13 software distributed under the License is distributed on an
14 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 KIND, either express or implied. See the License for the
16 specific language governing permissions and limitations
17 under the License.
18 -->
20 # org.apache.cordova.dialogs
22 這個外掛程式提供了對一些本機對話方塊的使用者介面元素的訪問。
24 ## 安裝
26 cordova plugin add org.apache.cordova.dialogs
29 ## 方法
31 * `navigator.notification.alert`
32 * `navigator.notification.confirm`
33 * `navigator.notification.prompt`
34 * `navigator.notification.beep`
36 ## navigator.notification.alert
38 顯示一個自訂的警報或對話方塊框。 大多數科爾多瓦實現使用本機對話方塊中的此項功能,但一些平臺使用瀏覽器的 `alert` 函數,這是通常不那麼可自訂。
40 navigator.notification.alert(message, alertCallback, [title], [buttonName])
43 * **消息**: 消息對話方塊。*(字串)*
45 * **alertCallback**: 當警報對話方塊的被解雇時要調用的回檔。*(函數)*
47 * **標題**: 標題對話方塊。*(字串)*(可選,預設值為`Alert`)
49 * **buttonName**: 按鈕名稱。*(字串)*(可選,預設值為`OK`)
51 ### 示例
53 function alertDismissed() {
54 // do something
55 }
57 navigator.notification.alert(
58 'You are the winner!', // message
59 alertDismissed, // callback
60 'Game Over', // title
61 'Done' // buttonName
62 );
65 ### 支援的平臺
67 * 亞馬遜火 OS
68 * Android 系統
69 * 黑莓 10
70 * 火狐瀏覽器作業系統
71 * iOS
72 * Tizen
73 * Windows Phone 7 和 8
74 * Windows 8
76 ### Windows Phone 7 和 8 怪癖
78 * 有沒有內置瀏覽器警報,但你可以綁定一個,如下所示調用 `alert()` 在全球範圍內:
80 window.alert = navigator.notification.alert;
83 * 兩個 `alert` 和 `confirm` 的非阻塞的調用,其中的結果才是可用的非同步。
85 ### 火狐瀏覽器作業系統怪癖:
87 這兩個本機阻止 `window.alert()` 和非阻塞 `navigator.notification.alert()` 可用。
89 ## navigator.notification.confirm
91 顯示一個可自訂的確認對話方塊。
93 navigator.notification.confirm(message, confirmCallback, [title], [buttonLabels])
96 * **消息**: 消息對話方塊。*(字串)*
98 * **confirmCallback**: 要用索引 (1、 2 或 3) 按下的按鈕,或者在沒有按下按鈕 (0) 駁回了對話方塊中時調用的回檔。*(函數)*
100 * **標題**: 標題對話方塊。*(字串)*(可選,預設值為`Confirm`)
102 * **buttonLabels**: 指定按鈕標籤的字串陣列。*(陣列)*(可選,預設值為 [ `OK,Cancel` ])
104 ### confirmCallback
106 `confirmCallback`當使用者按下確認對話方塊中的按鈕之一的時候執行。
108 回檔將參數 `buttonIndex` *(編號)*,它是按下的按鈕的索引。 請注意索引使用基於 1 的索引,所以值是 `1` , `2` , `3` ,等等。
110 ### 示例
112 function onConfirm(buttonIndex) {
113 alert('You selected button ' + buttonIndex);
114 }
116 navigator.notification.confirm(
117 'You are the winner!', // message
118 onConfirm, // callback to invoke with index of button pressed
119 'Game Over', // title
120 ['Restart','Exit'] // buttonLabels
121 );
124 ### 支援的平臺
126 * 亞馬遜火 OS
127 * Android 系統
128 * 黑莓 10
129 * 火狐瀏覽器作業系統
130 * iOS
131 * Tizen
132 * Windows Phone 7 和 8
133 * Windows 8
135 ### Windows Phone 7 和 8 怪癖
137 * 有沒有內置的瀏覽器功能的 `window.confirm` ,但你可以將它綁定通過分配:
139 window.confirm = navigator.notification.confirm;
142 * 調用到 `alert` 和 `confirm` 的非阻塞,所以結果就是只可用以非同步方式。
144 ### 火狐瀏覽器作業系統怪癖:
146 這兩個本機阻止 `window.confirm()` 和非阻塞 `navigator.notification.confirm()` 可用。
148 ## navigator.notification.prompt
150 顯示本機的對話方塊,更可自訂的瀏覽器比 `prompt` 函數。
152 navigator.notification.prompt(message, promptCallback, [title], [buttonLabels], [defaultText])
155 * **消息**: 消息對話方塊。*(字串)*
157 * **promptCallback**: 要用索引 (1、 2 或 3) 按下的按鈕,或者在沒有按下按鈕 (0) 駁回了對話方塊中時調用的回檔。*(函數)*
159 * **標題**: 對話方塊的標題*(字串)* (可選,預設值為`Prompt`)
161 * **buttonLabels**: 陣列,這些字串指定按鈕標籤*(陣列)* (可選,預設值為`["OK","Cancel"]`)
163 * **defaultText**: 預設文字方塊中輸入值 ( `String` ) (可選,預設值: 空字串)
165 ### promptCallback
167 `promptCallback`當使用者按下一個提示對話方塊中的按鈕時執行。`results`物件傳遞給回檔的包含以下屬性:
169 * **buttonIndex**: 按下的按鈕的索引。*(人數)*請注意索引使用基於 1 的索引,所以值是 `1` , `2` , `3` ,等等。
171 * **輸入 1**: 在提示對話方塊中輸入的文本。*(字串)*
173 ### 示例
175 function onPrompt(results) {
176 alert("You selected button number " + results.buttonIndex + " and entered " + results.input1);
177 }
179 navigator.notification.prompt(
180 'Please enter your name', // message
181 onPrompt, // callback to invoke
182 'Registration', // title
183 ['Ok','Exit'], // buttonLabels
184 'Jane Doe' // defaultText
185 );
188 ### 支援的平臺
190 * 亞馬遜火 OS
191 * Android 系統
192 * 火狐瀏覽器作業系統
193 * iOS
194 * Windows Phone 7 和 8
196 ### Android 的怪癖
198 * Android 支援最多的三個按鈕,並忽略任何更多。
200 * 關於 Android 3.0 及更高版本,使用全息主題的設備按相反的順序顯示按鈕。
202 ### 火狐瀏覽器作業系統怪癖:
204 這兩個本機阻止 `window.prompt()` 和非阻塞 `navigator.notification.prompt()` 可用。
206 ## navigator.notification.beep
208 該設備播放提示音聲音。
210 navigator.notification.beep(times);
213 * **時間**: 的次數重複發出蜂鳴音。*(人數)*
215 ### 示例
217 // Beep twice!
218 navigator.notification.beep(2);
221 ### 支援的平臺
223 * 亞馬遜火 OS
224 * Android 系統
225 * 黑莓 10
226 * iOS
227 * Tizen
228 * Windows Phone 7 和 8
229 * Windows 8
231 ### 亞馬遜火 OS 怪癖
233 * 亞馬遜火 OS 播放預設**設置/顯示 & 聲音**面板下指定的**通知聲音**。
235 ### Android 的怪癖
237 * Android 系統播放的預設**通知鈴聲****設置/聲音和顯示**面板下指定。
239 ### Windows Phone 7 和 8 怪癖
241 * 依賴泛型蜂鳴音檔從科爾多瓦分佈。
243 ### Tizen 怪癖
245 * Tizen 通過播放音訊檔通過媒體 API 實現會發出蜂鳴聲。
247 * 蜂鳴音檔必須很短,必須設在 `sounds` 子目錄中的應用程式的根目錄中,並且必須命名`beep.wav`.