cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kam...@apache.org
Subject cordova-plugin-dialogs git commit: CB-7955 Add support "browser" platform
Date Tue, 16 Dec 2014 22:30:19 GMT
Repository: cordova-plugin-dialogs
Updated Branches:
  refs/heads/master abe48ce39 -> c93d34bd4


CB-7955 Add support "browser" platform

This currently uses the blocking built-in functions like alert(). Need to come
up with some non blocking version, probably with a z-index based overlay. Like
in this example http://jsfiddle.net/CSLD2/1/

GitHub: close #46


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs/commit/c93d34bd
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs/tree/c93d34bd
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs/diff/c93d34bd

Branch: refs/heads/master
Commit: c93d34bd415a61d42191995158fdcaf1e58f142a
Parents: abe48ce
Author: James Messinger <james.messinger@gmail.com>
Authored: Thu Dec 11 13:25:22 2014 -0600
Committer: Mark Koudritsky <kamrik@gmail.com>
Committed: Tue Dec 16 17:23:08 2014 -0500

----------------------------------------------------------------------
 plugin.xml                  |  8 ++++
 www/browser/notification.js | 94 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 102 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs/blob/c93d34bd/plugin.xml
----------------------------------------------------------------------
diff --git a/plugin.xml b/plugin.xml
index ca1aa21..a11856c 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -69,6 +69,14 @@
         </js-module>
 
     </platform>
+
+    <!-- browser -->
+    <platform name="browser">
+        <js-module src="www/browser/notification.js" name="notification_browser">
+            <merges target="navigator.notification" />
+        </js-module>
+
+    </platform>
     
      <!-- amazon-fireos -->
     <platform name="amazon-fireos">

http://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs/blob/c93d34bd/www/browser/notification.js
----------------------------------------------------------------------
diff --git a/www/browser/notification.js b/www/browser/notification.js
new file mode 100644
index 0000000..fa5eb79
--- /dev/null
+++ b/www/browser/notification.js
@@ -0,0 +1,94 @@
+// Platform: browser
+window.navigator.notification = window.navigator.notification || {};
+
+module.exports.alert = window.navigator.notification.alert = function(message, callback)
{
+    // `notification.alert` executes asynchronously
+    setTimeout(function() {
+        window.alert(message);
+        if (callback) {
+            callback();
+        }
+    }, 0);
+};
+
+
+module.exports.confirm = window.navigator.notification.confirm = function(message, callback)
{
+    // `notification.confirm` executes asynchronously
+    setTimeout(function() {
+        var result = window.confirm(message);
+        if (callback) {
+            if (result) {
+                callback(1); // OK
+            }
+            else {
+                callback(2); // Cancel
+            }
+        }
+    }, 0);
+};
+
+
+module.exports.prompt = window.navigator.notification.prompt = function(message, callback,
title, buttonLabels, defaultText) {
+    // `notification.prompt` executes asynchronously
+    setTimeout(function() {
+        var result = window.prompt(message,  defaultText || '');
+        if (callback) {
+            if (result === null) {
+                callback({ buttonIndex: 2, input1: '' }); // Cancel
+            }
+            else {
+                callback({ buttonIndex: 1, input1: result }); // OK
+            }
+        }
+    }, 0);
+};
+
+
+module.exports.beep = window.navigator.notification.beep = function(times) {
+    if (times > 0) {
+        var BEEP_DURATION = 700;
+        var BEEP_INTERVAL = 300;
+
+        if (audioContext) {
+            // Start a beep, using the Audio API
+            var osc = audioContext.createOscillator();
+            osc.type = 0; // sounds like a "beep"
+            osc.connect(audioContext.destination);
+            osc.start(0);
+
+            setTimeout(function() {
+                // Stop the beep after the BEEP_DURATION
+                osc.stop(0);
+
+                if (--times > 0) {
+                    // Beep again, after a pause
+                    setTimeout(function() {
+                        navigator.notification.beep(times);
+                    }, BEEP_INTERVAL);
+                }
+
+            }, BEEP_DURATION);
+        }
+        else if (typeof(console) !== 'undefined' && typeof(console.log) === 'function')
{
+            // Audio API isn't supported, so just write `beep` to the console
+            for (var i = 0; i < times; i++) {
+                console.log('Beep!');
+            }
+        }
+    }
+};
+
+var audioContext = (function() {
+    // Determine if the Audio API is supported by this browser
+    var AudioApi = window.AudioContext;
+    if (!AudioApi) {
+        AudioApi = window.webkitAudioContext;
+    }
+
+    if (AudioApi) {
+        // The Audio API is supported, so create a singleton instance of the AudioContext
+        return new AudioApi();
+    }
+
+    return undefined;
+}());


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


Mime
View raw message