You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by he...@apache.org on 2014/04/25 22:00:28 UTC
[1/2] git commit: CB-4966 Dialogs are in window now No need to add
anything to manifest or index.html
Repository: cordova-plugin-dialogs
Updated Branches:
refs/heads/master 8a23a2a45 -> 4ebf797ab
CB-4966
Dialogs are in window now
No need to add anything to manifest or index.html
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/4ebf797a
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs/tree/4ebf797a
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs/diff/4ebf797a
Branch: refs/heads/master
Commit: 4ebf797ab39d903e5ad796adf87393223818e5f2
Parents: 59b70c4
Author: Piotr Zalewa <pi...@zalewa.info>
Authored: Tue Feb 18 10:43:02 2014 +0100
Committer: hermwong <he...@gmail.com>
Committed: Fri Apr 25 13:00:18 2014 -0700
----------------------------------------------------------------------
src/firefoxos/notification.js | 100 ++++++++++++++++++++-----------------
1 file changed, 55 insertions(+), 45 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs/blob/4ebf797a/src/firefoxos/notification.js
----------------------------------------------------------------------
diff --git a/src/firefoxos/notification.js b/src/firefoxos/notification.js
index 08f0a39..78516dc 100644
--- a/src/firefoxos/notification.js
+++ b/src/firefoxos/notification.js
@@ -35,52 +35,46 @@ if (!document.getElementById(cssId))
function _empty() {}
function modal(message, callback, title, buttonLabels, domObjects) {
- /*
- <form role="dialog">
- <section>
- <h1>Some Title</h1>
- <p>Can't find a proper question for that ...</p>
- </section>
- <menu>
- <button>Cancel</button>
- <button class="danger">Delete</button>
- <button class="recommend">Recommend</button>
- <button>Standard</button>
- </menu>
- </form>
- */
- // create a modal window
- var box = document.createElement('form');
+ var mainWindow = window;
+ var modalWindow = window.open();
+ var modalDocument = modalWindow.document;
+
+ modalDocument.write(
+ '<html><head>' +
+ '<link rel="stylesheet" type="text/css" href="/css/index.css" />' +
+ '<link rel="stylesheet" type="text/css" href="/css/notification.css" />' +
+ '</head><body></body></html>');
+
+ var box = modalDocument.createElement('form');
box.setAttribute('role', 'dialog');
// prepare and append empty section
- var section = document.createElement('section');
+ var section = modalDocument.createElement('section');
box.appendChild(section);
// add title
- var boxtitle = document.createElement('h1');
- boxtitle.appendChild(document.createTextNode(title));
+ var boxtitle = modalDocument.createElement('h1');
+ boxtitle.appendChild(modalDocument.createTextNode(title));
section.appendChild(boxtitle);
// add message
- var boxMessage = document.createElement('p');
- boxMessage.appendChild(document.createTextNode(message));
+ var boxMessage = modalDocument.createElement('p');
+ boxMessage.appendChild(modalDocument.createTextNode(message));
section.appendChild(boxMessage);
// inject what's needed
if (domObjects) {
section.appendChild(domObjects);
}
// add buttons and assign callbackButton on click
- var menu = document.createElement('menu');
+ var menu = modalDocument.createElement('menu');
box.appendChild(menu);
for (var index = 0; index < buttonLabels.length; index++) {
- // TODO: last button listens to the cancel key
addButton(buttonLabels[index], index, (index === 0));
}
- document.body.appendChild(box);
+ modalDocument.body.appendChild(box);
function addButton(label, index, recommended) {
- var button = document.createElement('button');
- button.appendChild(document.createTextNode(label));
- button.labelIndex = index + 1;
- button.addEventListener('click', callbackButton, false);
+ var thisButtonCallback = makeCallbackButton(index + 1);
+ var button = modalDocument.createElement('button');
+ button.appendChild(modalDocument.createTextNode(label));
+ button.addEventListener('click', thisButtonCallback, false);
if (recommended) {
// TODO: default one listens to Enter key
button.classList.add('recommend');
@@ -88,20 +82,40 @@ function modal(message, callback, title, buttonLabels, domObjects) {
menu.appendChild(button);
}
+ // TODO: onUnload listens to the cancel key
+ function onUnload() {
+ var result = 0;
+ if (modalDocument.getElementById('prompt-input')) {
+ result = {
+ input1: '',
+ buttonIndex: 0
+ }
+ }
+ mainWindow.setTimeout(function() {
+ callback(result);
+ }, 10);
+ };
+ modalWindow.addEventListener('unload', onUnload, false);
+
// call callback and destroy modal
- function callbackButton() {
- var promptInput = document.getElementById('prompt-input');
- var promptValue;
- var response;
- if (promptInput) {
- response = {
+ function makeCallbackButton(labelIndex) {
+ return function() {
+ if (modalWindow) {
+ modalWindow.removeEventListener('unload', onUnload, false);
+ modalWindow.close();
+ }
+ // checking if prompt
+ var promptInput = modalDocument.getElementById('prompt-input');
+ var response;
+ if (promptInput) {
+ response = {
input1: promptInput.value,
- buttonIndex: this.labelIndex
- }
+ buttonIndex: labelIndex
+ };
+ }
+ response = response || labelIndex;
+ callback(response);
}
- response = response || this.labelIndex;
- callback(response);
- box.parentNode.removeChild(box);
}
}
@@ -128,11 +142,6 @@ var Notification = {
var title = args[1];
var buttonLabels = args[2];
var defaultText = args[3];
- var _callback = (successCallback || _empty);
- // function _callback(labelIndex) {
- // console.log(content);
- // successCallback(labelIndex, content);
- // }
var inputParagraph = document.createElement('p');
inputParagraph.classList.add('input');
var inputElement = document.createElement('input');
@@ -142,9 +151,10 @@ var Notification = {
inputElement.setAttribute('placeholder', defaultText);
}
inputParagraph.appendChild(inputElement);
- modal(message, _callback, title, buttonLabels, inputParagraph);
+ modal(message, successCallback, title, buttonLabels, inputParagraph);
}
};
+
module.exports = Notification;
require('cordova/firefoxos/commandProxy').add('Notification', Notification);
[2/2] git commit: Removing FirefoxOS Quirks * no need to add special
permission (it's different API with the same name) * notification.css is
added automatically
Posted by he...@apache.org.
Removing FirefoxOS Quirks
* no need to add special permission (it's different API with the same name)
* notification.css is added automatically
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/59b70c43
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs/tree/59b70c43
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs/diff/59b70c43
Branch: refs/heads/master
Commit: 59b70c4349316c4cd479b54eb83b91d60ab94c6d
Parents: 8a23a2a
Author: Piotr Zalewa <zalun@ubuntu.(none)>
Authored: Wed Mar 26 06:20:19 2014 -0700
Committer: hermwong <he...@gmail.com>
Committed: Fri Apr 25 13:00:18 2014 -0700
----------------------------------------------------------------------
doc/index.md | 16 ----------------
src/firefoxos/notification.js | 13 +++++++++++++
2 files changed, 13 insertions(+), 16 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs/blob/59b70c43/doc/index.md
----------------------------------------------------------------------
diff --git a/doc/index.md b/doc/index.md
index 1cb3e09..e07d21f 100644
--- a/doc/index.md
+++ b/doc/index.md
@@ -25,22 +25,6 @@ This plugin provides access to some native dialog UI elements.
cordova plugin add org.apache.cordova.dialogs
-### Firefox OS Quirks
-
-Create __www/manifest.webapp__ as described in
-[Manifest Docs](https://developer.mozilla.org/en-US/Apps/Developing/Manifest).
-Add permisions:
-
- "permissions": {
- "desktop-notification": {
- "description": "Describe why you need to enable notifications"
- }
- }
-
-Edit __www/index.html__ and add following in `head` section:
-
- <link rel="stylesheet" type="text/css" href="css/notification.css" />
-
## Methods
- `navigator.notification.alert`
http://git-wip-us.apache.org/repos/asf/cordova-plugin-dialogs/blob/59b70c43/src/firefoxos/notification.js
----------------------------------------------------------------------
diff --git a/src/firefoxos/notification.js b/src/firefoxos/notification.js
index ca7c5c0..08f0a39 100644
--- a/src/firefoxos/notification.js
+++ b/src/firefoxos/notification.js
@@ -19,6 +19,19 @@
*
*/
+var cssId = 'notification-plugin-css';
+if (!document.getElementById(cssId))
+{
+ var head = document.getElementsByTagName('head')[0];
+ var link = document.createElement('link');
+ link.id = cssId;
+ link.rel = 'stylesheet';
+ link.type = 'text/css';
+ link.href = '/css/notification.css';
+ link.media = 'all';
+ head.appendChild(link);
+}
+
function _empty() {}
function modal(message, callback, title, buttonLabels, domObjects) {