cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject [01/15] git commit: first (blind) try
Date Mon, 28 Oct 2013 22:12:09 GMT
Updated Branches:
  refs/heads/master c8b0f9539 -> 439fd253c


first (blind) try


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

Branch: refs/heads/master
Commit: cd576b9b4d2ce6bd71c00b3873c7f8e9d0187917
Parents: 8eab453
Author: Piotr Zalewa <piotr@zalewa.info>
Authored: Wed Sep 18 16:42:19 2013 +0200
Committer: Piotr Zalewa <piotr@zalewa.info>
Committed: Wed Sep 18 16:42:19 2013 +0200

----------------------------------------------------------------------
 plugin.xml               | 13 ++++++++
 src/firefoxos/dialogs.js | 76 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 89 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs/blob/cd576b9b/plugin.xml
----------------------------------------------------------------------
diff --git a/plugin.xml b/plugin.xml
index 3d47847..0253a35 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -13,6 +13,19 @@
         <merges target="navigator.notification" />
     </js-module>
 
+    <!-- firefoxos -->
+    <platform name="firefoxos">
+        <config-file target="config.xml" parent="/*">
+            <feature name="Dialogs">
+                <param name="firefoxos-package" value="Dialogs" />
+            </feature>
+        </config-file>                                         
+        
+        <js-module src="src/firefoxos/dialogs.js" name="dialogs-impl">
+          <runs />
+        </js-module>
+    </platform>
+
     <!-- android -->
     <platform name="android">
         <config-file target="res/xml/config.xml" parent="/*">

http://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs/blob/cd576b9b/src/firefoxos/dialogs.js
----------------------------------------------------------------------
diff --git a/src/firefoxos/dialogs.js b/src/firefoxos/dialogs.js
new file mode 100644
index 0000000..3a16ed2
--- /dev/null
+++ b/src/firefoxos/dialogs.js
@@ -0,0 +1,76 @@
+
+var firefoxos = require('cordova/platform');
+
+function modal(message, callback, tittle, buttonLabels, cancelButton) {
+    // create a modal window
+    var box = document.createElement('div');
+    box.classList.add('fxos-modal-window');
+    // add title
+    if (tittle) {
+        var boxTittle = document.createElement('h3');
+        boxTittle.appendChild(document.createTextNode(tittle));
+        box.appendChild(boxTittle);
+    }
+    // add message
+    var boxMessage = document.createElement('p');
+    boxMessage.appendChild(document.createTextNode(message));
+    box.appendChild(boxMessage);
+    // add buttons and assign callbackButton on click
+    // TODO: find a way handle different languages
+    if (cancelButton) {
+        addButton('Cancel', -1, true);
+        // TODO: listen escape key
+    }
+    if (buttonLabels.length == 0) {
+        // only OK button
+        addButton('OK');
+        // TODO: listen to Enter Key
+    } else {
+        for (var index = 0; index < buttonLabels.length; index++) {
+            // TODO: first button is the default one (listens to Enter
+            // key)
+            addButton(buttonLabels[index], index);
+        }
+    }
+    document.body.appendChild(box);
+
+    function addButton(label, index, cancelButton) {
+        var button = document.createElement('button');
+        button.appendChild(document.createTextNode(label));
+        if (cancelButton) {
+            button.classList.add('cancel');
+        }
+        if (!index) {
+            index = 0;
+        }
+        if (cancelButton) {
+            index = -1;
+        }
+        button.labelIndex = index;
+        button.addEventListener('click', callbackButton, false);
+        box.appendChild(button);
+    }
+
+    // call callback and destroy modal
+    function callbackButton() {
+        callback(this.labelIndex);
+        // destroy window
+        box.parentNode.removeChild(box);
+    }
+}
+
+var Dialogs = {
+    vibrate: function(milliseconds) {
+        navigator.vibrate(milliseconds);
+    },
+    alert: function(message, alertCallback, tittle, buttonName) {
+        // TODO: display tittle and buttonName
+        modal(message, alertCallback, tittle, [buttonName]);
+    },
+    confirm: function(message, confirmCallback, tittle, buttonLabels) {
+        // TODO: display tittle and multiple buttons
+        modal(message, confirmCallback, tittle, buttonLabels, true);
+    }
+};
+
+firefoxos.registerPlugin('Dialogs', Dialogs);


Mime
View raw message