You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by lo...@apache.org on 2013/06/25 02:05:21 UTC

git commit: [CB-3975] blackberry 10 dialogs plugin breakout initial commit

Updated Branches:
  refs/heads/master [created] 60526f201


[CB-3975] blackberry 10 dialogs plugin breakout initial commit


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/60526f20
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs/tree/60526f20
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs/diff/60526f20

Branch: refs/heads/master
Commit: 60526f20115ffa26ec541b506bab28eba2dd5450
Parents: 
Author: lorinbeer <lo...@adobe.com>
Authored: Mon Jun 24 17:04:59 2013 -0700
Committer: lorinbeer <lo...@adobe.com>
Committed: Mon Jun 24 17:04:59 2013 -0700

----------------------------------------------------------------------
 plugin.xml                | 19 +++++++++
 src/blackberry10/index.js | 91 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 110 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs/blob/60526f20/plugin.xml
----------------------------------------------------------------------
diff --git a/plugin.xml b/plugin.xml
new file mode 100644
index 0000000..1c61bad
--- /dev/null
+++ b/plugin.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<plugin xmlns="http://cordova.apache.org/ns/plugins/1.0"
+id="org.apache.cordova.core.Notification" version="0.1.0">
+    <name>Notification</name>
+<!--
+    <js-module src="www/notification.js" name="notification">
+        <clobbers target="navigator.notification" />
+    </js-module>
+-->
+    <!-- blackberry10 -->
+    <platform name="blackberry10">
+        <source-file src="src/blackberry10/index.js" target-dir="Notification" />
+        <config-file target="www/config.xml" parent="/widget">
+            <feature name="Notification" value="Notification"/>
+        </config-file>
+    </platform>
+
+</plugin>

http://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs/blob/60526f20/src/blackberry10/index.js
----------------------------------------------------------------------
diff --git a/src/blackberry10/index.js b/src/blackberry10/index.js
new file mode 100644
index 0000000..fad04f7
--- /dev/null
+++ b/src/blackberry10/index.js
@@ -0,0 +1,91 @@
+/*
+* Copyright 2013 Research In Motion Limited.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+function showDialog(args, dialogType, result) {
+    //Unpack and map the args
+    var msg = JSON.parse(decodeURIComponent(args[0])),
+    title = JSON.parse(decodeURIComponent(args[1])),
+    btnLabel = JSON.parse(decodeURIComponent(args[2]));
+
+    if (!Array.isArray(btnLabel)) {
+        //Converts to array for (string) and (string,string, ...) cases
+        btnLabel = btnLabel.split(",");
+    }
+
+    if (msg && typeof msg === "string") {
+        msg = msg.replace(/^"|"$/g, "").replace(/\\"/g, '"').replace(/\\\\/g, '\\');
+    } else {
+        result.error("message is undefined");
+        return;
+    }
+
+    var messageObj = {
+        title : title,
+        htmlmessage :  msg,
+        dialogType : dialogType,
+        optionalButtons : btnLabel
+    };
+
+    //TODO replace with getOverlayWebview() when available in webplatform
+    qnx.webplatform.getWebViews()[2].dialog.show(messageObj, function (data) {
+        if (typeof data === "number") {
+            //Confirm dialog call back needs to be called with one-based indexing [1,2,3 etc]
+            result.callbackOk(++data, false);
+        } else {
+            //Prompt dialog callback expects object
+            result.callbackOk({
+                buttonIndex: data.ok ? 1 : 0,
+                input1: (data.oktext) ? decodeURIComponent(data.oktext) : ""
+            }, false);
+        }
+    });
+
+    result.noResult(true);
+}
+
+module.exports = {
+    alert: function (success, fail, args, env) {
+        var result = new PluginResult(args, env);
+
+        if (Object.keys(args).length < 3) {
+            result.error("Notification action - alert arguments not found.");
+        } else {
+            showDialog(args, "CustomAsk", result);
+        }
+    },
+    confirm: function (success, fail, args, env) {
+        var result = new PluginResult(args, env);
+
+        if (Object.keys(args).length < 3) {
+            result.error("Notification action - confirm arguments not found.");
+        } else {
+            showDialog(args, "CustomAsk", result);
+        }
+    },
+    prompt: function (success, fail, args, env) {
+        var result = new PluginResult(args, env);
+
+        if (Object.keys(args).length < 3) {
+            result.error("Notification action - prompt arguments not found.");
+        } else {
+            showDialog(args, "JavaScriptPrompt", result);
+        }
+    },
+    beep: function (success, fail, args, env) {
+        var result = new PluginResult(args, env);
+        result.error("Beep not supported");
+    }
+};