Touchgui/plugins/org.apache.cordova.dialogs/doc/index.md

Thu, 04 Jun 2015 14:50:33 +0200

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 04 Jun 2015 14:50:33 +0200
changeset 0
e8ccd40d0ef6
permissions
-rw-r--r--

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 This plugin provides access to some native dialog UI elements
    23 via a global `navigator.notification` object.
    25 Although the object is attached to the global scoped `navigator`, it is not available until after the `deviceready` event.
    27     document.addEventListener("deviceready", onDeviceReady, false);
    28     function onDeviceReady() {
    29         console.log(navigator.notification);
    30     }
    32 ## Installation
    34     cordova plugin add org.apache.cordova.dialogs
    36 ## Methods
    38 - `navigator.notification.alert`
    39 - `navigator.notification.confirm`
    40 - `navigator.notification.prompt`
    41 - `navigator.notification.beep`
    43 ## navigator.notification.alert
    45 Shows a custom alert or dialog box.  Most Cordova implementations use a native
    46 dialog box for this feature, but some platforms use the browser's `alert`
    47 function, which is typically less customizable.
    49     navigator.notification.alert(message, alertCallback, [title], [buttonName])
    51 - __message__: Dialog message. _(String)_
    53 - __alertCallback__: Callback to invoke when alert dialog is dismissed. _(Function)_
    55 - __title__: Dialog title. _(String)_ (Optional, defaults to `Alert`)
    57 - __buttonName__: Button name. _(String)_ (Optional, defaults to `OK`)
    60 ### Example
    62     function alertDismissed() {
    63         // do something
    64     }
    66     navigator.notification.alert(
    67         'You are the winner!',  // message
    68         alertDismissed,         // callback
    69         'Game Over',            // title
    70         'Done'                  // buttonName
    71     );
    73 ### Supported Platforms
    75 - Amazon Fire OS
    76 - Android
    77 - BlackBerry 10
    78 - Firefox OS
    79 - iOS
    80 - Tizen
    81 - Windows Phone 7 and 8
    82 - Windows 8
    83 - Windows
    85 ### Windows Phone 7 and 8 Quirks
    87 - There is no built-in browser alert, but you can bind one as follows to call `alert()` in the global scope:
    89         window.alert = navigator.notification.alert;
    91 - Both `alert` and `confirm` are non-blocking calls, results of which are only available asynchronously.
    93 ### Firefox OS Quirks:
    95 Both native-blocking `window.alert()` and non-blocking `navigator.notification.alert()` are available.
    97 ### BlackBerry 10 Quirks
    98 `navigator.notification.alert('text', callback, 'title', 'text')` callback parameter is passed the number 1.
   100 ## navigator.notification.confirm
   102 Displays a customizable confirmation dialog box.
   104     navigator.notification.confirm(message, confirmCallback, [title], [buttonLabels])
   106 - __message__: Dialog message. _(String)_
   108 - __confirmCallback__: Callback to invoke with index of button pressed (1, 2, or 3) or when the dialog is dismissed without a button press (0). _(Function)_
   110 - __title__: Dialog title. _(String)_ (Optional, defaults to `Confirm`)
   112 - __buttonLabels__: Array of strings specifying button labels. _(Array)_  (Optional, defaults to [`OK,Cancel`])
   115 ### confirmCallback
   117 The `confirmCallback` executes when the user presses one of the
   118 buttons in the confirmation dialog box.
   120 The callback takes the argument `buttonIndex` _(Number)_, which is the
   121 index of the pressed button. Note that the index uses one-based
   122 indexing, so the value is `1`, `2`, `3`, etc.
   124 ### Example
   126     function onConfirm(buttonIndex) {
   127         alert('You selected button ' + buttonIndex);
   128     }
   130     navigator.notification.confirm(
   131         'You are the winner!', // message
   132          onConfirm,            // callback to invoke with index of button pressed
   133         'Game Over',           // title
   134         ['Restart','Exit']     // buttonLabels
   135     );
   137 ### Supported Platforms
   139 - Amazon Fire OS
   140 - Android
   141 - BlackBerry 10
   142 - Firefox OS
   143 - iOS
   144 - Tizen
   145 - Windows Phone 7 and 8
   146 - Windows 8
   147 - Windows
   149 ### Windows Phone 7 and 8 Quirks
   151 - There is no built-in browser function for `window.confirm`, but you can bind it by assigning:
   153         window.confirm = navigator.notification.confirm;
   155 - Calls to `alert` and `confirm` are non-blocking, so the result is only available asynchronously.
   157 ### Windows Quirks
   159 - On Windows8/8.1 it is not possible to add more than three buttons to MessageDialog instance.
   161 - On Windows Phone 8.1 it's not possible to show dialog with more than two buttons.
   163 ### Firefox OS Quirks:
   165 Both native-blocking `window.confirm()` and non-blocking `navigator.notification.confirm()` are available.
   167 ## navigator.notification.prompt
   169 Displays a native dialog box that is more customizable than the browser's `prompt` function.
   171     navigator.notification.prompt(message, promptCallback, [title], [buttonLabels], [defaultText])
   173 - __message__: Dialog message. _(String)_
   175 - __promptCallback__: Callback to invoke with index of button pressed (1, 2, or 3) or when the dialog is dismissed without a button press (0). _(Function)_
   177 - __title__: Dialog title _(String)_ (Optional, defaults to `Prompt`)
   179 - __buttonLabels__: Array of strings specifying button labels _(Array)_ (Optional, defaults to `["OK","Cancel"]`)
   181 - __defaultText__: Default textbox input value (`String`) (Optional, Default: empty string)
   183 ### promptCallback
   185 The `promptCallback` executes when the user presses one of the buttons
   186 in the prompt dialog box. The `results` object passed to the callback
   187 contains the following properties:
   189 - __buttonIndex__: The index of the pressed button. _(Number)_ Note that the index uses one-based indexing, so the value is `1`, `2`, `3`, etc.
   193 - __input1__: The text entered in the prompt dialog box. _(String)_
   195 ### Example
   197     function onPrompt(results) {
   198         alert("You selected button number " + results.buttonIndex + " and entered " + results.input1);
   199     }
   201     navigator.notification.prompt(
   202         'Please enter your name',  // message
   203         onPrompt,                  // callback to invoke
   204         'Registration',            // title
   205         ['Ok','Exit'],             // buttonLabels
   206         'Jane Doe'                 // defaultText
   207     );
   209 ### Supported Platforms
   211 - Amazon Fire OS
   212 - Android
   213 - Firefox OS
   214 - iOS
   215 - Windows Phone 7 and 8
   217 ### Android Quirks
   219 - Android supports a maximum of three buttons, and ignores any more than that.
   221 - On Android 3.0 and later, buttons are displayed in reverse order for devices that use the Holo theme.
   223 ### Firefox OS Quirks:
   225 Both native-blocking `window.prompt()` and non-blocking `navigator.notification.prompt()` are available.
   227 ## navigator.notification.beep
   229 The device plays a beep sound.
   231     navigator.notification.beep(times);
   233 - __times__: The number of times to repeat the beep. _(Number)_
   235 ### Example
   237     // Beep twice!
   238     navigator.notification.beep(2);
   240 ### Supported Platforms
   242 - Amazon Fire OS
   243 - Android
   244 - BlackBerry 10
   245 - iOS
   246 - Tizen
   247 - Windows Phone 7 and 8
   248 - Windows 8
   250 ### Amazon Fire OS Quirks
   252 - Amazon Fire OS plays the default __Notification Sound__ specified under the __Settings/Display & Sound__ panel.
   254 ### Android Quirks
   256 - Android plays the default __Notification ringtone__ specified under the __Settings/Sound & Display__ panel.
   258 ### Windows Phone 7 and 8 Quirks
   260 - Relies on a generic beep file from the Cordova distribution.
   262 ### Tizen Quirks
   264 - Tizen implements beeps by playing an audio file via the media API.
   266 - The beep file must be short, must be located in a `sounds` subdirectory of the application's root directory, and must be named `beep.wav`.

mercurial